62 lines
2.6 KiB
TypeScript
62 lines
2.6 KiB
TypeScript
/**
|
||
* features/chat/constants/shipping.ts
|
||
* 用途:发货通知功能常量 — 任务编号正则、菜单动作规格与决策动作集合。
|
||
* 依赖:types/shipping.types(ShippingMenuAction)、vue-i18n(菜单展示文案)。
|
||
* 逻辑:shipping/* handler 与 useChatShipping 引用本模块,避免动作 id 硬编码分散。
|
||
*/
|
||
import i18n from '@/i18n';
|
||
import type { ShippingMenuAction } from '../types/shipping.types';
|
||
|
||
/** 工作区发货任务编号格式(如 SN-20250610-ABCDEF12) */
|
||
export const SHIPPING_TASK_ID_RE = /SN-\d{8}-[A-F0-9]{8}/i;
|
||
|
||
/** 菜单动作 id / variant(展示文案经 resolveShippingMenuActionSpec 取 i18n) */
|
||
export const SHIPPING_MENU_ACTION_SPECS: Record<
|
||
ShippingMenuAction,
|
||
{ id: string; label: string; message: string; variant: 'primary' | 'secondary' | 'danger' }
|
||
> = {
|
||
upload: { id: 'upload_inventory_file', label: '选择库存文件', message: '我要上传库存 Excel', variant: 'primary' },
|
||
retry_rpa: { id: 'retry_rpa', label: '重新获取库存', message: '重新获取库存', variant: 'secondary' },
|
||
confirm: { id: 'confirm', label: '确认', message: '确认', variant: 'primary' },
|
||
reparse: { id: 'reparse', label: '重新解析', message: '重新解析', variant: 'secondary' },
|
||
reject: { id: 'reject', label: '驳回', message: '驳回', variant: 'danger' },
|
||
};
|
||
|
||
/**
|
||
* 解析菜单动作的展示 label / message(四语言)。
|
||
* 核心逻辑:id/variant 来自静态规格;文案走 chat.shippingNoticeMenu.*。
|
||
* @param action - 菜单动作键
|
||
* @param t - 可选翻译函数;缺省用全局 i18n
|
||
* @returns 含 id/label/message/variant 的完整动作规格
|
||
*/
|
||
export function resolveShippingMenuActionSpec(
|
||
action: ShippingMenuAction,
|
||
t?: (key: string, ...args: unknown[]) => string,
|
||
) {
|
||
const base = SHIPPING_MENU_ACTION_SPECS[action];
|
||
const translate = t || ((key: string, ...args: unknown[]) => String(i18n.global.t(key, ...(args as []))));
|
||
return {
|
||
...base,
|
||
label: translate(`chat.shippingNoticeMenu.${action}.label`),
|
||
message: translate(`chat.shippingNoticeMenu.${action}.message`),
|
||
};
|
||
}
|
||
|
||
export const SHIPPING_DECISION_ACTIONS = new Set([
|
||
'confirm',
|
||
'reparse_inventory',
|
||
'retry_rpa',
|
||
'reject',
|
||
'reparse',
|
||
'rematch',
|
||
]);
|
||
|
||
/** 从文件名或 URL 提取扩展名(小写,不含点) */
|
||
export const extractExt = (value: string) => {
|
||
const text = (value || '').trim().toLowerCase();
|
||
const withoutQuery = (text.split('?')[0] || '').split('#')[0] || '';
|
||
const idx = withoutQuery.lastIndexOf('.');
|
||
if (idx < 0) return '';
|
||
return withoutQuery.slice(idx + 1).trim();
|
||
};
|