Align admin section default routes

This commit is contained in:
2026-07-06 11:29:33 +08:00
parent ca0a550af8
commit 4043de2473
2 changed files with 58 additions and 12 deletions
+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 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 = {
'post-list-submit': {
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 = [
globalSection,
pageDisplaySection,
withoutChildren(postListSection, DEMOTED_CHILDREN['post-list']),
permissionsSection,
withoutChildren(usersSection, DEMOTED_CHILDREN.users),
withoutChildren(paymentSection, DEMOTED_CHILDREN.payment),
withoutChildren(shopSection, DEMOTED_CHILDREN.shop),
withoutChildren(forumSection, DEMOTED_CHILDREN.forum),
withoutChildren(extensionsSection, DEMOTED_CHILDREN.extensions),
attachSectionDefaultRoute(globalSection),
attachSectionDefaultRoute(pageDisplaySection),
attachSectionDefaultRoute(withoutChildren(postListSection, DEMOTED_CHILDREN['post-list'])),
attachSectionDefaultRoute(permissionsSection),
attachSectionDefaultRoute(withoutChildren(usersSection, DEMOTED_CHILDREN.users)),
attachSectionDefaultRoute(withoutChildren(paymentSection, DEMOTED_CHILDREN.payment)),
attachSectionDefaultRoute(withoutChildren(shopSection, DEMOTED_CHILDREN.shop)),
attachSectionDefaultRoute(withoutChildren(forumSection, DEMOTED_CHILDREN.forum)),
attachSectionDefaultRoute(withoutChildren(extensionsSection, DEMOTED_CHILDREN.extensions)),
]
const compatChildren = [
@@ -212,19 +239,23 @@ const compatChildren = [
return leftIndex - rightIndex
})
export const compatToolsSection = {
export const compatToolsSection = attachSectionDefaultRoute({
key: 'tools-compat',
label: '兼容&工具',
icon: toolsSection.icon,
route: '/tools',
children: compatChildren,
}
})
export const ADMIN_SECTIONS = [
...primarySections,
compatToolsSection,
]
export function getAdminSections() {
return ADMIN_SECTIONS
}
export function getAllAdminPages() {
const pages = []
+16 -1
View File
@@ -1,5 +1,5 @@
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'
const ADMIN_DEFAULT_ROUTE = '/global/common'
@@ -57,8 +57,23 @@ function createRouteMeta(page) {
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 = [
{ path: '/', redirect: ADMIN_DEFAULT_ROUTE },
...createSectionRedirectRoutes(),
...getAllAdminPages().map((page) => ({
path: page.route,
name: page.name,