/** * Purpose: MANAGE_MODULES supports permission.js by holding or executing the manage modules page or API role. * Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow. */ const MANAGE_MODULES = [ { key: 'users', title: '用户管理', description: '用户资料、停用删除、解绑、余额与 VIP', path: '/pages/users/index', permissionCodes: ['user:view'], requiresShopContext: false }, { key: 'products', title: '作品管理', description: '作品新增、编辑、图片上传、点赞收藏维护', path: '/pages/products/index', permissionCodes: ['product:view'], requiresShopContext: true }, { key: 'coupons', title: '优惠券', description: '普通券、VIP 自动券、发放与活动配置', path: '/pages/coupons/index', permissionCodes: ['coupon:view'], requiresShopContext: true }, { key: 'comments', title: '评论管理', description: '查看作品评论与回复,删除不合规内容', path: '/pages/comments/index', permissionCodes: ['comment:view'], requiresShopContext: true }, { key: 'tags', title: '标签管理', description: '店铺标签、颜色配置与作品关联', path: '/pages/tags/index', permissionCodes: ['tag:view'], requiresShopContext: true }, { key: 'artists', title: '美甲师', description: '美甲师资料、档期信息与作品绑定', path: '/pages/artists/index', permissionCodes: ['nail_artist:view'], requiresShopContext: true }, { key: 'schedules', title: '排班管理', description: '查看和维护美甲师班次、休息日与预约容量', path: '/pages/schedules/index', permissionCodes: ['schedule:view'], requiresShopContext: true }, { key: 'afterSales', title: '售后处理', description: '查看售后申请,完成同意、驳回和处理说明', path: '/pages/after-sales/index', permissionCodes: ['after_sale:view'], requiresShopContext: true }, { key: 'inventory', title: '库存管理', description: '查看耗材库存、预警并快速调整入库出库', path: '/pages/inventory/index', permissionCodes: ['inventory:view'], requiresShopContext: true }, { key: 'campaigns', title: '活动管理', description: '查看营销活动、推荐位和轻量活动配置', path: '/pages/campaigns/index', permissionCodes: ['campaign:view'], requiresShopContext: true }, { key: 'shops', title: '店铺管理', description: '门店创建、启停、轮播图与店铺信息维护', path: '/pages/shops/index', permissionCodes: ['shop:view'], requiresShopContext: false }, { key: 'permissions', title: '权限管理', description: '权限字典、用户授权与范围控制', path: '/pages/permissions/index', permissionCodes: ['permission:view'], requiresShopContext: false }, { key: 'systemMessages', title: '系统消息', description: '发布消息、查看弹窗配置和业务跳转信息', path: '/pages/system-messages/index', permissionCodes: ['message:view'], requiresShopContext: false }, { key: 'securityAudit', title: '审计日志', description: '查看高危操作的成功、失败原因与操作者', path: '/pages/security-audit/index', permissionCodes: ['security:audit:view'], requiresShopContext: false } ] /** * Purpose: getPermissionCodes supports permission.js by holding or executing the get permission codes page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function getPermissionCodes(source) { const list = Array.isArray(source) ? source : [] return list .map(item => { if (typeof item === 'string') { return item } return item && item.permissionCode ? item.permissionCode : '' }) .filter(Boolean) } /** * Purpose: hasPermission supports permission.js by holding or executing the has permission page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function hasPermission(source, permissionCode) { if (!permissionCode) { return true } const codes = getPermissionCodes(source) return codes.includes(permissionCode) } /** * Purpose: hasAnyPermission supports permission.js by holding or executing the has any permission page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function hasAnyPermission(source, permissionCodes) { const codes = Array.isArray(permissionCodes) ? permissionCodes : [] if (!codes.length) { return true } return codes.some(code => hasPermission(source, code)) } /** * Purpose: hasAllPermissions supports permission.js by holding or executing the has all permissions page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function hasAllPermissions(source, permissionCodes) { const codes = Array.isArray(permissionCodes) ? permissionCodes : [] if (!codes.length) { return true } return codes.every(code => hasPermission(source, code)) } /** * Purpose: isPlatformAdmin supports permission.js by holding or executing the is platform admin page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function isPlatformAdmin(userInfo) { return Number(userInfo && userInfo.type) === 4 } /** * Purpose: isShopManager supports permission.js by holding or executing the is shop manager page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function isShopManager(userInfo) { return Number(userInfo && userInfo.type) === 2 } /** * Purpose: isNailArtist supports permission.js by holding or executing the is nail artist page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function isNailArtist(userInfo) { return Number(userInfo && userInfo.type) === 3 } /** * Purpose: getRoleLabel supports permission.js by holding or executing the get role label page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function getRoleLabel(type) { const value = Number(type) if (value === 4) { return '平台管理员' } if (value === 2) { return '店长' } if (value === 3) { return '美甲师' } return '用户' } /** * Purpose: groupPermissionsByGroup supports permission.js by holding or executing the group permissions by group page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function groupPermissionsByGroup(permissions) { return (Array.isArray(permissions) ? permissions : []).reduce((result, item) => { const group = item && item.permissionGroup ? item.permissionGroup : '未分组' if (!result[group]) { result[group] = [] } result[group].push(item) return result }, {}) } /** * Purpose: checkModuleAccess supports permission.js by holding or executing the check module access page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function checkModuleAccess(module, userInfo, permissionCodes, currentShop) { if (!hasAnyPermission(permissionCodes, module.permissionCodes)) { return { allowed: false, reason: '当前账号没有该板块权限' } } if (module.requiresShopContext && !currentShop) { if (isPlatformAdmin(userInfo)) { return { allowed: true, reason: '平台总览模式下该模块仅可查看,编辑操作已关闭', readonly: true } } return { allowed: false, reason: '当前账号没有可用店铺' } } return { allowed: true, reason: '' } } /** * Purpose: getManageModules supports permission.js by holding or executing the get manage modules page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function getManageModules(userInfo, permissionCodes, currentShop) { return MANAGE_MODULES.map(module => { const access = checkModuleAccess(module, userInfo, permissionCodes, currentShop) return { ...module, allowed: access.allowed, readonly: Boolean(access.readonly), disabledReason: access.reason } }) } module.exports = { MANAGE_MODULES, getPermissionCodes, hasPermission, hasAnyPermission, hasAllPermissions, isPlatformAdmin, isShopManager, isNailArtist, getRoleLabel, groupPermissionsByGroup, checkModuleAccess, getManageModules }