菜单搜索bug

This commit is contained in:
2026-09-20 14:21:10 +08:00
parent 2a0ac458de
commit ec62f03acf

View File

@@ -246,6 +246,7 @@ export default {
// 查询参数
queryParams: {
name: undefined,
status: undefined,
visible: undefined
},
// 表单参数
@@ -286,10 +287,20 @@ export default {
getList() {
this.loading = true;
listMenu(this.queryParams).then(response => {
this.menuList = this.handleTree(response.data, "id");
const data = response.data || [];
// 无搜索条件:后端返回全量菜单,可构建成完整树形展示
// 有搜索条件:后端只返回匹配到的局部数据,父节点可能不在结果集中,
// 此时再走 handleTree 会因父级缺失导致大量数据不显示,故直接平铺展示
this.menuList = this.isSearching() ? data : this.handleTree(data, "id");
this.loading = false;
});
},
/** 是否存在搜索条件 */
isSearching() {
const { name, status } = this.queryParams;
const isEmpty = (val) => val === undefined || val === null || val === '';
return !isEmpty(name) || !isEmpty(status);
},
/** 转换菜单数据结构 */
normalizer(node) {
if (node.children && !node.children.length) {