format.ts
1.42 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
export function formatTimeLabel(value?: string | null): string {
if (!value) {
return '暂无记录'
}
const parsed = new Date(value)
if (Number.isNaN(parsed.getTime())) {
return value
}
return new Intl.DateTimeFormat('zh-CN', {
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
}).format(parsed)
}
export function joinDisplay(values: string[] | undefined, fallback = '暂无'): string {
if (!values || values.length === 0) {
return fallback
}
return values.filter(Boolean).join('、')
}
export function statusTone(status: string): string {
if (['running', 'researching', 'logging_in', 'checking', 'awaiting_scan', 'pending'].includes(status)) {
return 'running'
}
if (['completed', 'reported', 'logged_in', 'ready'].includes(status)) {
return 'success'
}
if (['error', 'cancelled', 'logged_out'].includes(status)) {
return 'danger'
}
return 'neutral'
}
export function appLabel(app: string): string {
const labels: Record<string, string> = {
insight: 'Insight 洞察',
media: 'Media 表达',
query: 'Query 补证',
forum: 'Forum 研判',
report: 'Report 报告',
}
return labels[app] ?? app
}
export function buildEngineUrl(port?: number | null): string {
if (!port) {
return ''
}
const protocol = window.location.protocol
const host = window.location.hostname || '127.0.0.1'
return `${protocol}//${host}:${port}`
}