Skip to content

Commit 00224ef

Browse files
author
piexlMax(奇淼
committed
fix: 字典搜索bug
1 parent 506c9ea commit 00224ef

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

web/src/view/superAdmin/dictionary/sysDictionaryDetail.vue

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<template #append>
1818
<el-button
1919
:type="searchName ? 'primary' : 'info'"
20-
@click="getTreeData"
20+
@click="applySearch"
2121
>搜索</el-button
2222
>
2323
</template>
@@ -29,7 +29,7 @@
2929
</div>
3030
<!-- 表格视图 -->
3131
<el-table
32-
:data="treeData"
32+
:data="displayTreeData"
3333
style="width: 100%"
3434
tooltip-effect="dark"
3535
:tree-props="{ children: 'children'}"
@@ -238,6 +238,7 @@
238238
})
239239
240240
const treeData = ref([])
241+
const displayTreeData = ref([])
241242
242243
// 级联选择器配置
243244
const cascadeProps = {
@@ -249,6 +250,34 @@
249250
}
250251
251252
253+
const normalizeSearch = (value) => (value ?? '').toString().toLowerCase()
254+
255+
const filterTree = (nodes, keyword) => {
256+
const trimmed = normalizeSearch(keyword).trim()
257+
if (!trimmed) {
258+
return nodes
259+
}
260+
const walk = (list) => {
261+
const result = []
262+
for (const node of list) {
263+
const label = normalizeSearch(node.label)
264+
const children = Array.isArray(node.children) ? walk(node.children) : []
265+
if (label.includes(trimmed) || children.length > 0) {
266+
result.push({
267+
...node,
268+
children
269+
})
270+
}
271+
}
272+
return result
273+
}
274+
return walk(nodes)
275+
}
276+
277+
const applySearch = () => {
278+
displayTreeData.value = filterTree(treeData.value, searchName.value)
279+
}
280+
252281
// 获取树形数据
253282
const getTreeData = async () => {
254283
if (!props.sysDictionaryID) return
@@ -258,6 +287,7 @@
258287
})
259288
if (res.code === 0) {
260289
treeData.value = res.data.list || []
290+
applySearch()
261291
}
262292
} catch (error) {
263293
console.error('获取树形数据失败:', error)
@@ -374,16 +404,16 @@
374404
375405
const clearSearchInput = () => {
376406
searchName.value = ''
377-
getTreeData()
407+
applySearch()
378408
}
379409
380410
const handleCloseSearchInput = () => {
381411
// 处理搜索输入框关闭
382412
}
383413
384414
const handleInputKeyDown = (e) => {
385-
if (e.key === 'Enter' && searchName.value.trim() !== '') {
386-
getTreeData()
415+
if (e.key === 'Enter') {
416+
applySearch()
387417
}
388418
}
389419

0 commit comments

Comments
 (0)