vue流程图

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

<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>


相关推荐

  1. vue2 + antvx6 实现流程图功能

    2024-01-20 22:50:02       26 阅读
  2. VUE-配置-流程

    2024-01-20 22:50:02       33 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-20 22:50:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-20 22:50:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-20 22:50:02       87 阅读
  4. Python语言-面向对象

    2024-01-20 22:50:02       96 阅读

热门阅读

  1. Python装饰器

    2024-01-20 22:50:02       70 阅读
  2. SQL中的几个区别

    2024-01-20 22:50:02       50 阅读
  3. Python爬虫实战014:利用requests库实现自动评论

    2024-01-20 22:50:02       59 阅读
  4. stm32 - GPIO高级用法

    2024-01-20 22:50:02       67 阅读
  5. Oracle学习笔记——基础一起学 16

    2024-01-20 22:50:02       53 阅读
  6. python元类模型和class语句协议

    2024-01-20 22:50:02       67 阅读
  7. leetcode-路径总和

    2024-01-20 22:50:02       70 阅读
  8. C语言零基础入门(结构体)

    2024-01-20 22:50:02       54 阅读
  9. 解决Spring Boot应用打包后文件访问问题

    2024-01-20 22:50:02       73 阅读