diff --git a/apps/web-tdesign/src/views/system/menu/index.vue b/apps/web-tdesign/src/views/system/menu/index.vue index e540273..91d1f73 100644 --- a/apps/web-tdesign/src/views/system/menu/index.vue +++ b/apps/web-tdesign/src/views/system/menu/index.vue @@ -18,20 +18,13 @@ import { const { hasAccessByCodes } = useAccess(); const loading = ref(false); -// 扁平化后的菜单列表(含 depth 用于缩进展示),避免依赖 t-table 的 tree 渲染 -const flatList = ref<(MenuNode & { depth: number })[]>([]); +// 菜单树(嵌套 children 结构),由 t-enhanced-table 树形模式渲染 +const tree = ref([]); +// t-enhanced-table 实例:异步数据加载完成后手动展开全部节点 +const tableRef = ref(null); const dialogOpen = ref(false); const editing = ref(null); -/** 递归将树扁平化为数组,按层级加 depth 字段用于 UI 缩进 */ -function flatten(nodes: MenuNode[], depth: number, acc: (MenuNode & { depth: number })[] = []): (MenuNode & { depth: number })[] { - for (const n of nodes) { - acc.push({ ...n, depth }); - if (n.children?.length) flatten(n.children, depth + 1, acc); - } - return acc; -} - const form = reactive({ parentId: 0, name: '', @@ -49,8 +42,10 @@ async function load() { loading.value = true; try { const data = await getMenuTree(); - // 扁平化:td-table 的 tree 模式在全量注册 TDesign 后渲染不稳定,改为按 depth 缩进的一维列表 - flatList.value = flatten(data.tree ?? [], 0); + tree.value = data.tree ?? []; + // 异步数据就绪后手动展开全部节点(defaultExpandAll 只在首次渲染时生效) + await nextTick(); + tableRef.value?.expandAll?.(); } finally { loading.value = false; } @@ -138,18 +133,22 @@ onMounted(load); - - +