/** * 任务状态 → 颜色/标签映射(全局唯一数据源) * * 供 TaskTreeViewer / TaskListCard / ProductCard 等组件共用, * 避免在多处重复维护相同的映射逻辑。 */ import { TASK_STATUS } from "../types/api"; export interface StatusStyle { bg: string; text: string; ring: string; label: string; } export const STATUS_CONFIG: Record = { [TASK_STATUS.PENDING]: { bg: "bg-yellow-50", text: "text-yellow-700", ring: "ring-yellow-400", label: "待接收", }, [TASK_STATUS.WIP]: { bg: "bg-blue-50", text: "text-blue-700", ring: "ring-blue-400", label: "进行中", }, [TASK_STATUS.COMPLETED]: { bg: "bg-green-50", text: "text-green-700", ring: "ring-green-400", label: "已完成", }, [TASK_STATUS.REJECTED]: { bg: "bg-red-50", text: "text-red-700", ring: "ring-red-400", label: "待接收", }, [TASK_STATUS.ARCHIVED]: { bg: "bg-gray-50", text: "text-gray-600", ring: "ring-gray-300", label: "已完成", }, }; const FALLBACK: StatusStyle = { bg: "bg-gray-50", text: "text-gray-600", ring: "ring-gray-300", label: "", }; /** 获取状态的完整样式配置(bg / text / ring / label)— 大小写不敏感 */ export function getStatusConfig(status: string): StatusStyle { const key = status?.toUpperCase?.() ?? status; return STATUS_CONFIG[key] ?? { ...FALLBACK, label: status }; } /** 仅获取 bg + text 类名,用于简单的状态标签着色 */ export function statusColor(status: string): string { const cfg = getStatusConfig(status); return `${cfg.bg} ${cfg.text}`; } /** 仅获取中文标签 */ export function statusLabel(status: string): string { return getStatusConfig(status).label; }