来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
85 lines
3.2 KiB
JavaScript
85 lines
3.2 KiB
JavaScript
/**
|
|
* 通知类型 → 工作台模块映射(纯前端,供工作台角标与点击直达使用)。
|
|
* 候选按账号可见模块取首个命中,无命中则该通知不产生角标、不可直达。
|
|
* 见 docs/design/20260822-mp-home-notification-badges.md
|
|
*/
|
|
const NOTIFICATION_MODULE_MAP = {
|
|
// 备货:管理员视角「供应商备货表」,供应商视角「供货录入」
|
|
preparation_created: ['admin-preparations', 'preparation'],
|
|
// 自采:管理员「自采列表」,采购员「今日采购」
|
|
purchase_task_created: ['admin-purchase', 'purchase'],
|
|
// 验收
|
|
inspection_created: ['inspection', 'admin-preparations'],
|
|
inspection_rejected: ['inspection', 'admin-preparations'],
|
|
inspection_timeout: ['inspection', 'admin-preparations'],
|
|
// 分拣 / 配送
|
|
picking_task_created: ['picking'],
|
|
delivery_task_created: ['delivery'],
|
|
// 订单相关归口「订单列表」
|
|
order_delivered: ['order-manage'],
|
|
aftersale_created: ['order-manage'],
|
|
aftersale_rejected: ['order-manage'],
|
|
allocation_backup: ['order-manage'],
|
|
substitution_pending: ['order-manage'],
|
|
zero_sale_price: ['order-manage'],
|
|
// 供应商改价:待审(管理员)/ 被驳回(供应商追加改价)
|
|
supplier_prep_amend_pending: ['prep-amend-review'],
|
|
supplier_prep_amend_rejected: ['prep-price-amend', 'preparation'],
|
|
// 库存/入库
|
|
inventory_shortage: ['stock-inbound', 'inspection'],
|
|
pass_through_over_qty: ['stock-inbound', 'inspection'],
|
|
// 竞价
|
|
bid_round_opened: ['bid'],
|
|
};
|
|
|
|
/** 将账号可见模块 id 集合化 */
|
|
function toVisibleSet(visibleModuleIds) {
|
|
const set = new Set();
|
|
(visibleModuleIds || []).forEach((id) => {
|
|
const key = String(id || '').trim();
|
|
if (key) set.add(key);
|
|
});
|
|
return set;
|
|
}
|
|
|
|
/**
|
|
* 解析单条通知类型对应的工作台模块。
|
|
* @param {string} notifyType 通知类型
|
|
* @param {string[]|Set<string>} visibleModuleIds 账号当前可见模块 id
|
|
* @returns {string|null} 命中的模块 id;无命中返回 null
|
|
*/
|
|
function resolveNotificationModule(notifyType, visibleModuleIds) {
|
|
const candidates = NOTIFICATION_MODULE_MAP[String(notifyType || '').trim()];
|
|
if (!candidates || !candidates.length) return null;
|
|
const visible = visibleModuleIds instanceof Set ? visibleModuleIds : toVisibleSet(visibleModuleIds);
|
|
for (const moduleId of candidates) {
|
|
if (visible.has(moduleId)) return moduleId;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* 将「按类型的未读数」聚合为「按模块的未读数」。
|
|
* @param {Object<string, number>} unreadByType { notify_type: 未读数 }
|
|
* @param {string[]} visibleModuleIds 账号当前可见模块 id
|
|
* @returns {Object<string, number>} { moduleId: 未读数 }
|
|
*/
|
|
function resolveModuleMsgBadges(unreadByType, visibleModuleIds) {
|
|
const visible = toVisibleSet(visibleModuleIds);
|
|
const badges = {};
|
|
Object.keys(unreadByType || {}).forEach((notifyType) => {
|
|
const count = Number(unreadByType[notifyType]) || 0;
|
|
if (count <= 0) return;
|
|
const moduleId = resolveNotificationModule(notifyType, visible);
|
|
if (!moduleId) return;
|
|
badges[moduleId] = (badges[moduleId] || 0) + count;
|
|
});
|
|
return badges;
|
|
}
|
|
|
|
module.exports = {
|
|
NOTIFICATION_MODULE_MAP,
|
|
resolveNotificationModule,
|
|
resolveModuleMsgBadges,
|
|
};
|