Files
crawler-plugin/admin-frontend-vue/src/components/status-pill-model.ts
T

38 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 状态药丸配色/分类模型(module 13 task 247):统一 admin.html 的三态语义色
* success 绿 / danger 红 / warning 琥珀 / info 蓝 / primary 深蓝),供视频任务、
* 店铺数据任务、数字人版本等页面复用;未知文本回落 info。
*/
export type PillTone = 'success' | 'danger' | 'warning' | 'info' | 'primary'
export interface PillToneStyle {
text: string
bg: string
}
export const PILL_TONES: Record<PillTone, PillToneStyle> = {
success: { text: '#4e806d', bg: '#e6f6ec' },
danger: { text: '#b35f6a', bg: '#fdecec' },
warning: { text: '#a8793e', bg: '#fdf0dc' },
info: { text: '#4f78a5', bg: '#e7f0f8' },
primary: { text: '#2f5d8b', bg: '#e6f0f8' },
}
/** 取某 tone 的配色;未知 tone 回退 info(不抛错)。 */
export function pillToneStyle(tone: PillTone): PillToneStyle {
return PILL_TONES[tone] ?? PILL_TONES.info
}
const SUCCESS_PATTERN = /success|succeed|已发布|发布|成功|正常|可用/
const DANGER_PATTERN = /fail|error|已废弃|失败|不可用|异常/
const WARNING_PATTERN = /running|pending|waiting|进行|处理中|草稿|待执行|待/
/** 由状态文本(中英文)归类语义 tone。 */
export function statusTone(raw: string): PillTone {
const s = (raw || '').toLowerCase()
if (SUCCESS_PATTERN.test(s)) return 'success'
if (DANGER_PATTERN.test(s)) return 'danger'
if (WARNING_PATTERN.test(s)) return 'warning'
return 'info'
}