来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
145 lines
4.1 KiB
TypeScript
145 lines
4.1 KiB
TypeScript
export interface NotificationNavigateInput {
|
|
id?: string;
|
|
title: string | null;
|
|
content: string | null;
|
|
notify_type: string | null;
|
|
related_order_code: string | null;
|
|
}
|
|
|
|
export interface NotificationNavigateTarget {
|
|
path: string;
|
|
search?: Record<string, string>;
|
|
}
|
|
|
|
function extractFirst(content: string | null, patterns: RegExp[]): string | null {
|
|
if (!content) return null;
|
|
for (const pattern of patterns) {
|
|
const match = content.match(pattern);
|
|
if (match?.[1]) return match[1];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function isExceptionTicketCode(code: string | null | undefined): boolean {
|
|
return Boolean(code && /^(EXP|EXC)/i.test(code));
|
|
}
|
|
|
|
export function resolveNotificationTarget(item: NotificationNavigateInput): NotificationNavigateTarget {
|
|
const title = item.title || '';
|
|
const content = item.content || '';
|
|
const notifyType = item.notify_type || '';
|
|
|
|
const orderCode =
|
|
item.related_order_code ||
|
|
extractFirst(content, [
|
|
/订单\s+([A-Za-z0-9_-]+)/,
|
|
/order\s+([A-Za-z0-9_-]+)/i,
|
|
]);
|
|
const purchaseCode = extractFirst(content, [/采购单\s+([A-Za-z0-9_-]+)/]);
|
|
const ticketCode =
|
|
(isExceptionTicketCode(item.related_order_code) ? item.related_order_code : null) ||
|
|
extractFirst(content, [/工单\s+([A-Za-z0-9_-]+)/]);
|
|
const quoteVersionCode = extractFirst(content, [/报价版本\s+([A-Za-z0-9_-]+)/]);
|
|
const taskCode = extractFirst(content, [/配送任务\s+([A-Za-z0-9_-]+)/]);
|
|
|
|
if (notifyType === 'inspection_rejected') {
|
|
return {
|
|
path: '/inspection/review',
|
|
search: orderCode ? { q: orderCode } : undefined,
|
|
};
|
|
}
|
|
|
|
if (notifyType === 'inventory_shortage') {
|
|
if (orderCode) {
|
|
return {
|
|
path: '/orders',
|
|
search: { q: orderCode, open: '1' },
|
|
};
|
|
}
|
|
return { path: '/inventory' };
|
|
}
|
|
|
|
if (
|
|
notifyType === 'supplier_prep_amend_pending' ||
|
|
notifyType === 'supplier_prep_amend_rejected' ||
|
|
title.includes('追加修改')
|
|
) {
|
|
const related = String(item.related_order_code || '').trim();
|
|
const isUuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(related);
|
|
const search: Record<string, string> = { amend: '1' };
|
|
if (isUuid) search.amend_id = related;
|
|
else if (related) search.q = related;
|
|
else if (orderCode && orderCode !== related) search.q = orderCode;
|
|
return { path: '/purchase/preparations', search };
|
|
}
|
|
|
|
if (notifyType === 'quote_approval') {
|
|
return {
|
|
path: '/customers/quote-versions',
|
|
search: quoteVersionCode ? { q: quoteVersionCode } : undefined,
|
|
};
|
|
}
|
|
|
|
if (notifyType === 'exception_escalation' || title.includes('异常')) {
|
|
const q = ticketCode || orderCode;
|
|
return {
|
|
path: '/exceptions',
|
|
search: q ? { q, open: '1' } : undefined,
|
|
};
|
|
}
|
|
|
|
if (notifyType === 'allocation_backup') {
|
|
return {
|
|
path: '/orders',
|
|
search: orderCode ? { q: orderCode } : undefined,
|
|
};
|
|
}
|
|
|
|
if (notifyType === 'zero_sale_price') {
|
|
return {
|
|
path: '/orders',
|
|
search: orderCode ? { q: orderCode, open: '1' } : undefined,
|
|
};
|
|
}
|
|
|
|
if (title.includes('采购验收') || title.includes('采购入库')) {
|
|
const q = purchaseCode || orderCode;
|
|
return {
|
|
path: '/inspection',
|
|
search: q ? { q, open: '1' } : undefined,
|
|
};
|
|
}
|
|
|
|
if (notifyType === 'inspection_timeout' || title.includes('验收')) {
|
|
return {
|
|
path: '/inspection',
|
|
search: orderCode ? { q: orderCode, open: '1' } : undefined,
|
|
};
|
|
}
|
|
|
|
if (title.includes('配送') || taskCode) {
|
|
const q = taskCode || orderCode;
|
|
return {
|
|
path: '/delivery',
|
|
search: q ? { q, open: '1' } : undefined,
|
|
};
|
|
}
|
|
|
|
if (title.includes('订单') || orderCode) {
|
|
return {
|
|
path: '/orders',
|
|
search: orderCode ? { q: orderCode, open: '1' } : undefined,
|
|
};
|
|
}
|
|
|
|
return { path: '/system/notifications' };
|
|
}
|
|
|
|
export function buildNotificationNavigateUrl(target: NotificationNavigateTarget): string {
|
|
if (!target.search || Object.keys(target.search).length === 0) {
|
|
return target.path;
|
|
}
|
|
const params = new URLSearchParams(target.search);
|
|
return `${target.path}?${params.toString()}`;
|
|
}
|