From 4043de2473e540508df43c2382b9154808015f83 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Jul 2026 11:29:33 +0800 Subject: [PATCH] Align admin section default routes --- assets/admin/src/constants/sections/index.js | 53 ++++++++++++++++---- assets/admin/src/router/index.js | 17 ++++++- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/assets/admin/src/constants/sections/index.js b/assets/admin/src/constants/sections/index.js index ddb007c8..82b8ef49 100644 --- a/assets/admin/src/constants/sections/index.js +++ b/assets/admin/src/constants/sections/index.js @@ -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 = [] diff --git a/assets/admin/src/router/index.js b/assets/admin/src/router/index.js index 6d28ca64..d1bac765 100644 --- a/assets/admin/src/router/index.js +++ b/assets/admin/src/router/index.js @@ -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,