CusTreeItem.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div class="cus-tree-item">
  3. <template v-for="item in data">
  4. <template v-if="item._count > 0">
  5. <div
  6. class="cus-tree-item-slot"
  7. :style="`padding-left: ${options.left * level}px;`"
  8. >
  9. <div class="expend-img" @click="item._expend = !item._expend, $forceUpdate()">
  10. <template v-if="item?.[options.children]?.length > 0">
  11. <img v-if="item._expend" :src="options.expendTrueImg"/>
  12. <img v-else :src="options.expendFalseImg"/>
  13. </template>
  14. </div>
  15. <slot :data="item">
  16. <div
  17. class="cus-tree-item-label"
  18. >
  19. {{item[options.label]}}
  20. </div>
  21. </slot>
  22. </div>
  23. <CusTreeItem
  24. v-if="item?.[options.children]?.length > 0"
  25. v-show="item._expend"
  26. :data="item[options.children]"
  27. :options="options"
  28. :level="level + 1"
  29. >
  30. <template #default="{data}">
  31. <slot :data="data"/>
  32. </template>
  33. </CusTreeItem>
  34. </template>
  35. </template>
  36. </div>
  37. </template>
  38. <script lang="ts">
  39. import {
  40. defineComponent,
  41. onMounted,
  42. ref,
  43. toRefs,
  44. reactive,
  45. watch,
  46. getCurrentInstance,
  47. ComponentInternalInstance,
  48. computed, nextTick,
  49. } from "vue";
  50. import { useStore } from "vuex";
  51. import { useRouter } from "vue-router";
  52. import { ElMessage, ElMessageBox } from "element-plus";
  53. export default defineComponent({
  54. name: "CusTreeItem",
  55. components: {
  56. },
  57. props: {
  58. data: {
  59. required: true
  60. },
  61. options: {
  62. required: true
  63. },
  64. level: {
  65. default: 0
  66. }
  67. },
  68. setup(props) {
  69. const store = useStore();
  70. const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties;
  71. const state = reactive({
  72. });
  73. onMounted(() => {
  74. })
  75. return {
  76. ...toRefs(state),
  77. }
  78. },
  79. });
  80. </script>
  81. <style scoped lang="scss">
  82. .cus-tree {
  83. width: 100%;
  84. height: calc(100vh);
  85. .cus-tree-item-slot {
  86. display: flex;
  87. align-items: center;
  88. .cus-tree-item-label {
  89. width: 100%;
  90. cursor: pointer;
  91. &:hover {
  92. background-color: #F5F7FA;
  93. }
  94. }
  95. .expend-img {
  96. width: 16px;
  97. height: 16px;
  98. margin-right: 5px;
  99. >img {
  100. cursor: pointer;
  101. width: 100%;
  102. height: 100%;
  103. }
  104. }
  105. }
  106. }
  107. </style>