返回 AiToEarn
tagConfig.ts
根目录 / project / aitoearn-web / src / app / config / tagConfig.ts
1 /**
2 * tagConfig - 任务标签配置中心
3 * 前端统一管理所有 tag 值、标签、颜色,供创建任务、筛选、卡片渲染使用
4 * 后端无"查询所有 tags"接口,故由前端维护
5 */
6
7 import { directTrans } from '@/app/i18n/client'
8
9 /** 标签类型枚举,值与 CreateTabType 一致但类型解耦 */
10 export enum TagType {
11 CPS = 'cps',
12 CPM = 'cpm',
13 CPE = 'cpe',
14 INTERACTION = 'interaction',
15 FOLLOW = 'follow',
16 BRAND_COMMENT = 'brand_comment',
17 FIXED = 'fixed',
18 }
19
20 /** 标签信息 */
21 export interface ITagInfo {
22 /** 显示名称(通过 directTrans 动态解析 i18n) */
23 label: string
24 /** 标签描述(通过 directTrans 动态解析 i18n) */
25 description: string
26 /** Tailwind badge 样式类(背景 + 文字颜色) */
27 colorClass: string
28 }
29
30 /** 标签信息映射表 */
31 export const TagInfoMap = new Map<TagType, ITagInfo>([
32 [TagType.CPS, {
33 label: 'tag.cps',
34 description: 'create.tabCpsDesc',
35 colorClass: 'bg-blue-50 text-blue-700 dark:bg-blue-950 dark:text-blue-300',
36 }],
37 [TagType.CPM, {
38 label: 'tag.cpm',
39 description: 'create.tabCpmDesc',
40 colorClass: 'bg-amber-50 text-amber-700 dark:bg-amber-950 dark:text-amber-300',
41 }],
42 [TagType.CPE, {
43 label: 'tag.promotion',
44 description: 'create.tabPromotionMergedDesc',
45 colorClass: 'bg-orange-50 text-orange-700 dark:bg-orange-950 dark:text-orange-300',
46 }],
47 [TagType.INTERACTION, {
48 label: 'tag.interaction',
49 description: 'create.tabInteractionDesc',
50 colorClass: 'bg-emerald-50 text-emerald-700 dark:bg-emerald-950 dark:text-emerald-300',
51 }],
52 [TagType.FOLLOW, {
53 label: 'tag.follow',
54 description: 'create.tabFollowDesc',
55 colorClass: 'bg-cyan-50 text-cyan-700 dark:bg-cyan-950 dark:text-cyan-300',
56 }],
57 [TagType.BRAND_COMMENT, {
58 label: 'tag.brandComment',
59 description: 'create.tabBrandCommentDesc',
60 colorClass: 'bg-rose-50 text-rose-700 dark:bg-rose-950 dark:text-rose-300',
61 }],
62 [TagType.FIXED, {
63 label: 'tag.fixed',
64 description: 'create.tabFixedDesc',
65 colorClass: 'bg-violet-50 text-violet-700 dark:bg-violet-950 dark:text-violet-300',
66 }],
67 ])
68
69 // 遍历设置 label/description getter,实现运行时 i18n 翻译
70 TagInfoMap.forEach((info) => {
71 const rawLabel = info.label
72 const rawDescription = info.description
73 Object.defineProperty(info, 'label', {
74 get() {
75 if (typeof directTrans === 'function') {
76 return directTrans('task', rawLabel)
77 }
78 return rawLabel
79 },
80 configurable: true,
81 enumerable: true,
82 })
83 Object.defineProperty(info, 'description', {
84 get() {
85 if (typeof directTrans === 'function') {
86 return directTrans('task', rawDescription)
87 }
88 return rawDescription
89 },
90 configurable: true,
91 enumerable: true,
92 })
93 })
94
95 /** 标签信息数组,用于遍历 */
96 export const TagInfoArr = Array.from(TagInfoMap)
97
98 /** 根据 tag 值获取标签信息 */
99 export function getTagInfo(tag: string): ITagInfo | undefined {
100 return TagInfoMap.get(tag as TagType)
101 }
102
102 lines TYPESCRIPT