antd-import-export 0.0.0-stage → 1.0.1

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/index.mjs ADDED
@@ -0,0 +1,2172 @@
1
+ import e from "dayjs";
2
+ import t from "decimal.js";
3
+ import { saveAs as n } from "file-saver";
4
+ import r from "exceljs";
5
+ import { useCallback as i, useEffect as a, useMemo as o, useRef as s, useState as c, useSyncExternalStore as l } from "react";
6
+ import { DeleteOutlined as u, DownloadOutlined as d, FileOutlined as f, UploadOutlined as p } from "@ant-design/icons";
7
+ import { App as m, Button as h, Flex as g, Input as _, InputNumber as v, Modal as y, Popover as b, Progress as x, Select as S, Space as C, Table as ee, Tag as w, Tooltip as te, Typography as T, message as E, theme as ne } from "antd";
8
+ import { Fragment as re, jsx as D, jsxs as O } from "react/jsx-runtime";
9
+ // \0rolldown/runtime.js
10
+ var ie = Object.create, k = Object.defineProperty, A = Object.getOwnPropertyDescriptor, j = Object.getOwnPropertyNames, ae = Object.getPrototypeOf, oe = Object.prototype.hasOwnProperty, se = (e, t) => () => (t || (e((t = { exports: {} }).exports, t, t.exports), e = null), t.exports), M = (e, t, n, r) => {
11
+ if (t && typeof t == "object" || typeof t == "function") for (var i = j(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !oe.call(e, s) && s !== n && k(e, s, {
12
+ get: ((e) => t[e]).bind(null, s),
13
+ enumerable: !(r = A(t, s)) || r.enumerable
14
+ });
15
+ return e;
16
+ }, ce = (e, t, n) => (n = e == null ? {} : ie(ae(e)), M(t || !e || !e.__esModule || !oe.call(e, "default") ? k(n, "default", {
17
+ value: e,
18
+ enumerable: !0
19
+ }) : n, e));
20
+ // src/core/schema/index.ts
21
+ function le(e) {
22
+ return e.filter((e) => e.importable !== !1);
23
+ }
24
+ // src/core/schema/multiValue.ts
25
+ var ue = ";", de = /[;;]/;
26
+ function N(e) {
27
+ return e.map((e) => String(e)).join(";");
28
+ }
29
+ function P(e) {
30
+ return e.split(de).map((e) => e.trim()).filter(Boolean);
31
+ }
32
+ // src/core/schema/validate.ts
33
+ var fe = /* @__PURE__ */ ce((/* @__PURE__ */ se(((e, t, n) => {
34
+ (function(n, r) {
35
+ typeof e == "object" && t !== void 0 ? t.exports = r() : typeof define == "function" && define.amd ? define(r) : (n = typeof globalThis < "u" ? globalThis : n || self).dayjs_plugin_customParseFormat = r();
36
+ })(n, (function() {
37
+ var e = {
38
+ LTS: "h:mm:ss A",
39
+ LT: "h:mm A",
40
+ L: "MM/DD/YYYY",
41
+ LL: "MMMM D, YYYY",
42
+ LLL: "MMMM D, YYYY h:mm A",
43
+ LLLL: "dddd, MMMM D, YYYY h:mm A"
44
+ }, t = /(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|Q|YYYY|YY?|ww?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g, n = /\d/, r = /\d\d/, i = /\d\d?/, a = /\d*[^-_:/,()\s\d]+/, o = {}, s = function(e) {
45
+ return (e = +e) + (e > 68 ? 1900 : 2e3);
46
+ }, c = function(e) {
47
+ return function(t) {
48
+ this[e] = +t;
49
+ };
50
+ }, l = [/[+-]\d\d:?(\d\d)?|Z/, function(e) {
51
+ (this.zone ||= {}).offset = function(e) {
52
+ if (!e || e === "Z") return 0;
53
+ var t = e.match(/([+-]|\d\d)/g), n = 60 * t[1] + (+t[2] || 0);
54
+ return n === 0 ? 0 : t[0] === "+" ? -n : n;
55
+ }(e);
56
+ }], u = function(e) {
57
+ var t = o[e];
58
+ return t && (t.indexOf ? t : t.s.concat(t.f));
59
+ }, d = function(e, t) {
60
+ var n, r = o.meridiem;
61
+ if (r) {
62
+ for (var i = 1; i <= 24; i += 1) if (e.indexOf(r(i, 0, t)) > -1) {
63
+ n = i > 12;
64
+ break;
65
+ }
66
+ } else n = e === (t ? "pm" : "PM");
67
+ return n;
68
+ }, f = {
69
+ A: [a, function(e) {
70
+ this.afternoon = d(e, !1);
71
+ }],
72
+ a: [a, function(e) {
73
+ this.afternoon = d(e, !0);
74
+ }],
75
+ Q: [n, function(e) {
76
+ this.month = 3 * (e - 1) + 1;
77
+ }],
78
+ S: [n, function(e) {
79
+ this.milliseconds = 100 * e;
80
+ }],
81
+ SS: [r, function(e) {
82
+ this.milliseconds = 10 * e;
83
+ }],
84
+ SSS: [/\d{3}/, function(e) {
85
+ this.milliseconds = +e;
86
+ }],
87
+ s: [i, c("seconds")],
88
+ ss: [i, c("seconds")],
89
+ m: [i, c("minutes")],
90
+ mm: [i, c("minutes")],
91
+ H: [i, c("hours")],
92
+ h: [i, c("hours")],
93
+ HH: [i, c("hours")],
94
+ hh: [i, c("hours")],
95
+ D: [i, c("day")],
96
+ DD: [r, c("day")],
97
+ Do: [a, function(e) {
98
+ var t = o.ordinal, n = e.match(/\d+/);
99
+ if (this.day = n[0], t) for (var r = 1; r <= 31; r += 1) t(r).replace(/\[|\]/g, "") === e && (this.day = r);
100
+ }],
101
+ w: [i, c("week")],
102
+ ww: [r, c("week")],
103
+ M: [i, c("month")],
104
+ MM: [r, c("month")],
105
+ MMM: [a, function(e) {
106
+ var t = u("months"), n = (u("monthsShort") || t.map((function(e) {
107
+ return e.slice(0, 3);
108
+ }))).indexOf(e) + 1;
109
+ if (n < 1) throw Error();
110
+ this.month = n % 12 || n;
111
+ }],
112
+ MMMM: [a, function(e) {
113
+ var t = u("months").indexOf(e) + 1;
114
+ if (t < 1) throw Error();
115
+ this.month = t % 12 || t;
116
+ }],
117
+ Y: [/[+-]?\d+/, c("year")],
118
+ YY: [r, function(e) {
119
+ this.year = s(e);
120
+ }],
121
+ YYYY: [/\d{4}/, c("year")],
122
+ Z: l,
123
+ ZZ: l
124
+ };
125
+ function p(n) {
126
+ for (var r = n, i = o && o.formats, a = (n = r.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, (function(t, n, r) {
127
+ var a = r && r.toUpperCase();
128
+ return n || i[r] || e[r] || i[a].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, (function(e, t, n) {
129
+ return t || n.slice(1);
130
+ }));
131
+ }))).match(t), s = a.length, c = 0; c < s; c += 1) {
132
+ var l = a[c], u = f[l], d = u && u[0], p = u && u[1];
133
+ a[c] = p ? {
134
+ regex: d,
135
+ parser: p
136
+ } : l.replace(/^\[|\]$/g, "");
137
+ }
138
+ return function(e) {
139
+ for (var t = {}, n = 0, r = 0; n < s; n += 1) {
140
+ var i = a[n];
141
+ if (typeof i == "string") r += i.length;
142
+ else {
143
+ var o = i.regex, c = i.parser, l = e.slice(r), u = o.exec(l)[0];
144
+ c.call(t, u), e = e.replace(u, "");
145
+ }
146
+ }
147
+ return function(e) {
148
+ var t = e.afternoon;
149
+ if (t !== void 0) {
150
+ var n = e.hours;
151
+ t ? n < 12 && (e.hours += 12) : n === 12 && (e.hours = 0), delete e.afternoon;
152
+ }
153
+ }(t), t;
154
+ };
155
+ }
156
+ return function(e, t, n) {
157
+ n.p.customParseFormat = !0, e && e.parseTwoDigitYear && (s = e.parseTwoDigitYear);
158
+ var r = t.prototype, i = r.parse;
159
+ r.parse = function(e) {
160
+ var t = e.date, r = e.utc, a = e.args;
161
+ this.$u = r;
162
+ var s = a[1];
163
+ if (typeof s == "string") {
164
+ var c = !0 === a[2], l = !0 === a[3], u = c || l, d = a[2];
165
+ l && (d = a[2]), o = this.$locale(), !c && d && (o = n.Ls[d]), this.$d = function(e, t, n, r) {
166
+ try {
167
+ if (["x", "X"].indexOf(t) > -1) return /* @__PURE__ */ new Date((t === "X" ? 1e3 : 1) * e);
168
+ var i = p(t)(e), a = i.year, o = i.month, s = i.day, c = i.hours, l = i.minutes, u = i.seconds, d = i.milliseconds, f = i.zone, m = i.week, h = /* @__PURE__ */ new Date(), g = s || (a || o ? 1 : h.getDate()), _ = a || h.getFullYear(), v = 0;
169
+ a && !o || (v = o > 0 ? o - 1 : h.getMonth());
170
+ var y, b = c || 0, x = l || 0, S = u || 0, C = d || 0;
171
+ return f ? new Date(Date.UTC(_, v, g, b, x, S, C + 60 * f.offset * 1e3)) : n ? new Date(Date.UTC(_, v, g, b, x, S, C)) : (y = new Date(_, v, g, b, x, S, C), m && (y = r(y).week(m).toDate()), y);
172
+ } catch {
173
+ return /* @__PURE__ */ new Date("");
174
+ }
175
+ }(t, s, r, n), this.init(), d && !0 !== d && (this.$L = this.locale(d).$L), u && t != this.format(s) && (this.$d = /* @__PURE__ */ new Date("")), o = {};
176
+ } else if (s instanceof Array) for (var f = s.length, m = 1; m <= f; m += 1) {
177
+ a[1] = s[m - 1];
178
+ var h = n.apply(this, a);
179
+ if (h.isValid()) {
180
+ this.$d = h.$d, this.$L = h.$L, this.init();
181
+ break;
182
+ }
183
+ m === f && (this.$d = /* @__PURE__ */ new Date(""));
184
+ }
185
+ else i.call(this, e);
186
+ };
187
+ };
188
+ }));
189
+ })))(), 1);
190
+ e.extend(fe.default);
191
+ function pe(e, t) {
192
+ return e.length > t.property.max_length ? {
193
+ validateSuccess: !1,
194
+ validateMessage: `长度不能超过 ${t.property.max_length}`
195
+ } : {
196
+ validateSuccess: !0,
197
+ validateValue: e
198
+ };
199
+ }
200
+ function me(e, n) {
201
+ let r = Number(e);
202
+ if (!Number.isFinite(r)) return {
203
+ validateSuccess: !1,
204
+ validateMessage: "不是有效数字"
205
+ };
206
+ let i = n.property.precision, a;
207
+ try {
208
+ a = new t(e);
209
+ } catch {
210
+ return {
211
+ validateSuccess: !1,
212
+ validateMessage: "不是有效数字"
213
+ };
214
+ }
215
+ if (a.decimalPlaces() > i) return {
216
+ validateSuccess: !1,
217
+ validateMessage: `精度不能超过 ${i} 位小数`
218
+ };
219
+ let o = n.property.max_digits;
220
+ if (o !== void 0) {
221
+ let e = a.abs().trunc().toFixed(0).replace(/^0+/, "").length, t = o - i;
222
+ if (e > t) return {
223
+ validateSuccess: !1,
224
+ validateMessage: `整数部分不能超过 ${t} 位`
225
+ };
226
+ }
227
+ return n.property.min_value !== void 0 && r < n.property.min_value ? {
228
+ validateSuccess: !1,
229
+ validateMessage: `不能小于 ${n.property.min_value}`
230
+ } : n.property.max_value !== void 0 && r > n.property.max_value ? {
231
+ validateSuccess: !1,
232
+ validateMessage: `不能大于 ${n.property.max_value}`
233
+ } : {
234
+ validateSuccess: !0,
235
+ validateValue: r
236
+ };
237
+ }
238
+ function he(e, t) {
239
+ return e === t.property.true_label ? {
240
+ validateSuccess: !0,
241
+ validateValue: !0
242
+ } : e === t.property.false_label ? {
243
+ validateSuccess: !0,
244
+ validateValue: !1
245
+ } : {
246
+ validateSuccess: !1,
247
+ validateMessage: `内容必须是 ${t.property.true_label}|${t.property.false_label}`
248
+ };
249
+ }
250
+ function F(t) {
251
+ let n = e(t, "YYYY-MM-DD", !0);
252
+ return n.isValid() ? {
253
+ validateSuccess: !0,
254
+ validateValue: n.format("YYYY-MM-DD")
255
+ } : {
256
+ validateSuccess: !1,
257
+ validateMessage: "不是有效的日期格式 YYYY-MM-DD"
258
+ };
259
+ }
260
+ function ge(e) {
261
+ let t = /^([01]?[0-9]|2[0-3]):([0-5][0-9])$/.exec(e);
262
+ return t ? {
263
+ validateSuccess: !0,
264
+ validateValue: `${t[1].padStart(2, "0")}:${t[2]}`
265
+ } : {
266
+ validateSuccess: !1,
267
+ validateMessage: "不是有效的日期格式 HH:mm"
268
+ };
269
+ }
270
+ function I(t) {
271
+ let n = e(t, "YYYY-MM-DD HH:mm", !0);
272
+ return n.isValid() ? {
273
+ validateSuccess: !0,
274
+ validateValue: n.format("YYYY-MM-DD HH:mm")
275
+ } : {
276
+ validateSuccess: !1,
277
+ validateMessage: "不是有效的日期时间格式 YYYY-MM-DD HH:mm"
278
+ };
279
+ }
280
+ function L(e, t) {
281
+ let n = P(e);
282
+ if (n.length > t.property.list_max_length) return {
283
+ validateSuccess: !1,
284
+ validateMessage: `列表长度不能超过 ${t.property.list_max_length}`
285
+ };
286
+ for (let e of n) if (e.length > t.property.text_max_length) return {
287
+ validateSuccess: !1,
288
+ validateMessage: `单项文本长度不能超过 ${t.property.text_max_length}`
289
+ };
290
+ return {
291
+ validateSuccess: !0,
292
+ validateValue: n
293
+ };
294
+ }
295
+ function _e(e, t) {
296
+ return e in t.property.option_map ? {
297
+ validateSuccess: !0,
298
+ validateValue: t.property.option_map[e]
299
+ } : {
300
+ validateSuccess: !1,
301
+ validateMessage: `内容必须是 ${Object.keys(t.property.option_map).join("|")}`
302
+ };
303
+ }
304
+ function R(e, t) {
305
+ let n = P(e), r = t.property.option_map, i = [];
306
+ for (let e of n) {
307
+ if (!(e in r)) return {
308
+ validateSuccess: !1,
309
+ validateMessage: `内容必须是 ${Object.keys(r).join("|")}`
310
+ };
311
+ i.push(r[e]);
312
+ }
313
+ return {
314
+ validateSuccess: !0,
315
+ validateValue: i
316
+ };
317
+ }
318
+ function z(e, t) {
319
+ if (e === null) return t.property.required ? {
320
+ validateSuccess: !1,
321
+ validateMessage: "不能为空"
322
+ } : {
323
+ validateSuccess: !0,
324
+ validateValue: t.property.default_value
325
+ };
326
+ if (t.type === "text") return pe(e, t);
327
+ if (t.type === "number") return me(e, t);
328
+ if (t.type === "boolean") return he(e, t);
329
+ if (t.type === "date") return F(e);
330
+ if (t.type === "time") return ge(e);
331
+ if (t.type === "datetime") return I(e);
332
+ if (t.type === "list") return L(e, t);
333
+ if (t.type === "single_choice") return _e(e, t);
334
+ if (t.type === "multiple_choice") return R(e, t);
335
+ throw Error("未知的字段类型");
336
+ }
337
+ // src/core/limits.ts
338
+ var B = 2e4, ve = 2e4, ye = 20971520;
339
+ // src/core/excel/importEditor.ts
340
+ function be(e, t) {
341
+ if (t != null) {
342
+ if (e.type !== "single_choice" && e.type !== "multiple_choice") return String(t);
343
+ for (let [n, r] of Object.entries(e.property.option_map)) if (r === t) return n;
344
+ return String(t);
345
+ }
346
+ }
347
+ function xe(e, t) {
348
+ return e.type === "boolean" ? t === !0 ? e.property.true_label : t === !1 ? e.property.false_label : void 0 : e.type === "single_choice" ? be(e, t) : e.type === "multiple_choice" ? Array.isArray(t) ? t.map((t) => be(e, t)).filter(Boolean) : [] : e.type === "list" ? Array.isArray(t) ? N(t) : "" : e.type === "number" ? typeof t == "number" ? t : void 0 : t == null ? "" : String(t);
349
+ }
350
+ function Se(e, t) {
351
+ return t === null ? e.type === "multiple_choice" ? [] : "" : e.type === "multiple_choice" ? P(t) : t;
352
+ }
353
+ function Ce(e, t) {
354
+ return t == null ? "" : e.type === "boolean" || e.type === "single_choice" ? String(t) : (e.type === "multiple_choice" || e.type === "list") && Array.isArray(t) ? N(t) : String(t);
355
+ }
356
+ // src/core/excel/importRow.ts
357
+ function we(e, t, n) {
358
+ let r = {};
359
+ return t.forEach((t) => {
360
+ if (!n.includes(t.key)) return;
361
+ let i = Ce(t, e.values[t.key]), a = z(i.trim() === "" ? null : i, t);
362
+ if (!a.validateSuccess) throw Error(a.validateMessage);
363
+ r[t.key] = a.validateValue ?? null;
364
+ }), r;
365
+ }
366
+ // src/core/excel/parseSheet.ts
367
+ function Te(e) {
368
+ return !Number.isFinite(e) || e < 1 || e >= 2958466 ? null : new Date(Math.round((e - 25569) * 24 * 3600 * 1e3));
369
+ }
370
+ function V(e, t = !1) {
371
+ let n = String(e.getUTCMonth() + 1).padStart(2, "0"), r = String(e.getUTCDate()).padStart(2, "0"), i = `${e.getUTCFullYear()}-${n}-${r}`;
372
+ return t ? `${i} ${String(e.getUTCHours()).padStart(2, "0")}:${String(e.getUTCMinutes()).padStart(2, "0")}` : i;
373
+ }
374
+ function Ee(e, t) {
375
+ let n = (e) => e.trim() === "" ? null : e.trim(), i = t === "datetime", a = t === "date" || i;
376
+ if (e.type === r.ValueType.Null) return null;
377
+ if (e.type === r.ValueType.Date) return V(e.value, i);
378
+ if (e.type === r.ValueType.Formula) {
379
+ if (e.result === null || e.result === void 0) return null;
380
+ if (e.result instanceof Date) return V(e.result, i);
381
+ if (a && typeof e.result == "number") {
382
+ let t = Te(e.result);
383
+ if (t) return V(t, i);
384
+ }
385
+ return n(String(e.result));
386
+ }
387
+ if (e.type === r.ValueType.Number) {
388
+ if (a && typeof e.value == "number") {
389
+ let t = Te(e.value);
390
+ if (t) return V(t, i);
391
+ }
392
+ return n(String(e.value));
393
+ }
394
+ return n(e.text);
395
+ }
396
+ function De(e) {
397
+ let t = e.property.default_value;
398
+ if (t == null) return null;
399
+ if (e.type === "boolean") return t ? e.property.true_label : e.property.false_label;
400
+ if (Array.isArray(t)) return t.length > 0 ? N(t) : null;
401
+ let n = String(t);
402
+ return n.trim() === "" ? null : n;
403
+ }
404
+ function Oe(e, t) {
405
+ let n = new Map(t.map((e) => [e.title, e])), r = [];
406
+ for (let t = 1; t <= e.columnCount; t++) {
407
+ let i = e.getRow(1).getCell(t).text.split("\n")[0].trim();
408
+ r[t - 1] = n.get(i) ?? null;
409
+ }
410
+ return r;
411
+ }
412
+ function H(e, t) {
413
+ let n = [], i = [], a = [], o = 0, s = !1, c = Oe(e, t), l = c.filter((e) => e !== null).map((e) => e.key), u = new Set(l);
414
+ if (t.forEach((e) => {
415
+ e.property.required && !u.has(e.key) && n.push(`缺少列: ${e.title}`);
416
+ }), n.length > 0) return {
417
+ headerMessages: n,
418
+ formulaMessages: i,
419
+ rows: a,
420
+ includedKeys: l
421
+ };
422
+ let d = 0;
423
+ return e.eachRow({ includeEmpty: !1 }, (e, l) => {
424
+ if (l === 1) return;
425
+ let f = {};
426
+ if (c.forEach((t, n) => {
427
+ t && (f[t.key] = Ee(e.getCell(n + 1), t.type));
428
+ }), c.forEach((t, n) => {
429
+ if (!t) return;
430
+ let a = e.getCell(n + 1);
431
+ a.type === r.ValueType.Formula && (a.result === null || a.result === void 0) && (o += 1, i.length < 20 && i.push(`第 ${l} 行 [${t.title}] 是公式且没有保存计算结果, 请用 Excel 打开并保存后再导入`));
432
+ }), Object.values(f).every((e) => e === null)) return;
433
+ if (d += 1, d > 2e4) {
434
+ s ||= (n.push(`导入数据超出限制(${B} 条), 请分批导入`), !0);
435
+ return;
436
+ }
437
+ let p = {
438
+ key: String(a.length),
439
+ rowNumber: l,
440
+ values: {},
441
+ errors: {}
442
+ };
443
+ t.forEach((e) => {
444
+ if (!u.has(e.key)) return;
445
+ let t = z(f[e.key] ?? De(e), e);
446
+ t.validateSuccess ? p.values[e.key] = xe(e, t.validateValue ?? null) : (p.values[e.key] = Se(e, f[e.key] ?? null), p.errors[e.key] = t.validateMessage);
447
+ }), a.push(p);
448
+ }), o > i.length && i.push(`还有 ${o - i.length} 个公式单元格没有保存计算结果`), {
449
+ headerMessages: n,
450
+ formulaMessages: i,
451
+ rows: a,
452
+ includedKeys: l
453
+ };
454
+ }
455
+ // src/core/excel/worksheet.ts
456
+ function U(t, n) {
457
+ let r = n[t.key];
458
+ if (r == null || r === "") return null;
459
+ switch (t.type) {
460
+ case "datetime": return e(r).format("YYYY-MM-DD HH:mm");
461
+ case "boolean": return r ? t.property.true_label : t.property.false_label;
462
+ case "single_choice": {
463
+ let e = t.property.option_map;
464
+ return Object.keys(e).find((t) => e[t] === r) ?? String(r);
465
+ }
466
+ case "multiple_choice": {
467
+ let e = t.property.option_map;
468
+ return N((Array.isArray(r) ? r : [r]).map((t) => Object.keys(e).find((n) => e[n] === t) ?? String(t)));
469
+ }
470
+ case "list": {
471
+ let e = Array.isArray(r) ? r : [r], n = t.property.item_key;
472
+ return N(e.map((e) => String(n && typeof e == "object" && e ? e[n] ?? "" : e)));
473
+ }
474
+ default: return r;
475
+ }
476
+ }
477
+ function ke(e, t) {
478
+ t.forEach((t, n) => {
479
+ t.type === "text" && (e.getColumn(n + 1).numFmt = "@");
480
+ });
481
+ }
482
+ function Ae(e, t, n) {
483
+ let r = n.map((e) => e.importable === !1 ? `${e.title}\n(仅导出)` : e.title), i = e.addRow(r);
484
+ i.height = 20 + (Math.max(...r.map((e) => e.split("\n").length)) - 1) * 15, i.eachCell({ includeEmpty: !0 }, (e) => {
485
+ e.font = {
486
+ bold: !0,
487
+ size: 14,
488
+ color: { argb: "FFFFFFFF" }
489
+ }, e.fill = {
490
+ type: "pattern",
491
+ pattern: "solid",
492
+ fgColor: { argb: "FF4472C4" }
493
+ }, e.alignment = {
494
+ vertical: "middle",
495
+ wrapText: !0
496
+ };
497
+ }), t.forEach((t) => {
498
+ e.addRow(n.map((e) => U(e, t))).eachCell({ includeEmpty: !0 }, (e) => {
499
+ e.alignment = {
500
+ ...e.alignment,
501
+ wrapText: !0,
502
+ vertical: "top"
503
+ };
504
+ });
505
+ }), ke(e, n), Ne(e);
506
+ }
507
+ function je(e) {
508
+ let t = [e.property.required ? "必填" : "可选"];
509
+ switch (e.type) {
510
+ case "text":
511
+ t.push(`最长 ${e.property.max_length} 个字符`);
512
+ break;
513
+ case "number":
514
+ t.push(`最多 ${e.property.precision} 位小数`), e.property.max_digits !== void 0 && t.push(`整数最多 ${e.property.max_digits - e.property.precision} 位`), e.property.min_value !== void 0 && t.push(`最小 ${e.property.min_value}`), e.property.max_value !== void 0 && t.push(`最大 ${e.property.max_value}`);
515
+ break;
516
+ case "boolean":
517
+ t.push(`填 ${e.property.true_label} 或 ${e.property.false_label}`);
518
+ break;
519
+ case "date":
520
+ t.push("格式 YYYY-MM-DD");
521
+ break;
522
+ case "time":
523
+ t.push("格式 HH:mm");
524
+ break;
525
+ case "datetime":
526
+ t.push("格式 YYYY-MM-DD HH:mm");
527
+ break;
528
+ case "list":
529
+ t.push(`多个值用分号分隔(中英文均可), 最多 ${e.property.list_max_length} 个`);
530
+ break;
531
+ case "single_choice":
532
+ t.push(`填其一: ${Object.keys(e.property.option_map).join(" / ")}`);
533
+ break;
534
+ case "multiple_choice": t.push(`可多选, 分号分隔(中英文均可): ${Object.keys(e.property.option_map).join(" / ")}`);
535
+ }
536
+ e.key.endsWith("_name") ? t.push("填对应记录的名称") : e.key.endsWith("_number") && t.push("填对应记录的编号");
537
+ let n = U(e, { [e.key]: e.property.default_value });
538
+ return t.push(`默认值: ${n == null || n === "" ? "空" : n}`), t.join("\n");
539
+ }
540
+ function Me(e, t) {
541
+ let n = t.map((e) => `${e.title}\n\n${je(e)}`), r = e.addRow(n);
542
+ r.height = 20 + (Math.max(...n.map((e) => e.split("\n").length)) - 1) * 15, r.eachCell({ includeEmpty: !0 }, (e) => {
543
+ e.font = {
544
+ bold: !0,
545
+ size: 14,
546
+ color: { argb: "FFFFFFFF" }
547
+ }, e.fill = {
548
+ type: "pattern",
549
+ pattern: "solid",
550
+ fgColor: { argb: "FF4472C4" }
551
+ }, e.alignment = {
552
+ vertical: "top",
553
+ wrapText: !0
554
+ };
555
+ }), ke(e, t), Ne(e);
556
+ }
557
+ function Ne(e, t = 20, n = 60) {
558
+ let r = [];
559
+ e.eachRow({ includeEmpty: !1 }, (e) => {
560
+ e.eachCell({ includeEmpty: !1 }, (e, t) => {
561
+ let n = t - 1, i = e.text, a = e.font?.size || 11, o = .8 + a / 11 * .4, s = i.split("\n"), c = 0;
562
+ for (let e of s) {
563
+ let t = 0;
564
+ for (let n of e) {
565
+ let e = n.charCodeAt(0);
566
+ t += e > 255 || e >= 65280 && e <= 65519 ? 2 : 1;
567
+ }
568
+ c = Math.max(c, t);
569
+ }
570
+ let l = c * 7 * (a / 11) * o;
571
+ (!r[n] || l > r[n]) && (r[n] = l);
572
+ });
573
+ }), r.forEach((r, i) => {
574
+ let a = r / 7;
575
+ e.getColumn(i + 1).width = Math.min(Math.max(a, t), n);
576
+ });
577
+ }
578
+ // src/core/excel/runtime.ts
579
+ var Pe = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", Fe;
580
+ function Ie() {
581
+ return Fe ??= import("exceljs").then((e) => e.default ?? e), Fe;
582
+ }
583
+ function Le() {
584
+ return new Promise((e) => {
585
+ requestAnimationFrame(() => setTimeout(e, 0));
586
+ });
587
+ }
588
+ function Re(e) {
589
+ if (e?.aborted) throw new DOMException("任务已取消", "AbortError");
590
+ }
591
+ async function ze(e, t, n) {
592
+ let r = await Ie();
593
+ Re(n), await Le();
594
+ let i = new r.Workbook();
595
+ Ae(i.addWorksheet("Sheet"), e, t);
596
+ let a = await i.xlsx.writeBuffer();
597
+ return Re(n), new Blob([a], { type: Pe });
598
+ }
599
+ async function Be(e, t, r) {
600
+ let i = await ze(e, t);
601
+ return n(i, `${r}.xlsx`), i;
602
+ }
603
+ async function Ve(e, t) {
604
+ let r = await Ie();
605
+ await Le();
606
+ let i = new r.Workbook();
607
+ Me(i.addWorksheet("导入模板"), e);
608
+ let a = await i.xlsx.writeBuffer();
609
+ n(new Blob([a], { type: Pe }), `${t}.xlsx`);
610
+ }
611
+ async function He(e, t) {
612
+ let n = await Ie(), r = await e.arrayBuffer();
613
+ await Le();
614
+ let i = new n.Workbook();
615
+ if (await i.xlsx.load(r), i.worksheets.length > 1) return {
616
+ headerMessages: ["文件包含多个工作表, 只支持单个工作表, 请删除其他工作表后再导入"],
617
+ formulaMessages: [],
618
+ rows: [],
619
+ includedKeys: []
620
+ };
621
+ let a = i.worksheets[0];
622
+ return a ? H(a, t) : {
623
+ headerMessages: ["文件里没有工作表"],
624
+ formulaMessages: [],
625
+ rows: [],
626
+ includedKeys: []
627
+ };
628
+ }
629
+ // src/core/httpError.ts
630
+ function Ue(e) {
631
+ let t = e;
632
+ return t !== null && (t.isAxiosError === !0 || t.response !== void 0);
633
+ }
634
+ function We(e) {
635
+ let t = e?.response?.status;
636
+ return typeof t == "number" ? t : void 0;
637
+ }
638
+ function Ge(e) {
639
+ return e?.response?.data;
640
+ }
641
+ // src/core/taskManager.ts
642
+ var W = class extends Error {
643
+ constructor(e) {
644
+ super(e), this.name = "ImportPauseError";
645
+ }
646
+ }, Ke = 100, G = { tasks: [] }, qe = /* @__PURE__ */ new Set(), Je = /* @__PURE__ */ new Map(), K = /* @__PURE__ */ new Map(), q = /* @__PURE__ */ new Map();
647
+ function Ye() {
648
+ G = { ...G }, qe.forEach((e) => e());
649
+ }
650
+ function Xe(e) {
651
+ return qe.add(e), () => {
652
+ qe.delete(e);
653
+ };
654
+ }
655
+ function Ze(e) {
656
+ return Xe(e);
657
+ }
658
+ function Qe() {
659
+ return G.tasks;
660
+ }
661
+ function $e() {
662
+ return `task-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
663
+ }
664
+ function J(e) {
665
+ return G.tasks.find((t) => t.id === e);
666
+ }
667
+ function Y(e, t) {
668
+ let n = !1, r = G.tasks.map((r) => r.id === e ? (n = !0, {
669
+ ...r,
670
+ ...t
671
+ }) : r);
672
+ n && (G = {
673
+ ...G,
674
+ tasks: r
675
+ }, Ye());
676
+ }
677
+ function et(e, t) {
678
+ let n = J(e), r = Date.now();
679
+ return [...n?.samples ?? [], {
680
+ time: r,
681
+ processed: t
682
+ }].filter((e) => r - e.time <= 15e3).slice(-20);
683
+ }
684
+ var tt = 100, X = /* @__PURE__ */ new Set(), Z = null;
685
+ function nt(e, t, n) {
686
+ let r = K.get(e);
687
+ r && (r.rowStates[t] = {
688
+ ...r.rowStates[t],
689
+ ...n
690
+ }, rt(e));
691
+ }
692
+ function rt(e) {
693
+ X.add(e), Z === null && (Z = setTimeout(() => {
694
+ Z = null;
695
+ let e = [...X];
696
+ X.clear(), e.forEach(it);
697
+ }, tt));
698
+ }
699
+ function Q(e) {
700
+ X.delete(e);
701
+ }
702
+ function $(e, t) {
703
+ return {
704
+ processed: t.processed,
705
+ total: at(t),
706
+ successCount: t.successCount,
707
+ failureCount: t.failures.length,
708
+ validationFailedCount: t.validationFailedCount,
709
+ failures: t.failures,
710
+ rowStates: t.rowStates,
711
+ samples: et(e, t.processed)
712
+ };
713
+ }
714
+ function it(e) {
715
+ let t = K.get(e);
716
+ t && J(e) && Y(e, $(e, t));
717
+ }
718
+ function at(e) {
719
+ return e.options.rows.length - e.deletedIndexes.size;
720
+ }
721
+ async function ot(e, t, r) {
722
+ let { options: i } = t;
723
+ t.controller = r, t.cancelRequested = !1;
724
+ try {
725
+ for (; !t.cancelRequested;) {
726
+ let n = t.cursorId === void 0 ? {} : { cursor_id: t.cursorId }, a = await i.fetchPage(n, r.signal);
727
+ if (r.signal.aborted) throw new DOMException("任务已取消", "AbortError");
728
+ if (t.total = a.count, a.results.length === 0) break;
729
+ t.rows = t.rows.concat(a.results);
730
+ let o = t.rows.length;
731
+ Y(e, {
732
+ total: t.total,
733
+ processed: o,
734
+ samples: et(e, o)
735
+ });
736
+ let s = a.results[a.results.length - 1]?.id;
737
+ if (typeof s != "number") throw Error("导出数据缺少 id");
738
+ t.cursorId = s;
739
+ }
740
+ if (t.cancelRequested) {
741
+ Y(e, {
742
+ status: "canceled",
743
+ pausing: !1,
744
+ canceling: !1,
745
+ finalizing: !1
746
+ });
747
+ return;
748
+ }
749
+ if (t.rows.length === 0) throw Error("没有可导出的数据");
750
+ Y(e, { finalizing: !0 });
751
+ let a = await ze(t.rows, i.fieldSchemas, r.signal);
752
+ if (r.signal.aborted) throw new DOMException("任务已取消", "AbortError");
753
+ try {
754
+ n(a, `${i.fileName}.xlsx`);
755
+ } catch (e) {
756
+ console.error(`自动下载失败: ${e}`);
757
+ }
758
+ Y(e, {
759
+ status: "completed",
760
+ pausing: !1,
761
+ finalizing: !1,
762
+ canceling: !1,
763
+ total: t.rows.length,
764
+ processed: t.rows.length,
765
+ blob: a
766
+ });
767
+ } catch (t) {
768
+ if (r.signal.aborted) {
769
+ Y(e, {
770
+ status: "canceled",
771
+ pausing: !1,
772
+ finalizing: !1,
773
+ canceling: !1
774
+ });
775
+ return;
776
+ }
777
+ Y(e, {
778
+ status: "failed",
779
+ pausing: !1,
780
+ finalizing: !1,
781
+ canceling: !1,
782
+ errorMessage: st(t)
783
+ });
784
+ } finally {
785
+ t.controller = null;
786
+ }
787
+ }
788
+ function st(e) {
789
+ if (!Ue(e)) return e instanceof Error ? e.message : "导出失败";
790
+ let t = We(e);
791
+ return t === void 0 ? "网络异常, 导出失败" : t === 401 ? "登录已过期, 导出失败" : t === 403 ? "没有导出权限, 导出失败" : t === 404 ? "导出接口不存在, 导出失败" : t === 400 ? "导出参数错误, 导出失败" : t >= 500 ? "服务器错误, 导出失败" : "导出失败";
792
+ }
793
+ function ct(e) {
794
+ return `导入完成: 成功 ${e.successCount} 条, 失败 ${e.failures.length} 条`;
795
+ }
796
+ async function lt(e, t, n) {
797
+ let r = t.options.rows.length;
798
+ if (t.controller = n, t.pauseRequested = !1, t.cancelRequested = !1, t.cycleFailureCount = 0, r === 0) {
799
+ Y(e, {
800
+ status: "failed",
801
+ pausing: !1,
802
+ errorMessage: "没有可导入的数据"
803
+ }), t.options.onFinished?.();
804
+ return;
805
+ }
806
+ Y(e, {
807
+ ...$(e, t),
808
+ status: "running",
809
+ samples: [{
810
+ time: Date.now(),
811
+ processed: t.processed
812
+ }]
813
+ });
814
+ let i = Math.min(Math.max(t.options.batchSize ?? 20, 1), 200), a = Math.min(Math.max(t.options.concurrency ?? 3, 1), 5), o = () => {
815
+ let n = [];
816
+ for (; n.length < i;) {
817
+ let i = t.nextIndex;
818
+ if (t.nextIndex += 1, i >= r) break;
819
+ t.deletedIndexes.has(i) || J(e)?.rowStates?.[i]?.status !== "completed" && (t.skippedIndexes.has(i) || n.push(i));
820
+ }
821
+ return n;
822
+ }, s = async () => {
823
+ for (;;) {
824
+ if (n.signal.aborted || t.pauseRequested || t.cancelRequested) return;
825
+ let r = o();
826
+ if (r.length === 0) return;
827
+ r.forEach((t) => {
828
+ nt(e, t, {
829
+ status: "running",
830
+ message: void 0,
831
+ fieldErrors: void 0
832
+ });
833
+ });
834
+ try {
835
+ let i = r.map((e) => t.options.rows[e]), a = await t.options.importRows(i, n.signal);
836
+ if (n.signal.aborted) return;
837
+ if (a.length !== r.length) throw new W("导入接口返回结果数量不正确, 任务已暂停");
838
+ a.forEach((n, i) => {
839
+ let a = r[i], o = t.options.rows[a];
840
+ n.success ? (t.successCount += 1, nt(e, a, {
841
+ status: "completed",
842
+ fieldErrors: void 0
843
+ })) : (t.failures.push({
844
+ index: a,
845
+ rowNumber: o.rowNumber,
846
+ message: n.message ?? "导入失败",
847
+ fieldErrors: n.fieldErrors
848
+ }), nt(e, a, {
849
+ status: "failed",
850
+ message: n.message,
851
+ fieldErrors: n.fieldErrors
852
+ }), t.cycleFailureCount += 1, t.cycleFailureCount > Ke && (t.pauseRequested = !0));
853
+ });
854
+ } catch (i) {
855
+ if (n.signal.aborted) return;
856
+ let a = i instanceof W, o = i instanceof Error ? i.message : "导入失败";
857
+ r.forEach((n) => {
858
+ t.failures.push({
859
+ index: n,
860
+ rowNumber: t.options.rows[n].rowNumber,
861
+ message: o
862
+ }), nt(e, n, {
863
+ status: "failed",
864
+ message: o
865
+ }), t.cycleFailureCount += 1;
866
+ }), a ? (t.pauseRequested = !0, n.abort()) : t.cycleFailureCount > Ke && (t.pauseRequested = !0);
867
+ } finally {
868
+ t.processed += r.length, rt(e);
869
+ }
870
+ }
871
+ }, c = Math.min(a, Math.max(1, r));
872
+ if (await Promise.all(Array.from({ length: c }, () => s())), t.controller = null, !J(e)) return;
873
+ if (t.cancelRequested) {
874
+ Q(e), t.rowStates = t.rowStates.map((e) => e.status === "queued" || e.status === "running" ? { status: "canceled" } : e), Y(e, {
875
+ ...$(e, t),
876
+ status: "canceled",
877
+ pausing: !1,
878
+ canceling: !1
879
+ }), t.options.onFinished?.();
880
+ return;
881
+ }
882
+ if (t.pauseRequested && n.signal.aborted) {
883
+ Q(e), t.rowStates = t.rowStates.map((e) => e.status === "running" ? {
884
+ status: "queued",
885
+ validationErrors: e.validationErrors
886
+ } : e), Y(e, {
887
+ ...$(e, t),
888
+ status: "paused",
889
+ pausing: !1,
890
+ errorMessage: t.failures.length > 0 ? `累计失败 ${t.failures.length} 条, 任务已暂停, 可继续导入` : void 0
891
+ }), t.options.onFinished?.();
892
+ return;
893
+ }
894
+ if (n.signal.aborted) {
895
+ Q(e), t.rowStates = t.rowStates.map((e) => e.status === "queued" || e.status === "running" ? { status: "canceled" } : e), Y(e, {
896
+ ...$(e, t),
897
+ status: "canceled",
898
+ pausing: !1,
899
+ canceling: !1
900
+ }), t.options.onFinished?.();
901
+ return;
902
+ }
903
+ if (t.pauseRequested && t.nextIndex < r) {
904
+ Q(e), Y(e, {
905
+ ...$(e, t),
906
+ status: "paused",
907
+ pausing: !1,
908
+ errorMessage: t.failures.length > 0 ? `累计失败 ${t.failures.length} 条, 任务已暂停, 可继续导入` : void 0
909
+ }), t.options.onFinished?.();
910
+ return;
911
+ }
912
+ if (t.failures.length > 0) {
913
+ Q(e), Y(e, {
914
+ ...$(e, t),
915
+ status: "paused",
916
+ pausing: !1,
917
+ errorMessage: ct(t)
918
+ }), t.options.onFinished?.();
919
+ return;
920
+ }
921
+ let l = [...t.skippedIndexes].filter((e) => !t.deletedIndexes.has(e)).length;
922
+ l > 0 ? (Q(e), Y(e, {
923
+ ...$(e, t),
924
+ status: "paused",
925
+ pausing: !1,
926
+ errorMessage: `有 ${l} 条校验失败数据待修复`
927
+ }), t.options.onFinished?.()) : (Q(e), Y(e, {
928
+ ...$(e, t),
929
+ status: "completed",
930
+ pausing: !1
931
+ }), t.options.onFinished?.());
932
+ }
933
+ function ut(e, t) {
934
+ let n = new AbortController();
935
+ q.set(e, n), ot(e, t, n).finally(() => {
936
+ q.delete(e), Je.delete(e);
937
+ });
938
+ }
939
+ function dt(e, t) {
940
+ let n = new AbortController();
941
+ q.set(e, n), lt(e, t, n).finally(() => {
942
+ q.delete(e), X.delete(e), J(e)?.status !== "paused" && K.delete(e);
943
+ });
944
+ }
945
+ function ft(e) {
946
+ let t = $e(), n = {
947
+ id: t,
948
+ type: "export",
949
+ title: e.title,
950
+ status: "running",
951
+ total: 0,
952
+ processed: 0,
953
+ fileName: e.fileName,
954
+ samples: []
955
+ };
956
+ G = {
957
+ ...G,
958
+ tasks: [...G.tasks, n]
959
+ };
960
+ let r = {
961
+ options: e,
962
+ rows: [],
963
+ total: 0,
964
+ cancelRequested: !1,
965
+ controller: null
966
+ };
967
+ return Je.set(t, r), Ye(), ut(t, r), t;
968
+ }
969
+ function pt(e) {
970
+ let t = $e(), n = e.rows.map((e) => ({
971
+ status: "queued",
972
+ validationErrors: Object.keys(e.errors).length > 0 ? e.errors : void 0
973
+ })), r = new Set(e.rows.flatMap((e, t) => Object.keys(e.errors).length > 0 ? [t] : [])), i = r.size, a = {
974
+ id: t,
975
+ type: "import",
976
+ title: e.title,
977
+ status: "running",
978
+ total: e.rows.length,
979
+ processed: 0,
980
+ canceling: !1,
981
+ successCount: 0,
982
+ failureCount: 0,
983
+ validationFailedCount: i,
984
+ rowStates: n,
985
+ failures: [],
986
+ samples: []
987
+ };
988
+ G = {
989
+ ...G,
990
+ tasks: [...G.tasks, a]
991
+ };
992
+ let o = {
993
+ options: e,
994
+ nextIndex: 0,
995
+ processed: 0,
996
+ successCount: 0,
997
+ failures: [],
998
+ rowStates: n,
999
+ validationFailedCount: i,
1000
+ pauseRequested: !1,
1001
+ cancelRequested: !1,
1002
+ deletedIndexes: /* @__PURE__ */ new Set(),
1003
+ skippedIndexes: r,
1004
+ cycleFailureCount: 0,
1005
+ controller: null
1006
+ };
1007
+ return K.set(t, o), Ye(), dt(t, o), t;
1008
+ }
1009
+ function mt(e) {
1010
+ let t = J(e);
1011
+ if (!t || t.type !== "import" || t.status !== "paused") return;
1012
+ let n = K.get(e);
1013
+ if (!n) return;
1014
+ let r = n.rowStates.filter((e) => e.status === "completed").length, i = n.rowStates.map((e) => e.status === "completed" || e.status === "deleted" ? e : {
1015
+ status: "queued",
1016
+ validationErrors: e.validationErrors
1017
+ }), a = i.filter((e) => e.validationErrors && Object.keys(e.validationErrors).length > 0).length;
1018
+ n.rowStates = i, n.validationFailedCount = a, n.nextIndex = 0, n.processed = r, n.successCount = r, n.failures = [], n.pauseRequested = !1, n.cancelRequested = !1, n.cycleFailureCount = 0, Y(e, {
1019
+ status: "running",
1020
+ pausing: !1,
1021
+ canceling: !1,
1022
+ processed: r,
1023
+ successCount: r,
1024
+ failureCount: 0,
1025
+ validationFailedCount: a,
1026
+ failures: [],
1027
+ rowStates: i,
1028
+ errorMessage: void 0
1029
+ }), dt(e, n);
1030
+ }
1031
+ function ht(e) {
1032
+ let t = J(e);
1033
+ if (!t || t.type !== "import" || t.status !== "running" || t.canceling) return;
1034
+ let n = K.get(e);
1035
+ n && (n.pauseRequested = !0, Y(e, { pausing: !0 }));
1036
+ }
1037
+ function gt(e, t, n) {
1038
+ let r = J(e), i = K.get(e);
1039
+ if (!r || r.type !== "import" || r.status !== "paused" && r.status !== "failed" || !i) return;
1040
+ let a = r.rowStates?.[t]?.status;
1041
+ (a === "queued" || a === "failed") && (i.options.rows[t] = n);
1042
+ }
1043
+ function _t(e, t, n) {
1044
+ let r = J(e), i = K.get(e);
1045
+ if (!r || r.type !== "import" || !i || r.status !== "paused" && r.status !== "failed") return;
1046
+ let a = Object.keys(n).length > 0, o = i.rowStates[t]?.validationErrors, s = !!(o && Object.keys(o).length > 0);
1047
+ a ? (i.skippedIndexes.add(t), s || (i.validationFailedCount += 1)) : (i.skippedIndexes.delete(t), s && --i.validationFailedCount), i.rowStates[t] = {
1048
+ ...i.rowStates[t],
1049
+ validationErrors: a ? n : void 0
1050
+ }, i.options.rows[t] = {
1051
+ ...i.options.rows[t],
1052
+ errors: n
1053
+ }, Y(e, {
1054
+ validationFailedCount: i.validationFailedCount,
1055
+ rowStates: i.rowStates
1056
+ });
1057
+ }
1058
+ function vt(e, t) {
1059
+ let n = J(e), r = K.get(e);
1060
+ n && n.type === "import" && n.status === "paused" && r && (t.forEach((e) => {
1061
+ let t = r.rowStates[e];
1062
+ t?.status === "queued" && (t.validationErrors && Object.keys(t.validationErrors).length > 0 && --r.validationFailedCount, r.deletedIndexes.add(e), r.rowStates[e] = {
1063
+ status: "deleted",
1064
+ fieldErrors: void 0
1065
+ });
1066
+ }), Y(e, {
1067
+ total: at(r),
1068
+ validationFailedCount: r.validationFailedCount,
1069
+ rowStates: r.rowStates
1070
+ }));
1071
+ }
1072
+ function yt(e, t, n) {
1073
+ let r = J(e)?.rowStates?.[t];
1074
+ if (!r?.fieldErrors?.some((e) => n in e)) return;
1075
+ let i = r.fieldErrors.filter((e) => !(n in e));
1076
+ nt(e, t, {
1077
+ ...r,
1078
+ fieldErrors: i.length > 0 ? i : void 0
1079
+ });
1080
+ }
1081
+ function bt(e) {
1082
+ let t = J(e);
1083
+ if (!t) return;
1084
+ if (t.status === "paused") {
1085
+ Y(e, {
1086
+ status: "canceled",
1087
+ pausing: !1,
1088
+ canceling: !1,
1089
+ rowStates: (t.rowStates ?? []).map((e) => e.status === "queued" || e.status === "running" ? { status: "canceled" } : e)
1090
+ }), K.delete(e), X.delete(e);
1091
+ return;
1092
+ }
1093
+ if (t.status !== "running") return;
1094
+ if (t.type === "export") {
1095
+ if (t.canceling) return;
1096
+ let n = Je.get(e);
1097
+ if (!n) return;
1098
+ n.cancelRequested = !0, n.controller?.abort(), Y(e, { canceling: !0 });
1099
+ return;
1100
+ }
1101
+ if (t.canceling) return;
1102
+ let n = K.get(e);
1103
+ n && (n.cancelRequested = !0, Y(e, { canceling: !0 }));
1104
+ }
1105
+ function xt(e) {
1106
+ let t = J(e);
1107
+ t && (t.status === "running" && q.get(e)?.abort(), Je.delete(e), K.delete(e), X.delete(e), G = {
1108
+ ...G,
1109
+ tasks: G.tasks.filter((t) => t.id !== e)
1110
+ }, Ye());
1111
+ }
1112
+ function St(e, t) {
1113
+ try {
1114
+ return n(e, `${t}.xlsx`), !0;
1115
+ } catch (e) {
1116
+ return console.error(`下载失败: ${e}`), !1;
1117
+ }
1118
+ }
1119
+ function Ct(e) {
1120
+ let t = J(e);
1121
+ return t?.type !== "export" || !t.blob || !t.fileName ? !1 : St(t.blob, t.fileName);
1122
+ }
1123
+ function wt() {
1124
+ q.forEach((e) => e.abort()), q.clear(), Je.clear(), K.clear(), X.clear(), Z !== null && (clearTimeout(Z), Z = null), G = { tasks: [] }, Ye();
1125
+ }
1126
+ function Tt(e) {
1127
+ if (e.status !== "running" || e.total <= 0) return null;
1128
+ let t = Math.max(0, e.total - (e.validationFailedCount ?? 0) - e.processed);
1129
+ if (t === 0) return 0;
1130
+ if (e.samples.length < 2) return null;
1131
+ let n = e.samples[0], r = e.samples[e.samples.length - 1], i = (r.time - n.time) / 1e3, a = r.processed - n.processed;
1132
+ return i <= 0 || a <= 0 ? null : t / (a / i);
1133
+ }
1134
+ function Et(e) {
1135
+ return e.type === "import" ? e.successCount === void 0 ? e.rowStates?.filter((e) => e.status === "completed").length ?? e.processed : e.successCount : e.processed;
1136
+ }
1137
+ function Dt(e) {
1138
+ return e.total <= 0 ? 0 : Math.min(100, Et(e) / e.total * 100);
1139
+ }
1140
+ function Ot(e) {
1141
+ let t = Dt(e);
1142
+ return t >= 100 ? 100 : Math.trunc(t * 10) / 10;
1143
+ }
1144
+ function kt(e) {
1145
+ return `${(Math.trunc(e * 10) / 10).toFixed(1)}%`;
1146
+ }
1147
+ function At(e) {
1148
+ if (e === null) return "计算中...";
1149
+ let t = Math.ceil(e);
1150
+ return t < 60 ? `约 ${t} 秒` : `约 ${Math.floor(t / 60)} 分 ${t % 60} 秒`;
1151
+ }
1152
+ // src/react/useTaskDetail.ts
1153
+ function jt(e) {
1154
+ let t = i(() => e ? Qe().find((t) => t.id === e) : void 0, [e]);
1155
+ return l(Ze, t);
1156
+ }
1157
+ // src/components/BatchExportButton.tsx
1158
+ var Mt = ({ title: t, fieldSchemas: n, selectedRows: r, disabled: i }) => {
1159
+ let [a, o] = c(!1);
1160
+ return /* @__PURE__ */ D(h, {
1161
+ type: "default",
1162
+ icon: /* @__PURE__ */ D(d, {}),
1163
+ loading: a,
1164
+ disabled: i ?? r.length === 0,
1165
+ onClick: async () => {
1166
+ if (r.length === 0) return;
1167
+ if (r.length > 2e4) {
1168
+ E.error(`导出数据 ${r.length.toLocaleString()} 条,超过上限 ${ve} 条,请分批导出`);
1169
+ return;
1170
+ }
1171
+ let i = `${t}_${e().format("YYYYMMDDHHmmss")}`;
1172
+ o(!0);
1173
+ try {
1174
+ await Be(r, n, i), E.success("导出成功");
1175
+ } catch (e) {
1176
+ console.error(`导出失败: ${e}`), E.error("导出失败");
1177
+ } finally {
1178
+ o(!1);
1179
+ }
1180
+ },
1181
+ children: "批量导出"
1182
+ });
1183
+ };
1184
+ // src/components/ExportTaskModal.tsx
1185
+ function Nt(e) {
1186
+ if (e.canceling) return "正在取消";
1187
+ if (e.finalizing) return "正在生成文件";
1188
+ switch (e.status) {
1189
+ case "running": return "进行中";
1190
+ case "paused": return "已暂停";
1191
+ case "completed": return "已完成";
1192
+ case "failed": return "失败";
1193
+ case "canceled": return "已取消";
1194
+ }
1195
+ }
1196
+ function Pt(e) {
1197
+ if (e.canceling) return "warning";
1198
+ if (e.finalizing) return "processing";
1199
+ }
1200
+ function Ft(e) {
1201
+ switch (e.status) {
1202
+ case "failed": return "exception";
1203
+ case "completed": return "success";
1204
+ default: return "normal";
1205
+ }
1206
+ }
1207
+ var It = ({ taskId: e, onClose: t }) => {
1208
+ let n = jt(e), { message: r } = m.useApp();
1209
+ if (!n) return null;
1210
+ let i = n.status === "completed" || n.status === "failed" || n.status === "canceled", a = Ot(n), o = () => {
1211
+ xt(n.id), t();
1212
+ }, s = () => {
1213
+ Ct(n.id) || r.error("文件不存在");
1214
+ }, c = Nt(n);
1215
+ return /* @__PURE__ */ D(y, {
1216
+ title: "导出任务",
1217
+ open: !0,
1218
+ maskClosable: !1,
1219
+ closable: i,
1220
+ keyboard: i,
1221
+ onCancel: () => {
1222
+ i && o();
1223
+ },
1224
+ footer: i ? /* @__PURE__ */ O(g, {
1225
+ justify: "flex-end",
1226
+ gap: 8,
1227
+ children: [n.status === "completed" ? /* @__PURE__ */ D(h, {
1228
+ onClick: s,
1229
+ children: "重新下载"
1230
+ }) : null, /* @__PURE__ */ D(h, {
1231
+ type: "primary",
1232
+ onClick: o,
1233
+ children: "关闭"
1234
+ })]
1235
+ }) : /* @__PURE__ */ D(g, {
1236
+ justify: "flex-end",
1237
+ children: /* @__PURE__ */ D(h, {
1238
+ danger: !0,
1239
+ loading: n.canceling,
1240
+ disabled: n.canceling || n.finalizing,
1241
+ onClick: () => bt(n.id),
1242
+ children: n.canceling ? "取消中" : n.finalizing ? "正在生成文件" : "取消任务"
1243
+ })
1244
+ }),
1245
+ children: /* @__PURE__ */ O(g, {
1246
+ vertical: !0,
1247
+ gap: 12,
1248
+ children: [
1249
+ /* @__PURE__ */ O(g, {
1250
+ justify: "space-between",
1251
+ align: "center",
1252
+ gap: 12,
1253
+ children: [/* @__PURE__ */ D(T.Text, {
1254
+ strong: !0,
1255
+ ellipsis: !0,
1256
+ children: n.title
1257
+ }), /* @__PURE__ */ D(w, {
1258
+ color: Pt(n),
1259
+ children: c
1260
+ })]
1261
+ }),
1262
+ /* @__PURE__ */ D(x, {
1263
+ percent: a,
1264
+ format: () => kt(a),
1265
+ status: Ft(n),
1266
+ size: "small"
1267
+ }),
1268
+ /* @__PURE__ */ O(g, {
1269
+ justify: "space-between",
1270
+ children: [
1271
+ /* @__PURE__ */ O(T.Text, {
1272
+ type: "secondary",
1273
+ children: [
1274
+ "已导出 ",
1275
+ Et(n).toLocaleString(),
1276
+ " / 总数 ",
1277
+ n.total > 0 ? n.total.toLocaleString() : "--"
1278
+ ]
1279
+ }),
1280
+ n.finalizing ? /* @__PURE__ */ D(T.Text, {
1281
+ type: "secondary",
1282
+ children: "正在生成文件..."
1283
+ }) : null,
1284
+ n.canceling ? /* @__PURE__ */ D(T.Text, {
1285
+ type: "secondary",
1286
+ children: "正在取消..."
1287
+ }) : null
1288
+ ]
1289
+ }),
1290
+ n.errorMessage ? /* @__PURE__ */ D(T.Text, {
1291
+ type: "danger",
1292
+ children: n.errorMessage
1293
+ }) : null
1294
+ ]
1295
+ })
1296
+ });
1297
+ }, Lt = ({ title: t, buttonText: n = "导出", fieldSchemas: r, filters: i, totalCount: o, disabled: l, fetchPage: u }) => {
1298
+ let { message: f } = m.useApp(), [p, g] = c(), _ = s(void 0);
1299
+ return a(() => {
1300
+ _.current = p;
1301
+ }, [p]), a(() => () => {
1302
+ _.current && xt(_.current);
1303
+ }, []), /* @__PURE__ */ O(re, { children: [/* @__PURE__ */ D(te, {
1304
+ title: "导出 Excel",
1305
+ children: /* @__PURE__ */ D(h, {
1306
+ type: "default",
1307
+ icon: /* @__PURE__ */ D(d, {}),
1308
+ disabled: l,
1309
+ onClick: () => {
1310
+ if (o === 0) {
1311
+ f.error("没有可导出的数据");
1312
+ return;
1313
+ }
1314
+ if (o > 2e4) {
1315
+ f.error(`导出数据共 ${o.toLocaleString()} 条, 超过上限 ${ve} 条, 请缩小筛选范围后分批导出`);
1316
+ return;
1317
+ }
1318
+ let n = `${t}_${e().format("YYYYMMDDHHmmss")}`;
1319
+ g(ft({
1320
+ title: `${t}导出`,
1321
+ fileName: n,
1322
+ fieldSchemas: r,
1323
+ fetchPage: (e, t) => u({
1324
+ ...i,
1325
+ ...e
1326
+ }, t)
1327
+ }));
1328
+ },
1329
+ children: n
1330
+ })
1331
+ }), p ? /* @__PURE__ */ D(It, {
1332
+ taskId: p,
1333
+ onClose: () => g(void 0)
1334
+ }) : null] });
1335
+ }, { Text: Rt } = T, zt = ({ missingTitles: e, headerMessages: t }) => /* @__PURE__ */ O(g, {
1336
+ vertical: !0,
1337
+ gap: 4,
1338
+ children: [e.length > 0 ? /* @__PURE__ */ D(Rt, { children: `缺少必填列: ${e.join(", ")}` }) : null, t.map((e, t) => /* @__PURE__ */ D(Rt, { children: e }, t))]
1339
+ });
1340
+ // src/react/useDebouncedValue.ts
1341
+ function Bt(e, t) {
1342
+ let [n, r] = c(e);
1343
+ return a(() => {
1344
+ let n = setTimeout(() => r(e), t);
1345
+ return () => clearTimeout(n);
1346
+ }, [e, t]), n;
1347
+ }
1348
+ // src/react/useThrottledValue.ts
1349
+ function Vt(e, t) {
1350
+ let [n, r] = c(e), i = s(e), o = s(0), l = s(null);
1351
+ return i.current = e, a(() => {
1352
+ let n = Date.now() - o.current;
1353
+ n >= t ? (o.current = Date.now(), r(e)) : l.current === null && (l.current = setTimeout(() => {
1354
+ l.current = null, o.current = Date.now(), r(i.current);
1355
+ }, t - n));
1356
+ }, [e, t]), a(() => () => {
1357
+ l.current !== null && clearTimeout(l.current);
1358
+ }, []), n;
1359
+ }
1360
+ // src/components/ImportPreviewModal.tsx
1361
+ function Ht(e) {
1362
+ return e == null || e === "" ? "" : Array.isArray(e) ? N(e) : String(e);
1363
+ }
1364
+ var Ut = ({ field: e, record: t, disabled: n, onChange: r, onSave: i }) => {
1365
+ let { token: a } = ne.useToken(), [o, s] = c(!1), [l, u] = c(!1), d = t.values[e.key];
1366
+ if (o && !n) return e.type === "boolean" ? /* @__PURE__ */ D(S, {
1367
+ autoFocus: !0,
1368
+ open: !0,
1369
+ size: "small",
1370
+ style: { width: "100%" },
1371
+ value: typeof d == "string" ? d : void 0,
1372
+ options: [{
1373
+ value: e.property.true_label,
1374
+ label: e.property.true_label
1375
+ }, {
1376
+ value: e.property.false_label,
1377
+ label: e.property.false_label
1378
+ }],
1379
+ onChange: (e) => {
1380
+ r(e), i(e), s(!1);
1381
+ },
1382
+ onBlur: () => s(!1)
1383
+ }) : e.type === "single_choice" ? /* @__PURE__ */ D(S, {
1384
+ autoFocus: !0,
1385
+ open: !0,
1386
+ size: "small",
1387
+ style: { width: "100%" },
1388
+ value: typeof d == "string" ? d : void 0,
1389
+ options: Object.keys(e.property.option_map).map((e) => ({
1390
+ value: e,
1391
+ label: e
1392
+ })),
1393
+ onChange: (e) => {
1394
+ r(e), i(e), s(!1);
1395
+ },
1396
+ onBlur: () => s(!1)
1397
+ }) : e.type === "multiple_choice" ? /* @__PURE__ */ D(S, {
1398
+ autoFocus: !0,
1399
+ open: !0,
1400
+ mode: "multiple",
1401
+ size: "small",
1402
+ style: { width: "100%" },
1403
+ value: Array.isArray(d) ? d : [],
1404
+ options: Object.keys(e.property.option_map).map((e) => ({
1405
+ value: e,
1406
+ label: e
1407
+ })),
1408
+ onChange: r,
1409
+ onBlur: () => {
1410
+ s(!1), i(d);
1411
+ }
1412
+ }) : e.type === "number" ? /* @__PURE__ */ D(v, {
1413
+ autoFocus: !0,
1414
+ size: "small",
1415
+ style: { width: "100%" },
1416
+ value: typeof d == "number" || typeof d == "string" ? d : void 0,
1417
+ onChange: r,
1418
+ onBlur: () => {
1419
+ s(!1), i(d);
1420
+ },
1421
+ onPressEnter: () => {
1422
+ s(!1), i(d);
1423
+ }
1424
+ }) : /* @__PURE__ */ D(_, {
1425
+ autoFocus: !0,
1426
+ size: "small",
1427
+ value: typeof d == "string" ? d : "",
1428
+ placeholder: e.type === "list" ? "多个值用分号分隔(中英文均可)" : void 0,
1429
+ onChange: (e) => r(e.target.value),
1430
+ onBlur: () => {
1431
+ s(!1), i(d);
1432
+ },
1433
+ onPressEnter: () => {
1434
+ s(!1), i(d);
1435
+ }
1436
+ });
1437
+ let f = Ht(d);
1438
+ return /* @__PURE__ */ D("div", {
1439
+ title: f || void 0,
1440
+ style: {
1441
+ height: 24,
1442
+ boxSizing: "border-box",
1443
+ display: "flex",
1444
+ alignItems: "center",
1445
+ minWidth: 0,
1446
+ padding: "0 7px",
1447
+ lineHeight: "22px",
1448
+ whiteSpace: "nowrap",
1449
+ overflow: "hidden",
1450
+ border: `1px solid ${l && !n ? a.colorBorder : "transparent"}`,
1451
+ borderRadius: a.borderRadiusSM,
1452
+ cursor: n ? "default" : "text"
1453
+ },
1454
+ onMouseEnter: () => u(!0),
1455
+ onMouseLeave: () => u(!1),
1456
+ onClick: () => {
1457
+ n || s(!0);
1458
+ },
1459
+ children: /* @__PURE__ */ D("span", {
1460
+ style: {
1461
+ minWidth: 0,
1462
+ overflow: "hidden",
1463
+ textOverflow: "ellipsis",
1464
+ whiteSpace: "nowrap"
1465
+ },
1466
+ children: f
1467
+ })
1468
+ });
1469
+ };
1470
+ function Wt(e) {
1471
+ if (e.canceling) return {
1472
+ label: "正在取消",
1473
+ color: "warning"
1474
+ };
1475
+ switch (e.status) {
1476
+ case "running": return {
1477
+ label: "进行中",
1478
+ color: "processing"
1479
+ };
1480
+ case "paused": return {
1481
+ label: "已暂停",
1482
+ color: "warning"
1483
+ };
1484
+ case "completed": return {
1485
+ label: "已完成",
1486
+ color: "success"
1487
+ };
1488
+ case "failed": return {
1489
+ label: "失败",
1490
+ color: "error"
1491
+ };
1492
+ case "canceled": return {
1493
+ label: "已取消",
1494
+ color: "warning"
1495
+ };
1496
+ }
1497
+ }
1498
+ function Gt(e, t) {
1499
+ if (e.canceling) return "正在取消...";
1500
+ switch (e.status) {
1501
+ case "running": return `预计剩余 ${At(t)}`;
1502
+ default: return null;
1503
+ }
1504
+ }
1505
+ function Kt(e) {
1506
+ switch (e.status) {
1507
+ case "failed": return "exception";
1508
+ case "completed": return "success";
1509
+ default: return "normal";
1510
+ }
1511
+ }
1512
+ var qt = {
1513
+ valid: {
1514
+ label: "已校验",
1515
+ color: "success"
1516
+ },
1517
+ invalid: {
1518
+ label: "校验失败",
1519
+ color: "error"
1520
+ }
1521
+ }, Jt = {
1522
+ pending: {
1523
+ label: "待导入",
1524
+ color: "default"
1525
+ },
1526
+ running: {
1527
+ label: "进行中",
1528
+ color: "processing"
1529
+ },
1530
+ completed: {
1531
+ label: "已完成",
1532
+ color: "success"
1533
+ },
1534
+ failed: {
1535
+ label: "导入失败",
1536
+ color: "error"
1537
+ },
1538
+ canceled: {
1539
+ label: "已取消",
1540
+ color: "warning"
1541
+ }
1542
+ };
1543
+ function Yt(e) {
1544
+ return Object.keys(e.errors).length > 0 ? "invalid" : "valid";
1545
+ }
1546
+ function Xt(e, t, n) {
1547
+ if (!t || e.taskIndex === void 0) return "pending";
1548
+ switch (n?.rowStates?.[e.taskIndex]?.status) {
1549
+ case "running": return "running";
1550
+ case "completed": return "completed";
1551
+ case "failed": return "failed";
1552
+ case "canceled": return "canceled";
1553
+ default: return "pending";
1554
+ }
1555
+ }
1556
+ var Zt = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: i, includedKeys: a, onChangeCell: s, onSaveCell: l, onDelete: d, onConfirm: f, onClose: p }) => {
1557
+ let [m, v] = c("all"), [C, te] = c("all"), [E, ne] = c(""), ie = Bt(E, 300), k = () => {
1558
+ v("all"), te("all"), ne("");
1559
+ }, A = jt(i), [j, ae] = c(), oe = o(() => new Set(a), [a]), se = n.filter((e) => oe.has(e.key));
1560
+ A && A !== j && ae(A);
1561
+ let M = A ?? (j?.id === i ? j : void 0), ce = M ? Wt(M) : void 0, le = !!(M && M.status !== "completed" && M.status !== "failed" && M.status !== "canceled"), ue = Vt(M?.status === "running" ? Tt(M) : null, 1e3), de = M ? Gt(M, ue) : null, N = (e) => e.taskIndex === void 0 ? void 0 : M?.rowStates?.[e.taskIndex], P = !(!A || A.status !== "failed" && A.status !== "paused"), fe = (e) => {
1562
+ if (!i) return !0;
1563
+ let t = N(e)?.status;
1564
+ return P && (t === "queued" || t === "failed") ? !0 : P && e.taskIndex === void 0 && Object.keys(e.errors).length > 0;
1565
+ }, pe = (e) => !i || A?.status === "paused" && N(e)?.status === "queued", me = o(() => ["valid", "invalid"].map((e) => ({
1566
+ value: e,
1567
+ label: qt[e].label
1568
+ })), []), he = o(() => [
1569
+ "pending",
1570
+ "running",
1571
+ "completed",
1572
+ "failed",
1573
+ "canceled"
1574
+ ].map((e) => ({
1575
+ value: e,
1576
+ label: Jt[e].label
1577
+ })), []), F = M?.status === "running", ge = F ? "" : ie, I = !F && m !== "all" && me.some((e) => e.value === m) ? m : "all", L = !F && C !== "all" && he.some((e) => e.value === C) ? C : "all", _e = I !== "all" || ge.trim() !== "", R = L !== "all", z = _e || R, B = o(() => {
1578
+ if (!_e) return r;
1579
+ let e = ge.trim().toLowerCase();
1580
+ return r.filter((t) => I !== "all" && Yt(t) !== I ? !1 : !e || Object.values(t.values).some((t) => (Array.isArray(t) ? t.join(" ") : String(t ?? "")).toLowerCase().includes(e)));
1581
+ }, [
1582
+ r,
1583
+ I,
1584
+ ge,
1585
+ _e
1586
+ ]), ve = Vt(M, 300), ye = R ? ve : void 0, be = o(() => R ? B.filter((e) => Xt(e, i, ye) === L) : i && M ? B.slice() : B, [
1587
+ B,
1588
+ L,
1589
+ R,
1590
+ ye,
1591
+ M,
1592
+ i
1593
+ ]), xe = (e) => {
1594
+ let t = Object.entries(e.errors);
1595
+ return /* @__PURE__ */ D(g, {
1596
+ vertical: !0,
1597
+ gap: 4,
1598
+ style: { maxWidth: 320 },
1599
+ children: t.map(([e, t]) => {
1600
+ let r = n.find((t) => t.key === e)?.title ?? e;
1601
+ return /* @__PURE__ */ O(T.Text, { children: [
1602
+ /* @__PURE__ */ D(T.Text, {
1603
+ strong: !0,
1604
+ children: r
1605
+ }),
1606
+ ": ",
1607
+ t
1608
+ ] }, e);
1609
+ })
1610
+ });
1611
+ }, Se = (e) => {
1612
+ let t = Yt(e), n = qt[t];
1613
+ return t === "invalid" ? /* @__PURE__ */ D(b, {
1614
+ trigger: "hover",
1615
+ placement: "topRight",
1616
+ title: "错误信息",
1617
+ content: xe(e),
1618
+ children: /* @__PURE__ */ D(w, {
1619
+ color: n.color,
1620
+ children: n.label
1621
+ })
1622
+ }) : /* @__PURE__ */ D(w, {
1623
+ color: n.color,
1624
+ children: n.label
1625
+ });
1626
+ }, Ce = (e) => {
1627
+ let t = N(e), r = t?.fieldErrors ?? [], i = t?.message;
1628
+ if (r.length === 0) return /* @__PURE__ */ D(T.Text, { children: i ?? "导入失败" });
1629
+ let a = /* @__PURE__ */ new Map();
1630
+ r.forEach((e) => {
1631
+ let [t, r] = Object.entries(e)[0] ?? [], i = t === "detail" || t === "non_field_errors" ? "错误" : n.find((e) => e.key === t)?.title ?? "数据", o = a.get(i) ?? [];
1632
+ o.push(r), a.set(i, o);
1633
+ });
1634
+ let o = [...a.entries()], s = o.slice(0, 3), c = o.length - s.length;
1635
+ return /* @__PURE__ */ O(g, {
1636
+ vertical: !0,
1637
+ gap: 8,
1638
+ style: { maxWidth: 360 },
1639
+ children: [
1640
+ i ? /* @__PURE__ */ D(T.Text, { children: i }) : null,
1641
+ s.map(([e, t]) => /* @__PURE__ */ O(g, {
1642
+ vertical: !0,
1643
+ gap: 2,
1644
+ children: [/* @__PURE__ */ D(T.Text, {
1645
+ strong: !0,
1646
+ children: e
1647
+ }), t.map((e, t) => /* @__PURE__ */ O(T.Text, { children: ["• ", e] }, t))]
1648
+ }, e)),
1649
+ c > 0 ? /* @__PURE__ */ O(T.Text, {
1650
+ type: "secondary",
1651
+ children: [
1652
+ "还有 ",
1653
+ c,
1654
+ " 个字段错误"
1655
+ ]
1656
+ }) : null
1657
+ ]
1658
+ });
1659
+ }, we = (e) => {
1660
+ let t = Xt(e, i, M), n = Jt[t];
1661
+ if (t === "failed") {
1662
+ let t = N(e), r = (t?.fieldErrors?.length ?? 0) + +!!t?.message, i = r > 0 ? `导入失败(${r})` : n.label;
1663
+ return /* @__PURE__ */ D(b, {
1664
+ trigger: "hover",
1665
+ placement: "topRight",
1666
+ title: "错误信息",
1667
+ content: Ce(e),
1668
+ children: /* @__PURE__ */ D(w, {
1669
+ color: n.color,
1670
+ children: i
1671
+ })
1672
+ });
1673
+ }
1674
+ return /* @__PURE__ */ D(w, {
1675
+ color: n.color,
1676
+ children: n.label
1677
+ });
1678
+ }, Te = (e) => /* @__PURE__ */ D(h, {
1679
+ type: "primary",
1680
+ danger: !0,
1681
+ size: "small",
1682
+ disabled: !pe(e),
1683
+ icon: /* @__PURE__ */ D(u, {}),
1684
+ onClick: () => {
1685
+ d(e), A && e.taskIndex !== void 0 && vt(A.id, [e.taskIndex]);
1686
+ },
1687
+ children: "删除"
1688
+ }), V = [
1689
+ {
1690
+ key: "rowNumber",
1691
+ title: "行号",
1692
+ dataIndex: "rowNumber",
1693
+ width: 60,
1694
+ fixed: "left"
1695
+ },
1696
+ ...se.map((e) => ({
1697
+ key: e.key,
1698
+ title: e.title,
1699
+ dataIndex: e.key,
1700
+ width: 160,
1701
+ render: (t, n) => /* @__PURE__ */ D(Ut, {
1702
+ field: e,
1703
+ record: n,
1704
+ disabled: !fe(n),
1705
+ onChange: (t) => s(n, e, t),
1706
+ onSave: (t) => l(n, e, t)
1707
+ })
1708
+ })),
1709
+ {
1710
+ key: "dataStatus",
1711
+ title: "数据状态",
1712
+ width: 100,
1713
+ fixed: "right",
1714
+ render: (e, t) => Se(t)
1715
+ },
1716
+ {
1717
+ key: "importStatus",
1718
+ title: "导入状态",
1719
+ width: 110,
1720
+ fixed: "right",
1721
+ render: (e, t) => we(t)
1722
+ },
1723
+ {
1724
+ key: "action",
1725
+ title: "操作",
1726
+ width: 80,
1727
+ fixed: "right",
1728
+ render: (e, t) => Te(t)
1729
+ }
1730
+ ], Ee = Math.max(1200, 60 + se.length * 160 + 100 + 110 + 80), De = M && M.total > 0 ? Ot(M) : 0, Oe = M?.failureCount ?? M?.failures?.length ?? 0, H = M?.validationFailedCount ?? r.filter((e) => Object.keys(e.errors).length > 0).length, U = r.filter((e) => Object.keys(e.errors).length > 0).length, ke = r.length > 0 && U === r.length;
1731
+ return /* @__PURE__ */ D(re, { children: /* @__PURE__ */ O(y, {
1732
+ title: i ? `${t}导入` : `${t}导入预览`,
1733
+ open: e,
1734
+ width: "min(1400px, 96vw)",
1735
+ maskClosable: !1,
1736
+ closable: !1,
1737
+ keyboard: !1,
1738
+ onCancel: () => {
1739
+ le || p();
1740
+ },
1741
+ footer: (() => {
1742
+ if (!i) return /* @__PURE__ */ O(g, {
1743
+ justify: "space-between",
1744
+ align: "center",
1745
+ gap: 8,
1746
+ wrap: !0,
1747
+ children: [/* @__PURE__ */ D("span", { children: r.length > 0 && U > 0 ? /* @__PURE__ */ D(T.Text, {
1748
+ type: ke ? "danger" : "secondary",
1749
+ children: ke ? "全部行校验失败, 请先修正后再导入" : `有 ${U} 行校验失败, 不会导入`
1750
+ }) : null }), /* @__PURE__ */ O(g, {
1751
+ gap: 8,
1752
+ children: [/* @__PURE__ */ D(h, {
1753
+ onClick: p,
1754
+ children: "取消"
1755
+ }), /* @__PURE__ */ D(h, {
1756
+ type: "primary",
1757
+ disabled: r.length === 0 || ke,
1758
+ onClick: () => {
1759
+ k(), f();
1760
+ },
1761
+ children: "开始导入"
1762
+ })]
1763
+ })]
1764
+ });
1765
+ if (!A || !M) return /* @__PURE__ */ D(g, {
1766
+ justify: "flex-end",
1767
+ children: /* @__PURE__ */ D(h, {
1768
+ onClick: p,
1769
+ children: "关闭"
1770
+ })
1771
+ });
1772
+ let e = M.status === "running", t = M.status === "paused";
1773
+ return /* @__PURE__ */ O(g, {
1774
+ justify: "flex-end",
1775
+ gap: 8,
1776
+ children: [
1777
+ e ? /* @__PURE__ */ O(re, { children: [/* @__PURE__ */ D(h, {
1778
+ danger: !0,
1779
+ loading: M.canceling,
1780
+ disabled: M.canceling,
1781
+ onClick: () => bt(M.id),
1782
+ children: M.canceling ? "取消中" : "取消任务"
1783
+ }), /* @__PURE__ */ D(h, {
1784
+ loading: M.pausing,
1785
+ disabled: M.canceling,
1786
+ onClick: () => ht(M.id),
1787
+ children: "暂停"
1788
+ })] }) : null,
1789
+ t ? /* @__PURE__ */ O(re, { children: [/* @__PURE__ */ D(h, {
1790
+ danger: !0,
1791
+ onClick: () => bt(M.id),
1792
+ children: "取消任务"
1793
+ }), /* @__PURE__ */ D(h, {
1794
+ type: "primary",
1795
+ onClick: () => {
1796
+ k(), mt(M.id);
1797
+ },
1798
+ children: "继续导入"
1799
+ })] }) : null,
1800
+ !e && !t ? /* @__PURE__ */ D(h, {
1801
+ type: "primary",
1802
+ onClick: p,
1803
+ children: "关闭"
1804
+ }) : null
1805
+ ]
1806
+ });
1807
+ })(),
1808
+ children: [
1809
+ M && ce ? /* @__PURE__ */ O(g, {
1810
+ vertical: !0,
1811
+ gap: 4,
1812
+ style: { marginBottom: 12 },
1813
+ children: [/* @__PURE__ */ O(g, {
1814
+ justify: "space-between",
1815
+ align: "center",
1816
+ children: [/* @__PURE__ */ O(T.Text, {
1817
+ type: "secondary",
1818
+ children: [
1819
+ "已导入 ",
1820
+ Et(M).toLocaleString(),
1821
+ " / 总数 ",
1822
+ M.total.toLocaleString()
1823
+ ]
1824
+ }), /* @__PURE__ */ O(g, {
1825
+ align: "center",
1826
+ gap: 8,
1827
+ children: [
1828
+ de ? /* @__PURE__ */ D(T.Text, {
1829
+ type: "secondary",
1830
+ children: de
1831
+ }) : null,
1832
+ H > 0 ? /* @__PURE__ */ O(w, {
1833
+ color: "error",
1834
+ children: [
1835
+ "校验失败 ",
1836
+ H,
1837
+ " 条"
1838
+ ]
1839
+ }) : null,
1840
+ Oe > 0 ? /* @__PURE__ */ O(w, {
1841
+ color: "error",
1842
+ children: [
1843
+ "导入失败 ",
1844
+ Oe,
1845
+ " 条"
1846
+ ]
1847
+ }) : null,
1848
+ /* @__PURE__ */ D(w, {
1849
+ color: ce.color,
1850
+ children: ce.label
1851
+ })
1852
+ ]
1853
+ })]
1854
+ }), /* @__PURE__ */ D(x, {
1855
+ percent: De,
1856
+ format: () => kt(De),
1857
+ status: Kt(M),
1858
+ size: "small"
1859
+ })]
1860
+ }) : i ? null : /* @__PURE__ */ O(g, {
1861
+ vertical: !0,
1862
+ gap: 4,
1863
+ style: { marginBottom: 12 },
1864
+ children: [/* @__PURE__ */ O(g, {
1865
+ justify: "space-between",
1866
+ align: "center",
1867
+ children: [/* @__PURE__ */ O(T.Text, {
1868
+ type: "secondary",
1869
+ children: ["总数 ", r.length.toLocaleString()]
1870
+ }), /* @__PURE__ */ O(g, {
1871
+ align: "center",
1872
+ gap: 8,
1873
+ children: [H > 0 ? /* @__PURE__ */ O(w, {
1874
+ color: "error",
1875
+ children: [
1876
+ "校验失败 ",
1877
+ H,
1878
+ " 条"
1879
+ ]
1880
+ }) : null, /* @__PURE__ */ D(w, { children: "待导入" })]
1881
+ })]
1882
+ }), /* @__PURE__ */ D(x, {
1883
+ percent: 0,
1884
+ format: () => "0.0%",
1885
+ size: "small"
1886
+ })]
1887
+ }),
1888
+ /* @__PURE__ */ O(g, {
1889
+ justify: "space-between",
1890
+ align: "center",
1891
+ gap: 8,
1892
+ wrap: !0,
1893
+ style: { marginBottom: 8 },
1894
+ children: [/* @__PURE__ */ O(g, {
1895
+ align: "center",
1896
+ gap: 8,
1897
+ wrap: !0,
1898
+ children: [
1899
+ /* @__PURE__ */ D(_, {
1900
+ allowClear: !0,
1901
+ disabled: F,
1902
+ placeholder: "搜索所有字段",
1903
+ value: F ? "" : E,
1904
+ style: { width: 260 },
1905
+ onChange: (e) => {
1906
+ ne(e.target.value);
1907
+ }
1908
+ }),
1909
+ /* @__PURE__ */ D(S, {
1910
+ allowClear: !0,
1911
+ disabled: F,
1912
+ placeholder: "数据状态",
1913
+ value: I === "all" ? void 0 : I,
1914
+ options: me,
1915
+ style: { width: 140 },
1916
+ onChange: (e) => {
1917
+ v(e ?? "all");
1918
+ }
1919
+ }),
1920
+ /* @__PURE__ */ D(S, {
1921
+ allowClear: !0,
1922
+ disabled: F,
1923
+ placeholder: "导入状态",
1924
+ value: L === "all" ? void 0 : L,
1925
+ options: he,
1926
+ style: { width: 140 },
1927
+ onChange: (e) => {
1928
+ te(e ?? "all");
1929
+ }
1930
+ })
1931
+ ]
1932
+ }), z ? /* @__PURE__ */ O(T.Text, {
1933
+ type: "secondary",
1934
+ children: [
1935
+ "筛选出 ",
1936
+ be.length,
1937
+ " 条"
1938
+ ]
1939
+ }) : null]
1940
+ }),
1941
+ /* @__PURE__ */ D(ee, {
1942
+ rowKey: "key",
1943
+ size: "middle",
1944
+ tableLayout: "fixed",
1945
+ virtual: !0,
1946
+ columns: V,
1947
+ dataSource: be,
1948
+ pagination: !1,
1949
+ scroll: {
1950
+ x: Ee,
1951
+ y: 520
1952
+ },
1953
+ locale: { emptyText: z ? "没有符合条件的行" : void 0 }
1954
+ })
1955
+ ]
1956
+ }) });
1957
+ }, Qt = "缺少列: ", $t = [
1958
+ /期望为一个包含物件的列表/,
1959
+ /expected a list/i,
1960
+ /得到的类型是/,
1961
+ /not a list/i
1962
+ ];
1963
+ function en(e) {
1964
+ return $t.some((t) => t.test(e)) ? "数据格式不正确, 请检查导入内容" : e;
1965
+ }
1966
+ function tn(e) {
1967
+ if (Object.keys(e).length === 0) return { success: !0 };
1968
+ let t = [], n;
1969
+ return Object.entries(e).forEach(([e, r]) => {
1970
+ let i = Array.isArray(r) ? r : [r];
1971
+ e === "detail" || e === "non_field_errors" ? n = i.map((e) => en(String(e))).join("; ") : i.forEach((n) => t.push({ [e]: en(String(n)) }));
1972
+ }), {
1973
+ success: !1,
1974
+ ...n ? { message: n } : {},
1975
+ ...t.length > 0 ? { fieldErrors: t } : {}
1976
+ };
1977
+ }
1978
+ function nn(e) {
1979
+ if (!Ue(e)) return "导入失败, 任务已暂停";
1980
+ let t = We(e);
1981
+ return t === void 0 ? "网络异常, 任务已暂停" : t === 401 ? "登录已过期, 任务已暂停" : t === 403 ? "没有导入权限, 任务已暂停" : t === 404 ? "导入接口不存在, 任务已暂停" : t === 400 ? "请求参数错误, 任务已暂停" : t >= 500 ? "服务器错误, 任务已暂停" : "导入失败, 任务已暂停";
1982
+ }
1983
+ function rn(e) {
1984
+ let t = Ge(e);
1985
+ if (t && typeof t == "object") {
1986
+ let e = t;
1987
+ if (typeof e.detail == "string") return e.detail;
1988
+ let n = Object.entries(e)[0];
1989
+ if (n) {
1990
+ let [e, t] = n, r = Array.isArray(t) ? t[0] : t;
1991
+ return `${e}: ${String(r)}`;
1992
+ }
1993
+ }
1994
+ return "导入数据校验失败";
1995
+ }
1996
+ var an = ({ title: e, fieldSchemas: t, importRows: n, onImported: r }) => {
1997
+ let [i, l] = c(!1), [u, d] = c([]), [g, _] = c(), [v, y] = c("empty"), [b, x] = c(!1), [S, ee] = c(!1), [w, T] = c([]), { modal: ne } = m.useApp(), ie = s(null), k = s(void 0), A = o(() => le(t), [t]);
1998
+ a(() => {
1999
+ k.current = g;
2000
+ }, [g]), a(() => () => {
2001
+ k.current && xt(k.current);
2002
+ }, []);
2003
+ let j = () => ie.current?.click(), ae = (e, t) => {
2004
+ ne.warning({
2005
+ title: t ?? (e.missingTitles.length > 0 ? "文件表头不完整" : "文件检查未通过"),
2006
+ width: 480,
2007
+ content: /* @__PURE__ */ D(zt, { ...e }),
2008
+ okCancel: !0,
2009
+ okText: "重新选择文件",
2010
+ cancelText: "关闭",
2011
+ closable: !0,
2012
+ onOk: j
2013
+ });
2014
+ }, oe = async (e) => {
2015
+ if (e.size > 20971520) E.error("文件大小超过 20MB, 请拆分后再导入");
2016
+ else {
2017
+ _(void 0), T([]), x(!0);
2018
+ try {
2019
+ let { headerMessages: t, formulaMessages: n, rows: r, includedKeys: i } = await He(e, A);
2020
+ if (n.length > 0) {
2021
+ ae({
2022
+ missingTitles: [],
2023
+ headerMessages: n
2024
+ }, "文件里的公式还没有计算结果");
2025
+ return;
2026
+ }
2027
+ if (t.length > 0) {
2028
+ ae({
2029
+ missingTitles: t.filter((e) => e.startsWith(Qt)).map((e) => e.slice(5)),
2030
+ headerMessages: t.filter((e) => !e.startsWith(Qt))
2031
+ });
2032
+ return;
2033
+ }
2034
+ if (r.length === 0) {
2035
+ E.error("文件里没有数据行");
2036
+ return;
2037
+ }
2038
+ T(i), y(`${e.name}-${Date.now()}`), d(r), l(!0);
2039
+ } catch (e) {
2040
+ console.error(`导入文件解析失败: ${e}`), E.error("导入文件解析失败, 请确认上传的是 Excel 文件");
2041
+ } finally {
2042
+ x(!1);
2043
+ }
2044
+ }
2045
+ };
2046
+ return /* @__PURE__ */ O(re, { children: [
2047
+ /* @__PURE__ */ O(C.Compact, {
2048
+ block: !0,
2049
+ children: [/* @__PURE__ */ D(te, {
2050
+ title: "Excel 导入",
2051
+ children: /* @__PURE__ */ D(h, {
2052
+ type: "default",
2053
+ icon: /* @__PURE__ */ D(p, {}),
2054
+ loading: b,
2055
+ disabled: b,
2056
+ onClick: j,
2057
+ children: "导入"
2058
+ })
2059
+ }), /* @__PURE__ */ D(te, {
2060
+ title: "Excel 导入模板",
2061
+ children: /* @__PURE__ */ D(h, {
2062
+ type: "default",
2063
+ icon: /* @__PURE__ */ D(f, {}),
2064
+ loading: S,
2065
+ onClick: async () => {
2066
+ ee(!0);
2067
+ try {
2068
+ await Ve(A, `${e}导入模板`);
2069
+ } catch (e) {
2070
+ console.error(`模板下载失败: ${e}`), E.error("模板下载失败");
2071
+ } finally {
2072
+ ee(!1);
2073
+ }
2074
+ },
2075
+ children: "下载模板"
2076
+ })
2077
+ })]
2078
+ }),
2079
+ /* @__PURE__ */ D("input", {
2080
+ ref: ie,
2081
+ type: "file",
2082
+ accept: ".xlsx",
2083
+ style: { display: "none" },
2084
+ onChange: (e) => {
2085
+ let t = e.target.files?.[0];
2086
+ e.target.value = "", t && oe(t);
2087
+ }
2088
+ }),
2089
+ /* @__PURE__ */ D(Zt, {
2090
+ open: i,
2091
+ title: e,
2092
+ fieldSchemas: A,
2093
+ rows: u,
2094
+ taskId: g,
2095
+ includedKeys: w,
2096
+ onChangeCell: (e, t, n) => {
2097
+ if (!w.includes(t.key)) return;
2098
+ let r = Ce(t, n), i = z(r.trim() === "" ? null : r, t);
2099
+ d((r) => r.map((r) => {
2100
+ if (r.key !== e.key) return r;
2101
+ let a = { ...r.errors };
2102
+ return i.validateSuccess ? delete a[t.key] : a[t.key] = i.validateMessage, {
2103
+ ...r,
2104
+ values: {
2105
+ ...r.values,
2106
+ [t.key]: n
2107
+ },
2108
+ errors: a
2109
+ };
2110
+ }));
2111
+ },
2112
+ onSaveCell: (e, t, n) => {
2113
+ if (!w.includes(t.key)) return;
2114
+ let r = {
2115
+ ...e.values,
2116
+ [t.key]: n
2117
+ }, i = {};
2118
+ A.forEach((e) => {
2119
+ if (!w.includes(e.key)) return;
2120
+ let t = Ce(e, r[e.key]), n = z(t.trim() === "" ? null : t, e);
2121
+ n.validateSuccess || (i[e.key] = n.validateMessage);
2122
+ });
2123
+ let a = {
2124
+ ...e,
2125
+ values: r,
2126
+ errors: i
2127
+ };
2128
+ d((t) => t.map((t) => t.key === e.key ? a : t)), g && e.taskIndex !== void 0 && (yt(g, e.taskIndex, t.key), _t(g, e.taskIndex, i), gt(g, e.taskIndex, a));
2129
+ },
2130
+ onDelete: (e) => {
2131
+ d((t) => t.filter((t) => t.key !== e.key));
2132
+ },
2133
+ onConfirm: () => {
2134
+ let t = u;
2135
+ if (t.length === 0) {
2136
+ E.error("没有可导入的数据");
2137
+ return;
2138
+ }
2139
+ if (t.every((e) => Object.keys(e.errors).length > 0)) {
2140
+ E.error("所有行都有校验错误, 请先修正后再导入");
2141
+ return;
2142
+ }
2143
+ let i = t.map((e, t) => ({
2144
+ ...e,
2145
+ taskIndex: t
2146
+ }));
2147
+ d(i);
2148
+ let a = pt({
2149
+ title: `${e}导入`,
2150
+ rows: i,
2151
+ fieldSchemas: A,
2152
+ includedKeys: w,
2153
+ importRows: async (e, t) => {
2154
+ try {
2155
+ let r = await n(e.map((e) => we(e, A, w)), t);
2156
+ if (r.length !== e.length) throw new W("导入接口返回结果数量不正确, 任务已暂停");
2157
+ return r.map(tn);
2158
+ } catch (e) {
2159
+ throw t.aborted || e instanceof W ? e : We(e) === 422 ? Error(rn(e)) : new W(nn(e));
2160
+ }
2161
+ },
2162
+ onFinished: r
2163
+ });
2164
+ _(a);
2165
+ },
2166
+ onClose: () => {
2167
+ g && xt(g), l(!1), _(void 0), d([]), T([]);
2168
+ }
2169
+ }, v)
2170
+ ] });
2171
+ };
2172
+ export { Mt as BatchExportButton, Lt as ExcelExportButton, an as ExcelImportButton, It as ExportTaskModal, W as ImportPauseError, ve as MAX_EXPORT_ROWS, ye as MAX_IMPORT_FILE_SIZE, B as MAX_IMPORT_ROWS, ue as MULTI_VALUE_SEPARATOR, Ne as autoAdjustColumnWidths, ze as buildExportBlob, we as buildImportPayload, bt as cancelTask, yt as clearImportRowFieldError, mt as continueTask, vt as deleteImportRows, xt as dismissTask, Ve as downloadImportTemplate, Ct as downloadTask, ft as enqueueExport, pt as enqueueImport, Be as exportExcel, kt as formatTaskPercent, At as formatTaskRemainingSeconds, Ot as getTaskDisplayPercent, Tt as getTaskRemainingSeconds, Et as getTaskSuccessCount, Qe as getTasksSnapshot, le as importableFields, N as joinMultiValues, He as parseImportFile, ht as pauseTask, wt as resetTasks, _t as setImportRowValidation, P as splitMultiValues, Ze as subscribeTasks, gt as updateImportRowData, jt as useTaskDetail, he as validateBooleanField, F as validateDateField, I as validateDateTimeField, z as validateField, L as validateListField, R as validateMultipleChoiceField, me as validateNumberField, _e as validateSingleChoiceField, pe as validateTextField, ge as validateTimeField };