order_customer 只能看自己 customer_portal_users 绑定订单;首页内嵌 customer-trace-panel;不返回内部字段。
464 lines
16 KiB
JavaScript
464 lines
16 KiB
JavaScript
/**
|
||
* 小程序业务模块注册表:新增移动端能力在此追加。
|
||
* badgeKey 只声明“该模块有角标数据源”;具体拉取由 utils/badgeCenter.js 按当前角色上下文成功后才写入。
|
||
*/
|
||
const MOBILE_MODULES = [
|
||
{
|
||
id: 'order-manage',
|
||
title: '订单列表',
|
||
subtitle: '查看、推进与修改订单(删除请用电脑网页端)',
|
||
page: '/pages/order-manage/order-manage',
|
||
roles: ['admin', 'operator'],
|
||
permissionKey: 'order_manage',
|
||
badgeKey: 'orderPickingPendingCount',
|
||
handler: 'goOrderManage',
|
||
homeEmbed: 'order-manage-panel',
|
||
},
|
||
{
|
||
id: 'admin-preparations',
|
||
title: '供备货表',
|
||
subtitle: '按供应商查看备货、改价、代完成、无货转自采',
|
||
page: '/pages/admin-preparations/admin-preparations',
|
||
roles: ['admin', 'operator'],
|
||
permissionKey: 'preparation_manage',
|
||
badgeKey: 'adminPrepPendingBadgeCount',
|
||
handler: 'goAdminPreparations',
|
||
homeEmbed: 'admin-preparations-panel',
|
||
},
|
||
{
|
||
id: 'admin-purchase',
|
||
title: '自采列表',
|
||
subtitle: '分公司全部待采:完成、转供应商、加单改单',
|
||
page: '/pages/admin-purchase/admin-purchase',
|
||
roles: ['admin', 'operator'],
|
||
badgeKey: 'adminPurchasePendingBadgeCount',
|
||
handler: 'goAdminPurchase',
|
||
homeEmbed: 'purchase-today-panel',
|
||
},
|
||
{
|
||
id: 'delivery',
|
||
title: '配送任务',
|
||
subtitle: '验货上车、查看配送单、开始与结束配送',
|
||
page: '/pages/delivery/delivery',
|
||
roles: ['delivery'],
|
||
featureFlag: 'deliveryEnabled',
|
||
handler: 'goDelivery',
|
||
homeEmbed: 'delivery-panel',
|
||
badgeKey: 'deliveryPendingBadgeCount',
|
||
},
|
||
{
|
||
id: 'picking',
|
||
title: '分拣',
|
||
subtitle: '扫码复核分拣、提交出库',
|
||
page: '/pages/picking/picking',
|
||
roles: ['picker', 'delivery'],
|
||
featureFlag: 'pickingEnabled',
|
||
badgeKey: 'pickingPendingTaskCount',
|
||
handler: 'goPicking',
|
||
homeEmbed: 'picking-panel',
|
||
homeEmbedRoles: ['picker'],
|
||
},
|
||
{
|
||
id: 'purchase',
|
||
title: '自采列表',
|
||
subtitle: '按分类查看今日待采购商品',
|
||
page: '/pages/purchase/purchase',
|
||
roles: ['purchaser'],
|
||
badgeKey: 'purchasePendingBadgeCount',
|
||
handler: 'goPurchase',
|
||
homeEmbed: 'purchase-today-panel',
|
||
},
|
||
{
|
||
id: 'supplier-status',
|
||
title: '供应商完成状态',
|
||
subtitle: '查看各供应商供货任务是否已完成',
|
||
page: '/pages/supplier-status/supplier-status',
|
||
roles: ['purchaser'],
|
||
featureFlag: 'supplierStatusEnabled',
|
||
dynamicSubtitleKey: 'oneClickSupplierInspectionEnabled',
|
||
handler: 'goSupplierStatus',
|
||
homeEmbed: 'supplier-status-panel',
|
||
},
|
||
{
|
||
id: 'prep-amend-review',
|
||
title: '改价待审',
|
||
subtitle: '确认或驳回供应商追加修改,确认后才计入成本结算',
|
||
page: '/pages/prep-amend-review/prep-amend-review',
|
||
roles: ['admin', 'operator', 'purchaser'],
|
||
badgeKey: 'prepAmendPendingCount',
|
||
handler: 'goPrepAmendReview',
|
||
homeEmbed: 'prep-amend-panel',
|
||
},
|
||
{
|
||
id: 'preparation',
|
||
title: '供货录入',
|
||
subtitle: '查看并完成待供货商品',
|
||
page: '/pages/preparation/preparation',
|
||
roles: ['supplier'],
|
||
badgeKey: 'preparationTaskCount',
|
||
handler: 'goPreparation',
|
||
homeEmbed: 'preparation-panel',
|
||
},
|
||
{
|
||
id: 'prep-history',
|
||
title: '历史订单',
|
||
subtitle: '按周期查看已完成供货',
|
||
page: '/pages/preparation/preparation?tab=archived',
|
||
roles: ['supplier'],
|
||
handler: 'goPreparationHistory',
|
||
homeEmbed: 'preparation-panel',
|
||
},
|
||
{
|
||
id: 'prep-price-amend',
|
||
title: '修改价格',
|
||
subtitle: '完成供货后时限内改价,待管理员确认',
|
||
page: '/pages/preparation/preparation?tab=price_amend',
|
||
roles: ['supplier'],
|
||
featureFlag: 'supplierPriceAmendEnabled',
|
||
badgeKey: 'prepPriceAmendCount',
|
||
handler: 'goPreparationPriceAmend',
|
||
homeEmbed: 'preparation-panel',
|
||
},
|
||
{
|
||
id: 'bid',
|
||
title: '竞价报价',
|
||
subtitle: '查看邀约并在时限内提交报价,超时本轮出局',
|
||
page: '/pages/bid/bid',
|
||
roles: ['supplier'],
|
||
featureFlag: 'bidEnabled',
|
||
badgeKey: 'bidPendingQuoteCount',
|
||
handler: 'goBid',
|
||
homeEmbed: 'bid-panel',
|
||
},
|
||
{
|
||
id: 'quality-reports',
|
||
title: '报告上传',
|
||
subtitle: '上传与查看检验报告,入库后显示溯源批次',
|
||
page: '/pages/quality-reports/quality-reports',
|
||
roles: ['supplier'],
|
||
badgeKey: 'qualityReportPendingCount',
|
||
handler: 'goQualityReports',
|
||
homeEmbed: 'quality-reports-panel',
|
||
},
|
||
{
|
||
id: 'inspection',
|
||
title: '订单入库',
|
||
subtitle: '拍照验收、确认数量与结果后入库',
|
||
page: '/pages/inspection/inspection',
|
||
roles: ['warehouse', 'inspector'],
|
||
permissionKey: 'inspection_manage',
|
||
badgeKey: 'inspectionPendingBadgeCount',
|
||
handler: 'goInspection',
|
||
homeEmbed: 'inspection-panel',
|
||
},
|
||
{
|
||
id: 'stock-inbound',
|
||
title: '库存入库',
|
||
subtitle: '无订单进仓:选品/新建后入库',
|
||
page: '/pages/stock-inbound/stock-inbound',
|
||
roles: ['warehouse', 'inspector'],
|
||
permissionKey: 'inventory_manage',
|
||
handler: 'goStockInbound',
|
||
homeEmbed: 'stock-inbound-panel',
|
||
},
|
||
{
|
||
id: 'processing',
|
||
title: '加工',
|
||
subtitle: '需加工商品加工作业、拍照验收',
|
||
page: '/pages/processing/processing',
|
||
roles: ['warehouse', 'inspector'],
|
||
permissionKey: 'processing_manage',
|
||
handler: 'goProcessing',
|
||
homeEmbed: 'processing-panel',
|
||
badgeKey: 'processingPendingCount',
|
||
},
|
||
{
|
||
id: 'warehouse',
|
||
title: '仓库管理',
|
||
subtitle: '库存批次、成本价与报告状态,可批量上传报告',
|
||
page: '/pages/warehouse/warehouse',
|
||
// 默认给仓管;其他角色由管理员在「角色权限」勾 warehouse_manage 后可用(grantable)
|
||
roles: ['warehouse'],
|
||
grantable: true,
|
||
permissionKey: 'warehouse_manage',
|
||
handler: 'goWarehouse',
|
||
// 与其它模块一致:作为首页一级 Tab 内嵌同一套面板
|
||
homeEmbed: 'warehouse-panel',
|
||
},
|
||
{
|
||
id: 'order-entry',
|
||
title: '录单',
|
||
subtitle: '语音/图片/文字录入客户订单',
|
||
page: '/pages/order-entry/order-entry',
|
||
roles: ['order_entry'],
|
||
roleOnly: 'order_entry',
|
||
// 录单台是否可见由后端 available_roles 决定:operator + customer_order 也算可录单;
|
||
// 不再单点要求 order_entry 权限,避免把这类录单员误隐藏。
|
||
handler: 'goOrderEntry',
|
||
homeEmbed: 'order-entry-panel',
|
||
},
|
||
{
|
||
id: 'cost-management',
|
||
title: '成本录入',
|
||
subtitle: '录入其他成本、查看自己的历史',
|
||
page: '/pages/cost-management/cost-management',
|
||
roles: ['purchaser', 'delivery'],
|
||
permissionKey: 'mp_purchaser_free_cost',
|
||
handler: 'goCostManagement',
|
||
homeEmbed: 'cost-management-panel',
|
||
},
|
||
{
|
||
id: 'product-trace',
|
||
title: '商品溯源',
|
||
subtitle: '按批次/订单查询,可扫公开码',
|
||
page: '/pages/trace/trace',
|
||
// 仅管理员(含超管)使用;不再按内部角色/权限点下放
|
||
roles: ['admin'],
|
||
handler: 'goProductTrace',
|
||
homeEmbed: 'product-trace-panel',
|
||
},
|
||
{
|
||
id: 'customer-trace',
|
||
title: '商品溯源',
|
||
subtitle: '查看您订单的商品、实收、照片与报告',
|
||
page: '/pages/home/home',
|
||
roles: ['order_customer'],
|
||
homeEmbed: 'customer-trace-panel',
|
||
},
|
||
{
|
||
id: 'mall',
|
||
title: '下单',
|
||
subtitle: '选购商品并下单',
|
||
page: '/pages/home/home',
|
||
roles: ['order_customer'],
|
||
homeEmbed: 'mall-panel',
|
||
},
|
||
];
|
||
|
||
/** 首页合并展示时的稳定排序 */
|
||
const MODULE_SORT_ORDER = [
|
||
'delivery',
|
||
'order-manage',
|
||
'admin-preparations',
|
||
'admin-purchase',
|
||
'purchase',
|
||
'prep-amend-review',
|
||
'cost-management',
|
||
'order-entry',
|
||
'inspection',
|
||
'stock-inbound',
|
||
'processing',
|
||
'warehouse',
|
||
'picking',
|
||
'supplier-status',
|
||
'preparation',
|
||
'prep-history',
|
||
'prep-price-amend',
|
||
'bid',
|
||
'quality-reports',
|
||
'product-trace',
|
||
];
|
||
|
||
function isModuleVisible(mod, pageData) {
|
||
if (mod.id === 'quality-reports') return false;
|
||
const roleType = pageData.roleType;
|
||
const currentRole = pageData.currentRoleType || roleType;
|
||
const perms = pageData.permissions || [];
|
||
const permissionHit =
|
||
Boolean(mod.permissionKey) && (pageData.isSuperAdmin === true || perms.includes(mod.permissionKey));
|
||
const roleHit = mod.currentRoleOnly
|
||
? !mod.roles || mod.roles.includes(currentRole)
|
||
: (!mod.roleOnly || mod.roleOnly === roleType) && (!mod.roles || mod.roles.includes(roleType));
|
||
if (mod.grantable) {
|
||
// 可授权模块(2026-10-23 仓库管理):角色命中 **或** 权限命中即可见;
|
||
// 其它模块保持原来的「角色 AND 权限」语义,行为不变。
|
||
if (!roleHit && !permissionHit) return false;
|
||
} else {
|
||
if (!roleHit) return false;
|
||
if (mod.permissionKey && !permissionHit) return false;
|
||
}
|
||
if (mod.featureFlag === 'supplierStatusEnabled' && !pageData.supplierStatusEnabled) return false;
|
||
if (mod.featureFlag === 'pickingEnabled') {
|
||
if (roleType === 'picker') return true;
|
||
if (!pageData.pickingEnabled) return false;
|
||
}
|
||
if (mod.featureFlag === 'deliveryEnabled' && pageData.deliveryEnabled === false) return false;
|
||
if (mod.featureFlag === 'bidEnabled' && !pageData.bidEnabled) return false;
|
||
if (mod.featureFlag === 'supplierPriceAmendEnabled' && !pageData.supplierPriceAmendEnabled) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
function resolveTitle(mod, pageData) {
|
||
if (mod.id === 'cost-management') {
|
||
const role = pageData.currentRoleType || pageData.roleType;
|
||
if (role === 'delivery') return '其他费用';
|
||
}
|
||
return mod.title;
|
||
}
|
||
|
||
function resolveSubtitle(mod, pageData) {
|
||
if (mod.id === 'inspection' && pageData.photoInspectionEnabled) {
|
||
return '拍照验收、确认数量与结果后入库';
|
||
}
|
||
if (mod.id === 'inspection') {
|
||
return '确认数量与结果后完成入库';
|
||
}
|
||
if (mod.id === 'supplier-status' && pageData.oneClickSupplierInspectionEnabled) {
|
||
return '查看供货进度,可一键验收供应商到货';
|
||
}
|
||
return mod.subtitle;
|
||
}
|
||
|
||
function normalizeRoleList(availableRoles, fallbackRole) {
|
||
const list = (availableRoles || [])
|
||
.map((item) => (typeof item === 'string' ? item : item && (item.role_type || item.value)))
|
||
.map((role) => String(role || '').trim())
|
||
.filter(Boolean);
|
||
if (list.length) return [...new Set(list)];
|
||
const fallback = String(fallbackRole || '').trim();
|
||
return fallback ? [fallback] : [];
|
||
}
|
||
|
||
const INTERNAL_STAFF_ROLES = ['admin', 'operator', 'warehouse', 'inspector', 'picker', 'order_entry'];
|
||
|
||
/**
|
||
* 首页展示角色不做硬改写:operator 不再被当成录单员。
|
||
* 仅补一条显示过滤:内部员工账号被绑了供应商档案,但没分配供应商管理/供货权限时,不出供应商模块;
|
||
* 纯供应商门户账号不含内部角色,不受影响。
|
||
*/
|
||
function resolveDisplayMobileRoles(availableRoles, fallbackRole, ctx) {
|
||
const roles = normalizeRoleList(availableRoles, fallbackRole);
|
||
const roleType = String(fallbackRole || '').trim();
|
||
if (!roles.length) return { roles, roleType };
|
||
|
||
const perms = Array.isArray(ctx?.permissions) ? ctx.permissions : [];
|
||
const isSuperAdmin = ctx?.is_super_admin === true || ctx?.isSuperAdmin === true;
|
||
const hasInternalStaff = roles.some((role) => INTERNAL_STAFF_ROLES.includes(role));
|
||
let next = roles;
|
||
if (
|
||
hasInternalStaff &&
|
||
!isSuperAdmin &&
|
||
next.includes('supplier') &&
|
||
!perms.includes('supplier_manage') &&
|
||
!perms.includes('supplier_supply_manage')
|
||
) {
|
||
next = next.filter((role) => role !== 'supplier');
|
||
}
|
||
|
||
return {
|
||
roles: next,
|
||
roleType: next.includes(roleType) ? roleType : next[0] || roleType,
|
||
};
|
||
}
|
||
|
||
function buildVisibleModules(pageData) {
|
||
return MOBILE_MODULES.filter((mod) => isModuleVisible(mod, pageData)).map((mod) => ({
|
||
...mod,
|
||
title: resolveTitle(mod, pageData),
|
||
subtitle: resolveSubtitle(mod, pageData),
|
||
badge: mod.badgeKey ? pageData[mod.badgeKey] || 0 : 0,
|
||
}));
|
||
}
|
||
|
||
/**
|
||
* 按账号 available_roles 合并可见模块(id 去重)。
|
||
* 用于取消「切换工作台」后的管理员等身兼多角色首页。
|
||
*/
|
||
function buildUnionModules(pageData, availableRoles) {
|
||
const resolved = resolveDisplayMobileRoles(
|
||
availableRoles,
|
||
pageData && pageData.roleType,
|
||
pageData
|
||
);
|
||
const roles = resolved.roles;
|
||
if (!roles.length) return buildVisibleModules(pageData || {});
|
||
|
||
const byId = new Map();
|
||
for (const roleType of roles) {
|
||
const mods = buildVisibleModules({
|
||
...(pageData || {}),
|
||
roleType,
|
||
currentRoleType: (pageData && pageData.currentRoleType) || (pageData && pageData.roleType),
|
||
});
|
||
for (const mod of mods) {
|
||
const prev = byId.get(mod.id);
|
||
if (!prev) {
|
||
byId.set(mod.id, { ...mod });
|
||
continue;
|
||
}
|
||
byId.set(mod.id, {
|
||
...prev,
|
||
badge: Math.max(Number(prev.badge) || 0, Number(mod.badge) || 0),
|
||
title: resolveTitle(prev, { ...(pageData || {}), roleType: pageData.roleType || roleType, currentRoleType: pageData.currentRoleType || pageData.roleType }),
|
||
subtitle: resolveSubtitle(prev, { ...(pageData || {}), roleType: pageData.roleType || roleType }),
|
||
});
|
||
}
|
||
}
|
||
|
||
let list = [...byId.values()];
|
||
if (roles.includes('admin') || roles.includes('operator')) {
|
||
list = list.filter((mod) => mod.id !== 'admin-purchase');
|
||
}
|
||
|
||
const orderIndex = new Map(MODULE_SORT_ORDER.map((id, idx) => [id, idx]));
|
||
return list.sort((a, b) => {
|
||
const ai = orderIndex.has(a.id) ? orderIndex.get(a.id) : 999;
|
||
const bi = orderIndex.has(b.id) ? orderIndex.get(b.id) : 999;
|
||
if (ai !== bi) return ai - bi;
|
||
return String(a.title || '').localeCompare(String(b.title || ''), 'zh');
|
||
});
|
||
}
|
||
|
||
function findModuleById(id) {
|
||
return MOBILE_MODULES.find((mod) => mod.id === id) || null;
|
||
}
|
||
|
||
/** 当前账号应在首页内嵌的业务面板(优先 homeEmbedRoles,否则模块 roles) */
|
||
function getHomeEmbedModules(availableRoles, fallbackRole) {
|
||
const roles = new Set(normalizeRoleList(availableRoles, fallbackRole));
|
||
if (!roles.size) return [];
|
||
return MOBILE_MODULES.filter((mod) => {
|
||
if (!mod.homeEmbed) return false;
|
||
const embedRoles = Array.isArray(mod.homeEmbedRoles) ? mod.homeEmbedRoles : mod.roles;
|
||
return Array.isArray(embedRoles) && embedRoles.some((role) => roles.has(role));
|
||
});
|
||
}
|
||
|
||
function filterModulesForHomeGrid(modules, availableRoles, fallbackRole) {
|
||
const embeds = getHomeEmbedModules(availableRoles, fallbackRole);
|
||
const hideIds = new Set(
|
||
embeds.filter((mod) => mod.hideFromGridWhenEmbedded).map((mod) => mod.id)
|
||
);
|
||
if (!hideIds.size) return modules || [];
|
||
return (modules || []).filter((mod) => !hideIds.has(mod.id));
|
||
}
|
||
|
||
/** 带 homeEmbed 且当前账号角色与模块 roles 有交集时,点击走首页底部切换 */
|
||
function isHomeWorkspaceModule(mod, availableRoles, fallbackRole, permissions) {
|
||
if (!mod || !mod.homeEmbed) return false;
|
||
const roles = new Set(normalizeRoleList(availableRoles, fallbackRole));
|
||
const embedRoles = Array.isArray(mod.homeEmbedRoles) ? mod.homeEmbedRoles : mod.roles;
|
||
if (Array.isArray(embedRoles) && embedRoles.some((role) => roles.has(role))) return true;
|
||
// 可授权模块(仓库管理):角色不命中但持入口权限 ⇒ 同样作为首页一级 Tab
|
||
if (mod.grantable === true && mod.permissionKey) {
|
||
const perms = Array.isArray(permissions) ? permissions : [];
|
||
return perms.includes(mod.permissionKey);
|
||
}
|
||
return false;
|
||
}
|
||
|
||
module.exports = {
|
||
MOBILE_MODULES,
|
||
MODULE_SORT_ORDER,
|
||
buildVisibleModules,
|
||
buildUnionModules,
|
||
normalizeRoleList,
|
||
resolveDisplayMobileRoles,
|
||
findModuleById,
|
||
getHomeEmbedModules,
|
||
filterModulesForHomeGrid,
|
||
isHomeWorkspaceModule,
|
||
};
|