diff --git a/packages/core/database/src/interfaces/boolean-interface.ts b/packages/core/database/src/interfaces/boolean-interface.ts index b263a3641f..583186fd4a 100644 --- a/packages/core/database/src/interfaces/boolean-interface.ts +++ b/packages/core/database/src/interfaces/boolean-interface.ts @@ -40,7 +40,12 @@ export class BooleanInterface extends BaseInterface { const option = enumConfig.find((item) => item.value === value); return option?.label; } else { - return value ? '是' : value === null || value === undefined ? '' : '否'; + const label = value ? 'True' : value === null || value === undefined ? '' : 'False'; + if (ctx?.t) { + return ctx.t(label, { ns: 'action-export' }); + } + + return label; } } } diff --git a/packages/core/database/src/interfaces/multiple-select-interface.ts b/packages/core/database/src/interfaces/multiple-select-interface.ts index 66548c3e35..3f3203dda5 100644 --- a/packages/core/database/src/interfaces/multiple-select-interface.ts +++ b/packages/core/database/src/interfaces/multiple-select-interface.ts @@ -36,7 +36,16 @@ export class MultipleSelectInterface extends BaseInterface { .castArray(value) .map((value) => { const option = enumConfig.find((item) => item.value === value); - return option ? option.label : value; + + if (option) { + if (ctx?.t) { + return ctx.t(option.label, { ns: 'lm-collections' }); + } + + return option.label; + } + + return value; }) .join(','); } diff --git a/packages/core/database/src/interfaces/select-interface.ts b/packages/core/database/src/interfaces/select-interface.ts index e05f283f49..cd12a0fc5b 100644 --- a/packages/core/database/src/interfaces/select-interface.ts +++ b/packages/core/database/src/interfaces/select-interface.ts @@ -32,6 +32,15 @@ export class SelectInterface extends BaseInterface { toString(value: any, ctx?: any) { const enumConfig = this.options.uiSchema?.enum || []; const option = enumConfig.find((item) => item.value === value); - return option?.label || value; + + if (option) { + if (ctx?.t) { + return ctx.t(option.label, { ns: 'lm-collections' }); + } + + return option.label; + } + + return value; } } diff --git a/packages/plugins/@nocobase/plugin-action-export/src/locale/en-US.json b/packages/plugins/@nocobase/plugin-action-export/src/locale/en-US.json index 19f7aaa58e..c2a5cd203e 100644 --- a/packages/plugins/@nocobase/plugin-action-export/src/locale/en-US.json +++ b/packages/plugins/@nocobase/plugin-action-export/src/locale/en-US.json @@ -1,4 +1,6 @@ { "Export warning": "You can export up to {{limit}} rows of data at a time, any excess will be ignored.", - "Start export": "Start export" + "Start export": "Start export", + "True": "True", + "False": "False" } diff --git a/packages/plugins/@nocobase/plugin-action-export/src/locale/zh-CN.json b/packages/plugins/@nocobase/plugin-action-export/src/locale/zh-CN.json index 7fc1bd6309..d8f5bbda9e 100644 --- a/packages/plugins/@nocobase/plugin-action-export/src/locale/zh-CN.json +++ b/packages/plugins/@nocobase/plugin-action-export/src/locale/zh-CN.json @@ -1,5 +1,7 @@ { "Export warning": "每次最多导出 {{limit}} 行数据,超出的将被忽略。", "Start export": "开始导出", - "another export action is running, please try again later.": "另一导出任务正在运行,请稍后重试。" + "another export action is running, please try again later.": "另一导出任务正在运行,请稍后重试。", + "True": "是", + "False": "否" } diff --git a/packages/plugins/@nocobase/plugin-action-export/src/server/__tests__/export-to-xlsx.test.ts b/packages/plugins/@nocobase/plugin-action-export/src/server/__tests__/export-to-xlsx.test.ts index 707c31ebea..01276726e6 100644 --- a/packages/plugins/@nocobase/plugin-action-export/src/server/__tests__/export-to-xlsx.test.ts +++ b/packages/plugins/@nocobase/plugin-action-export/src/server/__tests__/export-to-xlsx.test.ts @@ -31,6 +31,67 @@ describe('export to xlsx with preset', () => { await app.destroy(); }); + it('should export with checkbox field', async () => { + const Post = app.db.collection({ + name: 'posts', + fields: [ + { type: 'string', name: 'title' }, + { + type: 'boolean', + name: 'test_field', + interface: 'checkbox', + uiSchema: { + type: 'boolean', + 'x-component': 'Checkbox', + }, + }, + ], + }); + + await app.db.sync(); + + await Post.repository.create({ + values: { + title: 'p1', + test_field: true, + }, + }); + + const exporter = new XlsxExporter({ + collectionManager: app.mainDataSource.collectionManager, + collection: Post, + chunkSize: 10, + columns: [ + { dataIndex: ['title'], defaultTitle: 'Title' }, + { + dataIndex: ['test_field'], + defaultTitle: 'test_field', + }, + ], + }); + + const wb = await exporter.run(); + + const xlsxFilePath = path.resolve(__dirname, `t_${uid()}.xlsx`); + + try { + XLSX.writeFile(wb, xlsxFilePath); + + // read xlsx file + const workbook = XLSX.readFile(xlsxFilePath); + const firstSheet = workbook.Sheets[workbook.SheetNames[0]]; + const sheetData = XLSX.utils.sheet_to_json(firstSheet, { header: 1 }); + + const header = sheetData[0]; + expect(header).toEqual(['Title', 'test_field']); + + const data = sheetData[1]; + expect(data[1]).toBe('True'); + } finally { + fs.unlinkSync(xlsxFilePath); + } + }); + it('should export number field with cell format', async () => { const Post = app.db.collection({ name: 'posts',