Files
SupplierSystem/miniprogram/modules/registry.js
T
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库: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 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

424 lines
14 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 小程序业务模块注册表:新增移动端能力在此追加。
* 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: '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',
},
];
/** 首页合并展示时的稳定排序 */
const MODULE_SORT_ORDER = [
'delivery',
'order-manage',
'admin-preparations',
'admin-purchase',
'purchase',
'prep-amend-review',
'cost-management',
'order-entry',
'inspection',
'stock-inbound',
'processing',
'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;
if (mod.currentRoleOnly) {
if (mod.roles && !mod.roles.includes(currentRole)) return false;
} else {
if (mod.roleOnly && mod.roleOnly !== roleType) return false;
if (mod.roles && !mod.roles.includes(roleType)) return false;
}
if (mod.permissionKey) {
const perms = pageData.permissions || [];
if (!pageData.isSuperAdmin && !perms.includes(mod.permissionKey)) 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) {
if (!mod || !mod.homeEmbed) return false;
const roles = new Set(normalizeRoleList(availableRoles, fallbackRole));
const embedRoles = Array.isArray(mod.homeEmbedRoles) ? mod.homeEmbedRoles : mod.roles;
return Array.isArray(embedRoles) && embedRoles.some((role) => roles.has(role));
}
module.exports = {
MOBILE_MODULES,
MODULE_SORT_ORDER,
buildVisibleModules,
buildUnionModules,
normalizeRoleList,
resolveDisplayMobileRoles,
findModuleById,
getHomeEmbedModules,
filterModulesForHomeGrid,
isHomeWorkspaceModule,
};