207 lines
14 KiB
TypeScript
207 lines
14 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: 'notifications',
|
|
label: '消息中心',
|
|
items: [
|
|
{ code: 'merchant:notification:view', label: '查看我的消息', description: '查看本企业和当前成员可见的站内消息' },
|
|
{ code: 'merchant:notification:read', label: '标记消息已读', description: '将已查看的站内消息标记为已读' },
|
|
{ code: 'merchant:notification:read-all', label: '全部标记已读', description: '将当前成员的全部站内消息标记为已读' },
|
|
],
|
|
},
|
|
{
|
|
key: 'finance',
|
|
label: '财务账单',
|
|
items: [
|
|
{ code: 'merchant:finance:account:view', label: '查看资金账户', description: '查看本企业实际、冻结和可用余额及资金流水' },
|
|
{ code: 'merchant:finance:recharge:create', label: '提交充值申请', description: '上传付款截图并提交本企业充值申请' },
|
|
{ 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:customs-list', label: '查看报关资料', description: '查看本企业装柜后的退税报关资料、文件版本和报关行回执' },
|
|
{ code: 'order:first-leg:pricing-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: '分页查询本企业海外仓派送单' },
|
|
],
|
|
},
|
|
{
|
|
key: 'overseas-warehouse',
|
|
label: '海外仓业务',
|
|
items: [
|
|
{ code: 'merchant:warehouse:inbound:list', label: '查看海外入库单', description: '查看本企业海外仓入库订单列表和详情' },
|
|
{ code: 'merchant:overseas-warehouse:last-mile-order:list', label: '查看海外尾程订单', description: '查看本企业尾程订单列表和详情' },
|
|
{ code: 'merchant:overseas-warehouse:relabel:list', label: '查看贴标申请', description: '查看本企业贴标申请列表和详情' },
|
|
{ code: 'merchant:overseas-warehouse:relabel:create', label: '创建贴标申请', description: '使用本企业可用库存创建贴标申请' },
|
|
{ code: 'merchant:overseas-warehouse:relabel:files', label: '管理贴标文件', description: '上传本企业贴标申请的面单和明细文件' },
|
|
{ code: 'merchant:overseas-warehouse:relabel:confirm', label: '确认贴标完成', description: '确认仓库完成的贴标结果并继续出库' },
|
|
{ code: 'merchant:overseas-warehouse:transfer:list', label: '查看仓储转运', description: '查看本企业仓储转运单列表和详情' },
|
|
{ code: 'merchant:overseas-warehouse:transfer:create', label: '创建仓储转运', description: '创建和提交本企业仓储转运单' },
|
|
{ code: 'merchant:overseas-warehouse:transfer:confirm', label: '确认转运实测', description: '确认仓库回传的箱数、尺寸、重量和打托数据' },
|
|
{ code: 'merchant:overseas-warehouse:discard:list', label: '查看货物废弃', description: '查看本企业货物废弃申请列表和详情' },
|
|
{ code: 'merchant:overseas-warehouse:discard:create', label: '创建货物废弃', description: '使用本企业可用库存创建废弃申请' },
|
|
{ code: 'merchant:overseas-warehouse:discard:confirm', label: '确认废弃完成', description: '核对本企业废弃现场照片并确认完结' },
|
|
{ code: 'merchant:overseas-warehouse:discard:cancel', label: '取消货物废弃', description: '取消本企业尚未审核的废弃申请' },
|
|
{ code: 'merchant:overseas-warehouse:return-order:list', label: '查看退货预报', description: '查看本企业退货预报和仓库签收结果' },
|
|
{ code: 'merchant:overseas-warehouse:return-order:create', label: '创建退货预报', description: '创建本企业退货 SKU 和数量预报' },
|
|
{ code: 'merchant:overseas-warehouse:return-order:relabel', label: '退货转换标', description: '将已签收退货库存转换为换标申请' },
|
|
{ code: 'merchant:overseas-warehouse:return-inventory:list', label: '查看退货库存', description: '查看本企业退货 SKU 库存和箱号明细' },
|
|
],
|
|
},
|
|
{
|
|
key: 'cross-border',
|
|
label: '海外业务',
|
|
items: [
|
|
{ code: 'merchant:cross-border:procurement:list', label: '查看海外采购', description: '查看本企业海外采购订单列表和详情' },
|
|
{ code: 'merchant:cross-border:procurement:create', label: '创建海外采购', description: '创建本企业海外采购订单' },
|
|
{ code: 'merchant:cross-border:domestic-trucking:list', label: '查看美国本土卡', description: '查看本企业美国本土卡订单' },
|
|
{ code: 'merchant:cross-border:domestic-trucking:create', label: '创建美国本土卡', description: '创建本企业美国本土卡订单' },
|
|
{ code: 'merchant:cross-border:domestic-trucking:edit', label: '编辑美国本土卡', description: '编辑本企业允许修改的美国本土卡订单' },
|
|
{ code: 'merchant:cross-border:pallet-shipping:list', label: '查看美本土散板', description: '查看本企业美本土散板订单' },
|
|
{ code: 'merchant:cross-border:pallet-shipping:create', label: '创建美本土散板', description: '创建本企业美本土散板订单' },
|
|
{ code: 'merchant:cross-border:pallet-shipping:edit', 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[]>> = {
|
|
'merchant:finance:account:view': ['merchant:finance:account:view'],
|
|
'merchant:finance:recharge:create': ['merchant:finance:recharge:create'],
|
|
'order:first-leg:list': ['merchant:order:list', 'merchant:order:view'],
|
|
'order:first-leg:customs-list': ['merchant:order:list', 'merchant:order:view'],
|
|
'order:first-leg:pricing-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'],
|
|
'merchant:warehouse:delivery:list': ['merchant:warehouse:delivery:list'],
|
|
'merchant:warehouse:inbound:list': ['merchant:warehouse:inbound:list'],
|
|
'merchant:overseas-warehouse:return-inventory:list': ['merchant:overseas-warehouse:return-inventory:list'],
|
|
'merchant:overseas-warehouse:last-mile-order:list': ['merchant:overseas-warehouse:last-mile-order:list'],
|
|
'merchant:overseas-warehouse:relabel:list': ['merchant:overseas-warehouse:relabel:list'],
|
|
'merchant:overseas-warehouse:relabel:create': ['merchant:overseas-warehouse:relabel:create'],
|
|
'merchant:overseas-warehouse:relabel:files': ['merchant:overseas-warehouse:relabel:files'],
|
|
'merchant:overseas-warehouse:relabel:confirm': ['merchant:overseas-warehouse:relabel:confirm'],
|
|
'merchant:overseas-warehouse:transfer:list': ['merchant:overseas-warehouse:transfer:list'],
|
|
'merchant:overseas-warehouse:transfer:create': ['merchant:overseas-warehouse:transfer:create'],
|
|
'merchant:overseas-warehouse:transfer:confirm': ['merchant:overseas-warehouse:transfer:confirm'],
|
|
'merchant:overseas-warehouse:discard:list': ['merchant:overseas-warehouse:discard:list'],
|
|
'merchant:overseas-warehouse:discard:create': ['merchant:overseas-warehouse:discard:create'],
|
|
'merchant:overseas-warehouse:discard:confirm': ['merchant:overseas-warehouse:discard:confirm'],
|
|
'merchant:overseas-warehouse:discard:cancel': ['merchant:overseas-warehouse:discard:cancel'],
|
|
'merchant:overseas-warehouse:return-order:list': ['merchant:overseas-warehouse:return-order:list'],
|
|
'merchant:overseas-warehouse:return-order:create': ['merchant:overseas-warehouse:return-order:create'],
|
|
'merchant:overseas-warehouse:return-order:relabel': ['merchant:overseas-warehouse:return-order:relabel'],
|
|
'merchant:cross-border:procurement:list': ['merchant:cross-border:procurement:list'],
|
|
'merchant:cross-border:procurement:create': ['merchant:cross-border:procurement:create'],
|
|
'merchant:cross-border:domestic-trucking:list': ['merchant:cross-border:domestic-trucking:list'],
|
|
'merchant:cross-border:domestic-trucking:create': ['merchant:cross-border:domestic-trucking:create'],
|
|
'merchant:cross-border:domestic-trucking:edit': ['merchant:cross-border:domestic-trucking:edit'],
|
|
'merchant:cross-border:pallet-shipping:list': ['merchant:cross-border:pallet-shipping:list'],
|
|
'merchant:cross-border:pallet-shipping:create': ['merchant:cross-border:pallet-shipping:create'],
|
|
'merchant:cross-border:pallet-shipping:edit': ['merchant:cross-border:pallet-shipping:edit'],
|
|
'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))
|
|
}
|