当前位置:   article > 正文

VUE中使用工作流流程图树结构(JSON数据驱动动态树结构)_vue 工作流

vue 工作流

这篇文章主要讲解通过JSON数据递归渲染流程图树,如果需要具体静态页面样式,请移步:工作流流程图树结构HTML+CSS_包子源的博客-CSDN博客https://blog.csdn.net/ziwoods/article/details/121640122

首先看一下数据格式,其实和el-tree的数据格式是一样的:

  1. data() {
  2. return {
  3. flowArr: [
  4. {
  5. taskName: "流程1",
  6. approverName: "审计测试人员,test1",
  7. children: [
  8. {
  9. taskName: "流程2",
  10. approverName: "admin,审计局",
  11. children: [
  12. { taskName: "流程2", approverName: "admin,审计局" },
  13. { taskName: "流程2", approverName: "admin,审计局" },
  14. ],
  15. },
  16. {
  17. taskName: "流程2",
  18. approverName: "admin,审计局",
  19. children: [
  20. { taskName: "流程2", approverName: "admin,审计局" },
  21. { taskName: "流程2", approverName: "admin,审计局" },
  22. ],
  23. },
  24. ],
  25. },
  26. { taskName: "流程3", approverName: "审计单位账号,admin" },
  27. ]
  28. };
  29. },

然后需要封装workTree组件(其实就是递归渲染树结构):

  1. <template>
  2. <div>
  3. <div v-if="list.length == 1">
  4. <div v-for="(item, index) in list" :key="index" class="branch-one">
  5. <div class="condition-node-box">
  6. <div class="line"></div>
  7. <div class="deal-node-box">
  8. <div class="audit-background head-row">
  9. {{ item.taskName }}
  10. </div>
  11. <div class="foot-row">{{ item.approverName }}</div>
  12. <a class="del-node">×</a>
  13. </div>
  14. <div class="add-btn-box">
  15. <button type="button" class="add-bar">+</button>
  16. </div>
  17. </div>
  18. <work-tree v-if="item.children" :list="item.children"></work-tree>
  19. </div>
  20. </div>
  21. <div v-if="list.length > 1" class="flow-child-box">
  22. <div class="branch">
  23. <div class="branch-box">
  24. <div v-for="(item, index) in list" :key="index" class="col-box">
  25. <div v-if="index == 0" class="top-left-cover-line"></div>
  26. <div
  27. v-if="index == list.length - 1"
  28. class="top-right-cover-line"
  29. ></div>
  30. <div class="branch-one">
  31. <div class="condition-node-box">
  32. <div class="line"></div>
  33. <div class="deal-node-box">
  34. <div class="audit-background head-row">
  35. {{ item.taskName }}
  36. </div>
  37. <div class="foot-row">{{ item.approverName }}</div>
  38. <a class="del-node">×</a>
  39. </div>
  40. <div class="add-btn-box">
  41. <button type="button" class="add-bar">+</button>
  42. </div>
  43. </div>
  44. </div>
  45. <work-tree v-if="item.children" :list="item.children"></work-tree>
  46. <div v-if="index == 0" class="bottom-left-cover-line"></div>
  47. <div
  48. v-if="index == list.length - 1"
  49. class="bottom-right-cover-line"
  50. ></div>
  51. </div>
  52. </div>
  53. <div class="line-in-middle">
  54. <div class="line"></div>
  55. <div class="add-btn-box">
  56. <button type="button" class="add-bar">+</button>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. export default {
  65. name: "workTree",
  66. props: {
  67. list: [Array, Object],
  68. },
  69. };
  70. </script>

在vue中的使用:

  1. <div class="wrapper">
  2. <div class="flow-parent-box">
  3. <div class="deal-node-box">
  4. <div class="fill-background head-row">发起人</div>
  5. <div class="foot-row">默认发起人</div>
  6. </div>
  7. <div class="line-in-middle">
  8. <div class="line"></div>
  9. <div class="add-btn-box">
  10. <button type="button" class="add-bar">+</button>
  11. </div>
  12. </div>
  13. </div>
  14. <div
  15. class="flow-parent-box"
  16. v-for="(item, index) in flowArr"
  17. :key="index"
  18. >
  19. <div class="flow-parent-box">
  20. <div class="deal-node-box">
  21. <div class="audit-background head-row">{{ item.taskName }}</div>
  22. <div class="foot-row">{{ item.approverName }}</div>
  23. <a class="del-node">×</a>
  24. </div>
  25. <div class="line-in-middle">
  26. <div class="line"></div>
  27. <div class="add-btn-box">
  28. <button type="button" class="add-bar">+</button>
  29. </div>
  30. </div>
  31. </div>
  32. <work-tree v-if="item.children" :list="item.children"></work-tree>
  33. </div>
  34. <div class="end-node">结束</div>
  35. </div>

看一下最终效果吧:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/852335
推荐阅读
相关标签
  

闽ICP备14008679号