vue流程图

news/2024/5/18 23:25:04 标签: vue.js, 流程图

效果图
在这里插入图片描述
组件

<template>
  <div class="processBox" v-if="list.length">
    <div class="childs">
      <div class="child" v-for="(item,index) in list" :key="item.id +'-child-'+index">
        <div class="child-item" :style="{marginRight: item.children && item.children.length > 1 ? '20px' :''}">
          <div class="childname" :id="item.id">
            <div class="shows">
              <slot :items="item">
                {{item.name}}
              </slot>
            </div>
            <div class="position-arrow" v-if="list.length > 1">
              <i class="el-icon-right"></i>
            </div>
            <div class="position-top" v-if="isFirst(item.id) && domready" :style="position_top(item.id,'top')"></div>
            <div class="position-top" v-if="isLast(item.id)" :style="position_top(item.id,'bottom')"></div>
          </div>
          <div class="childarrow" :style="{borderRight:item.children && item.children.length >1 ? '2px solid #606266' : '3px solid transparent'}">
            <div :class="item.children && item.children.length<=1?'long-img':''"></div>
              <i class="el-icon-right" v-if="item.children && item.children.length" ></i>

          </div>
        </div>
        <div class="child-children" v-if="item.children && item.children.length">
          <processJson :list="item.children" >
            <template v-slot="item">
              <slot :items='item.items' />
            </template>

          </processJson>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "processJson",
  components: {},
  data() {
    return {
      domready: false,
    };
  },
  props: {
    list: {
      type: Array,
      default: () => [],
    },
  },

  mounted() {
    this.$nextTick(() => {
      this.domready = true;
    });
  },
  methods: {
    position_top(id, position) {
      let dom = document.getElementById(id);
      let height;
      if (dom) {
        height = dom.clientHeight;
      }
      let rt;
      if (position === "top") {
        rt = {
          height: height / 2 - 2 + "px",
          top: 0,
        };
      }
      if (position === "bottom") {
        rt = {
          height: height / 2 + 1 + "px",
          bottom: 0,
        };
      }
      return rt;
    },

    isFirst(id) {
      return (
        this.list.length > 1 && this.list.map((x) => x.id).indexOf(id) === 0
      );
    },

    isLast(id) {
      return (
        this.list.length > 1 &&
        this.list.map((x) => x.id).indexOf(id) === this.list.length - 1
      );
    },
  },
};
</script>

