diff --git a/.gitignore b/.gitignore index 91ed8f6..64c4fda 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,8 @@ auto-imports.d.ts components.d.ts .env.local .env.*.local + +# 构建产物 (W17.4.6 补) +*.tsbuildinfo +vite.config.d.ts +vite.config.js diff --git a/src/components/AppLayout/AppLayout.vue b/src/components/AppLayout/AppLayout.vue index 2ba1043..7a2cea3 100644 --- a/src/components/AppLayout/AppLayout.vue +++ b/src/components/AppLayout/AppLayout.vue @@ -60,6 +60,56 @@ function isActive(path: string): boolean { return path === '/' ? route.path === '/' : route.path.startsWith(path) } +/** + * 面包屑: 从当前 route.path 在菜单树里 DFS 追溯完整父级链 + * 返回 [一级目录, ..., 末级菜单], 不含"工作台"前缀(template 里单独拼) + * 找不到时 fallback 到 route.meta.title + */ +const breadcrumbItems = computed(() => { + const currentPath = route.path + // 工作台首页不显示中间层级 + if (currentPath === '/' || currentPath === '/dashboard') return [] + // DFS 找父级链: 父菜单(有 children)的 path 是第一个子菜单的 path(见 + // resolveMenuItem), 不能用 path 前缀短路命中父菜单, 必须先递归子树, + // 子树没命中才考虑父菜单自身。 + function findChain(items: MenuItem[], target: string, chain: MenuItem[]): boolean { + for (const item of items) { + // 叶子节点: path 精确匹配 + if (!item.children?.length) { + if (item.path === target) { + chain.push(item) + return true + } + continue + } + // 父节点: 先递归子树 + chain.push(item) + if (findChain(item.children, target, chain)) return true + chain.pop() + // 子树没命中, 看父节点自身 path 是否是 target 的前缀(详情页场景) + if (item.path !== '/' && target.startsWith(item.path)) { + chain.push(item) + return true + } + } + return false + } + const chain: MenuItem[] = [] + findChain(menuList.value, currentPath, chain) + const metaTitle = route.meta?.title as string | undefined + if (chain.length) { + const titles: string[] = chain.map(i => i.title) + const last = chain[chain.length - 1] + if (last.path !== currentPath) { + // 详情页: 命中的是父前缀, 追加 meta.title + return metaTitle ? [...titles, metaTitle] : titles + } + return titles + } + // 菜单树没命中 (如 /inquiry/:id 详情页), 用 meta.title 兜底 + return metaTitle ? [metaTitle] : [] +}) + const PARENT_GROUP: Record = { '概览': '概览', '业务': '业务', @@ -224,7 +274,8 @@ const badges = ref>({}) async function loadBadges() { try { const data = await fetch('/sys/openapi/inquiry/list?page=1&limit=1', { - headers: { Authorization: `Bearer ${userStore.token}` } + headers: { Authorization: `Bearer ${userStore.token}` }, + credentials: 'omit' }).then(r => r.json()).catch(() => null) if (data?.code === 0) { const total = data.total ?? data.data?.length ?? 0 @@ -328,7 +379,7 @@ onMounted(loadBadges) 工作台 - {{ route.meta?.title || '' }} + {{ item }}
diff --git a/src/components/DataTable/DataTable.vue b/src/components/DataTable/DataTable.vue index fc8bbea..0c0b2b6 100644 --- a/src/components/DataTable/DataTable.vue +++ b/src/components/DataTable/DataTable.vue @@ -1,54 +1,40 @@