HcTreeDataV2.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <el-tree-v2
  3. ref="ElTreeRef" :class="[ui]" :data="datas" :props="ElTreeProps"
  4. class="hc-tree-node" :filter-method="filterMethod" :height="treeHeight"></el-tree-v2>
  5. </template>
  6. <script setup>
  7. import {ref, watch, nextTick} from "vue";
  8. //参数
  9. const props = defineProps({
  10. ui: {
  11. type: String,
  12. default: ''
  13. },
  14. height: {
  15. type: [Number, String],
  16. default: 0
  17. },
  18. datas: {
  19. type: Array,
  20. default: () => ([])
  21. },
  22. submitCounts: {
  23. type: Boolean,
  24. default: false
  25. },
  26. searchTreeVal: {
  27. type: String,
  28. default: ''
  29. },
  30. })
  31. //变量
  32. const ElTreeRef = ref(null)
  33. const ElTreeProps = ref({
  34. value: 'primaryKeyId',
  35. label: 'title',
  36. children: 'children',
  37. })
  38. const treeHeight = ref(0)
  39. const isSubmitCounts = ref(props.submitCounts);
  40. const searchInfo = ref(props.searchTreeVal)
  41. //监听
  42. watch(() => [
  43. props.height,
  44. props.submitCounts,
  45. props.searchTreeVal,
  46. ], ([height, submitCounts, searchTreeVal]) => {
  47. console.log('height', height)
  48. treeHeight.value = height
  49. isSubmitCounts.value = submitCounts
  50. searchInfo.value = searchTreeVal
  51. })
  52. //事件
  53. const emit = defineEmits(['menuTap', 'nodeTap', 'changeSearch', 'changetreelaod'])
  54. //节点被点击
  55. const ElTreeClick = async (data, node) => {
  56. console.log('node', node)
  57. console.log('data', data)
  58. }
  59. //筛选树节点
  60. const filterMethod = (query, node) => {
  61. console.log('query',query)
  62. return node.label?.includes(query)
  63. }
  64. // 暴露出去
  65. defineExpose({
  66. })
  67. </script>
  68. <style lang="scss" scoped>
  69. @import "../../../styles/app/tree.scss";
  70. </style>
  71. <style lang="scss">
  72. .el-tree.hc-tree-node .el-tree-node {
  73. white-space: nowrap;
  74. overflow: hidden;
  75. text-overflow: ellipsis;
  76. .el-tree-node_content {
  77. white-space: nowrap;
  78. overflow: hidden;
  79. text-overflow: ellipsis;
  80. }
  81. }
  82. </style>