Files
SupplierSystem/src/utils/authRouting.ts
T
Ubuntu 8d3865aa87
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
feat(功能收窄): 隐藏「市场价格监控」—— 供应商系统不需要该功能
开发者指令(原话):「将市场价格监控界面隐藏,当前供应商系统不需要使用这个功能。」

只删菜单项不够(直接敲 URL 仍能打开),四处一起摘:
  ① src/config/menuCatalog.ts:删除 market-monitor 条目
     —— 运行时菜单树只渲染目录里有的 key ⇒ **老布局(库里存过该项)也不会再显示**
  ② src/utils/menuLayout.ts:从「基础数据」规范条目删除
     —— 否则归位逻辑会把它塞回分组(规范条目是权威顺序表)
  ③ src/modules/businessModules.ts:删除 ops 模块的 route 与 menuKeys ⇒ /market-monitor 不再可达
  ④ src/utils/authRouting.ts:删除「只有 market_monitor 权限 ⇒ 落 /market-monitor」兜底
     —— 否则这类账号登录后被送到已隐藏的页面

有意保留(避免动到权限体系与将来恢复成本):
  · 权限码 market_monitor(permissionCatalog / permissionLabels / 角色目录 / 后端都在用)
  · 页面文件 MarketMonitor.tsx 与 AI 副驾合同(不删代码,恢复只需把①②③④加回去)
  · i18n 三语文案(无入口即不可见)

未动(开发者未要求,需单独裁决):后台「市场监控每日刷新」调度(每日 03:00,调外部行情接口)
与后端只读行情接口 —— 本轮只隐藏界面。

验证:新增 src/utils/hiddenFeatures.marketMonitor.test.ts 5 例(逐条钉 ①②③④ + 老布局不显示 +
同组其它菜单项不受影响);前端全量 722 用例(新增 5),失败仅另一条工作线遗留的
SystemConfig.allowZeroCost 2 条;tsc 通过;门禁同基线。
设计:docs/design/20261027-隐藏市场价格监控功能.md
2026-10-11 12:37:14 +08:00

54 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { UserRole } from '../hooks/useAuth';
type HasRole = (role: UserRole | UserRole[]) => boolean;
type HasPermission = (permission: string | string[]) => boolean;
interface ProfileAccess {
roles: UserRole[];
permissions: string[];
}
export function createAccessCheckers(profile: ProfileAccess) {
const hasRole: HasRole = (role) => {
if (Array.isArray(role)) return role.some((r) => profile.roles.includes(r));
return profile.roles.includes(role);
};
const hasPermission: HasPermission = (permission) => {
if (Array.isArray(permission)) {
return permission.some((p) => profile.permissions.includes(p));
}
return profile.permissions.includes(permission);
};
return { hasRole, hasPermission };
}
export function getDefaultHomePath(hasRole: HasRole, hasPermission: HasPermission): string {
// 与后端统一登录入口 accountLoginService.resolveWebHomePath 保持一致:
// 超管落地「系统设置」,而非数据看板 —— /dashboard 的路由守卫只放行 admin(roles: ['admin']),
// 超管的 roles 只有 'super_admin'(不会被补成 admin),落过去会命中 App.tsx 的
// 「无权限 → 跳回默认首页」而自环。超管现有权限为 system_manage / branch_manage / data_import_export。
if (hasRole('super_admin')) return '/system/config';
if (hasRole('admin')) return '/dashboard';
if (hasRole('purchaser')) return '/purchaser/dashboard';
if (hasPermission('order_entry')) return '/customer-order';
if (hasPermission('order_manage')) return '/orders';
if (hasPermission('customer_manage')) return '/customers';
if (hasPermission('supplier_manage')) return '/suppliers';
if (hasPermission('preparation_manage')) return '/purchase/preparations';
if (hasPermission('purchase_manage')) return '/purchase';
if (hasPermission('picking_manage')) return '/picking';
if (hasPermission('inventory_manage')) return '/inventory';
if (hasPermission('delivery_manage')) return '/delivery';
if (hasPermission('finance_manage')) return '/finance';
if (hasPermission('inspection_manage')) return '/inspection';
if (hasPermission('processing_manage')) return '/inspection/processing';
if (hasPermission(['system_manage', 'user_manage', 'role_manage', 'log_view'])) return '/system/config';
// 兜底必须是「不需要任何权限就能进」的页面。
// 原为 '/customer-order',但该路由守卫要求 order_entry,
// 无角色/无权限的账号落过去会被 App.tsx「无权限 → 回默认首页」打回这里 → 自环。
// 见 src/pages/auth/NoAccess.tsx 顶部说明。
return '/no-access';
}