Commit ff40a06bafb5557afa9da16f18cf05c13b032100
Merge branch 'fix/add-apitreeselect-search' into 'main_dev'
fix: 选择组织时增加搜索功能 See merge request yunteng/thingskit-front!1268
Showing
1 changed file
with
19 additions
and
2 deletions
| 1 | 1 | <template> |
| 2 | - <a-tree-select v-bind="getAttrs" @change="handleChange"> | |
| 2 | + <a-tree-select | |
| 3 | + v-bind="getAttrs" | |
| 4 | + @change="handleChange" | |
| 5 | + :showSearch="true" | |
| 6 | + :filterTreeNode="filterTreeNode" | |
| 7 | + > | |
| 3 | 8 | <template #[item]="data" v-for="item in Object.keys($slots)"> |
| 4 | 9 | <slot :name="item" v-bind="data || {}"></slot> |
| 5 | 10 | </template> |
| ... | ... | @@ -60,6 +65,18 @@ |
| 60 | 65 | props.immediate && fetch(); |
| 61 | 66 | }); |
| 62 | 67 | |
| 68 | + function filterTreeNode(value, options) { | |
| 69 | + const { props } = options || {}; | |
| 70 | + | |
| 71 | + if (!value) { | |
| 72 | + return true; | |
| 73 | + } | |
| 74 | + let { name } = props || {}; | |
| 75 | + value = value.toLowerCase(); | |
| 76 | + name = name.toLowerCase(); | |
| 77 | + return name.includes(value); | |
| 78 | + } | |
| 79 | + | |
| 63 | 80 | async function fetch() { |
| 64 | 81 | const { api } = props; |
| 65 | 82 | if (!api || !isFunction(api)) return; |
| ... | ... | @@ -80,7 +97,7 @@ |
| 80 | 97 | isFirstLoaded.value = true; |
| 81 | 98 | emit('options-change', treeData.value); |
| 82 | 99 | } |
| 83 | - return { getAttrs, loading, handleChange }; | |
| 100 | + return { getAttrs, loading, handleChange, filterTreeNode }; | |
| 84 | 101 | }, |
| 85 | 102 | }); |
| 86 | 103 | </script> | ... | ... |