/** * 电商平台展示:与后端 PlatformCode 枚举对齐,覆盖全部预置平台。 * 文案以字典 API / 后端 platformLabel 为准;色板仅前端展示用。 */ export type PlatformTagColor = | 'blue' | 'cyan' | 'default' | 'error' | 'geekblue' | 'gold' | 'green' | 'lime' | 'magenta' | 'orange' | 'processing' | 'purple' | 'red' | 'success' | 'volcano' | 'warning'; export interface PlatformDisplayMeta { code: string; /** 默认中文名(字典未加载时回退) */ label: string; color: PlatformTagColor; } /** 与 PlatformCode 一一对应;未知 code 走 fallback */ const PLATFORM_META: Record = { taobao: { code: 'taobao', label: '淘宝', color: 'orange' }, jd: { code: 'jd', label: '京东', color: 'red' }, pdd: { code: 'pdd', label: '拼多多', color: 'volcano' }, douyin: { code: 'douyin', label: '抖音', color: 'magenta' }, kuaishou: { code: 'kuaishou', label: '快手', color: 'gold' }, xiaohongshu: { code: 'xiaohongshu', label: '小红书', color: 'error' }, tmall: { code: 'tmall', label: '天猫', color: 'red' }, vip: { code: 'vip', label: '唯品会', color: 'purple' }, suning: { code: 'suning', label: '苏宁', color: 'blue' }, '1688': { code: '1688', label: '1688', color: 'cyan' }, }; export function getPlatformMeta(code?: null | string): PlatformDisplayMeta | null { if (!code || !code.trim()) return null; const key = code.trim().toLowerCase(); return PLATFORM_META[key] ?? null; } export function getPlatformTagColor(code?: null | string): PlatformTagColor { return getPlatformMeta(code)?.color ?? 'default'; } /** 展示名:优先后端/字典 label,再本地映射,最后原 code */ export function getPlatformLabel( code?: null | string, preferredLabel?: null | string, ): string { if (preferredLabel && preferredLabel.trim()) return preferredLabel.trim(); const meta = getPlatformMeta(code); if (meta) return meta.label; if (code && code.trim()) return code.trim(); return '未关联平台'; } export function listBuiltinPlatformMetas(): PlatformDisplayMeta[] { return Object.values(PLATFORM_META); }