背景: - 落实 11-前端路由与目录规范:URL、导航、面包屑、页面目录一一对应; - 「平台」更名「管理中心」,模块 key 由 platform 改为 system; - 原导航模块 key 与 URL 首段不一致(script vs /scripts、asset vs /assets), 占位页按 URL 解析不到模块,出现「页面不存在」。 改动: - nav-config:模块 key 改为 URL 首段(scripts / assets / system),平台更名 管理中心,管理中心全部路径收敛到 /system/*;用户页为 /system/users; - routes / router:ROUTES 按模块分组;新增 /system/users、/system/users/new、 /system/users/:id;旧 /users* 与 /platform* 加前端重定向;/system 落到用户列表; - 页面目录迁移:pages/users → pages/system/users,pages/home → pages/dashboard, 懒加载与所有引用同步; - 面包屑、AppLayout、登录回跳、通用占位页(按路径 + 权限解析,无权限进 403) 与单测 / e2e 路径同步; - 顺带修复 /scripts/library、/assets/library 等占位页因模块 key 不一致导致的 404。 影响面: - 仅前端路由与目录;后端 /api/v1/users 等接口与权限点不变; - 旧书签 /users*、/platform* 由前端重定向兼容一个版本。 回滚方式: - 回滚本提交即恢复 /users 与 /platform/* 路由、原页面目录与导航命名。 验证证据: - pnpm --filter @lingxi/web lint / typecheck / test 通过(15 files / 55 tests); - pnpm build 通过; - 浏览器:登录后落在 /system/users,导航显示「管理中心」;/users → /system/users, /platform/roles → /system/roles;有权限的 /scripts/library、/assets/library 显示占位页,无权限显示 403; - A1 e2e 6/6 通过(真实 API + 浏览器)。
This commit is contained in:
1 parent
a1e28daec5
commit
f97f97b0cd
40 files changed
+159
-106
No files matched your search
@@ -1,23 +1,25 @@
|
||||
import { ROUTES } from '@/routes';
|
||||
|
||||
import type { BreadcrumbEntry } from './nav-config';
|
||||
|
||||
/**
|
||||
* /users 下的子路由(新建 / 详情)不在 nav-config 的菜单项里,
|
||||
* 这里补齐面包屑:工作台 / 平台 / 用户与组织 / 当前页。
|
||||
* 用户模块下的子路由(新建 / 详情)不在 nav-config 的菜单项里,
|
||||
* 这里补齐面包屑:工作台 / 管理中心 / 用户与组织 / 当前页。
|
||||
*/
|
||||
export function getUserSectionTrail(pathname: string): BreadcrumbEntry[] | null {
|
||||
if (pathname === '/users/new') {
|
||||
if (pathname === ROUTES.system.userNew) {
|
||||
return [
|
||||
{ key: 'home', label: '工作台', path: '/' },
|
||||
{ key: 'platform', label: '平台' },
|
||||
{ key: 'users', label: '用户与组织', path: '/users' },
|
||||
{ key: 'home', label: '工作台', path: ROUTES.home },
|
||||
{ key: 'system', label: '管理中心' },
|
||||
{ key: 'users', label: '用户与组织', path: ROUTES.system.users },
|
||||
{ key: 'user-new', label: '新建用户' },
|
||||
];
|
||||
}
|
||||
if (/^\/users\/[^/]+$/.test(pathname)) {
|
||||
if (/^\/system\/users\/[^/]+$/.test(pathname)) {
|
||||
return [
|
||||
{ key: 'home', label: '工作台', path: '/' },
|
||||
{ key: 'platform', label: '平台' },
|
||||
{ key: 'users', label: '用户与组织', path: '/users' },
|
||||
{ key: 'home', label: '工作台', path: ROUTES.home },
|
||||
{ key: 'system', label: '管理中心' },
|
||||
{ key: 'users', label: '用户与组织', path: ROUTES.system.users },
|
||||
{ key: 'user-detail', label: '成员详情' },
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { Navigate, useLocation } from 'react-router';
|
||||
|
||||
import { ROUTES } from '@/routes';
|
||||
|
||||
function buildTarget(
|
||||
pathname: string,
|
||||
search: string,
|
||||
hash: string,
|
||||
from: string,
|
||||
to: string,
|
||||
): string {
|
||||
const rest = pathname === from ? '' : pathname.slice(from.length);
|
||||
return `${to}${rest}${search}${hash}`;
|
||||
}
|
||||
|
||||
/** 旧路径 `/users*` → `/system/users*`,保留一个版本后删除 */
|
||||
export function LegacyUsersRedirect(): ReactNode {
|
||||
const { pathname, search, hash } = useLocation();
|
||||
return (
|
||||
<Navigate to={buildTarget(pathname, search, hash, '/users', ROUTES.system.users)} replace />
|
||||
);
|
||||
}
|
||||
|
||||
/** 旧路径 `/platform*` → `/system*`;`/platform` 落到用户列表 */
|
||||
export function LegacySystemRedirect(): ReactNode {
|
||||
const { pathname, search, hash } = useLocation();
|
||||
const to = pathname === '/platform' ? ROUTES.system.users : ROUTES.system.root;
|
||||
const from = pathname === '/platform' ? '/platform' : '/platform';
|
||||
return <Navigate to={buildTarget(pathname, search, hash, from, to)} replace />;
|
||||
}
|
||||
@@ -16,9 +16,9 @@ describe('导航配置', () => {
|
||||
|
||||
it('缺少权限点时过滤菜单,模块没有子菜单时整组隐藏', () => {
|
||||
const modules = filterNavByPermissions(NAV_MODULES, new Set(['script:read']));
|
||||
const script = modules.find((module) => module.key === 'script');
|
||||
const script = modules.find((module) => module.key === 'scripts');
|
||||
expect(script?.items.map((item) => item.key)).toEqual(['library']);
|
||||
expect(modules.some((module) => module.key === 'platform')).toBe(false);
|
||||
expect(modules.some((module) => module.key === 'system')).toBe(false);
|
||||
});
|
||||
|
||||
it('只有无权限要求的菜单时仍然可见', () => {
|
||||
@@ -26,10 +26,10 @@ describe('导航配置', () => {
|
||||
expect(modules.map((module) => module.key)).toEqual(['dashboard']);
|
||||
});
|
||||
|
||||
it('子路由(/users/new、/users/:id)也归属用户与组织', () => {
|
||||
expect(findActiveNav(NAV_MODULES, '/users/new')?.item?.label).toBe('用户与组织');
|
||||
expect(findActiveNav(NAV_MODULES, '/users/01HZZZZZZZZZZZZZZZZZZZZZZZ')?.module.key).toBe(
|
||||
'platform',
|
||||
it('子路由(/system/users/new、/system/users/:id)也归属用户与组织', () => {
|
||||
expect(findActiveNav(NAV_MODULES, '/system/users/new')?.item?.label).toBe('用户与组织');
|
||||
expect(findActiveNav(NAV_MODULES, '/system/users/01HZZZZZZZZZZZZZZZZZZZZZZZ')?.module.key).toBe(
|
||||
'system',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('导航配置', () => {
|
||||
|
||||
it('面包屑从导航配置派生', () => {
|
||||
expect(getBreadcrumbs(NAV_MODULES, '/')).toEqual([{ key: 'home', label: '工作台', path: '/' }]);
|
||||
const breadcrumbs = getBreadcrumbs(NAV_MODULES, '/users');
|
||||
expect(breadcrumbs.map((entry) => entry.label)).toEqual(['工作台', '平台', '用户与组织']);
|
||||
const breadcrumbs = getBreadcrumbs(NAV_MODULES, '/system/users');
|
||||
expect(breadcrumbs.map((entry) => entry.label)).toEqual(['工作台', '管理中心', '用户与组织']);
|
||||
});
|
||||
});
|
||||
@@ -68,7 +68,7 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'script',
|
||||
key: 'scripts',
|
||||
label: '脚本',
|
||||
path: '/scripts/library',
|
||||
icon: IconScript,
|
||||
@@ -166,7 +166,7 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'asset',
|
||||
key: 'assets',
|
||||
label: '资产',
|
||||
path: '/assets/library',
|
||||
icon: IconAsset,
|
||||
@@ -240,16 +240,16 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'platform',
|
||||
label: '平台',
|
||||
path: '/users',
|
||||
key: 'system',
|
||||
label: '管理中心',
|
||||
path: '/system/users',
|
||||
icon: IconSettings,
|
||||
permission: Permission.USER_VIEW,
|
||||
items: [
|
||||
{
|
||||
key: 'users',
|
||||
label: '用户与组织',
|
||||
path: '/users',
|
||||
path: '/system/users',
|
||||
icon: IconUser,
|
||||
permission: Permission.USER_VIEW,
|
||||
description: '账号、组织与登录状态',
|
||||
@@ -257,7 +257,7 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
{
|
||||
key: 'roles',
|
||||
label: '角色权限',
|
||||
path: '/platform/roles',
|
||||
path: '/system/roles',
|
||||
icon: IconShield,
|
||||
permission: Permission.ROLE_MANAGE,
|
||||
description: '角色、权限点与职责互斥',
|
||||
@@ -265,7 +265,7 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
{
|
||||
key: 'customers',
|
||||
label: '客户',
|
||||
path: '/platform/customers',
|
||||
path: '/system/customers',
|
||||
icon: IconGlobal,
|
||||
permission: Permission.CUSTOMER_MANAGE,
|
||||
description: '客户、行业归属与数据范围',
|
||||
@@ -273,7 +273,7 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
{
|
||||
key: 'industries',
|
||||
label: '行业树',
|
||||
path: '/platform/industries',
|
||||
path: '/system/industries',
|
||||
icon: IconStack,
|
||||
permission: Permission.INDUSTRY_MANAGE,
|
||||
description: '行业分类树与行业包绑定',
|
||||
@@ -281,7 +281,7 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
{
|
||||
key: 'dicts',
|
||||
label: '字典',
|
||||
path: '/platform/dicts',
|
||||
path: '/system/dicts',
|
||||
icon: IconDocs,
|
||||
permission: Permission.DICT_MANAGE,
|
||||
description: '核心字典与业务枚举',
|
||||
@@ -289,7 +289,7 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
{
|
||||
key: 'audit',
|
||||
label: '审计日志',
|
||||
path: '/platform/audit',
|
||||
path: '/system/audit-logs',
|
||||
icon: IconView,
|
||||
permission: Permission.AUDIT_READ,
|
||||
description: '关键操作留痕与导出记录',
|
||||
@@ -297,7 +297,7 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
{
|
||||
key: 'ai',
|
||||
label: '模型接入',
|
||||
path: '/platform/ai',
|
||||
path: '/system/ai',
|
||||
icon: IconRobot,
|
||||
permission: Permission.AI_CONFIGURE,
|
||||
description: '供应商、路由与预算阈值',
|
||||
@@ -305,7 +305,7 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
{
|
||||
key: 'settings',
|
||||
label: '系统配置',
|
||||
path: '/platform/settings',
|
||||
path: '/system/settings',
|
||||
icon: IconSettings,
|
||||
permission: Permission.SYSTEM_CONFIGURE,
|
||||
description: '阈值、上限与功能开关',
|
||||
@@ -313,7 +313,7 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
{
|
||||
key: 'industry-packs',
|
||||
label: '行业包',
|
||||
path: '/platform/industry-packs',
|
||||
path: '/system/industry-packs',
|
||||
icon: IconGrid,
|
||||
permission: Permission.INDUSTRY_MANAGE,
|
||||
description: '行业包版本、发布与灰度',
|
||||
@@ -321,7 +321,7 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
{
|
||||
key: 'forms',
|
||||
label: '表单设计器',
|
||||
path: '/platform/forms',
|
||||
path: '/system/forms',
|
||||
icon: IconGrid,
|
||||
permission: Permission.FORM_DESIGN,
|
||||
description: '受控字段白名单与表单布局',
|
||||
@@ -329,7 +329,7 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
{
|
||||
key: 'customer-fields',
|
||||
label: '客户字段',
|
||||
path: '/platform/customer-fields',
|
||||
path: '/system/customer-fields',
|
||||
icon: IconTask,
|
||||
permission: Permission.CUSTOMER_MANAGE,
|
||||
description: '客户级扩展字段与审批',
|
||||
@@ -337,7 +337,7 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
{
|
||||
key: 'compliance',
|
||||
label: '合规规则',
|
||||
path: '/platform/compliance',
|
||||
path: '/system/compliance',
|
||||
icon: IconShield,
|
||||
permission: Permission.SYSTEM_CONFIGURE,
|
||||
description: '禁忌词、极限词与合规规则集',
|
||||
|
||||
Reference in new issue
Block a user