format.ts
8.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// 通用格式化与状态映射。tone:ok 绿 / warn 橙 / err 红 / info 灰 / primary 蓝。
export type Tone = 'ok' | 'warn' | 'err' | 'info' | 'primary'
export function fmtTime(v?: string | null): string {
if (!v) return '—'
return String(v).replace('T', ' ').slice(0, 19)
}
export function fmtShort(v?: string | null): string {
if (!v) return '—'
return String(v).replace('T', ' ').slice(5, 16)
}
export function fmtAge(sec?: number | null): string {
if (sec === null || sec === undefined) return '从未'
if (sec < 60) return `${Math.round(sec)} 秒前`
if (sec < 3600) return `${Math.round(sec / 60)} 分钟前`
if (sec < 86400) return `${Math.round(sec / 3600)} 小时前`
return `${Math.round(sec / 86400)} 天前`
}
export function fmtDuration(sec?: number | null): string {
if (sec === null || sec === undefined) return '—'
if (sec < 60) return `${Math.round(sec)} 秒`
if (sec < 3600) return `${Math.round(sec / 60)} 分钟`
return `${(sec / 3600).toFixed(1)} 小时`
}
export function fmtMoney(v?: number | null): string {
return v === null || v === undefined ? '—' : '¥' + Number(v).toFixed(2)
}
export function fmtSize(n?: number | null): string {
if (!n) return '—'
if (n < 1024) return `${n} B`
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`
return `${(n / 1024 / 1024).toFixed(1)} MB`
}
export const SEVERITY: Record<string, { text: string; tone: Tone }> = {
info: { text: '提示', tone: 'info' }, warn: { text: '注意', tone: 'warn' },
error: { text: '异常', tone: 'err' }, critical: { text: '紧急', tone: 'err' },
}
export const LEVEL_TONE: Record<string, Tone> = {
info: 'info', ok: 'ok', warn: 'warn', error: 'err', INFO: 'info', WARNING: 'warn', ERROR: 'err',
CRITICAL: 'err', DEBUG: 'info',
}
export const TASK_STATUS: Record<string, { text: string; tone: Tone }> = {
queued: { text: '待领取', tone: 'info' }, dispatched: { text: '执行中', tone: 'primary' },
done: { text: '完成', tone: 'ok' }, failed: { text: '失败', tone: 'err' },
expired: { text: '没人领取', tone: 'warn' }, unknown: { text: '结果未知', tone: 'err' },
late_done: { text: '迟到完成', tone: 'warn' }, late_failed: { text: '迟到失败', tone: 'err' },
}
export const TASK_TYPE: Record<string, string> = {
'sys.ping': '连通测试', 'sys.check': '自检', 'sys.upload_logs': '上传日志', 'sys.collect_diag': '收集诊断', 'restock.scan': '补货查询(旧)',
'restock.outbound': '零件出库明细', 'restock.quote': '查库存 / 主数据 / 全国仓', 'restock.so_sync': '同步近期 SO 单',
'restock.create_po': '创建采购单', 'restock.screenshot_po': '采购单截图', 'restock.submit_po': '提交采购单',
'restock.export_history': '历史数据导出',
'sys.update': '版本更新', 'sys.cleanup': '清理本地日志', 'sys.restart': '重启取数端',
}
export const STEP_CN: Record<string, string> = {
login: '登录 DMS', query_part: '查询配件', create_po: '创建采购单', verify_po: '回查采购单', screenshot: '截图',
query_outbound: '拉零件出库明细', so_sync: '同步 SO 单', screenshot_fallback: '截图兜底(接口数据渲染)',
upload: '上传文件', check: '自检', export: '导出数据', confirm: '等待人工确认', env: '采集环境', netdiag: '网络诊断',
browser_probe: '浏览器对照测试', pack: '打包数据', download: '下载更新包', verify: '校验更新包', install: '安装新版本', cleanup: '清理本地日志',
}
export const STRATEGY: Record<string, { text: string; desc: string }> = {
ui: { text: 'ui:浏览器模拟人工登录', desc: '打开 IAM 登录页,真实点击输入框、逐字输入账号密码、点登录;开启逐步确认时只在门店电脑 tool.bat 菜单 12 观看时执行' },
token: { text: 'token:把已有登录交给浏览器', desc: '用取数端接口登录拿到的 token 打开页面,最快' },
sso: { text: 'sso:浏览器自己走单点登录', desc: '把 IAM 登录 Cookie 交给浏览器,让 DMS 前端自己换 token' },
}
export const STAGE: Record<string, { text: string; tone: Tone }> = {
scanning: { text: '取数中', tone: 'primary' }, scan_retry: { text: '取数失败·等待重试', tone: 'warn' },
refreshing: { text: '刷新取数中', tone: 'primary' },
awaiting_confirm: { text: '待确认', tone: 'warn' }, creating: { text: '建单中', tone: 'primary' },
create_unknown: { text: '建单异常·核实中', tone: 'err' },
screenshotting: { text: '截图中', tone: 'primary' },
awaiting_submit: { text: '待确认提交', tone: 'warn' }, submitting: { text: '提交中', tone: 'primary' },
done: { text: '已完成', tone: 'ok' },
cancelled: { text: '不订', tone: 'info' }, error: { text: '出错', tone: 'err' },
superseded: { text: '已作废', tone: 'info' }, expired: { text: '已过期', tone: 'err' },
terminated: { text: '已终止', tone: 'info' },
}
export const KIND_CN: Record<string, string> = { scheduled: '定时补货', single: '单次补货' }
// 智能助手:技能 / 工具的中文名、被统一的闸拦下的原因(与云端 features/skills.py、guards.py 一致)
export const SKILL_CN: Record<string, string> = {
'restock.part_query': '查库存(已下线,仅显示历史记录)', 'restock.single': '单次补货', 'restock.scheduled': '定时补货',
}
export const TOOL_CN: Record<string, string> = {
query_part: '查库存(已下线)', single_restock: '发起单次补货', confirm_order: '建单', submit_order: '提交', cancel_order: '不订 / 不提交',
single_status: '单次补货进度', scheduled_status: '定时补货进度', scheduled_link: '定时补货单据页链接',
}
export const BLOCKED_CN: Record<string, string> = {
from_text: '零件号在原话和聊天记录里都没有,没有执行',
}
// 智能助手对一句话的处理结果(与云端 services/aitrace.py RESULT_CN 一致)
export const AI_RESULT: Record<string, { text: string; tone: 'ok' | 'warn' | 'err' | 'info' | 'primary' }> = {
tool: { text: '工具已回复', tone: 'ok' }, free_reply: { text: '助手直接回复', tone: 'ok' },
no_tool_text: { text: '没调工具就直接回复,已拦截', tone: 'warn' }, reply_blocked: { text: '直接回复涉及业务,已拦截', tone: 'warn' },
free_reply_blocked: { text: '(旧规则)回复里有长数字,改发引导语', tone: 'warn' }, refused: { text: '回了固定引导语', tone: 'info' },
llm_unavailable: { text: '大模型不可用', tone: 'err' }, tool_then_llm_error: { text: '工具已回复,之后大模型出错', tone: 'warn' },
no_skills: { text: '没有启用技能', tone: 'warn' },
}
// 一次工具调用的简写:「发起单次补货 5165156 2」
export function callText(c: any): string {
const args = Object.values(c?.args || {}).filter((v) => v !== '' && v != null).join(' ')
return `${TOOL_CN[c?.tool] || c?.tool}${args ? ' ' + args : ''}`
}
// DMS 全国仓库名 → 给人看的叫法(与云端 planner.wh_label 一致)
export function whLabel(name: string): string {
const m: Record<string, string> = { GTMC广州: '广州仓', 华南GTMC: '华南仓' }
if (m[name]) return m[name]
for (const k of ['广州', '华南']) if (name.includes(k)) return k + '仓'
return name
}
export const TRIGGER: Record<string, string> = { chat: '企微对话', schedule: '定时推送', console: '手动补充' }
export const GROUP: Record<string, string> = { stock: '历史常备件', other: '其他出库件', single: '单次补货' }
export const LOGIN_STATE: Record<string, { text: string; tone: Tone }> = {
ok: { text: '登录正常', tone: 'ok' }, failed: { text: '登录失败', tone: 'err' },
rejected: { text: '账号密码被拒', tone: 'err' }, none: { text: '未登录', tone: 'info' },
}
export function lineClass(l: any): string {
if (l.tag === 'error') return 'row-err'
if (l.short_after || l.tag === 'oos') return 'row-red'
if (l.wh_short || l.tag === 'capped') return 'row-orange'
if (!l.seq) return 'row-grey'
return ''
}
export function errMsg(e: any): string {
return e?.message || String(e)
}
export const WEEKDAYS = ['一', '二', '三', '四', '五', '六', '日']