mirror of
https://github.com/fantastic-admin/basic.git
synced 2026-10-07 11:34:10 +08:00
feat: 路由增加 meta.menu 配置,同时 meta.sidebar 进入弃用过渡期
This commit is contained in:
@@ -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() {
|
||||
}"
|
||||
>
|
||||
<template v-for="item in menu.children" :key="item.path ?? JSON.stringify(item)">
|
||||
<SubMenu v-if="item.meta?.sidebar !== false" :unique-key="[...uniqueKey, item.path ?? JSON.stringify(item)]" :menu="item" :level="level + 1" />
|
||||
<SubMenu v-if="item.meta?.menu !== false" :unique-key="[...uniqueKey, item.path ?? JSON.stringify(item)]" :menu="item" :level="level + 1" />
|
||||
</template>
|
||||
</OverlayScrollbarsComponent>
|
||||
</Transition>
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -169,10 +169,37 @@ const useRouteStore = defineStore(
|
||||
return returnRoutes
|
||||
})
|
||||
|
||||
// TODO 将设置 meta.sidebar 的属性转换成 meta.menu ,过渡处理,未来将被弃用
|
||||
let isUsedDeprecatedAttribute = false
|
||||
function converDeprecatedAttribute<T extends Route.recordMainRaw[]>(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()
|
||||
}
|
||||
|
||||
Vendored
+2
-1
@@ -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[]
|
||||
|
||||
Reference in New Issue
Block a user