diff --git a/src/layouts/components/Menu/sub.vue b/src/layouts/components/Menu/sub.vue index 65cc4b4c..43015669 100644 --- a/src/layouts/components/Menu/sub.vue +++ b/src/layouts/components/Menu/sub.vue @@ -96,7 +96,7 @@ const transitionClass = computed(() => { const hasChildren = computed(() => { let flag = true if (props.menu.children) { - if (props.menu.children.every((item: any) => item.meta?.sidebar === false)) { + if (props.menu.children.every((item: any) => item.meta?.menu === false)) { flag = false } } @@ -189,7 +189,7 @@ function handleMouseleave() { }" > diff --git a/src/layouts/components/Search/index.vue b/src/layouts/components/Search/index.vue index 4358ffb0..8ca79233 100755 --- a/src/layouts/components/Search/index.vue +++ b/src/layouts/components/Search/index.vue @@ -163,14 +163,14 @@ function initSourceList() { function hasChildren(item: RouteRecordRaw) { let flag = true - if (item.children?.every(i => i.meta?.sidebar === false)) { + if (item.children?.every(i => i.meta?.menu === false)) { flag = false } return flag } function getSourceList(arr: RouteRecordRaw[], basePath?: string, icon?: string, breadcrumb?: { title?: string | (() => string) }[]) { arr.forEach((item) => { - if (item.meta?.sidebar !== false) { + if (item.meta?.menu !== false) { const breadcrumbTemp = cloneDeep(breadcrumb) || [] if (item.children && hasChildren(item)) { breadcrumbTemp.push({ diff --git a/src/store/modules/menu.ts b/src/store/modules/menu.ts index d7f6f263..ac633a74 100755 --- a/src/store/modules/menu.ts +++ b/src/store/modules/menu.ts @@ -71,7 +71,7 @@ const useMenuStore = defineStore( function getDeepestPath(menu: Menu.recordRaw, rootPath = '') { let retnPath = '' if (menu.children) { - const item = menu.children.find(item => item.meta?.sidebar !== false) + const item = menu.children.find(item => item.meta?.menu !== false) if (item) { retnPath = getDeepestPath(item, resolveRoutePath(rootPath, menu.path)) } diff --git a/src/store/modules/route.ts b/src/store/modules/route.ts index 659b6b8a..1c4587f2 100755 --- a/src/store/modules/route.ts +++ b/src/store/modules/route.ts @@ -169,10 +169,37 @@ const useRouteStore = defineStore( return returnRoutes }) + // TODO 将设置 meta.sidebar 的属性转换成 meta.menu ,过渡处理,未来将被弃用 + let isUsedDeprecatedAttribute = false + function converDeprecatedAttribute(routes: T): T { + routes.forEach((route) => { + route.children = converDeprecatedAttributeRecursive(route.children) + }) + if (isUsedDeprecatedAttribute) { + console.warn('[Fantastic-admin] 路由配置中的 "sidebar" 属性即将被弃用, 请尽快替换为 "menu" 属性') + } + return routes + } + function converDeprecatedAttributeRecursive(routes: RouteRecordRaw[]) { + if (routes) { + routes.forEach((route) => { + if (typeof route.meta?.sidebar === 'boolean') { + isUsedDeprecatedAttribute = true + route.meta.menu = route.meta.sidebar + delete route.meta.sidebar + } + if (route.children) { + converDeprecatedAttributeRecursive(route.children) + } + }) + } + return routes + } + // 根据权限动态生成路由(前端生成) async function generateRoutesAtFront(asyncRoutes: Route.recordMainRaw[]) { // 设置 routes 数据 - routesRaw.value = cloneDeep(asyncRoutes) as any + routesRaw.value = converDeprecatedAttribute(cloneDeep(asyncRoutes) as any) if (settingsStore.settings.app.enablePermission) { await userStore.getPermissions() } @@ -203,7 +230,7 @@ const useRouteStore = defineStore( async function generateRoutesAtBack() { await apiApp.routeList().then(async (res) => { // 设置 routes 数据 - routesRaw.value = formatBackRoutes(res.data) as any + routesRaw.value = converDeprecatedAttribute(formatBackRoutes(res.data) as any) if (settingsStore.settings.app.enablePermission) { await userStore.getPermissions() } diff --git a/src/types/global.d.ts b/src/types/global.d.ts index c13a6c8a..86af9e71 100755 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -228,6 +228,7 @@ declare module 'vue-router' { defaultOpened?: boolean auth?: string | string[] sidebar?: boolean + menu?: boolean breadcrumb?: boolean activeMenu?: string cache?: boolean | string | string[] @@ -263,7 +264,7 @@ declare namespace Menu { icon?: string defaultOpened?: boolean auth?: string | string[] - sidebar?: boolean + menu?: boolean link?: string } children?: recordRaw[]