@arim-aisdc/public-components 2.3.94 → 2.3.96
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/components/TableMax/components/ColumnSort/customSortFns.d.ts +8 -8
- package/dist/components/TableMax/components/Export/index.js +3 -1
- package/dist/components/TableMax/components/Export/useTableExport.js +1 -1
- package/package.json +1 -1
- package/dist/components/TableMax/components/Export/index copy.d.ts +0 -48
- package/dist/components/TableMax/components/Export/index copy.js +0 -789
- package/dist/components/TableMax/components/Export/useTableExport copy.d.ts +0 -19
- package/dist/components/TableMax/components/Export/useTableExport copy.js +0 -538
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { TableMaxColumnType } from '../../type';
|
|
2
|
-
/**
|
|
3
|
-
* 流式导出配置
|
|
4
|
-
*/
|
|
5
|
-
export interface StreamExportOptions {
|
|
6
|
-
fileName?: string;
|
|
7
|
-
sheetName?: string;
|
|
8
|
-
maxConcurrent?: number;
|
|
9
|
-
onProgress?: (current: number, total: number, percent: number) => void;
|
|
10
|
-
onBatchComplete?: (batchIndex: number, totalBatches: number) => void;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* 表格导出Hook - 支持流式导出大数据量(带并发获取)
|
|
14
|
-
*/
|
|
15
|
-
export declare const useTableExport: () => {
|
|
16
|
-
exporting: boolean;
|
|
17
|
-
exportTableData: (data: any[], columns: TableMaxColumnType[], hasTotalRow: boolean, totalDatas: any[], customOptions: any) => Promise<void>;
|
|
18
|
-
streamExport: (getBatchData: (skipCount: number, batchSize: number) => Promise<any[]>, totalCount: number, columns: TableMaxColumnType[], options: StreamExportOptions, hasTotalRow?: boolean, totalDatas?: any[], retryCount?: number) => Promise<void>;
|
|
19
|
-
};
|
|
@@ -1,538 +0,0 @@
|
|
|
1
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
4
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
5
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
6
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
7
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
10
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
11
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
13
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
14
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
15
|
-
// hooks/useTableExport.ts
|
|
16
|
-
import { useCallback, useState } from 'react';
|
|
17
|
-
import * as XLSX from 'xlsx';
|
|
18
|
-
import { message } from 'antd';
|
|
19
|
-
// 定义列类型常量
|
|
20
|
-
var ColumnType = /*#__PURE__*/function (ColumnType) {
|
|
21
|
-
ColumnType["Selection"] = "selection-column";
|
|
22
|
-
ColumnType["Drag"] = "darg-column";
|
|
23
|
-
ColumnType["PlaceHolder"] = "placeholder-column";
|
|
24
|
-
ColumnType["Expander"] = "expander";
|
|
25
|
-
ColumnType["Index"] = "inner-index";
|
|
26
|
-
return ColumnType;
|
|
27
|
-
}(ColumnType || {});
|
|
28
|
-
/**
|
|
29
|
-
* 默认的单元格逻辑转换函数
|
|
30
|
-
*/
|
|
31
|
-
var defaultApplyCellLogic = function defaultApplyCellLogic(value, columnId, originalRow, column) {
|
|
32
|
-
var cell = column.cell,
|
|
33
|
-
accessorKey = column.accessorKey,
|
|
34
|
-
id = column.id,
|
|
35
|
-
exportValueFormat = column.exportValueFormat;
|
|
36
|
-
if (exportValueFormat) {
|
|
37
|
-
return exportValueFormat(originalRow);
|
|
38
|
-
}
|
|
39
|
-
if (cell) {
|
|
40
|
-
try {
|
|
41
|
-
var cellInfo = {
|
|
42
|
-
getValue: function getValue() {
|
|
43
|
-
return value;
|
|
44
|
-
},
|
|
45
|
-
row: {
|
|
46
|
-
original: originalRow
|
|
47
|
-
},
|
|
48
|
-
column: {
|
|
49
|
-
id: columnId
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
var cellResult = cell(cellInfo);
|
|
53
|
-
if (cellResult === null || cellResult === undefined || cellResult === false) {
|
|
54
|
-
return '';
|
|
55
|
-
}
|
|
56
|
-
if (cellResult && _typeof(cellResult) === 'object' && cellResult !== null && cellResult !== void 0 && cellResult.props) {
|
|
57
|
-
var _cellResult$props;
|
|
58
|
-
if ((_cellResult$props = cellResult.props) !== null && _cellResult$props !== void 0 && _cellResult$props.label) {
|
|
59
|
-
var _cellResult$props2;
|
|
60
|
-
return (_cellResult$props2 = cellResult.props) === null || _cellResult$props2 === void 0 ? void 0 : _cellResult$props2.label;
|
|
61
|
-
}
|
|
62
|
-
return value;
|
|
63
|
-
}
|
|
64
|
-
return cellResult !== null && cellResult !== void 0 ? cellResult : '';
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.warn("\u5904\u7406\u5217 ".concat(columnId, " \u7684cell\u51FD\u6570\u65F6\u51FA\u9519:"), error);
|
|
67
|
-
return value !== null && value !== void 0 ? value : '';
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return value !== null && value !== void 0 ? value : '';
|
|
71
|
-
};
|
|
72
|
-
var EnableExportColumnTypeList = [ColumnType.Selection, ColumnType.Drag, ColumnType.PlaceHolder, ColumnType.Expander];
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 流式导出配置
|
|
76
|
-
*/
|
|
77
|
-
/**
|
|
78
|
-
* 带重试功能的请求
|
|
79
|
-
*/
|
|
80
|
-
function fetchWithRetry(_x) {
|
|
81
|
-
return _fetchWithRetry.apply(this, arguments);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* 表格导出Hook - 支持流式导出大数据量(带并发获取)
|
|
85
|
-
*/
|
|
86
|
-
function _fetchWithRetry() {
|
|
87
|
-
_fetchWithRetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(fn) {
|
|
88
|
-
var retryCount,
|
|
89
|
-
lastError,
|
|
90
|
-
_loop,
|
|
91
|
-
_ret,
|
|
92
|
-
attempt,
|
|
93
|
-
_args7 = arguments;
|
|
94
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context7) {
|
|
95
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
96
|
-
case 0:
|
|
97
|
-
retryCount = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : 2;
|
|
98
|
-
lastError = null;
|
|
99
|
-
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
100
|
-
var delay;
|
|
101
|
-
return _regeneratorRuntime().wrap(function _loop$(_context6) {
|
|
102
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
103
|
-
case 0:
|
|
104
|
-
_context6.prev = 0;
|
|
105
|
-
_context6.next = 3;
|
|
106
|
-
return fn();
|
|
107
|
-
case 3:
|
|
108
|
-
_context6.t0 = _context6.sent;
|
|
109
|
-
return _context6.abrupt("return", {
|
|
110
|
-
v: _context6.t0
|
|
111
|
-
});
|
|
112
|
-
case 7:
|
|
113
|
-
_context6.prev = 7;
|
|
114
|
-
_context6.t1 = _context6["catch"](0);
|
|
115
|
-
lastError = _context6.t1;
|
|
116
|
-
if (!(attempt < retryCount)) {
|
|
117
|
-
_context6.next = 14;
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
delay = Math.pow(2, attempt) * 1000;
|
|
121
|
-
_context6.next = 14;
|
|
122
|
-
return new Promise(function (resolve) {
|
|
123
|
-
return setTimeout(resolve, delay);
|
|
124
|
-
});
|
|
125
|
-
case 14:
|
|
126
|
-
case "end":
|
|
127
|
-
return _context6.stop();
|
|
128
|
-
}
|
|
129
|
-
}, _loop, null, [[0, 7]]);
|
|
130
|
-
});
|
|
131
|
-
attempt = 0;
|
|
132
|
-
case 4:
|
|
133
|
-
if (!(attempt <= retryCount)) {
|
|
134
|
-
_context7.next = 12;
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
return _context7.delegateYield(_loop(), "t0", 6);
|
|
138
|
-
case 6:
|
|
139
|
-
_ret = _context7.t0;
|
|
140
|
-
if (!_ret) {
|
|
141
|
-
_context7.next = 9;
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
return _context7.abrupt("return", _ret.v);
|
|
145
|
-
case 9:
|
|
146
|
-
attempt++;
|
|
147
|
-
_context7.next = 4;
|
|
148
|
-
break;
|
|
149
|
-
case 12:
|
|
150
|
-
throw lastError;
|
|
151
|
-
case 13:
|
|
152
|
-
case "end":
|
|
153
|
-
return _context7.stop();
|
|
154
|
-
}
|
|
155
|
-
}, _callee6);
|
|
156
|
-
}));
|
|
157
|
-
return _fetchWithRetry.apply(this, arguments);
|
|
158
|
-
}
|
|
159
|
-
export var useTableExport = function useTableExport() {
|
|
160
|
-
var _useState = useState(false),
|
|
161
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
162
|
-
exporting = _useState2[0],
|
|
163
|
-
setExporting = _useState2[1];
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* 处理单条数据为行对象
|
|
167
|
-
*/
|
|
168
|
-
var processRowData = useCallback(function (item, columns) {
|
|
169
|
-
var isTotalRow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
170
|
-
var processedItem = {};
|
|
171
|
-
columns.filter(function (col) {
|
|
172
|
-
return !EnableExportColumnTypeList.includes(col === null || col === void 0 ? void 0 : col.id) && !(col !== null && col !== void 0 && col.disabledExport);
|
|
173
|
-
}).forEach(function (column) {
|
|
174
|
-
var header = column.header,
|
|
175
|
-
id = column.id,
|
|
176
|
-
accessorKey = column.accessorKey,
|
|
177
|
-
accessorFn = column.accessorFn;
|
|
178
|
-
var value;
|
|
179
|
-
if (isTotalRow) {
|
|
180
|
-
var _item$accessorKey;
|
|
181
|
-
value = (_item$accessorKey = item[accessorKey]) !== null && _item$accessorKey !== void 0 ? _item$accessorKey : item[id];
|
|
182
|
-
} else {
|
|
183
|
-
if (accessorFn) {
|
|
184
|
-
value = accessorFn(item, 0);
|
|
185
|
-
} else if (accessorKey) {
|
|
186
|
-
value = item[accessorKey];
|
|
187
|
-
} else {
|
|
188
|
-
value = item[id];
|
|
189
|
-
}
|
|
190
|
-
value = defaultApplyCellLogic(value, id, item, column);
|
|
191
|
-
}
|
|
192
|
-
processedItem[typeof header === "string" ? header : accessorKey !== null && accessorKey !== void 0 ? accessorKey : id] = value;
|
|
193
|
-
});
|
|
194
|
-
return processedItem;
|
|
195
|
-
}, []);
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* 计算列宽
|
|
199
|
-
*/
|
|
200
|
-
var calculateColumnWidth = function calculateColumnWidth(header) {
|
|
201
|
-
if (!header) return 12;
|
|
202
|
-
var chineseCharCount = (header.match(/[^\x00-\xff]/g) || []).length;
|
|
203
|
-
var otherCharCount = header.length - chineseCharCount;
|
|
204
|
-
var width = chineseCharCount * 2 + otherCharCount * 1.1 + 4;
|
|
205
|
-
return Math.min(Math.max(width, 12), 50);
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* 获取表头
|
|
210
|
-
*/
|
|
211
|
-
var getHeaders = useCallback(function (columns) {
|
|
212
|
-
return columns.filter(function (col) {
|
|
213
|
-
return !EnableExportColumnTypeList.includes(col === null || col === void 0 ? void 0 : col.id) && !(col !== null && col !== void 0 && col.disabledExport);
|
|
214
|
-
}).map(function (col) {
|
|
215
|
-
var _col$accessorKey;
|
|
216
|
-
return typeof col.header === 'string' ? col.header : (_col$accessorKey = col.accessorKey) !== null && _col$accessorKey !== void 0 ? _col$accessorKey : col.id;
|
|
217
|
-
});
|
|
218
|
-
}, []);
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* 并发获取所有批次数据(有序返回)
|
|
222
|
-
*/
|
|
223
|
-
var fetchAllBatchesConcurrent = useCallback( /*#__PURE__*/function () {
|
|
224
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(getBatchData, totalCount, batchSize, maxConcurrent, retryCount, onProgress) {
|
|
225
|
-
var totalBatches, results, errors, currentIndex, activeCount, loadedCount;
|
|
226
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
227
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
228
|
-
case 0:
|
|
229
|
-
totalBatches = Math.ceil(totalCount / batchSize);
|
|
230
|
-
results = new Map();
|
|
231
|
-
errors = [];
|
|
232
|
-
currentIndex = 0;
|
|
233
|
-
activeCount = 0;
|
|
234
|
-
loadedCount = 0;
|
|
235
|
-
return _context3.abrupt("return", new Promise(function (resolve, reject) {
|
|
236
|
-
var executeNext = /*#__PURE__*/function () {
|
|
237
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
238
|
-
var _batchIndex, _skipCount, currentBatchSize;
|
|
239
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
240
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
241
|
-
case 0:
|
|
242
|
-
if (!(currentIndex >= totalBatches && activeCount === 0)) {
|
|
243
|
-
_context2.next = 3;
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
if (errors.length > 0) {
|
|
247
|
-
reject(new Error("\u90E8\u5206\u8BF7\u6C42\u5931\u8D25: ".concat(errors[0].error.message)));
|
|
248
|
-
} else {
|
|
249
|
-
resolve(results);
|
|
250
|
-
}
|
|
251
|
-
return _context2.abrupt("return");
|
|
252
|
-
case 3:
|
|
253
|
-
if (currentIndex < totalBatches && activeCount < maxConcurrent) {
|
|
254
|
-
_batchIndex = currentIndex;
|
|
255
|
-
_skipCount = _batchIndex * batchSize;
|
|
256
|
-
currentBatchSize = Math.min(batchSize, totalCount - _skipCount);
|
|
257
|
-
currentIndex++;
|
|
258
|
-
activeCount++;
|
|
259
|
-
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
260
|
-
var data;
|
|
261
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
262
|
-
while (1) switch (_context.prev = _context.next) {
|
|
263
|
-
case 0:
|
|
264
|
-
_context.prev = 0;
|
|
265
|
-
_context.next = 3;
|
|
266
|
-
return fetchWithRetry(function () {
|
|
267
|
-
return getBatchData(_skipCount, currentBatchSize);
|
|
268
|
-
}, retryCount);
|
|
269
|
-
case 3:
|
|
270
|
-
data = _context.sent;
|
|
271
|
-
results.set(_batchIndex, data);
|
|
272
|
-
loadedCount += data.length;
|
|
273
|
-
onProgress === null || onProgress === void 0 || onProgress(loadedCount);
|
|
274
|
-
_context.next = 12;
|
|
275
|
-
break;
|
|
276
|
-
case 9:
|
|
277
|
-
_context.prev = 9;
|
|
278
|
-
_context.t0 = _context["catch"](0);
|
|
279
|
-
errors.push({
|
|
280
|
-
batchIndex: _batchIndex,
|
|
281
|
-
error: _context.t0
|
|
282
|
-
});
|
|
283
|
-
case 12:
|
|
284
|
-
_context.prev = 12;
|
|
285
|
-
activeCount--;
|
|
286
|
-
executeNext();
|
|
287
|
-
return _context.finish(12);
|
|
288
|
-
case 16:
|
|
289
|
-
case "end":
|
|
290
|
-
return _context.stop();
|
|
291
|
-
}
|
|
292
|
-
}, _callee, null, [[0, 9, 12, 16]]);
|
|
293
|
-
}))();
|
|
294
|
-
executeNext();
|
|
295
|
-
}
|
|
296
|
-
case 4:
|
|
297
|
-
case "end":
|
|
298
|
-
return _context2.stop();
|
|
299
|
-
}
|
|
300
|
-
}, _callee2);
|
|
301
|
-
}));
|
|
302
|
-
return function executeNext() {
|
|
303
|
-
return _ref2.apply(this, arguments);
|
|
304
|
-
};
|
|
305
|
-
}();
|
|
306
|
-
for (var i = 0; i < Math.min(maxConcurrent, totalBatches); i++) {
|
|
307
|
-
executeNext();
|
|
308
|
-
}
|
|
309
|
-
}));
|
|
310
|
-
case 7:
|
|
311
|
-
case "end":
|
|
312
|
-
return _context3.stop();
|
|
313
|
-
}
|
|
314
|
-
}, _callee3);
|
|
315
|
-
}));
|
|
316
|
-
return function (_x2, _x3, _x4, _x5, _x6, _x7) {
|
|
317
|
-
return _ref.apply(this, arguments);
|
|
318
|
-
};
|
|
319
|
-
}(), []);
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* 流式导出 - 支持并发获取,边获取边写入
|
|
323
|
-
*/
|
|
324
|
-
var streamExport = useCallback( /*#__PURE__*/function () {
|
|
325
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(getBatchData, totalCount, columns, options, hasTotalRow, totalDatas) {
|
|
326
|
-
var retryCount,
|
|
327
|
-
_options$fileName,
|
|
328
|
-
fileName,
|
|
329
|
-
_options$sheetName,
|
|
330
|
-
sheetName,
|
|
331
|
-
_options$maxConcurren,
|
|
332
|
-
maxConcurrent,
|
|
333
|
-
onProgress,
|
|
334
|
-
onBatchComplete,
|
|
335
|
-
workbook,
|
|
336
|
-
headers,
|
|
337
|
-
worksheet,
|
|
338
|
-
colWidths,
|
|
339
|
-
BATCH_SIZE,
|
|
340
|
-
_totalBatches,
|
|
341
|
-
writtenRowCount,
|
|
342
|
-
completedBatches,
|
|
343
|
-
pendingBatches,
|
|
344
|
-
writeBatchToSheet,
|
|
345
|
-
handleBatchComplete,
|
|
346
|
-
results,
|
|
347
|
-
i,
|
|
348
|
-
data,
|
|
349
|
-
totalRow,
|
|
350
|
-
totalSheetRow,
|
|
351
|
-
timestamp,
|
|
352
|
-
exportFilename,
|
|
353
|
-
_args4 = arguments;
|
|
354
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
355
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
356
|
-
case 0:
|
|
357
|
-
retryCount = _args4.length > 6 && _args4[6] !== undefined ? _args4[6] : 2;
|
|
358
|
-
_options$fileName = options.fileName, fileName = _options$fileName === void 0 ? 'export' : _options$fileName, _options$sheetName = options.sheetName, sheetName = _options$sheetName === void 0 ? 'Sheet1' : _options$sheetName, _options$maxConcurren = options.maxConcurrent, maxConcurrent = _options$maxConcurren === void 0 ? 3 : _options$maxConcurren, onProgress = options.onProgress, onBatchComplete = options.onBatchComplete;
|
|
359
|
-
if (!exporting) {
|
|
360
|
-
_context4.next = 5;
|
|
361
|
-
break;
|
|
362
|
-
}
|
|
363
|
-
message.warning('已有导出任务在进行中');
|
|
364
|
-
return _context4.abrupt("return");
|
|
365
|
-
case 5:
|
|
366
|
-
setExporting(true);
|
|
367
|
-
_context4.prev = 6;
|
|
368
|
-
// 创建工作簿和工作表
|
|
369
|
-
workbook = XLSX.utils.book_new();
|
|
370
|
-
headers = getHeaders(columns);
|
|
371
|
-
worksheet = XLSX.utils.aoa_to_sheet([headers]); // 设置列宽
|
|
372
|
-
colWidths = columns.filter(function (col) {
|
|
373
|
-
return !EnableExportColumnTypeList.includes(col === null || col === void 0 ? void 0 : col.id) && !(col !== null && col !== void 0 && col.disabledExport);
|
|
374
|
-
}).map(function (col) {
|
|
375
|
-
return {
|
|
376
|
-
wch: calculateColumnWidth(typeof col.header === 'string' ? col.header : undefined)
|
|
377
|
-
};
|
|
378
|
-
});
|
|
379
|
-
worksheet['!cols'] = colWidths;
|
|
380
|
-
BATCH_SIZE = 1000;
|
|
381
|
-
_totalBatches = Math.ceil(totalCount / BATCH_SIZE); // 记录已写入的行数
|
|
382
|
-
writtenRowCount = 0; // 记录已完成的批次(按顺序)
|
|
383
|
-
completedBatches = new Set(); // 缓存未按顺序到达的批次数据
|
|
384
|
-
pendingBatches = new Map(); // 写入数据到工作表
|
|
385
|
-
writeBatchToSheet = function writeBatchToSheet(batchIndex, data) {
|
|
386
|
-
var rows = data.map(function (item) {
|
|
387
|
-
return processRowData(item, columns, false);
|
|
388
|
-
});
|
|
389
|
-
var sheetRows = rows.map(function (row) {
|
|
390
|
-
return headers.map(function (header) {
|
|
391
|
-
var _row$header;
|
|
392
|
-
return (_row$header = row[header]) !== null && _row$header !== void 0 ? _row$header : '';
|
|
393
|
-
});
|
|
394
|
-
});
|
|
395
|
-
if (sheetRows.length > 0) {
|
|
396
|
-
// 计算写入位置:表头(1行) + 已写入的行数
|
|
397
|
-
var startRow = 1 + writtenRowCount;
|
|
398
|
-
XLSX.utils.sheet_add_aoa(worksheet, sheetRows, {
|
|
399
|
-
origin: "A".concat(startRow + 1)
|
|
400
|
-
});
|
|
401
|
-
writtenRowCount += sheetRows.length;
|
|
402
|
-
}
|
|
403
|
-
onBatchComplete === null || onBatchComplete === void 0 || onBatchComplete(batchIndex + 1, _totalBatches);
|
|
404
|
-
}; // 处理完成的数据(按顺序写入)
|
|
405
|
-
handleBatchComplete = function handleBatchComplete(batchIndex, data) {
|
|
406
|
-
pendingBatches.set(batchIndex, data);
|
|
407
|
-
|
|
408
|
-
// 按顺序写入
|
|
409
|
-
var nextBatchIndex = completedBatches.size;
|
|
410
|
-
while (pendingBatches.has(nextBatchIndex)) {
|
|
411
|
-
var batchData = pendingBatches.get(nextBatchIndex);
|
|
412
|
-
writeBatchToSheet(nextBatchIndex, batchData);
|
|
413
|
-
completedBatches.add(nextBatchIndex);
|
|
414
|
-
pendingBatches.delete(nextBatchIndex);
|
|
415
|
-
nextBatchIndex++;
|
|
416
|
-
}
|
|
417
|
-
}; // 并发获取所有批次
|
|
418
|
-
_context4.next = 21;
|
|
419
|
-
return fetchAllBatchesConcurrent(getBatchData, totalCount, BATCH_SIZE, maxConcurrent, retryCount, function (loadedCount) {
|
|
420
|
-
var percent = Math.floor(loadedCount / totalCount * 100);
|
|
421
|
-
onProgress === null || onProgress === void 0 || onProgress(loadedCount, totalCount, percent);
|
|
422
|
-
});
|
|
423
|
-
case 21:
|
|
424
|
-
results = _context4.sent;
|
|
425
|
-
// 按顺序处理所有结果
|
|
426
|
-
for (i = 0; i < _totalBatches; i++) {
|
|
427
|
-
data = results.get(i);
|
|
428
|
-
if (data) {
|
|
429
|
-
handleBatchComplete(i, data);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
// 添加合计行
|
|
434
|
-
if (hasTotalRow && totalDatas) {
|
|
435
|
-
totalRow = processRowData(totalDatas, columns, true);
|
|
436
|
-
totalSheetRow = [headers.map(function (header) {
|
|
437
|
-
var _totalRow$header;
|
|
438
|
-
return (_totalRow$header = totalRow[header]) !== null && _totalRow$header !== void 0 ? _totalRow$header : '';
|
|
439
|
-
})];
|
|
440
|
-
XLSX.utils.sheet_add_aoa(worksheet, totalSheetRow, {
|
|
441
|
-
origin: "A".concat(1 + writtenRowCount + 1)
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
// 添加工作表到工作簿
|
|
446
|
-
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
447
|
-
|
|
448
|
-
// 写入文件
|
|
449
|
-
timestamp = new Date().toISOString().slice(0, 19).replace(/:/g, '-');
|
|
450
|
-
exportFilename = "".concat(fileName, "_").concat(timestamp, ".xlsx");
|
|
451
|
-
XLSX.writeFile(workbook, exportFilename);
|
|
452
|
-
message.success("\u5BFC\u51FA\u6210\u529F: ".concat(exportFilename, " (\u5171 ").concat(totalCount, " \u6761\u6570\u636E)"));
|
|
453
|
-
_context4.next = 35;
|
|
454
|
-
break;
|
|
455
|
-
case 31:
|
|
456
|
-
_context4.prev = 31;
|
|
457
|
-
_context4.t0 = _context4["catch"](6);
|
|
458
|
-
console.error('导出失败:', _context4.t0);
|
|
459
|
-
message.error('导出失败,请重试');
|
|
460
|
-
case 35:
|
|
461
|
-
_context4.prev = 35;
|
|
462
|
-
setExporting(false);
|
|
463
|
-
return _context4.finish(35);
|
|
464
|
-
case 38:
|
|
465
|
-
case "end":
|
|
466
|
-
return _context4.stop();
|
|
467
|
-
}
|
|
468
|
-
}, _callee4, null, [[6, 31, 35, 38]]);
|
|
469
|
-
}));
|
|
470
|
-
return function (_x8, _x9, _x10, _x11, _x12, _x13) {
|
|
471
|
-
return _ref4.apply(this, arguments);
|
|
472
|
-
};
|
|
473
|
-
}(), [exporting, getHeaders, processRowData]);
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* 常规导出(小数据量)
|
|
477
|
-
*/
|
|
478
|
-
var exportTableData = useCallback( /*#__PURE__*/function () {
|
|
479
|
-
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(data, columns, hasTotalRow, totalDatas, customOptions) {
|
|
480
|
-
var _customOptions$isIncl, isIncludeTotalRow, _customOptions$fileNa, fileName, _customOptions$sheetN, sheetName, exportData, processedData, workbook, _worksheet, colWidths, timestamp, exportFilename;
|
|
481
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
482
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
483
|
-
case 0:
|
|
484
|
-
if (!exporting) {
|
|
485
|
-
_context5.next = 3;
|
|
486
|
-
break;
|
|
487
|
-
}
|
|
488
|
-
message.warning('已有导出任务在进行中');
|
|
489
|
-
return _context5.abrupt("return");
|
|
490
|
-
case 3:
|
|
491
|
-
setExporting(true);
|
|
492
|
-
try {
|
|
493
|
-
_customOptions$isIncl = customOptions.isIncludeTotalRow, isIncludeTotalRow = _customOptions$isIncl === void 0 ? true : _customOptions$isIncl, _customOptions$fileNa = customOptions.fileName, fileName = _customOptions$fileNa === void 0 ? 'export' : _customOptions$fileNa, _customOptions$sheetN = customOptions.sheetName, sheetName = _customOptions$sheetN === void 0 ? 'Sheet1' : _customOptions$sheetN;
|
|
494
|
-
exportData = _toConsumableArray(data);
|
|
495
|
-
if (isIncludeTotalRow && hasTotalRow && totalDatas) {
|
|
496
|
-
exportData.push(totalDatas);
|
|
497
|
-
}
|
|
498
|
-
processedData = exportData.map(function (item, index) {
|
|
499
|
-
var isTotalRow = isIncludeTotalRow && hasTotalRow && index === exportData.length - 1;
|
|
500
|
-
return processRowData(item, columns, isTotalRow);
|
|
501
|
-
});
|
|
502
|
-
workbook = XLSX.utils.book_new();
|
|
503
|
-
_worksheet = XLSX.utils.json_to_sheet(processedData);
|
|
504
|
-
colWidths = columns.filter(function (col) {
|
|
505
|
-
return !EnableExportColumnTypeList.includes(col === null || col === void 0 ? void 0 : col.id) && !(col !== null && col !== void 0 && col.disabledExport);
|
|
506
|
-
}).map(function (col) {
|
|
507
|
-
return {
|
|
508
|
-
wch: calculateColumnWidth(typeof col.header === 'string' ? col.header : undefined)
|
|
509
|
-
};
|
|
510
|
-
});
|
|
511
|
-
_worksheet['!cols'] = colWidths;
|
|
512
|
-
XLSX.utils.book_append_sheet(workbook, _worksheet, sheetName);
|
|
513
|
-
timestamp = new Date().toISOString().slice(0, 19).replace(/:/g, '-');
|
|
514
|
-
exportFilename = "".concat(fileName, "_").concat(timestamp, ".xlsx");
|
|
515
|
-
XLSX.writeFile(workbook, exportFilename);
|
|
516
|
-
message.success("\u5BFC\u51FA\u6210\u529F: ".concat(exportFilename));
|
|
517
|
-
} catch (error) {
|
|
518
|
-
console.error('导出失败:', error);
|
|
519
|
-
message.error('导出失败,请重试');
|
|
520
|
-
} finally {
|
|
521
|
-
setExporting(false);
|
|
522
|
-
}
|
|
523
|
-
case 5:
|
|
524
|
-
case "end":
|
|
525
|
-
return _context5.stop();
|
|
526
|
-
}
|
|
527
|
-
}, _callee5);
|
|
528
|
-
}));
|
|
529
|
-
return function (_x14, _x15, _x16, _x17, _x18) {
|
|
530
|
-
return _ref5.apply(this, arguments);
|
|
531
|
-
};
|
|
532
|
-
}(), [exporting, processRowData]);
|
|
533
|
-
return {
|
|
534
|
-
exporting: exporting,
|
|
535
|
-
exportTableData: exportTableData,
|
|
536
|
-
streamExport: streamExport
|
|
537
|
-
};
|
|
538
|
-
};
|