<style lang="scss" scoped>
.el-icon-right{
  font-weight: 600;
}
.processBox {
  p {
    margin: 0;
    font-size: 13px;
  }
  display: flex;
  .father {
    width: 70px;
    background-color: red;
    padding: 100px 10px;
  }
  .childs {
    .child {
      display: flex;
      background-color: #fff;
      .child-item {
        display: flex;
        align-items: center;
        margin: 10px 0;
        .childname {
          .shows {
            text-align: left;
            border: 1px solid #b4b4b4;
            padding: 10px;
            // height: 100px;
            width: 100%;
            box-shadow: 1px 2px 8px #00000033;
            &:hover{
              box-shadow: 1px 2px 8px #00000066;
            }
          }
          cursor: pointer;
          height: 100%;
          display: flex;
          align-items: center;
          text-align: center;
          justify-content: center;
          position: relative;
          padding: 10px 0;
          .position-arrow {
            position: absolute;
            // top: 50%;
            left: -22px;
          }
          .position-top {
            position: absolute;
            width: 3px;
            background-color: #fff;
            left: -23px;
            height: 10px;
          }
        }
        .childarrow {
          height: 100%;
          // border-right: ;
          display: flex;
          align-items: center;
        }
      }
    }
    .child-children {
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
  }
  .long-img{
    width: 20px;
    height: 2px;
    background-color: #606266;
  }
  .icon_arrow {
    // margin-left: 20px;
    &:after {
      width: 30px;
      height: 1px;
      background-color: #000;
    }
  }
}
</style>


调用

<template>
  <div>
    <josnToProcess :list="list">
      <template #default="{ items }">
        <div class="node_item ">
          {{items.unitName }}
        </div>
      </template>

    </josnToProcess>
  </div>
</template>

<script>
import josnToProcess from "./tree-right.vue";
export default {
  name: "",
  props: {},
  components: { josnToProcess },
  data() {
    return {
      list: [
        {
          unitName: "长沙供电公司1",
          id: "1",
          children: [
            {
              unitName: "长沙供电公司1-1",
              id: "1-1",
              children: [
                {
                  unitName: "长沙供电公司1-1-1",
                  id: "1-1-1",
                },
                {
                  unitName: "长沙供电公司1-1-2",
                  id: "1-1-2",
                },
              ],
            },
            {
              unitName: "1-2",
              id: "1-2",
              children: [
                {
                  unitName: "1-2-1",
                  id: "1-2-1",
                },
              ],
            },
            {
              unitName: "长沙供电公司1-3",
              id: "1-3",
              children: [
                {
                  unitName: "长沙供电公司1-3-1",
                  id: "1-3-1",
                },
                {
                  unitName: "长沙供电公司1-3-2",
                  id: "1-3-2",
                },
              ],
            },
            {
              unitName: "长沙供电公司1-4",
              id: "1-4",
            },
          ],
        },
        {
          unitName: "长沙供电公司2",
          id: "2",
        },
        {
          unitName: "长沙供电公司3",
          id: "3",
          children: [
            {
              unitName: "长沙供电公司3-1",
              id: "3-1",
              children: [
                {
                  unitName: "长沙供电公司3-1-1",
                  id: "3-1-1",
                },
              ],
            },
            {
              unitName: "长沙供电公司3-1-2",
              id: "3-1-2",
              children: [
                {
                  unitName: "长沙供电公司3-1-2-1",
                  id: "3-1-2-1",
                  children: [
                    {
                      unitName: "长沙供电公司3-1-2-1-1",
                      id: "3-1-2-1-1",
                    },
                  ],
                },
                {
                  unitName: "长沙供电公司3-1-2-2",
                  id: "3-3-1-2-2",
                },
              ],
            },
          ],
        },
        {
          unitName: "长沙供电公司1-3",
          id: "4",
        },
      ],
      showFields: [
        //show fields
        {
          name: "姓名:",
          key: "name",
        },
        {
          name: "年龄:",
          key: "age",
        },
      ],
    };
  },
  computed: {},
  watch: {},
  methods: {},
  created() {},
  mounted() {},
};
</script>

<style scoped lang="scss">
.node_item {
  width: 230px;
  height: 116px;
}
</style>



http://www.niftyadmin.cn/n/5336246.html

相关文章

.NET 8 中引入新的 IHostedLifecycleService 接口 实现定时任务

在这篇文章中&#xff0c;我们将了解 .NET 8 中为托管服务引入的一些新生命周期事件。请注意&#xff0c;这篇文章与 .NET 8 相关&#xff0c;在撰写本文时&#xff0c;.NET 8 目前处于预览状态。在 11 月 .NET 8 最终版本发布之前&#xff0c;类型和实现可能会发生变化。要继续…

状态管理库之 mobx

一文快速上手 mobx&#xff01; 一、概述 mobx 是一个简单的可拓展的状态管理库&#xff0c;无样本代码风格简约不推荐使用装饰器语法可以运行在任何支持 es5 的环境中&#xff0c;包含浏览器和 node 二、核心概念 2.1 observable 被 mobx 跟踪的状态 2.2 action 通过某个…

Python智能挖掘数据新秘器

大家好&#xff0c;本次分享一款在数据探索中表现出色的工具—Python Lux &#xff0c;通过自动化可视化和数据分析过程&#xff0c;使得数据探索变得更加快捷方便。 Lux的使用方法非常简单&#xff0c;只需在Jupyter notebook中输入dataframe&#xff0c;Lux就会智能推荐一组基…

Mybatis集成MySQL使用游标查询处理大批量数据

背景 基于数据的时间范围查询&#xff0c;给符合条件的用户推送积分即将到期的提醒。 初期用户量小使用最普通简单的分页查询扫描数据处理数据没问题。随着用户量的上升表数据已经上千万&#xff0c;每天扫描处理的数量也超百万&#xff0c;limit分页出现了慢sql&#xff0c;…

修改大型二进制库内部函数名的bash 脚本及其解释

1.大型lib库重命名函数名字 迭代的方式对于大型二进制库改名字的功能脚本 会将源文件中的函数 add_(...) 修改成 nubia_add_(...) 的方式来调用 此脚本分配来修改&#xff0c;可以避免突破资源限制 ulimit -a&#xff1b; 保存为&#xff1a;redef_func_name_01.sh chmod…

cmd一些常见操作

目录 1.cmd的介绍2.cmd打开方式3.cmd的常见操作文件目录操作&#xff08;学习Linux文件操作的时候可以对比看看&#xff09;网络操作进程操作&#xff08;当我们遇到什么程序卡死的时候用这个很不错&#xff09;服务操作&#xff08;数据库暂停服务删除服务我经常需要使用&…

Simulink|光伏并网逆变器低电压穿越仿真模型

目录 主要内容 模型研究 1.模型总览 2.boost模块 3.Inverter模块 4.控制模块 5.信号模块 结果一览 下载链接 主要内容 该模型为光伏逆变器低电压穿越仿真模型&#xff0c;采用boost加NPC拓扑结构&#xff0c;基于MATLAB/Simulink建模仿真。模型具备中点平衡…

redis复制和分区:主从复制、哨兵模式和集群模式

概述 在 Redis 中&#xff0c;复制和分区是用于数据冗余和性能扩展的关键特性。以下是主从复制、哨兵模式和集群模式的工作原理的简要概述&#xff1a; 主从复制 (Replication) 基本概念&#xff1a;Redis 的主从复制功能允许多个 Redis 服务器具有相同的数据副本。这在读取操…