@nocobase/plugin-action-export 1.0.0-alpha.9 → 1.0.1-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/ExportActionInitializer.d.ts +0 -6
- package/dist/client/index.js +2 -2
- package/dist/externalVersion.js +6 -5
- package/dist/locale/en-US.json +1 -1
- package/dist/locale/zh-CN.json +1 -1
- package/dist/node_modules/xlsx/LICENSE +201 -0
- package/dist/node_modules/xlsx/bin/xlsx.njs +310 -0
- package/dist/node_modules/xlsx/bower.json +22 -0
- package/dist/node_modules/xlsx/dist/cpexcel.d.ts +39 -0
- package/dist/node_modules/xlsx/dist/cpexcel.js +1506 -0
- package/dist/node_modules/xlsx/dist/shim.min.js +2 -0
- package/dist/node_modules/xlsx/dist/xlsx.core.min.js +17 -0
- package/dist/node_modules/xlsx/dist/xlsx.extendscript.js +27961 -0
- package/dist/node_modules/xlsx/dist/xlsx.full.min.js +24 -0
- package/dist/node_modules/xlsx/dist/xlsx.mini.min.js +10 -0
- package/dist/node_modules/xlsx/dist/xlsx.zahl.js +4 -0
- package/dist/node_modules/xlsx/dist/zahl.d.ts +4 -0
- package/dist/node_modules/xlsx/package.json +1 -0
- package/dist/node_modules/xlsx/types/index.d.ts +1033 -0
- package/dist/node_modules/xlsx/xlsx.js +7 -0
- package/dist/node_modules/xlsx/xlsxworker.js +14 -0
- package/dist/server/actions/export-xlsx.js +29 -29
- package/dist/server/index.d.ts +1 -2
- package/dist/server/index.js +0 -6
- package/dist/server/utils/{index.d.ts → deep-get.d.ts} +1 -1
- package/dist/server/utils/{columns2Appends.js → deep-get.js} +25 -21
- package/dist/server/xlsx-exporter.d.ts +45 -0
- package/dist/server/xlsx-exporter.js +168 -0
- package/package.json +5 -3
- package/dist/node_modules/node-xlsx/lib/helpers.js +0 -142
- package/dist/node_modules/node-xlsx/lib/index.js +0 -6
- package/dist/node_modules/node-xlsx/lib/workbook.js +0 -16
- package/dist/node_modules/node-xlsx/package.json +0 -1
- package/dist/server/renders/index.d.ts +0 -16
- package/dist/server/renders/index.js +0 -168
- package/dist/server/renders/renders.d.ts +0 -23
- package/dist/server/renders/renders.js +0 -176
- package/dist/server/utils/columns2Appends.d.ts +0 -9
- package/dist/server/utils/index.js +0 -30
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
|
|
2
|
+
importScripts('dist/shim.min.js');
|
|
3
|
+
/* uncomment the next line for encoding support */
|
|
4
|
+
importScripts('dist/cpexcel.js');
|
|
5
|
+
importScripts('xlsx.js');
|
|
6
|
+
postMessage({t:"ready"});
|
|
7
|
+
|
|
8
|
+
onmessage = function (evt) {
|
|
9
|
+
var v;
|
|
10
|
+
try {
|
|
11
|
+
v = XLSX.read(evt.data.d, {type: evt.data.b, codepage: evt.data.c});
|
|
12
|
+
postMessage({t:"xlsx", d:JSON.stringify(v)});
|
|
13
|
+
} catch(e) { postMessage({t:"e",d:e.stack||e}); }
|
|
14
|
+
};
|
|
@@ -39,10 +39,11 @@ __export(export_xlsx_exports, {
|
|
|
39
39
|
exportXlsx: () => exportXlsx
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(export_xlsx_exports);
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
|
|
42
|
+
var import_xlsx_exporter = __toESM(require("../xlsx-exporter"));
|
|
43
|
+
var import_xlsx = __toESM(require("xlsx"));
|
|
44
|
+
var import_async_mutex = require("async-mutex");
|
|
45
|
+
const mutex = new import_async_mutex.Mutex();
|
|
46
|
+
async function exportXlsxAction(ctx, next) {
|
|
46
47
|
var _a, _b;
|
|
47
48
|
const { title, filter, sort, fields, except } = ctx.action.params;
|
|
48
49
|
let columns = ((_a = ctx.action.params.values) == null ? void 0 : _a.columns) || ((_b = ctx.action.params) == null ? void 0 : _b.columns);
|
|
@@ -50,37 +51,36 @@ async function exportXlsx(ctx, next) {
|
|
|
50
51
|
columns = JSON.parse(columns);
|
|
51
52
|
}
|
|
52
53
|
const repository = ctx.getCurrentRepository();
|
|
54
|
+
const dataSource = ctx.dataSource;
|
|
53
55
|
const collection = repository.collection;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
except,
|
|
64
|
-
sort,
|
|
65
|
-
limit: 200,
|
|
66
|
-
context: ctx
|
|
67
|
-
});
|
|
68
|
-
const collectionFields = columns.map((col) => collection.fields.get(col.dataIndex[0]));
|
|
69
|
-
const { rows, ranges } = await (0, import_renders.default)({ columns, fields: collectionFields, data }, ctx);
|
|
70
|
-
ctx.body = import_node_xlsx.default.build([
|
|
71
|
-
{
|
|
72
|
-
name: "Sheet 1",
|
|
73
|
-
data: rows,
|
|
74
|
-
options: {
|
|
75
|
-
"!merges": ranges
|
|
76
|
-
}
|
|
56
|
+
const xlsxExporter = new import_xlsx_exporter.default({
|
|
57
|
+
collectionManager: dataSource.collectionManager,
|
|
58
|
+
collection,
|
|
59
|
+
columns,
|
|
60
|
+
findOptions: {
|
|
61
|
+
filter,
|
|
62
|
+
fields,
|
|
63
|
+
except,
|
|
64
|
+
sort
|
|
77
65
|
}
|
|
78
|
-
|
|
66
|
+
});
|
|
67
|
+
const wb = await xlsxExporter.run();
|
|
68
|
+
ctx.body = import_xlsx.default.write(wb, { type: "buffer", bookType: "xlsx" });
|
|
79
69
|
ctx.set({
|
|
80
70
|
"Content-Type": "application/octet-stream",
|
|
81
|
-
// to avoid "invalid character" error in header (RFC)
|
|
82
71
|
"Content-Disposition": `attachment; filename=${encodeURI(title)}.xlsx`
|
|
83
72
|
});
|
|
73
|
+
}
|
|
74
|
+
async function exportXlsx(ctx, next) {
|
|
75
|
+
if (mutex.isLocked()) {
|
|
76
|
+
throw new Error(`another export action is running, please try again later.`);
|
|
77
|
+
}
|
|
78
|
+
const release = await mutex.acquire();
|
|
79
|
+
try {
|
|
80
|
+
await exportXlsxAction(ctx, next);
|
|
81
|
+
} finally {
|
|
82
|
+
release();
|
|
83
|
+
}
|
|
84
84
|
await next();
|
|
85
85
|
}
|
|
86
86
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/server/index.d.ts
CHANGED
|
@@ -6,10 +6,9 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { Plugin } from '@nocobase/server';
|
|
10
10
|
export declare class PluginActionExportServer extends Plugin {
|
|
11
11
|
beforeLoad(): void;
|
|
12
12
|
load(): Promise<void>;
|
|
13
|
-
install(options: InstallOptions): Promise<void>;
|
|
14
13
|
}
|
|
15
14
|
export default PluginActionExportServer;
|
package/dist/server/index.js
CHANGED
|
@@ -37,10 +37,6 @@ class PluginActionExportServer extends import_server.Plugin {
|
|
|
37
37
|
}
|
|
38
38
|
async load() {
|
|
39
39
|
this.app.dataSourceManager.afterAddDataSource((dataSource) => {
|
|
40
|
-
var _a;
|
|
41
|
-
if (!((_a = dataSource.collectionManager) == null ? void 0 : _a.db)) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
40
|
dataSource.resourceManager.registerActionHandler("export", import_actions.exportXlsx);
|
|
45
41
|
dataSource.acl.setAvailableAction("export", {
|
|
46
42
|
displayName: '{{t("Export")}}',
|
|
@@ -48,8 +44,6 @@ class PluginActionExportServer extends import_server.Plugin {
|
|
|
48
44
|
});
|
|
49
45
|
});
|
|
50
46
|
}
|
|
51
|
-
async install(options) {
|
|
52
|
-
}
|
|
53
47
|
}
|
|
54
48
|
var server_default = PluginActionExportServer;
|
|
55
49
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
var __create = Object.create;
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
11
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
15
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
16
|
var __export = (target, all) => {
|
|
15
17
|
for (var name in all)
|
|
@@ -23,32 +25,34 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
25
|
}
|
|
24
26
|
return to;
|
|
25
27
|
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
26
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
-
var
|
|
28
|
-
__export(
|
|
29
|
-
|
|
37
|
+
var deep_get_exports = {};
|
|
38
|
+
__export(deep_get_exports, {
|
|
39
|
+
deepGet: () => deepGet
|
|
30
40
|
});
|
|
31
|
-
module.exports = __toCommonJS(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
appendColumns.push(column.dataIndex[i]);
|
|
42
|
-
collection = ctx.dataSource.collectionManager.getCollection(field.target);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (appendColumns.length > 0) {
|
|
46
|
-
appends.add(appendColumns.join("."));
|
|
41
|
+
module.exports = __toCommonJS(deep_get_exports);
|
|
42
|
+
var import_lodash = __toESM(require("lodash"));
|
|
43
|
+
function deepGet(object, path) {
|
|
44
|
+
const pathParts = Array.isArray(path) ? path : path.split(".");
|
|
45
|
+
let current = object;
|
|
46
|
+
for (const part of pathParts) {
|
|
47
|
+
if (Array.isArray(current)) {
|
|
48
|
+
current = current.map((item) => import_lodash.default.get(item, part));
|
|
49
|
+
} else {
|
|
50
|
+
current = import_lodash.default.get(current, part);
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
|
-
return
|
|
53
|
+
return current;
|
|
50
54
|
}
|
|
51
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
52
56
|
0 && (module.exports = {
|
|
53
|
-
|
|
57
|
+
deepGet
|
|
54
58
|
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { FindOptions, ICollection, ICollectionManager } from '@nocobase/data-source-manager';
|
|
10
|
+
import XLSX from 'xlsx';
|
|
11
|
+
type ExportColumn = {
|
|
12
|
+
dataIndex: Array<string>;
|
|
13
|
+
defaultTitle: string;
|
|
14
|
+
};
|
|
15
|
+
type ExportOptions = {
|
|
16
|
+
collectionManager: ICollectionManager;
|
|
17
|
+
collection: ICollection;
|
|
18
|
+
columns: Array<ExportColumn>;
|
|
19
|
+
findOptions?: FindOptions;
|
|
20
|
+
chunkSize?: number;
|
|
21
|
+
};
|
|
22
|
+
declare class XlsxExporter {
|
|
23
|
+
private options;
|
|
24
|
+
/**
|
|
25
|
+
* You can adjust the maximum number of exported rows based on business needs and system
|
|
26
|
+
* available resources. However, please note that you need to fully understand the risks
|
|
27
|
+
* after the modification. Increasing the maximum number of rows that can be exported may
|
|
28
|
+
* increase system resource usage, leading to increased processing delays for other
|
|
29
|
+
* requests, or even server processes being recycled by the operating system.
|
|
30
|
+
*
|
|
31
|
+
* 您可以根据业务需求和系统可用资源等参数,调整最大导出数量的限制。但请注意,您需要充分了解修改之后的风险,
|
|
32
|
+
* 增加最大可导出的行数可能会导致系统资源占用率升高,导致其他请求处理延迟增加、无法处理、甚至
|
|
33
|
+
* 服务端进程被操作系统回收等问题。
|
|
34
|
+
*/
|
|
35
|
+
limit: number;
|
|
36
|
+
constructor(options: ExportOptions);
|
|
37
|
+
run(ctx?: any): Promise<XLSX.WorkBook>;
|
|
38
|
+
private getAppendOptionsFromColumns;
|
|
39
|
+
private getFindOptions;
|
|
40
|
+
private findFieldByDataIndex;
|
|
41
|
+
private renderHeaders;
|
|
42
|
+
private renderRawValue;
|
|
43
|
+
private renderCellValue;
|
|
44
|
+
}
|
|
45
|
+
export default XlsxExporter;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var xlsx_exporter_exports = {};
|
|
38
|
+
__export(xlsx_exporter_exports, {
|
|
39
|
+
default: () => xlsx_exporter_default
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(xlsx_exporter_exports);
|
|
42
|
+
var import_xlsx = __toESM(require("xlsx"));
|
|
43
|
+
var import_deep_get = require("./utils/deep-get");
|
|
44
|
+
class XlsxExporter {
|
|
45
|
+
constructor(options) {
|
|
46
|
+
this.options = options;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* You can adjust the maximum number of exported rows based on business needs and system
|
|
50
|
+
* available resources. However, please note that you need to fully understand the risks
|
|
51
|
+
* after the modification. Increasing the maximum number of rows that can be exported may
|
|
52
|
+
* increase system resource usage, leading to increased processing delays for other
|
|
53
|
+
* requests, or even server processes being recycled by the operating system.
|
|
54
|
+
*
|
|
55
|
+
* 您可以根据业务需求和系统可用资源等参数,调整最大导出数量的限制。但请注意,您需要充分了解修改之后的风险,
|
|
56
|
+
* 增加最大可导出的行数可能会导致系统资源占用率升高,导致其他请求处理延迟增加、无法处理、甚至
|
|
57
|
+
* 服务端进程被操作系统回收等问题。
|
|
58
|
+
*/
|
|
59
|
+
limit = process.env["EXPORT_LIMIT"] ? parseInt(process.env["EXPORT_LIMIT"]) : 2e3;
|
|
60
|
+
async run(ctx) {
|
|
61
|
+
const { collection, columns, chunkSize } = this.options;
|
|
62
|
+
const workbook = import_xlsx.default.utils.book_new();
|
|
63
|
+
const worksheet = import_xlsx.default.utils.sheet_new();
|
|
64
|
+
import_xlsx.default.utils.sheet_add_aoa(worksheet, [this.renderHeaders()], {
|
|
65
|
+
origin: "A1"
|
|
66
|
+
});
|
|
67
|
+
let startRowNumber = 2;
|
|
68
|
+
await collection.repository.chunk({
|
|
69
|
+
...this.getFindOptions(),
|
|
70
|
+
chunkSize: chunkSize || 200,
|
|
71
|
+
callback: async (rows, options) => {
|
|
72
|
+
const chunkData = rows.map((r) => {
|
|
73
|
+
return columns.map((col) => {
|
|
74
|
+
return this.renderCellValue(r, col, ctx);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
import_xlsx.default.utils.sheet_add_aoa(worksheet, chunkData, {
|
|
78
|
+
origin: `A${startRowNumber}`
|
|
79
|
+
});
|
|
80
|
+
startRowNumber += rows.length;
|
|
81
|
+
await new Promise((resolve) => {
|
|
82
|
+
setTimeout(resolve, 50);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
import_xlsx.default.utils.book_append_sheet(workbook, worksheet, "Data");
|
|
87
|
+
return workbook;
|
|
88
|
+
}
|
|
89
|
+
getAppendOptionsFromColumns() {
|
|
90
|
+
return this.options.columns.map((col) => {
|
|
91
|
+
if (col.dataIndex.length > 1) {
|
|
92
|
+
return col.dataIndex.join(".");
|
|
93
|
+
}
|
|
94
|
+
const field = this.options.collection.getField(col.dataIndex[0]);
|
|
95
|
+
if (field.isRelationField()) {
|
|
96
|
+
return col.dataIndex[0];
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}).filter(Boolean);
|
|
100
|
+
}
|
|
101
|
+
getFindOptions() {
|
|
102
|
+
const { findOptions = {} } = this.options;
|
|
103
|
+
findOptions.limit = this.limit;
|
|
104
|
+
const appendOptions = this.getAppendOptionsFromColumns();
|
|
105
|
+
if (appendOptions.length) {
|
|
106
|
+
return {
|
|
107
|
+
...findOptions,
|
|
108
|
+
appends: appendOptions
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return findOptions;
|
|
112
|
+
}
|
|
113
|
+
findFieldByDataIndex(dataIndex) {
|
|
114
|
+
const { collection } = this.options;
|
|
115
|
+
const currentField = collection.getField(dataIndex[0]);
|
|
116
|
+
if (dataIndex.length > 1) {
|
|
117
|
+
let targetCollection;
|
|
118
|
+
for (let i = 0; i < dataIndex.length - 1; i++) {
|
|
119
|
+
const isLast = i === dataIndex.length - 1;
|
|
120
|
+
if (isLast) {
|
|
121
|
+
return targetCollection.getField(dataIndex[i]);
|
|
122
|
+
}
|
|
123
|
+
targetCollection = currentField.targetCollection();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return currentField;
|
|
127
|
+
}
|
|
128
|
+
renderHeaders() {
|
|
129
|
+
return this.options.columns.map((col) => {
|
|
130
|
+
const field = this.findFieldByDataIndex(col.dataIndex);
|
|
131
|
+
return (field == null ? void 0 : field.options.title) || col.defaultTitle;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
renderRawValue(value) {
|
|
135
|
+
if (typeof value === "object" && value !== null) {
|
|
136
|
+
return JSON.stringify(value);
|
|
137
|
+
}
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
renderCellValue(rowData, column, ctx) {
|
|
141
|
+
const { dataIndex } = column;
|
|
142
|
+
rowData = rowData.toJSON();
|
|
143
|
+
const value = rowData[dataIndex[0]];
|
|
144
|
+
if (dataIndex.length > 1) {
|
|
145
|
+
const deepValue = (0, import_deep_get.deepGet)(rowData, dataIndex);
|
|
146
|
+
if (Array.isArray(deepValue)) {
|
|
147
|
+
return deepValue.join(",");
|
|
148
|
+
}
|
|
149
|
+
return deepValue;
|
|
150
|
+
}
|
|
151
|
+
const field = this.findFieldByDataIndex(dataIndex);
|
|
152
|
+
if (!field) {
|
|
153
|
+
return this.renderRawValue(value);
|
|
154
|
+
}
|
|
155
|
+
const fieldOptions = field.options;
|
|
156
|
+
const interfaceName = fieldOptions["interface"];
|
|
157
|
+
if (!interfaceName) {
|
|
158
|
+
return this.renderRawValue(value);
|
|
159
|
+
}
|
|
160
|
+
const InterfaceClass = this.options.collectionManager.getFieldInterface(interfaceName);
|
|
161
|
+
if (!InterfaceClass) {
|
|
162
|
+
return this.renderRawValue(value);
|
|
163
|
+
}
|
|
164
|
+
const interfaceInstance = new InterfaceClass(fieldOptions);
|
|
165
|
+
return interfaceInstance.toString(value, ctx);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
var xlsx_exporter_default = XlsxExporter;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "操作:导出记录",
|
|
5
5
|
"description": "Export filtered records to excel, you can configure which fields to export.",
|
|
6
6
|
"description.zh-CN": "导出筛选后的记录到 Excel 中,可以配置导出哪些字段。",
|
|
7
|
-
"version": "1.0.
|
|
7
|
+
"version": "1.0.1-alpha.2",
|
|
8
8
|
"license": "AGPL-3.0",
|
|
9
9
|
"main": "./dist/server/index.js",
|
|
10
10
|
"homepage": "https://docs.nocobase.com/handbook/action-export",
|
|
@@ -14,10 +14,12 @@
|
|
|
14
14
|
"@formily/react": "2.x",
|
|
15
15
|
"@formily/shared": "2.x",
|
|
16
16
|
"@types/node-xlsx": "^0.15.1",
|
|
17
|
+
"async-mutex": "^0.3.2",
|
|
17
18
|
"file-saver": "^2.0.5",
|
|
18
19
|
"node-xlsx": "^0.16.1",
|
|
19
20
|
"react": "^18.2.0",
|
|
20
|
-
"react-i18next": "^11.15.1"
|
|
21
|
+
"react-i18next": "^11.15.1",
|
|
22
|
+
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz"
|
|
21
23
|
},
|
|
22
24
|
"peerDependencies": {
|
|
23
25
|
"@nocobase/actions": "1.x",
|
|
@@ -27,7 +29,7 @@
|
|
|
27
29
|
"@nocobase/test": "1.x",
|
|
28
30
|
"@nocobase/utils": "1.x"
|
|
29
31
|
},
|
|
30
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "fc5a8e3c812516f787cb22d3d198f058f45b1963",
|
|
31
33
|
"keywords": [
|
|
32
34
|
"Actions"
|
|
33
35
|
]
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
exports.__esModule = true;
|
|
6
|
-
exports.buildSheetFromMatrix = exports.buildExcelDate = exports.isCellDescriptor = exports.isObject = exports.isString = exports.isNumber = exports.isBoolean = void 0;
|
|
7
|
-
|
|
8
|
-
var _xlsx = _interopRequireDefault(require("xlsx"));
|
|
9
|
-
|
|
10
|
-
var ORIGIN_DATE = new Date(Date.UTC(1899, 11, 30));
|
|
11
|
-
|
|
12
|
-
var isBoolean = function isBoolean(maybeBoolean) {
|
|
13
|
-
return typeof maybeBoolean === 'boolean';
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
exports.isBoolean = isBoolean;
|
|
17
|
-
|
|
18
|
-
var isNumber = function isNumber(maybeNumber) {
|
|
19
|
-
return typeof maybeNumber === 'number';
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
exports.isNumber = isNumber;
|
|
23
|
-
|
|
24
|
-
var isString = function isString(maybeString) {
|
|
25
|
-
return typeof maybeString === 'string';
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
exports.isString = isString;
|
|
29
|
-
|
|
30
|
-
var isObject = function isObject(maybeObject) {
|
|
31
|
-
return maybeObject !== null && typeof maybeObject === 'object';
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
exports.isObject = isObject;
|
|
35
|
-
|
|
36
|
-
var isCellDescriptor = function isCellDescriptor(maybeCell) {
|
|
37
|
-
return isObject(maybeCell) && 'v' in maybeCell;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
exports.isCellDescriptor = isCellDescriptor;
|
|
41
|
-
|
|
42
|
-
var buildExcelDate = function buildExcelDate(value, is1904) {
|
|
43
|
-
var epoch = Date.parse(value + (is1904 ? 1462 : 0));
|
|
44
|
-
return (epoch - ORIGIN_DATE) / 864e5;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
exports.buildExcelDate = buildExcelDate;
|
|
48
|
-
|
|
49
|
-
var buildSheetFromMatrix = function buildSheetFromMatrix(data, options) {
|
|
50
|
-
if (options === void 0) {
|
|
51
|
-
options = {};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
var workSheet = {};
|
|
55
|
-
var range = {
|
|
56
|
-
s: {
|
|
57
|
-
c: 1e7,
|
|
58
|
-
r: 1e7
|
|
59
|
-
},
|
|
60
|
-
e: {
|
|
61
|
-
c: 0,
|
|
62
|
-
r: 0
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
if (!Array.isArray(data)) throw new Error('sheet data is not array');
|
|
66
|
-
|
|
67
|
-
for (var R = 0; R !== data.length; R += 1) {
|
|
68
|
-
for (var C = 0; C !== data[R].length; C += 1) {
|
|
69
|
-
if (!Array.isArray(data[R])) throw new Error(`${R}th row data is not array`);
|
|
70
|
-
if (range.s.r > R) range.s.r = R;
|
|
71
|
-
if (range.s.c > C) range.s.c = C;
|
|
72
|
-
if (range.e.r < R) range.e.r = R;
|
|
73
|
-
if (range.e.c < C) range.e.c = C;
|
|
74
|
-
|
|
75
|
-
if (data[R][C] === null) {
|
|
76
|
-
continue; // eslint-disable-line
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
var cell = isCellDescriptor(data[R][C]) ? data[R][C] : {
|
|
80
|
-
v: data[R][C]
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
var cellRef = _xlsx.default.utils.encode_cell({
|
|
84
|
-
c: C,
|
|
85
|
-
r: R
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (isNumber(cell.v)) {
|
|
89
|
-
cell.t = 'n';
|
|
90
|
-
} else if (isBoolean(cell.v)) {
|
|
91
|
-
cell.t = 'b';
|
|
92
|
-
} else if (cell.v instanceof Date) {
|
|
93
|
-
cell.t = 'n';
|
|
94
|
-
cell.v = buildExcelDate(cell.v);
|
|
95
|
-
cell.z = cell.z || _xlsx.default.SSF._table[14]; // eslint-disable-line no-underscore-dangle
|
|
96
|
-
|
|
97
|
-
/* eslint-disable spaced-comment, no-trailing-spaces */
|
|
98
|
-
|
|
99
|
-
/***
|
|
100
|
-
* Allows for an non-abstracted representation of the data
|
|
101
|
-
*
|
|
102
|
-
* example: {t:'n', z:10, f:'=AVERAGE(A:A)'}
|
|
103
|
-
*
|
|
104
|
-
* Documentation:
|
|
105
|
-
* - Cell Object: https://sheetjs.gitbooks.io/docs/#cell-object
|
|
106
|
-
* - Data Types: https://sheetjs.gitbooks.io/docs/#data-types
|
|
107
|
-
* - Format: https://sheetjs.gitbooks.io/docs/#number-formats
|
|
108
|
-
**/
|
|
109
|
-
|
|
110
|
-
/* eslint-disable spaced-comment, no-trailing-spaces */
|
|
111
|
-
} else if (isObject(cell.v)) {
|
|
112
|
-
cell.t = cell.v.t;
|
|
113
|
-
cell.f = cell.v.f;
|
|
114
|
-
cell.F = cell.v.F;
|
|
115
|
-
cell.z = cell.v.z;
|
|
116
|
-
} else {
|
|
117
|
-
cell.t = 's';
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (isNumber(cell.z)) cell.z = _xlsx.default.SSF._table[cell.z]; // eslint-disable-line no-underscore-dangle
|
|
121
|
-
|
|
122
|
-
workSheet[cellRef] = cell;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (range.s.c < 1e7) {
|
|
127
|
-
workSheet['!ref'] = _xlsx.default.utils.encode_range(range);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (options['!cols']) {
|
|
131
|
-
workSheet['!cols'] = options['!cols'];
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (options['!merges']) {
|
|
135
|
-
workSheet['!merges'] = options['!merges'];
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return workSheet;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
exports.buildSheetFromMatrix = buildSheetFromMatrix;
|
|
142
|
-
//# sourceMappingURL=helpers.js.map
|