File tree Expand file tree Collapse file tree 1 file changed +35
-5
lines changed
web/src/view/superAdmin/dictionary Expand file tree Collapse file tree 1 file changed +35
-5
lines changed Original file line number Diff line number Diff line change 1717 <template #append >
1818 <el-button
1919 :type =" searchName ? 'primary' : 'info'"
20- @click =" getTreeData "
20+ @click =" applySearch "
2121 >搜索</el-button
2222 >
2323 </template >
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'}"
238238 })
239239
240240 const treeData = ref ([])
241+ const displayTreeData = ref ([])
241242
242243 // 级联选择器配置
243244 const cascadeProps = {
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
258287 })
259288 if (res .code === 0 ) {
260289 treeData .value = res .data .list || []
290+ applySearch ()
261291 }
262292 } catch (error) {
263293 console .error (' 获取树形数据失败:' , error)
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
You can’t perform that action at this time.
0 commit comments