categoryLabels.ts 803 Bytes
/** 与后端 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;
}