Files
hjc-web/server/utils/case.ts
T
weicw-dshsa cfe0749aff feat(cms): 案例/文章列表与详情改读 publishTime
配合后端拆出独立的 publish_time 列(见 ADR 0016)。

- 案例列表/详情、文章列表/详情统一取 publishTime,不再回退 createTime
  (createTime 是系统记录时间,运营没设过,展示它等于显示错误值)
- 案例详情页标签由「项目时间」更正为「发布时间」,并补 dayjs 格式化
  (原先直出 2026-09-23 19:06:37 完整时间戳)
- server/utils/case.ts 废弃 projectTime,改为输出 publishTime
- CaseItem 类型同步

仅改 template-07:其余 9 套模板的 CaseDetail 仍读已废弃的 projectTime,
因 CaseItem 带索引签名不会报编译错误,只会在换模板时静默显示创建时间。
该技术债已记入 docs/adr/0016 的「后果」一节,换模板前须先补这 9 套。
2026-09-29 03:36:04 +08:00

47 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { CaseItem } from '~/app/types'
/**
* 将 CMS 后端案例对象(字段:caseId / caseName / customer …)
* 映射为前端模板约定的 CaseItem(字段:id / title / clientName …)。
*
* 后端 cms-case 控制器返回的是 caseId / caseName / customer,
* 而 website-template 的全部模板组件(template-01 ~ template-07)均按
* id / title / clientName 渲染,故在此统一做一次字段归一化,
* 避免 8 套模板各自散落做字段转换。
*/
export function normalizeCaseItem(raw: any): CaseItem {
if (!raw) return raw
return {
// 主键与标题
id: raw.caseId ?? raw.id,
title: raw.caseName ?? raw.title,
// 封面 / 摘要 / 正文
cover: raw.cover ?? '',
summary: raw.summary ?? raw.subtitle ?? '',
// 正文:部分 CMS 版本正文在 description,兜底回退(content 优先)
content: raw.content ?? raw.description ?? '',
// 分类
categoryId: raw.categoryId ?? null,
categoryName: raw.categoryName ?? '',
// 客户(后端字段名 customer)→ 前端 clientName
clientName: raw.customer ?? raw.clientName ?? '',
industry: raw.industry ?? '',
// 发布时间:运营可见的对外时间,官网展示与排序的锚点(后端 cms_case.publish_time)。
// 不再回退 createTime——那是系统记录时间,运营没设过,展示它等于显示错误值。
publishTime: raw.publishTime ?? '',
// 关联产品(后端 productUsed)作为标签兜底
tags: raw.productUsed ? [raw.productUsed] : (raw.tags ?? []),
// 排序 / 状态 / 浏览量
sortNumber: raw.sortNum ?? raw.sortNumber ?? 0,
status: raw.status,
views: raw.views ?? 0,
// 置顶 / 推荐(当前上游 cms-case 暂无此字段,透传以便后续版本自动生效;
// 前端 useRecommend 检测到该字段后会将案例区块自动切换为「推荐」过滤)
top: raw.top ?? 0,
recommend: raw.recommend ?? 0,
createTime: raw.createTime ?? '',
updateTime: raw.updateTime ?? ''
}
}