fix(router): 修正转码设置菜单重复注入
This commit is contained in:
1 parent
7c10e057a5
commit
aa892fe7a8
1 file changed
+11
-13
+11
-13
@@ -10,16 +10,15 @@ const TRANSCODE_ROUTE_PATH = 'media-transcode'
|
||||
const TRANSCODE_COMPONENT = 'views/systemManagement/TranscodeSettingsView'
|
||||
const TRANSCODE_TITLE_KEY = 'router.transcodeSettings'
|
||||
|
||||
const findRouteByName = (
|
||||
routes: AppCustomRouteRecordRaw[],
|
||||
name: string
|
||||
): AppCustomRouteRecordRaw | undefined => {
|
||||
/** 服务端菜单可能用别的路由名指向同一个组件,这里按路由名或组件路径判定是否已存在 */
|
||||
const hasTranscodeRoute = (routes: AppCustomRouteRecordRaw[]): boolean => {
|
||||
for (const route of routes) {
|
||||
if (route.name === name) return route
|
||||
const child = findRouteByName(route.children || [], name)
|
||||
if (child) return child
|
||||
if (route.name === TRANSCODE_ROUTE_NAME || route.component === TRANSCODE_COMPONENT) {
|
||||
return true
|
||||
}
|
||||
if (hasTranscodeRoute(route.children || [])) return true
|
||||
}
|
||||
return undefined
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,12 +31,11 @@ export const supplementLocalAdminRoutes = (
|
||||
if (!permissions.includes(TRANSCODE_PERMISSION)) {
|
||||
return routes
|
||||
}
|
||||
const nextRoutes = cloneDeep(routes)
|
||||
const existing = findRouteByName(nextRoutes, TRANSCODE_ROUTE_NAME)
|
||||
if (existing) {
|
||||
existing.meta = { ...existing.meta, title: TRANSCODE_TITLE_KEY }
|
||||
return nextRoutes
|
||||
// 服务端菜单里已经有转码设置时不再补,否则侧边栏会出现两条
|
||||
if (hasTranscodeRoute(routes)) {
|
||||
return routes
|
||||
}
|
||||
const nextRoutes = cloneDeep(routes)
|
||||
const contentRoute = nextRoutes.find(
|
||||
(route) => route.path === CONTENT_ROUTE_PATH || route.name === CONTENT_ROUTE_NAME
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user