Files
wordpress-theme-aksrt/assets/admin/src/router/index.js
T
kate522 a3dde3874a feat(admin): strip SPA ops menus; redirect old hashes to native WP (Phase 4)
SPA shop/forum/payment/users sections now keep configuration pages only.
Operational workbenches were removed from the sidebar and loaders; legacy
hash routes open NativeOpsRedirect into the matching WP native admin page.
Admin SPA production build refreshed accordingly.
2026-07-15 02:10:05 +08:00

126 lines
4.8 KiB
JavaScript

import { createRouter, createWebHashHistory } from 'vue-router'
import { getAdminSections, getAllAdminPages } from '@/constants/admin-sections'
import { componentLoaders } from './component-loaders/index.js'
const ADMIN_DEFAULT_ROUTE = '/global/common'
function resolveComponent(page) {
if (componentLoaders[page.component]) {
return componentLoaders[page.component]
}
// Log missing component for debugging — avoids silent fallback to DeferredPage
if (page.component && page.component !== 'DeferredPage') {
console.warn(
`[AKSRT Route] Component "${page.component}" not found in componentLoaders for route "${page.route}". Falling back to DeferredPage.`
)
}
return componentLoaders.DeferredPage
}
function createRouteMeta(page) {
const meta = {
title: page.title,
section: page.sectionKey || '',
desc: page.desc || '',
status: page.status || 'available',
secondaryEntry: page.secondaryEntry === true,
}
if (page.compatSourceSection) {
meta.compatSourceSection = page.compatSourceSection
}
if (page.canonicalDomain) {
meta.canonicalDomain = page.canonicalDomain
}
if (page.section) {
meta.section = page.section
}
if (page.component === 'DeferredPage') {
meta.deferred = true
meta.deferredProps = {
title: page.title,
description: page.desc || '',
icon: page.iconClass || 'fas fa-compass-drafting',
phase: page.phase || '',
status: page.status || 'deferred',
dependsOn: page.dependsOn || [],
reason: page.reason || '',
features: page.features || [],
}
}
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,
}
})
}
/**
* Old SPA ops routes → native WP admin pages (Phase 4 transition).
* Bookmarks under #/shop/products etc. land on NativeOpsRedirect.
*/
const NATIVE_OPS_REDIRECTS = [
{ path: '/shop/products', title: '商品管理', nativeAdminPath: 'edit.php?post_type=aksrt_product' },
{ path: '/shop/orders', title: '订单管理', nativeAdminPath: 'admin.php?page=aksrt_orders' },
{ path: '/shop/after-sale', title: '售后管理', nativeAdminPath: 'admin.php?page=aksrt_after_sale' },
{ path: '/shop/shipping', title: '物流管理', nativeAdminPath: 'admin.php?page=aksrt_shipping' },
{ path: '/shop/coupons', title: '优惠券', nativeAdminPath: 'admin.php?page=aksrt_coupons' },
{ path: '/shop/withdrawals', title: '提现管理', nativeAdminPath: 'admin.php?page=aksrt_withdraw' },
{ path: '/shop/dashboard', title: '商城概览', nativeAdminPath: 'admin.php?page=aksrt_pay' },
{ path: '/forum/boards', title: '板块管理', nativeAdminPath: 'edit.php?post_type=aksrt_forum_plate' },
{ path: '/forum/topics', title: '主题治理', nativeAdminPath: 'edit.php?post_type=aksrt_forum_topic' },
{ path: '/forum/moderators', title: '版主管理', nativeAdminPath: 'edit.php?post_type=aksrt_forum_plate' },
{ path: '/forum/moderator-applications', title: '版主申请', nativeAdminPath: 'edit.php?post_type=aksrt_forum_plate' },
{ path: '/forum/dashboard', title: '论坛概览', nativeAdminPath: 'edit.php?post_type=aksrt_forum_topic' },
{ path: '/payment/charge-card', title: '充值卡', nativeAdminPath: 'admin.php?page=aksrt_charge_cards' },
{ path: '/payment/revenue', title: '创作分成', nativeAdminPath: 'admin.php?page=aksrt_income' },
{ path: '/payment/rebate', title: '返佣管理', nativeAdminPath: 'admin.php?page=aksrt_rebate' },
{ path: '/users/messages', title: '消息中心', nativeAdminPath: 'users.php?page=aksrt_messages' },
{ path: '/users/invite-codes', title: '邀请码运营', nativeAdminPath: 'users.php?page=aksrt_invite_codes' },
{ path: '/users/ban', title: '禁封管理', nativeAdminPath: 'users.php?page=aksrt_user_ban&tab=restrictions' },
{ path: '/users/report', title: '禁封/举报', nativeAdminPath: 'users.php?page=aksrt_user_ban&tab=reports' },
]
const routes = [
{ path: '/', redirect: ADMIN_DEFAULT_ROUTE },
...createSectionRedirectRoutes(),
...getAllAdminPages().map((page) => ({
path: page.route,
name: page.name,
component: resolveComponent(page),
meta: createRouteMeta(page),
})),
...NATIVE_OPS_REDIRECTS.map((item) => ({
path: item.path,
name: `NativeRedirect_${item.path.replace(/\W+/g, '_')}`,
component: componentLoaders.NativeOpsRedirect,
meta: {
title: item.title,
nativeAdminPath: item.nativeAdminPath,
status: 'redirect',
},
})),
]
export default createRouter({
history: createWebHashHistory(),
routes,
})