Commit dea7e5ccd60a55b0277d26c175aab79d8b48df75
Committed by
xp.Huang
1 parent
094e646b
fix: 选择组织时增加搜索功能
Showing
1 changed file
with
19 additions
and
2 deletions
| 1 | <template> | 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 | <template #[item]="data" v-for="item in Object.keys($slots)"> | 8 | <template #[item]="data" v-for="item in Object.keys($slots)"> |
| 4 | <slot :name="item" v-bind="data || {}"></slot> | 9 | <slot :name="item" v-bind="data || {}"></slot> |
| 5 | </template> | 10 | </template> |
| @@ -60,6 +65,18 @@ | @@ -60,6 +65,18 @@ | ||
| 60 | props.immediate && fetch(); | 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 | async function fetch() { | 80 | async function fetch() { |
| 64 | const { api } = props; | 81 | const { api } = props; |
| 65 | if (!api || !isFunction(api)) return; | 82 | if (!api || !isFunction(api)) return; |
| @@ -80,7 +97,7 @@ | @@ -80,7 +97,7 @@ | ||
| 80 | isFirstLoaded.value = true; | 97 | isFirstLoaded.value = true; |
| 81 | emit('options-change', treeData.value); | 98 | emit('options-change', treeData.value); |
| 82 | } | 99 | } |
| 83 | - return { getAttrs, loading, handleChange }; | 100 | + return { getAttrs, loading, handleChange, filterTreeNode }; |
| 84 | }, | 101 | }, |
| 85 | }); | 102 | }); |
| 86 | </script> | 103 | </script> |