128 lines
6.6 KiB
TypeScript
128 lines
6.6 KiB
TypeScript
export type MerchantTenantStatus = 'PROFILE_REQUIRED' | 'PENDING' | 'ACTIVE' | 'REJECTED' | 'DISABLED' | 'ARCHIVED'
|
|
|
|
export interface TenantPermissionItem {
|
|
code: string
|
|
label: string
|
|
description: string
|
|
}
|
|
|
|
export interface TenantPermissionGroup {
|
|
key: string
|
|
label: string
|
|
items: TenantPermissionItem[]
|
|
}
|
|
|
|
export const REQUIRED_TENANT_PERMISSION_CODES = ['account:profile:view', 'dashboard:view'] as const
|
|
|
|
export const TENANT_PERMISSION_GROUPS: readonly TenantPermissionGroup[] = [
|
|
{
|
|
key: 'account',
|
|
label: '个人账号',
|
|
items: [{ code: 'account:profile:view', label: '维护我的信息', description: '所有企业成员默认可用,可查看并维护自己的资料和登录密码' }],
|
|
},
|
|
{
|
|
key: 'dashboard',
|
|
label: '业务总览',
|
|
items: [{ code: 'dashboard:view', label: '查看总览', description: '所有企业成员默认可用,可查看企业统计和最近订单' }],
|
|
},
|
|
{
|
|
key: 'finance',
|
|
label: '财务账单',
|
|
items: [
|
|
{ code: 'finance:bill:view', label: '查看客户账单', description: '查看本企业账单、收款记录和未收余额' },
|
|
{ code: 'finance:bill:confirm', label: '确认客户账单', description: '确认本企业已出账且待客户确认的对账单' },
|
|
],
|
|
},
|
|
{
|
|
key: 'orders',
|
|
label: '头程订单',
|
|
items: [
|
|
{ code: 'order:first-leg:list', label: '查看订单', description: '查看本企业头程订单列表和详情' },
|
|
{ code: 'order:first-leg:create', label: '创建订单', description: '新建并保存订单草稿' },
|
|
{ code: 'order:first-leg:quick-create', label: '快速下单', description: '使用快速下单页面生成订单草稿,不包含提交订单权限' },
|
|
{ code: 'order:first-leg:edit', label: '编辑订单', description: '编辑本企业尚未提交的订单草稿' },
|
|
{ code: 'order:first-leg:submit', label: '提交订单', description: '提交草稿进入平台审核' },
|
|
{ code: 'order:first-leg:cancel', label: '取消订单', description: '在允许的状态下取消订单' },
|
|
{ code: 'merchant:warehouse:delivery:list', label: '查看派送单', description: '分页查询本企业海外仓派送单' },
|
|
{ code: 'merchant:warehouse:delivery:create', label: '创建派送单', description: '从排车单创建海外仓派送单' },
|
|
],
|
|
},
|
|
{
|
|
key: 'company',
|
|
label: '企业资料',
|
|
items: [
|
|
{ code: 'company:profile:view', label: '查看资料', description: '查看企业、联系人和资质资料' },
|
|
{ code: 'company:profile:edit', label: '编辑资料', description: '维护企业联系信息和业务地址' },
|
|
{ code: 'company:qualification:upload', label: '更新资质', description: '上传或更新企业资质文件' },
|
|
],
|
|
},
|
|
{
|
|
key: 'members',
|
|
label: '企业成员',
|
|
items: [
|
|
{ code: 'company:member:list', label: '查看成员', description: '查看本企业成员列表' },
|
|
{ code: 'company:member:create', label: '新增成员', description: '新增企业成员' },
|
|
{ code: 'company:member:edit', label: '编辑成员', description: '编辑企业成员资料' },
|
|
{ code: 'company:member:grant-role', label: '分配成员角色', description: '调整企业成员角色' },
|
|
{ code: 'company:member:status', label: '启停成员', description: '启用或停用企业成员' },
|
|
{ code: 'company:member:reset-password', label: '重置密码', description: '重置企业成员登录密码' },
|
|
],
|
|
},
|
|
{
|
|
key: 'roles',
|
|
label: '角色与权限',
|
|
items: [
|
|
{ code: 'company:role:list', label: '查看角色', description: '查看本企业角色列表' },
|
|
{ code: 'company:role:create', label: '新增角色', description: '新增企业角色' },
|
|
{ code: 'company:role:edit', label: '编辑角色', description: '编辑企业角色' },
|
|
{ code: 'company:role:status', label: '启停角色', description: '启用或停用企业角色' },
|
|
{ code: 'company:role:delete', label: '删除角色', description: '删除未分配成员的企业角色' },
|
|
{ code: 'company:permission:list', label: '查看权限', description: '查看角色拥有的菜单和操作权限' },
|
|
{ code: 'company:permission:assign', label: '分配权限', description: '为本企业角色分配菜单及操作权限' },
|
|
],
|
|
},
|
|
]
|
|
|
|
export const FRONTEND_TO_MERCHANT_PERMISSION_CODES: Readonly<Record<string, readonly string[]>> = {
|
|
'order:first-leg:list': ['merchant:order:list', 'merchant:order:view'],
|
|
'order:first-leg:create': ['merchant:order:create'],
|
|
'order:first-leg:quick-create': ['merchant:order:quick-create', 'merchant:order:create'],
|
|
'order:first-leg:edit': ['merchant:order:edit'],
|
|
'order:first-leg:submit': ['merchant:order:submit'],
|
|
'order:first-leg:cancel': ['merchant:order:cancel'],
|
|
'company:profile:view': ['merchant:profile:view'],
|
|
'company:profile:edit': ['merchant:profile:edit'],
|
|
'company:qualification:upload': ['merchant:qualification:upload'],
|
|
'company:member:list': ['merchant:member:list'],
|
|
'company:member:create': ['merchant:member:create'],
|
|
'company:member:edit': ['merchant:member:edit'],
|
|
'company:member:grant-role': ['merchant:member:grant-role'],
|
|
'company:member:status': ['merchant:member:status'],
|
|
'company:member:reset-password': ['merchant:member:reset-password'],
|
|
'company:role:list': ['merchant:role:list'],
|
|
'company:role:create': ['merchant:role:create'],
|
|
'company:role:edit': ['merchant:role:edit'],
|
|
'company:role:status': ['merchant:role:status'],
|
|
'company:role:delete': ['merchant:role:delete'],
|
|
'company:permission:list': ['merchant:role:list'],
|
|
'company:permission:assign': ['merchant:role:grant'],
|
|
'finance:bill:view': ['merchant:finance:statement:list', 'merchant:finance:statement:view'],
|
|
'finance:bill:confirm': ['merchant:finance:statement:confirm'],
|
|
'merchant:notification:view': ['merchant:notification:view'],
|
|
'merchant:notification:read': ['merchant:notification:read'],
|
|
'merchant:notification:read-all': ['merchant:notification:read-all'],
|
|
}
|
|
|
|
export const FRONTEND_PERMISSIONS_REQUIRING_ALL_BACKEND_CODES = new Set<string>([
|
|
'finance:bill:view',
|
|
'order:first-leg:quick-create',
|
|
])
|
|
|
|
export function hasMappedMerchantPermission(frontendCode: string, grantedBackendCodes: ReadonlySet<string>) {
|
|
const backendCodes = FRONTEND_TO_MERCHANT_PERMISSION_CODES[frontendCode]
|
|
if (!backendCodes?.length) return grantedBackendCodes.has(frontendCode)
|
|
return FRONTEND_PERMISSIONS_REQUIRING_ALL_BACKEND_CODES.has(frontendCode)
|
|
? backendCodes.every((code) => grantedBackendCodes.has(code))
|
|
: backendCodes.some((code) => grantedBackendCodes.has(code))
|
|
}
|