Files
SupplierSystem/miniprogram/pages/notifications/notifications.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

108 lines
3.2 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.
const {
fetchNotifications,
markAllNotificationsRead,
} = require('../../utils/request');
const { MOBILE_MODULES } = require('../../modules/registry');
const { resolveNotificationModule } = require('../../utils/notificationModuleMap');
/** 通知页不感知首页可见性:以全部注册模块作为候选,最终由工作台按角色校验 */
const ALL_MODULE_IDS = MOBILE_MODULES.map((mod) => mod.id);
/** 拆分订单号/SKU(小号)与核心问题(突出换行) */
function splitNotificationContent(raw, relatedOrderCode) {
const original = String(raw || '').trim();
let text = original;
const metaParts = [];
const orderMatch =
text.match(/\b(ORD[_A-Z0-9]+)\b/i) ||
text.match(/(?:订单)\s*[::]?\s*([A-Z0-9_-]+)/i);
const orderCode =
(orderMatch && orderMatch[1]) ||
(relatedOrderCode ? String(relatedOrderCode).trim() : '');
if (orderCode) {
metaParts.push(orderCode);
text = text
.replace(/\bORD[_A-Z0-9]+\b/gi, ' ')
.replace(/(?:订单)\s*[::]?\s*[A-Z0-9_-]+/gi, ' ');
}
const skuMatch = text.match(/\b(SKU[A-Z0-9_-]*)\b/i) || text.match(/(?:SKU)\s*[::]?\s*([A-Z0-9_-]+)/i);
if (skuMatch && skuMatch[1]) {
metaParts.push(skuMatch[1]);
text = text
.replace(/\bSKU[A-Z0-9_-]*\b/gi, ' ')
.replace(/(?:SKU)\s*[::]?\s*[A-Z0-9_-]+/gi, ' ');
}
text = text
.replace(/[//||]+/g, ' ')
.replace(/[::]\s*/g, ' ')
.replace(/\b商品\b/g, ' ')
.replace(/\s{2,}/g, ' ')
.replace(/^[\s\-–—·,,、]+|[\s\-–—·,,、]+$/g, '')
.trim();
return {
displayMeta: metaParts.join(' · '),
displayContent: text || original,
};
}
Page({
data: {
loading: true,
rows: [],
unreadCount: 0,
},
onShow() {
this.load();
},
async load() {
this.setData({ loading: true });
try {
const notifications = await fetchNotifications();
this.setData({
rows: (notifications.data || []).map((row) => {
const split = splitNotificationContent(row.content, row.related_order_code);
return {
...row,
displayMeta: split.displayMeta,
displayContent: split.displayContent,
displayTime: row.created_at ? new Date(row.created_at).toLocaleString() : '',
};
}),
unreadCount: Number(notifications.unread_count) || 0,
});
} catch (error) {
wx.showToast({ title: error.message || '加载失败', icon: 'none' });
} finally {
this.setData({ loading: false });
}
},
async markAllRead() {
try {
await markAllNotificationsRead();
await this.load();
} catch (error) {
wx.showToast({ title: error.message || '操作失败', icon: 'none' });
}
},
onNotificationTap(e) {
const type = String(e.currentTarget.dataset.type || '').trim();
if (!type) return;
// 通用直达:通知类型 → 工作台模块(含角色自动切换),由工作台统一落地
const moduleId = resolveNotificationModule(type, ALL_MODULE_IDS);
if (moduleId) {
wx.reLaunch({ url: `/pages/home/home?module=${encodeURIComponent(moduleId)}` });
return;
}
wx.showToast({ title: '该消息暂无对应入口', icon: 'none' });
},
});