feat(rest): 列表导出路由 (csv/xlsx/json) + 类型感知格式化 + 表头本地化#2487
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 5 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
Closes #2481
为列表导出补齐服务端导出能力:
GET /api/v1/data/:object/export,流式输出 CSV / XLSX / JSON。改了什么
GET /data/:object/export,支持format=csv|xlsx|json、fields、filter、orderby、limit、header等参数。XLSX 用 exceljsWorkbookWriter流式写出,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原值,连英文翻译包都绕过)。examples/app-crm商机视图开启exportOptions: ['csv','xlsx','json']。验证
pnpm --filter @objectstack/rest test→ 155 passed。["商机名称","Account","阶段","金额","赢单概率 (%)","Expected Revenue","预计成交日期"],与列头一致。配套前端
objectstack-ai/objectui#2111(导出按钮 + 服务端下载 + 权限门)。