Skip to content

feat(rest): 列表导出路由 (csv/xlsx/json) + 类型感知格式化 + 表头本地化#2487

Merged
os-zhuang merged 2 commits into
mainfrom
feat/rest-export-xlsx-2481
Jun 30, 2026
Merged

feat(rest): 列表导出路由 (csv/xlsx/json) + 类型感知格式化 + 表头本地化#2487
os-zhuang merged 2 commits into
mainfrom
feat/rest-export-xlsx-2481

Conversation

@baozhoutao

Copy link
Copy Markdown
Contributor

背景

Closes #2481

为列表导出补齐服务端导出能力:GET /api/v1/data/:object/export,流式输出 CSV / XLSX / JSON。

改了什么

  • 新路由 GET /data/:object/export,支持 format=csv|xlsx|jsonfieldsfilterorderbylimitheader 等参数。XLSX 用 exceljs WorkbookWriter 流式写出,useStyles:false,可承受 2w+ 行不爆内存。
  • 类型感知格式化(export-format.ts):lookup/user/master_detail → 关联记录名(非 id);select/radio → 选项 label(非 code);multiselect/tags → 多 label 拼接;boolean → 是/否;date → 格式化。无字段元数据时回退原值,与未格式化路径字节一致。
  • 自动 $expand 引用字段:批量 $in(在 findData 内),无 N+1。
  • 表头本地化:导出前用现成的 translateMetaItem 按请求 locale(Accept-Language / ?locale=)翻译对象 schema,表头与控制台列头一致(此前直接用 field.label 原值,连英文翻译包都绕过)。
  • demo:examples/app-crm 商机视图开启 exportOptions: ['csv','xlsx','json']

验证

  • pnpm --filter @objectstack/rest test155 passed
  • 真实控制台 UI 点「导出为 XLSX」下载到的 xlsx,表头为 ["商机名称","Account","阶段","金额","赢单概率 (%)","Expected Revenue","预计成交日期"],与列头一致。

配套前端

objectstack-ai/objectui#2111(导出按钮 + 服务端下载 + 权限门)。

@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jun 30, 2026 2:11pm

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/rest.

5 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:

  • content/docs/concepts/implementation-status.mdx (via @objectstack/rest)
  • content/docs/concepts/packages.mdx (via @objectstack/rest)
  • content/docs/guides/api-reference.mdx (via @objectstack/rest)
  • content/docs/guides/packages.mdx (via @objectstack/rest)
  • content/docs/guides/plugins.mdx (via @objectstack/rest)

Advisory only. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs origin/main → pass the list as args.docs.

@os-zhuang os-zhuang merged commit e38568b into main Jun 30, 2026
17 checks passed
@os-zhuang os-zhuang deleted the feat/rest-export-xlsx-2481 branch June 30, 2026 14:32
GET /data/:object/export streams CSV, XLSX (exceljs WorkbookWriter) or
JSON with type-aware, human-readable cells: lookup/user/master_detail →
referenced record name, select/radio → option label, multiselect → joined
labels, boolean → 是/否, dates formatted. Reference fields are auto-$expanded
(batched $in inside findData, no N+1). Header row uses localized field
labels (Accept-Language / ?locale=) via translateMetaItem so the exported
sheet matches the console column headers instead of leaking raw labels.

Closes #2481
Regression test for the export header localization: a zh request yields
'ID,标题,完成' and the default-locale request yields 'ID,Title,Done' (the
bundle's labels, never the raw schema 'RawTitle'/'RawDone'), proving the
header tracks Accept-Language / ?locale= via translateMetaItem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file size/l tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(rest): 列表导出支持 XLSX + 类型感知字段格式化(lookup/user/select/boolean/date)

2 participants