DivisionTree1.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <ElTree
  3. class="hc-tree-node tree-line"
  4. ref="ElTreeRef"
  5. :props="ElTreeProps"
  6. :data="datas"
  7. highlight-current
  8. accordion node-key="primaryKeyId"
  9. :indent="0"
  10. @node-click="ElTreeClick"
  11. show-checkbox
  12. @check-change="handleCheckChange"
  13. :default-checked-keys="defaultCheckarr"
  14. :default-expand-all="defaultExpandAll"
  15. v-loading="divisionLoading"
  16. >
  17. <template #default="{ node, data }">
  18. <div class="data-custom-tree-node" :id="`${idPrefix}${data['primaryKeyId']}`">
  19. <div class="label" :class="node.level === 1?'level-name':''">{{ node.label }}</div>
  20. </div>
  21. </template>
  22. </ElTree>
  23. </template>
  24. <script setup>
  25. import { ref , watch,nextTick} from "vue";
  26. //参数
  27. const props = defineProps({
  28. datas: {
  29. type: Array,
  30. default: () => ([])
  31. },
  32. idPrefix: {
  33. type: String,
  34. default: 'division-tree-data2-'
  35. },
  36. defaultCheckarr:{
  37. type: Array,
  38. default: () => ([])
  39. },
  40. ElTreeProps:{
  41. type:Object,
  42. default:{
  43. label:'fullName',
  44. children: 'children'
  45. }
  46. },
  47. defaultExpandAll:{
  48. type:Boolean,
  49. default:false
  50. },
  51. divisionLoading:{
  52. type:Boolean,
  53. default:false
  54. },
  55. linksRelateSearchTreeVal:{
  56. type: String,
  57. default: ''
  58. }
  59. })
  60. const linksRelateSearchTreeValInfo=ref('')
  61. //监听
  62. watch(() => [
  63. props.divisionLoading,
  64. props.linksRelateSearchTreeVal,
  65. ], ([divisionLoading,LinksRelateSearchTreeVal]) => {
  66. isdivisionLoading.value=divisionLoading
  67. linksRelateSearchTreeValInfo.value=LinksRelateSearchTreeVal
  68. })
  69. watch(linksRelateSearchTreeValInfo, (val) => {
  70. if(val){
  71. nextTick(()=> {
  72. ElTreeRef?.value.filter(val)
  73. })
  74. }else if(!val.length){
  75. }
  76. },
  77. {immediate:true}
  78. )
  79. //变量
  80. const ElTreeRef = ref(null)
  81. const isdivisionLoading=ref(props.divisionLoading)
  82. const ElTreeProps = ref({
  83. label: 'fullName',
  84. children: 'children'
  85. })
  86. // const defaultCheckarr = ref([])
  87. //事件
  88. const emit = defineEmits(['nodeTap','nodeCheck'])
  89. //节点被点击
  90. const ElTreeClick = async (data,node) => {
  91. emit('nodeTap', {node, data})
  92. }
  93. //节点被选中
  94. const handleCheckChange = (data,checked,indeterminate,) => {
  95. emit('nodeCheck',ElTreeRef.value?.getCheckedNodes(false, false))
  96. }
  97. const getReturnNode=(node,_array,value)=>{
  98. let isPass = node.data && node.data.title && node.data.title.indexOf(value) !== -1;
  99. isPass?_array.push(isPass):'';
  100. if(!isPass && node.level!=1 && node.parent){
  101. getReturnNode(node.parent,_array,value);
  102. }
  103. }
  104. const filterNode = (value, data,node) => {
  105. if(!value){
  106. return true;
  107. }
  108. let level = node.title;
  109. let _array = [];//这里使用数组存储 只是为了存储值。
  110. getReturnNode(node,_array,value);
  111. let result = false;
  112. _array.forEach((item)=>{
  113. result = result || item;
  114. });
  115. return result;
  116. }
  117. </script>
  118. <style lang="scss" scoped>
  119. @import "../../../../styles/app/tree.scss";
  120. </style>