Align admin section default routes

This commit is contained in:
kate522 committed 2026-07-06 11:29:33 +08:00
1 parent ca0a550af8
commit 4043de2473
2 files changed
+58 -12

No files matched your search

+42 -11
View File
@@ -66,6 +66,19 @@ const COMPAT_PAGE_ORDER = [
const COMPAT_PAGE_ORDER_INDEX = new Map(COMPAT_PAGE_ORDER.map((key, index) => [key, index])) const COMPAT_PAGE_ORDER_INDEX = new Map(COMPAT_PAGE_ORDER.map((key, index) => [key, index]))
const SECTION_DEFAULT_CHILDREN = {
global: 'global-common',
page_display: 'page-display-homepage',
'post-list': 'post-list-page',
permissions: 'permissions-comment',
users: 'users-auth',
payment: 'payment-gateway',
shop: 'shop-products',
forum: 'forum-boards',
extensions: 'extensions-ip',
'tools-compat': 'tools-import-export',
}
const DEMOTED_PAGE_OVERRIDES = { const DEMOTED_PAGE_OVERRIDES = {
'post-list-submit': { 'post-list-submit': {
label: '前台投稿(兼容)', label: '前台投稿(兼容)',
@@ -184,16 +197,30 @@ function pickChildren(section, childKeys = []) {
})) }))
} }
function attachSectionDefaultRoute(section) {
const defaultChildKey = SECTION_DEFAULT_CHILDREN[section.key]
const defaultChild = (section.children || []).find((child) => child.key === defaultChildKey)
if (!defaultChild) {
return section
}
return {
...section,
defaultRoute: defaultChild.route,
}
}
const primarySections = [ const primarySections = [
globalSection, attachSectionDefaultRoute(globalSection),
pageDisplaySection, attachSectionDefaultRoute(pageDisplaySection),
withoutChildren(postListSection, DEMOTED_CHILDREN['post-list']), attachSectionDefaultRoute(withoutChildren(postListSection, DEMOTED_CHILDREN['post-list'])),
permissionsSection, attachSectionDefaultRoute(permissionsSection),
withoutChildren(usersSection, DEMOTED_CHILDREN.users), attachSectionDefaultRoute(withoutChildren(usersSection, DEMOTED_CHILDREN.users)),
withoutChildren(paymentSection, DEMOTED_CHILDREN.payment), attachSectionDefaultRoute(withoutChildren(paymentSection, DEMOTED_CHILDREN.payment)),
withoutChildren(shopSection, DEMOTED_CHILDREN.shop), attachSectionDefaultRoute(withoutChildren(shopSection, DEMOTED_CHILDREN.shop)),
withoutChildren(forumSection, DEMOTED_CHILDREN.forum), attachSectionDefaultRoute(withoutChildren(forumSection, DEMOTED_CHILDREN.forum)),
withoutChildren(extensionsSection, DEMOTED_CHILDREN.extensions), attachSectionDefaultRoute(withoutChildren(extensionsSection, DEMOTED_CHILDREN.extensions)),
] ]
const compatChildren = [ const compatChildren = [
@@ -212,19 +239,23 @@ const compatChildren = [
return leftIndex - rightIndex return leftIndex - rightIndex
}) })
export const compatToolsSection = { export const compatToolsSection = attachSectionDefaultRoute({
key: 'tools-compat', key: 'tools-compat',
label: '兼容&工具', label: '兼容&工具',
icon: toolsSection.icon, icon: toolsSection.icon,
route: '/tools', route: '/tools',
children: compatChildren, children: compatChildren,
} })
export const ADMIN_SECTIONS = [ export const ADMIN_SECTIONS = [
...primarySections, ...primarySections,
compatToolsSection, compatToolsSection,
] ]
export function getAdminSections() {
return ADMIN_SECTIONS
}
export function getAllAdminPages() { export function getAllAdminPages() {
const pages = [] const pages = []
+16 -1
View File
@@ -1,5 +1,5 @@
import { createRouter, createWebHashHistory } from 'vue-router' import { createRouter, createWebHashHistory } from 'vue-router'
import { getAllAdminPages } from '@/constants/admin-sections' import { getAdminSections, getAllAdminPages } from '@/constants/admin-sections'
import { componentLoaders } from './component-loaders/index.js' import { componentLoaders } from './component-loaders/index.js'
const ADMIN_DEFAULT_ROUTE = '/global/common' const ADMIN_DEFAULT_ROUTE = '/global/common'
@@ -57,8 +57,23 @@ function createRouteMeta(page) {
return meta return meta
} }
function createSectionRedirectRoutes() {
const seenPaths = new Set(['/'])
return getAdminSections()
.filter((section) => section.defaultRoute && section.route !== section.defaultRoute && !seenPaths.has(section.route))
.map((section) => {
seenPaths.add(section.route)
return {
path: section.route,
redirect: section.defaultRoute,
}
})
}
const routes = [ const routes = [
{ path: '/', redirect: ADMIN_DEFAULT_ROUTE }, { path: '/', redirect: ADMIN_DEFAULT_ROUTE },
...createSectionRedirectRoutes(),
...getAllAdminPages().map((page) => ({ ...getAllAdminPages().map((page) => ({
path: page.route, path: page.route,
name: page.name, name: page.name,