Files
syops/frontend/src/features/chat/shipping/shippingTaskId.ts
T

17 lines
727 B
TypeScript

/**
* features/chat/shipping/shippingTaskId.ts
* 用途:从聊天消息中识别发货任务编号(SN- 格式)。
* 依赖:constants/shipping.SHIPPING_TASK_ID_RE、chat.types。
* 逻辑:useChatShipping 与 shipping refresh 只把这里作为消息级兜底,不再承担历史标题猜测。
*/
import { SHIPPING_TASK_ID_RE } from '../constants/shipping';
/** 从消息列表倒序查找最近出现的 SN- 任务编号。 */
export function findLatestShippingTaskId(msgs: Array<{ content?: string }>): string {
for (let i = msgs.length - 1; i >= 0; i -= 1) {
const match = String(msgs[i]?.content || '').match(SHIPPING_TASK_ID_RE);
if (match?.[0]) return match[0].toUpperCase();
}
return '';
}