来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
55 lines
2.7 KiB
TypeScript
55 lines
2.7 KiB
TypeScript
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('market_monitor')) return '/market-monitor';
|
||
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';
|
||
}
|