index.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <!--treeList组件封装-->
  2. <template>
  3. <div class="treeList">
  4. <div class="title commons-title">
  5. {{title}}
  6. </div>
  7. <div class="search">
  8. <el-input
  9. v-model="search"
  10. placeholder="请输入搜索内容"
  11. clearable
  12. @clear="search = ''"
  13. @keyup.enter="searchChange"
  14. ></el-input>
  15. <el-button type="primary" @click="searchChange">搜索</el-button>
  16. </div>
  17. <el-tree
  18. :data="data"
  19. ref="tree"
  20. :node-key="['node-key']"
  21. @node-click="treeChange"
  22. :filter-node-method="filterNode"
  23. >
  24. </el-tree>
  25. </div>
  26. </template>
  27. <script setup>
  28. defineProps({
  29. title: {
  30. type: String,
  31. default: '租户列表',
  32. },
  33. type: {
  34. type: String,
  35. default: 'radio',
  36. },
  37. data: {
  38. type: Array,
  39. default: () => [],
  40. },
  41. modelValue: {
  42. type: Array || String,
  43. },
  44. 'node-key': {
  45. type: String,
  46. default: 'id',
  47. },
  48. })
  49. const search = ref('')
  50. const emit = defineEmits(['update:modelValue'])
  51. const { proxy } = getCurrentInstance()
  52. const treeChange = (e, data) => {
  53. if (proxy.type == 'radio') {
  54. emit('update:modelValue', e.id)
  55. emit('change', e)
  56. } else {
  57. emit('change', e)
  58. }
  59. }
  60. const filterNode = (value, data,node) => {
  61. if (!value) return true
  62. return data.label.indexOf(value) !== -1
  63. }
  64. const searchChange = () => {
  65. proxy.$refs.tree.filter(search.value)
  66. }
  67. </script>
  68. <style lang="scss">
  69. .treeList {
  70. display: block;
  71. height: 100%;
  72. background: #fff;
  73. padding: 20px;
  74. .search {
  75. margin-bottom: 20px;
  76. .el-input {
  77. width: calc(100% - 70px);
  78. margin-right: 10px;
  79. text-align: center;
  80. }
  81. }
  82. }
  83. </style>