bc518174
王天杨
提交两个项目文件
|
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
|
/** 与后端 work_category、上传表单一致;含旧版 key 便于历史数据展示 */
export const CATEGORY_LABELS: Record<string, string> = {
landscape: "风景",
humanity: "人文",
ecology: "生态",
other: "其他",
/* 旧分类映射 */
mountain: "风景",
lake: "风景",
meadow: "生态",
temple: "人文",
culture: "人文",
};
/** 将接口返回的 category key 转为展示用中文标签 */
export function labelsFromCategoryKeys(
cats: string[] | undefined | null
): string[] {
if (!cats?.length) {
return [];
}
const out: string[] = [];
const seen = new Set<string>();
for (const c of cats) {
const label = CATEGORY_LABELS[c] ?? c;
if (label && !seen.has(label)) {
seen.add(label);
out.push(label);
}
}
return out;
}
|