antd-import-export 1.0.10 → 1.0.12
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/README.md +40 -78
- package/README_EN.md +41 -71
- package/dist/components/ImportButton.d.ts +5 -2
- package/dist/core/excel/exportFile.d.ts +1 -1
- package/dist/core/excel/importRow.d.ts +11 -0
- package/dist/core/excel/runtime.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +280 -260
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -13,24 +13,24 @@ var j = Object.create, M = Object.defineProperty, te = Object.getOwnPropertyDesc
|
|
|
13
13
|
enumerable: !(r = te(t, s)) || r.enumerable
|
|
14
14
|
});
|
|
15
15
|
return e;
|
|
16
|
-
},
|
|
16
|
+
}, ae = (e, t, n) => (n = e == null ? {} : j(ne(e)), ie(t || !e || !e.__esModule || !P.call(e, "default") ? M(n, "default", {
|
|
17
17
|
value: e,
|
|
18
18
|
enumerable: !0
|
|
19
19
|
}) : n, e));
|
|
20
20
|
// src/core/schema/index.ts
|
|
21
|
-
function
|
|
21
|
+
function oe(e) {
|
|
22
22
|
return e.filter((e) => e.importable !== !1);
|
|
23
23
|
}
|
|
24
24
|
// src/core/schema/multiValue.ts
|
|
25
|
-
var
|
|
26
|
-
function
|
|
25
|
+
var F = ";", se = /[;;]/;
|
|
26
|
+
function I(e) {
|
|
27
27
|
return e.map((e) => String(e)).join(";");
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
return e.split(
|
|
29
|
+
function L(e) {
|
|
30
|
+
return e.split(se).map((e) => e.trim()).filter(Boolean);
|
|
31
31
|
}
|
|
32
32
|
// src/core/schema/validate.ts
|
|
33
|
-
var ce = /* @__PURE__ */
|
|
33
|
+
var ce = /* @__PURE__ */ ae((/* @__PURE__ */ re(((e, t, n) => {
|
|
34
34
|
(function(n, r) {
|
|
35
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
36
|
})(n, (function() {
|
|
@@ -291,7 +291,7 @@ function pe(t) {
|
|
|
291
291
|
};
|
|
292
292
|
}
|
|
293
293
|
function z(e, t) {
|
|
294
|
-
let n =
|
|
294
|
+
let n = L(e);
|
|
295
295
|
if (n.length > t.property.list_max_length) return {
|
|
296
296
|
validateSuccess: !1,
|
|
297
297
|
validateMessage: `列表长度不能超过 ${t.property.list_max_length}`
|
|
@@ -315,7 +315,7 @@ function B(e, t) {
|
|
|
315
315
|
};
|
|
316
316
|
}
|
|
317
317
|
function V(e, t) {
|
|
318
|
-
let n =
|
|
318
|
+
let n = L(e), r = t.property.option_map, i = [];
|
|
319
319
|
for (let e of n) {
|
|
320
320
|
if (!(e in r)) return {
|
|
321
321
|
validateSuccess: !1,
|
|
@@ -358,59 +358,59 @@ function U(e, t) {
|
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
function he(e, t) {
|
|
361
|
-
return e.type === "boolean" ? t === !0 ? e.property.true_label : t === !1 ? e.property.false_label : void 0 : e.type === "single_choice" ? U(e, t) : e.type === "multiple_choice" ? Array.isArray(t) ? t.map((t) => U(e, t)).filter(Boolean) : [] : e.type === "list" ? Array.isArray(t) ?
|
|
361
|
+
return e.type === "boolean" ? t === !0 ? e.property.true_label : t === !1 ? e.property.false_label : void 0 : e.type === "single_choice" ? U(e, t) : e.type === "multiple_choice" ? Array.isArray(t) ? t.map((t) => U(e, t)).filter(Boolean) : [] : e.type === "list" ? Array.isArray(t) ? I(t) : "" : e.type === "number" ? typeof t == "number" ? t : void 0 : t == null ? "" : String(t);
|
|
362
362
|
}
|
|
363
363
|
function W(e, t) {
|
|
364
|
-
return t === null ? e.type === "multiple_choice" ? [] : "" : e.type === "multiple_choice" ?
|
|
364
|
+
return t === null ? e.type === "multiple_choice" ? [] : "" : e.type === "multiple_choice" ? L(t) : t;
|
|
365
365
|
}
|
|
366
|
-
function
|
|
367
|
-
return t == null ? "" : e.type === "boolean" || e.type === "single_choice" ? String(t) : (e.type === "multiple_choice" || e.type === "list") && Array.isArray(t) ?
|
|
366
|
+
function G(e, t) {
|
|
367
|
+
return t == null ? "" : e.type === "boolean" || e.type === "single_choice" ? String(t) : (e.type === "multiple_choice" || e.type === "list") && Array.isArray(t) ? I(t) : String(t);
|
|
368
368
|
}
|
|
369
369
|
// src/core/excel/parseSheet.ts
|
|
370
|
-
function
|
|
370
|
+
function ge(e) {
|
|
371
371
|
return !Number.isFinite(e) || e < 1 || e >= 2958466 ? null : new Date(Math.round((e - 25569) * 24 * 3600 * 1e3));
|
|
372
372
|
}
|
|
373
|
-
function
|
|
373
|
+
function _e(e, t = !1) {
|
|
374
374
|
let n = String(e.getUTCMonth() + 1).padStart(2, "0"), r = String(e.getUTCDate()).padStart(2, "0"), i = `${e.getUTCFullYear()}-${n}-${r}`;
|
|
375
375
|
if (!t) return i;
|
|
376
376
|
let a = String(e.getUTCHours()).padStart(2, "0"), o = String(e.getUTCMinutes()).padStart(2, "0"), s = e.getUTCSeconds();
|
|
377
377
|
return s === 0 ? `${i} ${a}:${o}` : `${i} ${a}:${o}:${s}`;
|
|
378
378
|
}
|
|
379
|
-
function
|
|
379
|
+
function ve(e) {
|
|
380
380
|
let t = String(e.getUTCHours()).padStart(2, "0"), n = String(e.getUTCMinutes()).padStart(2, "0"), r = e.getUTCSeconds();
|
|
381
381
|
return r === 0 ? `${t}:${n}` : `${t}:${n}:${r}`;
|
|
382
382
|
}
|
|
383
|
-
function
|
|
384
|
-
let n = (e) => e.trim() === "" ? null : e.trim(), i = t === "datetime", a = t === "time", o = t === "date" || i || a, s = (e) => a ?
|
|
383
|
+
function ye(e, t) {
|
|
384
|
+
let n = (e) => e.trim() === "" ? null : e.trim(), i = t === "datetime", a = t === "time", o = t === "date" || i || a, s = (e) => a ? ve(e) : _e(e, i);
|
|
385
385
|
if (e.type === r.ValueType.Null) return null;
|
|
386
386
|
if (e.type === r.ValueType.Date) return s(e.value);
|
|
387
387
|
if (e.type === r.ValueType.Formula) {
|
|
388
388
|
if (e.result === null || e.result === void 0) return null;
|
|
389
389
|
if (e.result instanceof Date) return s(e.result);
|
|
390
390
|
if (o && typeof e.result == "number") {
|
|
391
|
-
let t =
|
|
391
|
+
let t = ge(e.result);
|
|
392
392
|
if (t) return s(t);
|
|
393
393
|
}
|
|
394
394
|
return n(String(e.result));
|
|
395
395
|
}
|
|
396
396
|
if (e.type === r.ValueType.Number) {
|
|
397
397
|
if (o && typeof e.value == "number") {
|
|
398
|
-
let t =
|
|
398
|
+
let t = ge(e.value);
|
|
399
399
|
if (t) return s(t);
|
|
400
400
|
}
|
|
401
401
|
return n(String(e.value));
|
|
402
402
|
}
|
|
403
403
|
return n(e.text);
|
|
404
404
|
}
|
|
405
|
-
function
|
|
405
|
+
function be(e) {
|
|
406
406
|
let t = e.property.default_value;
|
|
407
407
|
if (t == null) return null;
|
|
408
408
|
if (e.type === "boolean") return t ? e.property.true_label : e.property.false_label;
|
|
409
|
-
if (Array.isArray(t)) return t.length > 0 ?
|
|
409
|
+
if (Array.isArray(t)) return t.length > 0 ? I(t) : null;
|
|
410
410
|
let n = String(t);
|
|
411
411
|
return n.trim() === "" ? null : n;
|
|
412
412
|
}
|
|
413
|
-
function
|
|
413
|
+
function xe(e, t) {
|
|
414
414
|
let n = new Map(t.map((e) => [e.title, e])), r = [];
|
|
415
415
|
for (let t = 1; t <= e.columnCount; t++) {
|
|
416
416
|
let i = e.getRow(1).getCell(t).text.split("\n")[0].trim();
|
|
@@ -418,15 +418,15 @@ function Se(e, t) {
|
|
|
418
418
|
}
|
|
419
419
|
return r;
|
|
420
420
|
}
|
|
421
|
-
function
|
|
422
|
-
let n = [], i = [], a = [], o = 0, s =
|
|
421
|
+
function Se(e, t) {
|
|
422
|
+
let n = [], i = [], a = [], o = 0, s = xe(e, t), c = s.filter((e) => e !== null).map((e) => e.key), l = new Set(c);
|
|
423
423
|
return t.forEach((e) => {
|
|
424
424
|
e.property.required && !l.has(e.key) && n.push(`缺少列: ${e.title}`);
|
|
425
425
|
}), n.length > 0 || (e.eachRow({ includeEmpty: !1 }, (e, n) => {
|
|
426
426
|
if (n === 1) return;
|
|
427
427
|
let c = {};
|
|
428
428
|
if (s.forEach((t, n) => {
|
|
429
|
-
t && (c[t.key] =
|
|
429
|
+
t && (c[t.key] = ye(e.getCell(n + 1), t.type));
|
|
430
430
|
}), s.forEach((t, a) => {
|
|
431
431
|
if (!t) return;
|
|
432
432
|
let s = e.getCell(a + 1);
|
|
@@ -440,7 +440,7 @@ function Ce(e, t) {
|
|
|
440
440
|
};
|
|
441
441
|
t.forEach((e) => {
|
|
442
442
|
if (!l.has(e.key)) return;
|
|
443
|
-
let t = H(c[e.key] ??
|
|
443
|
+
let t = H(c[e.key] ?? be(e), e);
|
|
444
444
|
t.validateSuccess ? u.values[e.key] = he(e, t.validateValue ?? null) : (u.values[e.key] = W(e, c[e.key] ?? null), u.errors[e.key] = t.validateMessage);
|
|
445
445
|
}), a.push(u);
|
|
446
446
|
}), o > i.length && i.push(`还有 ${o - i.length} 个公式单元格没有保存计算结果`)), {
|
|
@@ -451,7 +451,7 @@ function Ce(e, t) {
|
|
|
451
451
|
};
|
|
452
452
|
}
|
|
453
453
|
// src/core/excel/worksheet.ts
|
|
454
|
-
function
|
|
454
|
+
function Ce(t, n) {
|
|
455
455
|
let r = n[t.key];
|
|
456
456
|
if (r == null || r === "") return null;
|
|
457
457
|
switch (t.type) {
|
|
@@ -472,21 +472,21 @@ function we(t, n) {
|
|
|
472
472
|
}
|
|
473
473
|
case "multiple_choice": {
|
|
474
474
|
let e = t.property.option_map;
|
|
475
|
-
return
|
|
475
|
+
return I((Array.isArray(r) ? r : [r]).map((t) => Object.keys(e).find((n) => e[n] === t) ?? String(t)));
|
|
476
476
|
}
|
|
477
477
|
case "list": {
|
|
478
478
|
let e = Array.isArray(r) ? r : [r], n = t.property.item_key;
|
|
479
|
-
return
|
|
479
|
+
return I(e.map((e) => String(n && typeof e == "object" && e ? e[n] ?? "" : e)));
|
|
480
480
|
}
|
|
481
481
|
default: return r;
|
|
482
482
|
}
|
|
483
483
|
}
|
|
484
|
-
function
|
|
484
|
+
function we(e, t) {
|
|
485
485
|
t.forEach((t, n) => {
|
|
486
486
|
t.type === "text" && (e.getColumn(n + 1).numFmt = "@");
|
|
487
487
|
});
|
|
488
488
|
}
|
|
489
|
-
function
|
|
489
|
+
function Te(e, t, n) {
|
|
490
490
|
let r = n.map((e) => e.importable === !1 ? `${e.title}\n(仅导出)` : e.title), i = e.addRow(r);
|
|
491
491
|
i.height = 20 + (Math.max(1, ...r.map((e) => e.split("\n").length)) - 1) * 15, i.eachCell({ includeEmpty: !0 }, (e) => {
|
|
492
492
|
e.font = {
|
|
@@ -502,16 +502,16 @@ function Ee(e, t, n) {
|
|
|
502
502
|
wrapText: !0
|
|
503
503
|
};
|
|
504
504
|
}), t.forEach((t) => {
|
|
505
|
-
e.addRow(n.map((e) =>
|
|
505
|
+
e.addRow(n.map((e) => Ce(e, t))).eachCell({ includeEmpty: !0 }, (e) => {
|
|
506
506
|
e.alignment = {
|
|
507
507
|
...e.alignment,
|
|
508
508
|
wrapText: !0,
|
|
509
509
|
vertical: "top"
|
|
510
510
|
};
|
|
511
511
|
});
|
|
512
|
-
}),
|
|
512
|
+
}), we(e, n), Oe(e);
|
|
513
513
|
}
|
|
514
|
-
function
|
|
514
|
+
function Ee(e) {
|
|
515
515
|
let t = [e.property.required ? "必填" : "可选"];
|
|
516
516
|
switch (e.type) {
|
|
517
517
|
case "text":
|
|
@@ -541,11 +541,11 @@ function De(e) {
|
|
|
541
541
|
case "multiple_choice": t.push(`可多选, 分号分隔(中英文均可): ${Object.keys(e.property.option_map).join(" / ")}`);
|
|
542
542
|
}
|
|
543
543
|
e.key.endsWith("_name") ? t.push("填对应记录的名称") : e.key.endsWith("_number") && t.push("填对应记录的编号");
|
|
544
|
-
let n =
|
|
544
|
+
let n = Ce(e, { [e.key]: e.property.default_value });
|
|
545
545
|
return t.push(`默认值: ${n == null || n === "" ? "空" : n}`), t.join("\n");
|
|
546
546
|
}
|
|
547
|
-
function
|
|
548
|
-
let n = t.map((e) => `${e.title}\n\n${
|
|
547
|
+
function De(e, t) {
|
|
548
|
+
let n = t.map((e) => `${e.title}\n\n${Ee(e)}`), r = e.addRow(n);
|
|
549
549
|
r.height = 20 + (Math.max(1, ...n.map((e) => e.split("\n").length)) - 1) * 15, r.eachCell({ includeEmpty: !0 }, (e) => {
|
|
550
550
|
e.font = {
|
|
551
551
|
bold: !0,
|
|
@@ -559,9 +559,9 @@ function Oe(e, t) {
|
|
|
559
559
|
vertical: "top",
|
|
560
560
|
wrapText: !0
|
|
561
561
|
};
|
|
562
|
-
}),
|
|
562
|
+
}), we(e, t), Oe(e);
|
|
563
563
|
}
|
|
564
|
-
function
|
|
564
|
+
function Oe(e, t = 20, n = 60) {
|
|
565
565
|
let r = [];
|
|
566
566
|
e.eachRow({ includeEmpty: !1 }, (e) => {
|
|
567
567
|
e.eachCell({ includeEmpty: !1 }, (e, t) => {
|
|
@@ -583,47 +583,46 @@ function ke(e, t = 20, n = 60) {
|
|
|
583
583
|
});
|
|
584
584
|
}
|
|
585
585
|
// src/core/excel/runtime.ts
|
|
586
|
-
var
|
|
587
|
-
function
|
|
586
|
+
var ke = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
587
|
+
function Ae(e, t) {
|
|
588
588
|
n(e, `${t}.xlsx`);
|
|
589
589
|
}
|
|
590
|
-
var
|
|
591
|
-
function
|
|
592
|
-
return
|
|
593
|
-
throw
|
|
594
|
-
}),
|
|
590
|
+
var je;
|
|
591
|
+
function Me() {
|
|
592
|
+
return je ??= import("exceljs").then((e) => e.default ?? e, (e) => {
|
|
593
|
+
throw je = void 0, e;
|
|
594
|
+
}), je;
|
|
595
595
|
}
|
|
596
|
-
function
|
|
596
|
+
function Ne() {
|
|
597
597
|
return new Promise((e) => {
|
|
598
598
|
requestAnimationFrame(() => setTimeout(e, 0));
|
|
599
599
|
});
|
|
600
600
|
}
|
|
601
|
-
function
|
|
601
|
+
function Pe(e) {
|
|
602
602
|
if (e?.aborted) throw new DOMException("任务已取消", "AbortError");
|
|
603
603
|
}
|
|
604
|
-
async function
|
|
605
|
-
let r = await
|
|
606
|
-
|
|
604
|
+
async function Fe(e, t, n) {
|
|
605
|
+
let r = await Me();
|
|
606
|
+
Pe(n), await Ne();
|
|
607
607
|
let i = new r.Workbook();
|
|
608
|
-
|
|
608
|
+
Te(i.addWorksheet("Sheet"), e, t);
|
|
609
609
|
let a = await i.xlsx.writeBuffer();
|
|
610
|
-
return
|
|
610
|
+
return Pe(n), new Blob([a], { type: ke });
|
|
611
611
|
}
|
|
612
|
-
async function
|
|
613
|
-
|
|
614
|
-
return je(r, n), r;
|
|
612
|
+
async function Ie(e, t, n) {
|
|
613
|
+
Ae(await Fe(e, t), n);
|
|
615
614
|
}
|
|
616
|
-
async function
|
|
617
|
-
let n = await
|
|
618
|
-
await
|
|
615
|
+
async function Le(e, t) {
|
|
616
|
+
let n = await Me();
|
|
617
|
+
await Ne();
|
|
619
618
|
let r = new n.Workbook();
|
|
620
|
-
|
|
619
|
+
De(r.addWorksheet("导入模板"), e);
|
|
621
620
|
let i = await r.xlsx.writeBuffer();
|
|
622
|
-
|
|
621
|
+
Ae(new Blob([i], { type: ke }), t);
|
|
623
622
|
}
|
|
624
|
-
async function
|
|
625
|
-
let n = await
|
|
626
|
-
await
|
|
623
|
+
async function Re(e, t) {
|
|
624
|
+
let n = await Me(), r = await e.arrayBuffer();
|
|
625
|
+
await Ne();
|
|
627
626
|
let i = new n.Workbook();
|
|
628
627
|
if (await i.xlsx.load(r), i.worksheets.length > 1) return {
|
|
629
628
|
headerMessages: ["文件包含多个工作表, 只支持单个工作表, 请删除其他工作表后再导入"],
|
|
@@ -632,7 +631,7 @@ async function ze(e, t) {
|
|
|
632
631
|
includedKeys: []
|
|
633
632
|
};
|
|
634
633
|
let a = i.worksheets[0];
|
|
635
|
-
return a ?
|
|
634
|
+
return a ? Se(a, t) : {
|
|
636
635
|
headerMessages: ["文件里没有工作表"],
|
|
637
636
|
formulaMessages: [],
|
|
638
637
|
rows: [],
|
|
@@ -640,23 +639,23 @@ async function ze(e, t) {
|
|
|
640
639
|
};
|
|
641
640
|
}
|
|
642
641
|
// src/core/excel/exportFile.ts
|
|
643
|
-
function
|
|
642
|
+
function ze(t) {
|
|
644
643
|
return `${t}_${e().format("YYYYMMDDHHmmss")}`;
|
|
645
644
|
}
|
|
646
|
-
async function
|
|
645
|
+
async function Be(e) {
|
|
647
646
|
let { title: t, fieldSchemas: n, rows: r } = e;
|
|
648
647
|
if (r.length === 0) throw Error("没有可导出的数据");
|
|
649
|
-
|
|
648
|
+
await Ie(r, n, ze(t));
|
|
650
649
|
}
|
|
651
650
|
// src/core/task/stats.ts
|
|
652
|
-
function
|
|
651
|
+
function Ve(e, t) {
|
|
653
652
|
let n = Date.now();
|
|
654
653
|
return [...e, {
|
|
655
654
|
time: n,
|
|
656
655
|
processed: t
|
|
657
656
|
}].filter((e) => n - e.time <= 15e3).slice(-20);
|
|
658
657
|
}
|
|
659
|
-
function
|
|
658
|
+
function He(e) {
|
|
660
659
|
if (e.status !== "running" || e.total <= 0) return null;
|
|
661
660
|
let t = Math.max(0, e.total - (e.validationFailedCount ?? 0) - e.processed);
|
|
662
661
|
if (t === 0) return 0;
|
|
@@ -664,97 +663,97 @@ function Ue(e) {
|
|
|
664
663
|
let n = e.samples[0], r = e.samples[e.samples.length - 1], i = (r.time - n.time) / 1e3, a = r.processed - n.processed;
|
|
665
664
|
return i <= 0 || a <= 0 ? null : t / (a / i);
|
|
666
665
|
}
|
|
667
|
-
function
|
|
666
|
+
function Ue(e) {
|
|
668
667
|
return e.type === "import" ? e.successCount === void 0 ? e.rowStates?.filter((e) => e.status === "completed").length ?? e.processed : e.successCount : e.processed;
|
|
669
668
|
}
|
|
670
|
-
function
|
|
671
|
-
return e.total <= 0 ? 0 : Math.min(100,
|
|
669
|
+
function We(e) {
|
|
670
|
+
return e.total <= 0 ? 0 : Math.min(100, Ue(e) / e.total * 100);
|
|
672
671
|
}
|
|
673
|
-
function
|
|
672
|
+
function Ge(e) {
|
|
674
673
|
if (e.finalizing) return 100;
|
|
675
|
-
let t =
|
|
674
|
+
let t = We(e);
|
|
676
675
|
return t >= 100 ? 100 : Math.trunc(t * 10) / 10;
|
|
677
676
|
}
|
|
678
|
-
function
|
|
677
|
+
function Ke(e) {
|
|
679
678
|
return `${(Math.trunc(e * 10) / 10).toFixed(1)}%`;
|
|
680
679
|
}
|
|
681
|
-
function
|
|
680
|
+
function qe(e) {
|
|
682
681
|
if (e === null) return "计算中...";
|
|
683
682
|
let t = Math.ceil(e);
|
|
684
683
|
return t < 60 ? `约 ${t} 秒` : `约 ${Math.floor(t / 60)} 分 ${t % 60} 秒`;
|
|
685
684
|
}
|
|
686
685
|
// src/core/task/store.ts
|
|
687
|
-
var
|
|
688
|
-
function
|
|
689
|
-
|
|
686
|
+
var K = { tasks: [] }, Je = /* @__PURE__ */ new Set(), Ye = /* @__PURE__ */ new Map(), q = /* @__PURE__ */ new Map(), J = /* @__PURE__ */ new Map();
|
|
687
|
+
function Xe() {
|
|
688
|
+
K = { ...K }, Je.forEach((e) => e());
|
|
690
689
|
}
|
|
691
|
-
function
|
|
692
|
-
return
|
|
693
|
-
|
|
690
|
+
function Ze(e) {
|
|
691
|
+
return Je.add(e), () => {
|
|
692
|
+
Je.delete(e);
|
|
694
693
|
};
|
|
695
694
|
}
|
|
696
|
-
function
|
|
697
|
-
return
|
|
695
|
+
function Qe(e) {
|
|
696
|
+
return Ze(e);
|
|
698
697
|
}
|
|
699
|
-
function
|
|
700
|
-
return
|
|
698
|
+
function $e() {
|
|
699
|
+
return K.tasks;
|
|
701
700
|
}
|
|
702
|
-
function
|
|
701
|
+
function et() {
|
|
703
702
|
return `task-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
|
704
703
|
}
|
|
705
|
-
function
|
|
706
|
-
return
|
|
704
|
+
function Y(e) {
|
|
705
|
+
return K.tasks.find((t) => t.id === e);
|
|
707
706
|
}
|
|
708
|
-
function
|
|
709
|
-
let n = !1, r =
|
|
707
|
+
function X(e, t) {
|
|
708
|
+
let n = !1, r = K.tasks.map((r) => r.id === e ? (n = !0, {
|
|
710
709
|
...r,
|
|
711
710
|
...t
|
|
712
711
|
}) : r);
|
|
713
|
-
n && (
|
|
714
|
-
...
|
|
712
|
+
n && (K = {
|
|
713
|
+
...K,
|
|
715
714
|
tasks: r
|
|
716
|
-
},
|
|
715
|
+
}, Xe());
|
|
717
716
|
}
|
|
718
|
-
function
|
|
719
|
-
|
|
720
|
-
...
|
|
721
|
-
tasks: [...
|
|
722
|
-
},
|
|
717
|
+
function tt(e) {
|
|
718
|
+
K = {
|
|
719
|
+
...K,
|
|
720
|
+
tasks: [...K.tasks, e]
|
|
721
|
+
}, Xe();
|
|
723
722
|
}
|
|
724
|
-
function
|
|
725
|
-
|
|
726
|
-
...
|
|
727
|
-
tasks:
|
|
728
|
-
},
|
|
723
|
+
function nt(e) {
|
|
724
|
+
K = {
|
|
725
|
+
...K,
|
|
726
|
+
tasks: K.tasks.filter((t) => t.id !== e)
|
|
727
|
+
}, Xe();
|
|
729
728
|
}
|
|
730
|
-
function
|
|
731
|
-
|
|
729
|
+
function rt() {
|
|
730
|
+
J.forEach((e) => e.abort()), J.clear(), Ye.clear(), q.clear(), K = { tasks: [] }, Xe();
|
|
732
731
|
}
|
|
733
732
|
// src/core/task/types.ts
|
|
734
|
-
var
|
|
733
|
+
var it = class extends Error {
|
|
735
734
|
constructor(e) {
|
|
736
735
|
super(e), this.name = "ImportPauseError";
|
|
737
736
|
}
|
|
738
|
-
},
|
|
739
|
-
function
|
|
740
|
-
let r =
|
|
737
|
+
}, at = 100, ot = 20, st = 200, ct = 100, Z = /* @__PURE__ */ new Set(), Q = null;
|
|
738
|
+
function lt(e, t, n) {
|
|
739
|
+
let r = q.get(e);
|
|
741
740
|
r && (r.rowStates[t] = {
|
|
742
741
|
...r.rowStates[t],
|
|
743
742
|
...n
|
|
744
743
|
}, ut(e));
|
|
745
744
|
}
|
|
746
745
|
function ut(e) {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
let e = [...
|
|
750
|
-
|
|
751
|
-
},
|
|
746
|
+
Z.add(e), Q === null && (Q = setTimeout(() => {
|
|
747
|
+
Q = null;
|
|
748
|
+
let e = [...Z];
|
|
749
|
+
Z.clear(), e.forEach(mt);
|
|
750
|
+
}, ct));
|
|
752
751
|
}
|
|
753
752
|
function dt(e) {
|
|
754
|
-
|
|
753
|
+
Z.delete(e);
|
|
755
754
|
}
|
|
756
755
|
function ft() {
|
|
757
|
-
|
|
756
|
+
Z.clear(), Q !== null && (clearTimeout(Q), Q = null);
|
|
758
757
|
}
|
|
759
758
|
function pt(e, t) {
|
|
760
759
|
return {
|
|
@@ -765,12 +764,12 @@ function pt(e, t) {
|
|
|
765
764
|
validationFailedCount: t.validationFailedCount,
|
|
766
765
|
failures: t.failures,
|
|
767
766
|
rowStates: t.rowStates,
|
|
768
|
-
samples:
|
|
767
|
+
samples: Ve(Y(e)?.samples ?? [], t.processed)
|
|
769
768
|
};
|
|
770
769
|
}
|
|
771
770
|
function mt(e) {
|
|
772
|
-
let t =
|
|
773
|
-
t &&
|
|
771
|
+
let t = q.get(e);
|
|
772
|
+
t && Y(e) && X(e, pt(e, t));
|
|
774
773
|
}
|
|
775
774
|
function ht(e) {
|
|
776
775
|
return e.options.rows.length - e.deletedIndexes.size;
|
|
@@ -779,21 +778,21 @@ function gt(e) {
|
|
|
779
778
|
return `成功 ${e.successCount} 条, 失败 ${e.failures.length} 条, 可修正失败行后继续`;
|
|
780
779
|
}
|
|
781
780
|
function _t(e) {
|
|
782
|
-
if (e === void 0) return
|
|
781
|
+
if (e === void 0) return ot;
|
|
783
782
|
let t = Math.floor(e);
|
|
784
|
-
return !Number.isFinite(t) || t < 1 ?
|
|
783
|
+
return !Number.isFinite(t) || t < 1 ? ot : Math.min(t, st);
|
|
785
784
|
}
|
|
786
785
|
async function vt(e, t, n) {
|
|
787
786
|
let r = t.options.rows.length;
|
|
788
787
|
if (t.controller = n, t.pauseRequested = !1, t.cancelRequested = !1, t.runFailureCount = 0, r === 0) {
|
|
789
|
-
|
|
788
|
+
X(e, {
|
|
790
789
|
status: "failed",
|
|
791
790
|
pausing: !1,
|
|
792
791
|
errorMessage: "没有可导入的数据"
|
|
793
792
|
}), t.options.onFinished?.();
|
|
794
793
|
return;
|
|
795
794
|
}
|
|
796
|
-
|
|
795
|
+
X(e, {
|
|
797
796
|
...pt(e, t),
|
|
798
797
|
status: "running",
|
|
799
798
|
samples: [{
|
|
@@ -815,7 +814,7 @@ async function vt(e, t, n) {
|
|
|
815
814
|
let r = o();
|
|
816
815
|
if (r.length === 0) return;
|
|
817
816
|
r.forEach((t) => {
|
|
818
|
-
|
|
817
|
+
lt(e, t, {
|
|
819
818
|
status: "running",
|
|
820
819
|
message: void 0,
|
|
821
820
|
fieldErrors: void 0
|
|
@@ -824,10 +823,10 @@ async function vt(e, t, n) {
|
|
|
824
823
|
try {
|
|
825
824
|
let i = r.map((e) => t.options.rows[e]), a = await t.options.importRows(i);
|
|
826
825
|
if (n.signal.aborted) return;
|
|
827
|
-
if (a.length !== r.length) throw new
|
|
826
|
+
if (a.length !== r.length) throw new it("导入接口返回结果数量不正确, 任务已暂停");
|
|
828
827
|
a.forEach((n, i) => {
|
|
829
828
|
let a = r[i], o = t.options.rows[a];
|
|
830
|
-
n.success ? (t.successCount += 1,
|
|
829
|
+
n.success ? (t.successCount += 1, lt(e, a, {
|
|
831
830
|
status: "completed",
|
|
832
831
|
fieldErrors: void 0
|
|
833
832
|
})) : (t.failures.push({
|
|
@@ -835,31 +834,31 @@ async function vt(e, t, n) {
|
|
|
835
834
|
rowNumber: o.rowNumber,
|
|
836
835
|
message: n.message ?? "导入失败",
|
|
837
836
|
fieldErrors: n.fieldErrors
|
|
838
|
-
}),
|
|
837
|
+
}), lt(e, a, {
|
|
839
838
|
status: "failed",
|
|
840
839
|
message: n.message,
|
|
841
840
|
fieldErrors: n.fieldErrors
|
|
842
|
-
}), t.runFailureCount += 1, t.runFailureCount >
|
|
841
|
+
}), t.runFailureCount += 1, t.runFailureCount > at && (t.pauseRequested = !0));
|
|
843
842
|
});
|
|
844
843
|
} catch (i) {
|
|
845
844
|
if (n.signal.aborted) return;
|
|
846
|
-
let a = i instanceof
|
|
845
|
+
let a = i instanceof it, o = `${i instanceof Error ? i.message : "导入失败"}(该批结果未知,重试可能重复)`;
|
|
847
846
|
r.forEach((n) => {
|
|
848
847
|
t.failures.push({
|
|
849
848
|
index: n,
|
|
850
849
|
rowNumber: t.options.rows[n].rowNumber,
|
|
851
850
|
message: o
|
|
852
|
-
}),
|
|
851
|
+
}), lt(e, n, {
|
|
853
852
|
status: "failed",
|
|
854
853
|
message: o
|
|
855
854
|
}), t.runFailureCount += 1;
|
|
856
|
-
}), a ? (t.pauseRequested = !0, n.abort()) : t.runFailureCount >
|
|
855
|
+
}), a ? (t.pauseRequested = !0, n.abort()) : t.runFailureCount > at && (t.pauseRequested = !0);
|
|
857
856
|
} finally {
|
|
858
857
|
t.processed += r.length, ut(e);
|
|
859
858
|
}
|
|
860
859
|
}
|
|
861
860
|
}, c = Math.min(a, Math.max(1, r));
|
|
862
|
-
await Promise.all(Array.from({ length: c }, () => s())), t.controller = null,
|
|
861
|
+
await Promise.all(Array.from({ length: c }, () => s())), t.controller = null, Y(e) && St(e, t, n);
|
|
863
862
|
}
|
|
864
863
|
function yt(e) {
|
|
865
864
|
e.rowStates = e.rowStates.map((e) => e.status === "queued" || e.status === "running" ? { status: "canceled" } : e);
|
|
@@ -874,7 +873,7 @@ function xt(e) {
|
|
|
874
873
|
return e.failures.length > 0 ? `累计失败 ${e.failures.length} 条, 任务已暂停, 可继续导入` : void 0;
|
|
875
874
|
}
|
|
876
875
|
function $(e, t, n) {
|
|
877
|
-
|
|
876
|
+
X(e, {
|
|
878
877
|
...pt(e, t),
|
|
879
878
|
pausing: !1,
|
|
880
879
|
...n
|
|
@@ -924,12 +923,12 @@ function St(e, t, n) {
|
|
|
924
923
|
}
|
|
925
924
|
function Ct(e, t) {
|
|
926
925
|
let n = new AbortController();
|
|
927
|
-
|
|
928
|
-
|
|
926
|
+
J.set(e, n), vt(e, t, n).finally(() => {
|
|
927
|
+
J.delete(e), Z.delete(e), Y(e)?.status !== "paused" && q.delete(e);
|
|
929
928
|
});
|
|
930
929
|
}
|
|
931
930
|
function wt(e) {
|
|
932
|
-
let t =
|
|
931
|
+
let t = et(), n = e.rows.map((e) => ({
|
|
933
932
|
status: "queued",
|
|
934
933
|
validationErrors: Object.keys(e.errors).length > 0 ? e.errors : void 0
|
|
935
934
|
})), r = new Set(e.rows.flatMap((e, t) => Object.keys(e.errors).length > 0 ? [t] : [])), i = r.size, a = {
|
|
@@ -961,18 +960,18 @@ function wt(e) {
|
|
|
961
960
|
runFailureCount: 0,
|
|
962
961
|
controller: null
|
|
963
962
|
};
|
|
964
|
-
return
|
|
963
|
+
return q.set(t, o), tt(a), Ct(t, o), t;
|
|
965
964
|
}
|
|
966
965
|
function Tt(e) {
|
|
967
|
-
let t =
|
|
966
|
+
let t = Y(e);
|
|
968
967
|
if (!t || t.type !== "import" || t.status !== "paused") return;
|
|
969
|
-
let n =
|
|
968
|
+
let n = q.get(e);
|
|
970
969
|
if (!n) return;
|
|
971
970
|
let r = n.rowStates.filter((e) => e.status === "completed").length, i = n.rowStates.map((e) => e.status === "completed" || e.status === "deleted" ? e : {
|
|
972
971
|
status: "queued",
|
|
973
972
|
validationErrors: e.validationErrors
|
|
974
973
|
}), a = i.filter((e) => e.validationErrors && Object.keys(e.validationErrors).length > 0).length;
|
|
975
|
-
n.rowStates = i, n.validationFailedCount = a, n.nextIndex = 0, n.processed = r, n.successCount = r, n.failures = [], n.pauseRequested = !1, n.cancelRequested = !1, n.runFailureCount = 0,
|
|
974
|
+
n.rowStates = i, n.validationFailedCount = a, n.nextIndex = 0, n.processed = r, n.successCount = r, n.failures = [], n.pauseRequested = !1, n.cancelRequested = !1, n.runFailureCount = 0, X(e, {
|
|
976
975
|
status: "running",
|
|
977
976
|
pausing: !1,
|
|
978
977
|
canceling: !1,
|
|
@@ -986,19 +985,19 @@ function Tt(e) {
|
|
|
986
985
|
}), Ct(e, n);
|
|
987
986
|
}
|
|
988
987
|
function Et(e) {
|
|
989
|
-
let t =
|
|
988
|
+
let t = Y(e);
|
|
990
989
|
if (!t || t.type !== "import" || t.status !== "running" || t.canceling) return;
|
|
991
|
-
let n =
|
|
992
|
-
n && (n.pauseRequested = !0,
|
|
990
|
+
let n = q.get(e);
|
|
991
|
+
n && (n.pauseRequested = !0, X(e, { pausing: !0 }));
|
|
993
992
|
}
|
|
994
993
|
function Dt(e, t, n) {
|
|
995
|
-
let r =
|
|
994
|
+
let r = Y(e), i = q.get(e);
|
|
996
995
|
if (!r || r.type !== "import" || r.status !== "paused" && r.status !== "failed" || !i) return;
|
|
997
996
|
let a = r.rowStates?.[t]?.status;
|
|
998
997
|
(a === "queued" || a === "failed") && (i.options.rows[t] = n);
|
|
999
998
|
}
|
|
1000
999
|
function Ot(e, t, n) {
|
|
1001
|
-
let r =
|
|
1000
|
+
let r = Y(e), i = q.get(e);
|
|
1002
1001
|
if (!r || r.type !== "import" || !i || r.status !== "paused" && r.status !== "failed") return;
|
|
1003
1002
|
let a = Object.keys(n).length > 0, o = i.rowStates[t]?.validationErrors, s = !!(o && Object.keys(o).length > 0);
|
|
1004
1003
|
a ? (i.skippedIndexes.add(t), s || (i.validationFailedCount += 1)) : (i.skippedIndexes.delete(t), s && --i.validationFailedCount), i.rowStates[t] = {
|
|
@@ -1007,30 +1006,30 @@ function Ot(e, t, n) {
|
|
|
1007
1006
|
}, i.options.rows[t] = {
|
|
1008
1007
|
...i.options.rows[t],
|
|
1009
1008
|
errors: n
|
|
1010
|
-
},
|
|
1009
|
+
}, X(e, {
|
|
1011
1010
|
validationFailedCount: i.validationFailedCount,
|
|
1012
1011
|
rowStates: i.rowStates
|
|
1013
1012
|
});
|
|
1014
1013
|
}
|
|
1015
1014
|
function kt(e, t) {
|
|
1016
|
-
let n =
|
|
1015
|
+
let n = Y(e), r = q.get(e);
|
|
1017
1016
|
n && n.type === "import" && n.status === "paused" && r && (t.forEach((e) => {
|
|
1018
1017
|
let t = r.rowStates[e];
|
|
1019
1018
|
t?.status === "queued" && (t.validationErrors && Object.keys(t.validationErrors).length > 0 && --r.validationFailedCount, r.deletedIndexes.add(e), r.rowStates[e] = {
|
|
1020
1019
|
status: "deleted",
|
|
1021
1020
|
fieldErrors: void 0
|
|
1022
1021
|
});
|
|
1023
|
-
}),
|
|
1022
|
+
}), X(e, {
|
|
1024
1023
|
total: ht(r),
|
|
1025
1024
|
validationFailedCount: r.validationFailedCount,
|
|
1026
1025
|
rowStates: r.rowStates
|
|
1027
1026
|
}));
|
|
1028
1027
|
}
|
|
1029
1028
|
function At(e, t, n) {
|
|
1030
|
-
let r =
|
|
1029
|
+
let r = Y(e)?.rowStates?.[t];
|
|
1031
1030
|
if (!r?.fieldErrors?.some((e) => n in e)) return;
|
|
1032
1031
|
let i = r.fieldErrors.filter((e) => !(n in e));
|
|
1033
|
-
|
|
1032
|
+
lt(e, t, {
|
|
1034
1033
|
...r,
|
|
1035
1034
|
fieldErrors: i.length > 0 ? i : void 0
|
|
1036
1035
|
});
|
|
@@ -1081,17 +1080,17 @@ async function Rt(e, t, n) {
|
|
|
1081
1080
|
if (t.total = a.count, a.results.length === 0) break;
|
|
1082
1081
|
t.rows = t.rows.concat(a.results);
|
|
1083
1082
|
let o = t.rows.length;
|
|
1084
|
-
|
|
1083
|
+
X(e, {
|
|
1085
1084
|
total: t.total,
|
|
1086
1085
|
processed: o,
|
|
1087
|
-
samples:
|
|
1086
|
+
samples: Ve(Y(e)?.samples ?? [], o)
|
|
1088
1087
|
});
|
|
1089
1088
|
let s = a.results[a.results.length - 1]?.id;
|
|
1090
1089
|
if (typeof s != "number") throw Error("导出数据缺少 id");
|
|
1091
1090
|
t.cursorId = s;
|
|
1092
1091
|
}
|
|
1093
1092
|
if (t.cancelRequested) {
|
|
1094
|
-
|
|
1093
|
+
X(e, {
|
|
1095
1094
|
status: "canceled",
|
|
1096
1095
|
pausing: !1,
|
|
1097
1096
|
canceling: !1,
|
|
@@ -1100,15 +1099,15 @@ async function Rt(e, t, n) {
|
|
|
1100
1099
|
return;
|
|
1101
1100
|
}
|
|
1102
1101
|
if (t.rows.length === 0) throw Error("没有可导出的数据");
|
|
1103
|
-
|
|
1104
|
-
let i = await
|
|
1102
|
+
X(e, { finalizing: !0 }), await Lt(It);
|
|
1103
|
+
let i = await Fe(t.rows, r.fieldSchemas, n.signal);
|
|
1105
1104
|
if (n.signal.aborted) throw new DOMException("任务已取消", "AbortError");
|
|
1106
1105
|
try {
|
|
1107
|
-
|
|
1106
|
+
Ae(i, r.fileName);
|
|
1108
1107
|
} catch (e) {
|
|
1109
1108
|
console.error(`自动下载失败: ${e}`);
|
|
1110
1109
|
}
|
|
1111
|
-
|
|
1110
|
+
X(e, {
|
|
1112
1111
|
status: "completed",
|
|
1113
1112
|
pausing: !1,
|
|
1114
1113
|
finalizing: !1,
|
|
@@ -1119,7 +1118,7 @@ async function Rt(e, t, n) {
|
|
|
1119
1118
|
});
|
|
1120
1119
|
} catch (t) {
|
|
1121
1120
|
if (n.signal.aborted) {
|
|
1122
|
-
|
|
1121
|
+
X(e, {
|
|
1123
1122
|
status: "canceled",
|
|
1124
1123
|
pausing: !1,
|
|
1125
1124
|
finalizing: !1,
|
|
@@ -1127,7 +1126,7 @@ async function Rt(e, t, n) {
|
|
|
1127
1126
|
});
|
|
1128
1127
|
return;
|
|
1129
1128
|
}
|
|
1130
|
-
|
|
1129
|
+
X(e, {
|
|
1131
1130
|
status: "failed",
|
|
1132
1131
|
pausing: !1,
|
|
1133
1132
|
finalizing: !1,
|
|
@@ -1143,12 +1142,12 @@ function zt(e) {
|
|
|
1143
1142
|
}
|
|
1144
1143
|
function Bt(e, t) {
|
|
1145
1144
|
let n = new AbortController();
|
|
1146
|
-
|
|
1147
|
-
|
|
1145
|
+
J.set(e, n), Rt(e, t, n).finally(() => {
|
|
1146
|
+
J.delete(e), Ye.delete(e);
|
|
1148
1147
|
});
|
|
1149
1148
|
}
|
|
1150
1149
|
function Vt(e) {
|
|
1151
|
-
let t =
|
|
1150
|
+
let t = et(), n = {
|
|
1152
1151
|
id: t,
|
|
1153
1152
|
type: "export",
|
|
1154
1153
|
title: e.title,
|
|
@@ -1164,57 +1163,57 @@ function Vt(e) {
|
|
|
1164
1163
|
cancelRequested: !1,
|
|
1165
1164
|
controller: null
|
|
1166
1165
|
};
|
|
1167
|
-
return
|
|
1166
|
+
return Ye.set(t, r), tt(n), Bt(t, r), t;
|
|
1168
1167
|
}
|
|
1169
1168
|
function Ht(e, t) {
|
|
1170
1169
|
try {
|
|
1171
|
-
return
|
|
1170
|
+
return Ae(e, t), !0;
|
|
1172
1171
|
} catch (e) {
|
|
1173
1172
|
return console.error(`下载失败: ${e}`), !1;
|
|
1174
1173
|
}
|
|
1175
1174
|
}
|
|
1176
1175
|
function Ut(e) {
|
|
1177
|
-
let t =
|
|
1176
|
+
let t = Y(e);
|
|
1178
1177
|
return t?.type !== "export" || !t.blob || !t.fileName ? !1 : Ht(t.blob, t.fileName);
|
|
1179
1178
|
}
|
|
1180
1179
|
// src/core/task/index.ts
|
|
1181
1180
|
function Wt(e) {
|
|
1182
|
-
let t =
|
|
1181
|
+
let t = Y(e);
|
|
1183
1182
|
if (!t) return;
|
|
1184
1183
|
if (t.status === "paused") {
|
|
1185
|
-
|
|
1184
|
+
X(e, {
|
|
1186
1185
|
status: "canceled",
|
|
1187
1186
|
pausing: !1,
|
|
1188
1187
|
canceling: !1,
|
|
1189
1188
|
rowStates: (t.rowStates ?? []).map((e) => e.status === "queued" || e.status === "running" ? { status: "canceled" } : e)
|
|
1190
1189
|
});
|
|
1191
|
-
let n =
|
|
1192
|
-
|
|
1190
|
+
let n = q.get(e);
|
|
1191
|
+
q.delete(e), dt(e), n?.options.onFinished?.();
|
|
1193
1192
|
return;
|
|
1194
1193
|
}
|
|
1195
1194
|
if (t.status !== "running") return;
|
|
1196
1195
|
if (t.type === "export") {
|
|
1197
1196
|
if (t.canceling || t.finalizing) return;
|
|
1198
|
-
let n =
|
|
1197
|
+
let n = Ye.get(e);
|
|
1199
1198
|
if (!n) return;
|
|
1200
|
-
n.cancelRequested = !0, n.controller?.abort(),
|
|
1199
|
+
n.cancelRequested = !0, n.controller?.abort(), X(e, { canceling: !0 });
|
|
1201
1200
|
return;
|
|
1202
1201
|
}
|
|
1203
1202
|
if (t.canceling) return;
|
|
1204
|
-
let n =
|
|
1205
|
-
n && (n.cancelRequested = !0,
|
|
1203
|
+
let n = q.get(e);
|
|
1204
|
+
n && (n.cancelRequested = !0, X(e, { canceling: !0 }));
|
|
1206
1205
|
}
|
|
1207
1206
|
function Gt(e) {
|
|
1208
|
-
let t =
|
|
1209
|
-
t && (t.status === "running" &&
|
|
1207
|
+
let t = Y(e);
|
|
1208
|
+
t && (t.status === "running" && J.get(e)?.abort(), Ye.delete(e), q.delete(e), dt(e), nt(e));
|
|
1210
1209
|
}
|
|
1211
1210
|
function Kt() {
|
|
1212
|
-
ft(),
|
|
1211
|
+
ft(), rt();
|
|
1213
1212
|
}
|
|
1214
1213
|
// src/react/useTaskDetail.ts
|
|
1215
1214
|
function qt(e) {
|
|
1216
|
-
let t = C(() => e ?
|
|
1217
|
-
return O(
|
|
1215
|
+
let t = C(() => e ? $e().find((t) => t.id === e) : void 0, [e]);
|
|
1216
|
+
return O(Qe, t);
|
|
1218
1217
|
}
|
|
1219
1218
|
// src/components/ExportTaskModal.tsx
|
|
1220
1219
|
function Jt(e) {
|
|
@@ -1242,7 +1241,7 @@ function Xt(e) {
|
|
|
1242
1241
|
var Zt = ({ taskId: e, onClose: t }) => {
|
|
1243
1242
|
let n = qt(e), { message: r } = c.useApp();
|
|
1244
1243
|
if (!n) return null;
|
|
1245
|
-
let i = n.status === "completed" || n.status === "failed" || n.status === "canceled", a =
|
|
1244
|
+
let i = n.status === "completed" || n.status === "failed" || n.status === "canceled", a = Ge(n), o = () => {
|
|
1246
1245
|
Gt(n.id), t();
|
|
1247
1246
|
}, s = () => {
|
|
1248
1247
|
Ut(n.id) || r.error("文件不存在");
|
|
@@ -1289,7 +1288,7 @@ var Zt = ({ taskId: e, onClose: t }) => {
|
|
|
1289
1288
|
type: "secondary",
|
|
1290
1289
|
children: [
|
|
1291
1290
|
"已导出 ",
|
|
1292
|
-
|
|
1291
|
+
Ue(n).toLocaleString(),
|
|
1293
1292
|
" / 总数 ",
|
|
1294
1293
|
n.total > 0 ? n.total.toLocaleString() : "--"
|
|
1295
1294
|
]
|
|
@@ -1300,7 +1299,7 @@ var Zt = ({ taskId: e, onClose: t }) => {
|
|
|
1300
1299
|
}),
|
|
1301
1300
|
/* @__PURE__ */ k(h, {
|
|
1302
1301
|
percent: a,
|
|
1303
|
-
format: () =>
|
|
1302
|
+
format: () => Ke(a),
|
|
1304
1303
|
status: Xt(n),
|
|
1305
1304
|
size: "small"
|
|
1306
1305
|
}),
|
|
@@ -1339,7 +1338,7 @@ var $t = ({ title: e, fieldSchemas: t, buttonText: n = "导出", disabled: r, ex
|
|
|
1339
1338
|
}
|
|
1340
1339
|
p(Vt({
|
|
1341
1340
|
title: `${e}导出`,
|
|
1342
|
-
fileName:
|
|
1341
|
+
fileName: ze(e),
|
|
1343
1342
|
fieldSchemas: t,
|
|
1344
1343
|
exportRows: i,
|
|
1345
1344
|
onFinished: s
|
|
@@ -1360,7 +1359,7 @@ var $t = ({ title: e, fieldSchemas: t, buttonText: n = "导出", disabled: r, ex
|
|
|
1360
1359
|
});
|
|
1361
1360
|
// src/components/EditableImportCell.tsx
|
|
1362
1361
|
function nn(e) {
|
|
1363
|
-
return e == null || e === "" ? "" : Array.isArray(e) ?
|
|
1362
|
+
return e == null || e === "" ? "" : Array.isArray(e) ? I(e) : String(e);
|
|
1364
1363
|
}
|
|
1365
1364
|
var rn = ({ field: e, record: t, disabled: n, onChange: r, onSave: i }) => {
|
|
1366
1365
|
let { token: a } = S.useToken(), [o, s] = D(!1), [c, l] = D(!1), u = t.values[e.key];
|
|
@@ -1500,7 +1499,7 @@ function an(e) {
|
|
|
1500
1499
|
function on(e, t) {
|
|
1501
1500
|
if (e.canceling) return "正在取消...";
|
|
1502
1501
|
switch (e.status) {
|
|
1503
|
-
case "running": return `预计剩余 ${
|
|
1502
|
+
case "running": return `预计剩余 ${qe(t)}`;
|
|
1504
1503
|
default: return null;
|
|
1505
1504
|
}
|
|
1506
1505
|
}
|
|
@@ -1584,7 +1583,7 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1584
1583
|
w(() => {
|
|
1585
1584
|
P && (re.current = P);
|
|
1586
1585
|
}, [P]);
|
|
1587
|
-
let ie = T(() => new Set(o), [o]),
|
|
1586
|
+
let ie = T(() => new Set(o), [o]), ae = n.filter((e) => ie.has(e.key)), oe = re.current, F = P ?? (oe?.id === a ? oe : void 0), se = F ? an(F) : void 0, I = !!(F && F.status !== "completed" && F.status !== "failed" && F.status !== "canceled"), L = pn(F?.status === "running" ? He(F) : null, 1e3), ce = F ? on(F, L) : null, R = (e) => e.taskIndex === void 0 ? void 0 : F?.rowStates?.[e.taskIndex], le = !(!P || P.status !== "failed" && P.status !== "paused"), ue = (e) => {
|
|
1588
1587
|
if (!a) return !0;
|
|
1589
1588
|
let t = R(e)?.status;
|
|
1590
1589
|
return le && (t === "queued" || t === "failed") ? !0 : le && e.taskIndex === void 0 && Object.keys(e.errors).length > 0;
|
|
@@ -1600,7 +1599,7 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1600
1599
|
].map((e) => ({
|
|
1601
1600
|
value: e,
|
|
1602
1601
|
label: ln[e].label
|
|
1603
|
-
})), []), z =
|
|
1602
|
+
})), []), z = F?.status === "running", B = z ? "" : N, V = !z && S !== "all" && fe.some((e) => e.value === S) ? S : "all", H = !z && O !== "all" && pe.some((e) => e.value === O) ? O : "all", me = V !== "all" || B.trim() !== "", U = H !== "all", he = me || U, W = T(() => {
|
|
1604
1603
|
if (!me) return r;
|
|
1605
1604
|
let e = B.trim().toLowerCase();
|
|
1606
1605
|
return r.filter((t) => V !== "all" && un(t) !== V ? !1 : !e || Object.values(t.values).some((t) => (Array.isArray(t) ? t.join(" ") : String(t ?? "")).toLowerCase().includes(e)));
|
|
@@ -1609,14 +1608,14 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1609
1608
|
V,
|
|
1610
1609
|
B,
|
|
1611
1610
|
me
|
|
1612
|
-
]),
|
|
1611
|
+
]), G = pn(F, 300), ge = U ? G : void 0, _e = T(() => U ? W.filter((e) => dn(e, a, ge) === H) : a && F ? W.slice() : W, [
|
|
1613
1612
|
W,
|
|
1614
1613
|
H,
|
|
1615
1614
|
U,
|
|
1616
|
-
|
|
1617
|
-
|
|
1615
|
+
ge,
|
|
1616
|
+
F,
|
|
1618
1617
|
a
|
|
1619
|
-
]),
|
|
1618
|
+
]), ve = (e) => {
|
|
1620
1619
|
let t = Object.entries(e.errors);
|
|
1621
1620
|
return /* @__PURE__ */ k(u, {
|
|
1622
1621
|
vertical: !0,
|
|
@@ -1634,13 +1633,13 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1634
1633
|
] }, e);
|
|
1635
1634
|
})
|
|
1636
1635
|
});
|
|
1637
|
-
},
|
|
1636
|
+
}, ye = (e) => {
|
|
1638
1637
|
let t = un(e), n = cn[t];
|
|
1639
1638
|
return t === "invalid" ? /* @__PURE__ */ k(m, {
|
|
1640
1639
|
trigger: "hover",
|
|
1641
1640
|
placement: "topRight",
|
|
1642
1641
|
title: "错误信息",
|
|
1643
|
-
content:
|
|
1642
|
+
content: ve(e),
|
|
1644
1643
|
children: /* @__PURE__ */ k(y, {
|
|
1645
1644
|
color: n.color,
|
|
1646
1645
|
children: n.label
|
|
@@ -1649,7 +1648,7 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1649
1648
|
color: n.color,
|
|
1650
1649
|
children: n.label
|
|
1651
1650
|
});
|
|
1652
|
-
},
|
|
1651
|
+
}, be = (e) => {
|
|
1653
1652
|
let t = R(e), r = t?.fieldErrors ?? [], i = t?.message;
|
|
1654
1653
|
if (r.length === 0) return /* @__PURE__ */ k(x.Text, { children: i ?? "导入失败" });
|
|
1655
1654
|
let a = /* @__PURE__ */ new Map();
|
|
@@ -1682,15 +1681,15 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1682
1681
|
}) : null
|
|
1683
1682
|
]
|
|
1684
1683
|
});
|
|
1685
|
-
},
|
|
1686
|
-
let t = dn(e, a,
|
|
1684
|
+
}, xe = (e) => {
|
|
1685
|
+
let t = dn(e, a, F), n = ln[t];
|
|
1687
1686
|
if (t === "failed") {
|
|
1688
1687
|
let t = R(e), r = (t?.fieldErrors?.length ?? 0) + +!!t?.message, i = r > 0 ? `导入失败(${r})` : n.label;
|
|
1689
1688
|
return /* @__PURE__ */ k(m, {
|
|
1690
1689
|
trigger: "hover",
|
|
1691
1690
|
placement: "topRight",
|
|
1692
1691
|
title: "错误信息",
|
|
1693
|
-
content:
|
|
1692
|
+
content: be(e),
|
|
1694
1693
|
children: /* @__PURE__ */ k(y, {
|
|
1695
1694
|
color: n.color,
|
|
1696
1695
|
children: i
|
|
@@ -1701,7 +1700,7 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1701
1700
|
color: n.color,
|
|
1702
1701
|
children: n.label
|
|
1703
1702
|
});
|
|
1704
|
-
},
|
|
1703
|
+
}, Se = (e) => /* @__PURE__ */ k(l, {
|
|
1705
1704
|
type: "primary",
|
|
1706
1705
|
danger: !0,
|
|
1707
1706
|
size: "small",
|
|
@@ -1711,7 +1710,7 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1711
1710
|
f(e), P && e.taskIndex !== void 0 && kt(P.id, [e.taskIndex]);
|
|
1712
1711
|
},
|
|
1713
1712
|
children: "删除"
|
|
1714
|
-
}),
|
|
1713
|
+
}), Ce = [
|
|
1715
1714
|
{
|
|
1716
1715
|
key: "rowNumber",
|
|
1717
1716
|
title: "行号",
|
|
@@ -1719,7 +1718,7 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1719
1718
|
width: 60,
|
|
1720
1719
|
fixed: "left"
|
|
1721
1720
|
},
|
|
1722
|
-
...
|
|
1721
|
+
...ae.map((e) => ({
|
|
1723
1722
|
key: e.key,
|
|
1724
1723
|
title: e.title,
|
|
1725
1724
|
dataIndex: e.key,
|
|
@@ -1737,23 +1736,23 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1737
1736
|
title: "数据状态",
|
|
1738
1737
|
width: 100,
|
|
1739
1738
|
fixed: "right",
|
|
1740
|
-
render: (e, t) =>
|
|
1739
|
+
render: (e, t) => ye(t)
|
|
1741
1740
|
},
|
|
1742
1741
|
{
|
|
1743
1742
|
key: "importStatus",
|
|
1744
1743
|
title: "导入状态",
|
|
1745
1744
|
width: 110,
|
|
1746
1745
|
fixed: "right",
|
|
1747
|
-
render: (e, t) =>
|
|
1746
|
+
render: (e, t) => xe(t)
|
|
1748
1747
|
},
|
|
1749
1748
|
{
|
|
1750
1749
|
key: "action",
|
|
1751
1750
|
title: "操作",
|
|
1752
1751
|
width: 80,
|
|
1753
1752
|
fixed: "right",
|
|
1754
|
-
render: (e, t) =>
|
|
1753
|
+
render: (e, t) => Se(t)
|
|
1755
1754
|
}
|
|
1756
|
-
],
|
|
1755
|
+
], we = Math.max(1200, 60 + ae.length * 160 + 100 + 110 + 80), Te = F && F.total > 0 ? Ge(F) : 0, Ee = F?.failureCount ?? F?.failures?.length ?? 0, De = F?.validationFailedCount ?? r.filter((e) => Object.keys(e.errors).length > 0).length, Oe = r.filter((e) => Object.keys(e.errors).length > 0).length, ke = r.length > 0 && Oe === r.length;
|
|
1757
1756
|
return /* @__PURE__ */ k(ee, { children: /* @__PURE__ */ A(p, {
|
|
1758
1757
|
title: a ? `${t}导入` : `${t}导入预览`,
|
|
1759
1758
|
open: e,
|
|
@@ -1762,7 +1761,7 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1762
1761
|
closable: !1,
|
|
1763
1762
|
keyboard: !1,
|
|
1764
1763
|
onCancel: () => {
|
|
1765
|
-
|
|
1764
|
+
I || b();
|
|
1766
1765
|
},
|
|
1767
1766
|
footer: (() => {
|
|
1768
1767
|
if (!a) return /* @__PURE__ */ A(u, {
|
|
@@ -1770,9 +1769,9 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1770
1769
|
align: "center",
|
|
1771
1770
|
gap: 8,
|
|
1772
1771
|
wrap: !0,
|
|
1773
|
-
children: [/* @__PURE__ */ k("span", { children: r.length > 0 &&
|
|
1774
|
-
type:
|
|
1775
|
-
children:
|
|
1772
|
+
children: [/* @__PURE__ */ k("span", { children: r.length > 0 && Oe > 0 ? /* @__PURE__ */ k(x.Text, {
|
|
1773
|
+
type: ke ? "danger" : "secondary",
|
|
1774
|
+
children: ke ? "全部行校验失败, 请先修正后再导入" : `有 ${Oe} 行校验失败, 不会导入`
|
|
1776
1775
|
}) : null }), /* @__PURE__ */ A(u, {
|
|
1777
1776
|
gap: 8,
|
|
1778
1777
|
children: [/* @__PURE__ */ k(l, {
|
|
@@ -1780,7 +1779,7 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1780
1779
|
children: "取消"
|
|
1781
1780
|
}), /* @__PURE__ */ k(l, {
|
|
1782
1781
|
type: "primary",
|
|
1783
|
-
disabled: r.length === 0 ||
|
|
1782
|
+
disabled: r.length === 0 || ke,
|
|
1784
1783
|
onClick: () => {
|
|
1785
1784
|
ne(), _();
|
|
1786
1785
|
},
|
|
@@ -1788,38 +1787,38 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1788
1787
|
})]
|
|
1789
1788
|
})]
|
|
1790
1789
|
});
|
|
1791
|
-
if (!P || !
|
|
1790
|
+
if (!P || !F) return /* @__PURE__ */ k(u, {
|
|
1792
1791
|
justify: "flex-end",
|
|
1793
1792
|
children: /* @__PURE__ */ k(l, {
|
|
1794
1793
|
onClick: b,
|
|
1795
1794
|
children: "关闭"
|
|
1796
1795
|
})
|
|
1797
1796
|
});
|
|
1798
|
-
let e =
|
|
1797
|
+
let e = F.status === "running", t = F.status === "paused";
|
|
1799
1798
|
return /* @__PURE__ */ A(u, {
|
|
1800
1799
|
justify: "flex-end",
|
|
1801
1800
|
gap: 8,
|
|
1802
1801
|
children: [
|
|
1803
1802
|
e ? /* @__PURE__ */ A(ee, { children: [/* @__PURE__ */ k(l, {
|
|
1804
1803
|
danger: !0,
|
|
1805
|
-
loading:
|
|
1806
|
-
disabled:
|
|
1807
|
-
onClick: () => Wt(
|
|
1808
|
-
children:
|
|
1804
|
+
loading: F.canceling,
|
|
1805
|
+
disabled: F.canceling,
|
|
1806
|
+
onClick: () => Wt(F.id),
|
|
1807
|
+
children: F.canceling ? "取消中" : "取消任务"
|
|
1809
1808
|
}), /* @__PURE__ */ k(l, {
|
|
1810
|
-
loading:
|
|
1811
|
-
disabled:
|
|
1812
|
-
onClick: () => Et(
|
|
1809
|
+
loading: F.pausing,
|
|
1810
|
+
disabled: F.canceling,
|
|
1811
|
+
onClick: () => Et(F.id),
|
|
1813
1812
|
children: "暂停"
|
|
1814
1813
|
})] }) : null,
|
|
1815
1814
|
t ? /* @__PURE__ */ A(ee, { children: [/* @__PURE__ */ k(l, {
|
|
1816
1815
|
danger: !0,
|
|
1817
|
-
onClick: () => Wt(
|
|
1816
|
+
onClick: () => Wt(F.id),
|
|
1818
1817
|
children: "取消任务"
|
|
1819
1818
|
}), /* @__PURE__ */ k(l, {
|
|
1820
1819
|
type: "primary",
|
|
1821
1820
|
onClick: () => {
|
|
1822
|
-
ne(), Tt(
|
|
1821
|
+
ne(), Tt(F.id);
|
|
1823
1822
|
},
|
|
1824
1823
|
children: "继续导入"
|
|
1825
1824
|
})] }) : null,
|
|
@@ -1832,7 +1831,7 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1832
1831
|
});
|
|
1833
1832
|
})(),
|
|
1834
1833
|
children: [
|
|
1835
|
-
|
|
1834
|
+
F && se ? /* @__PURE__ */ A(u, {
|
|
1836
1835
|
vertical: !0,
|
|
1837
1836
|
gap: 4,
|
|
1838
1837
|
style: { marginBottom: 12 },
|
|
@@ -1843,9 +1842,9 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1843
1842
|
type: "secondary",
|
|
1844
1843
|
children: [
|
|
1845
1844
|
"已导入 ",
|
|
1846
|
-
|
|
1845
|
+
Ue(F).toLocaleString(),
|
|
1847
1846
|
" / 总数 ",
|
|
1848
|
-
|
|
1847
|
+
F.total.toLocaleString()
|
|
1849
1848
|
]
|
|
1850
1849
|
}), /* @__PURE__ */ A(u, {
|
|
1851
1850
|
align: "center",
|
|
@@ -1855,32 +1854,32 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1855
1854
|
type: "secondary",
|
|
1856
1855
|
children: ce
|
|
1857
1856
|
}) : null,
|
|
1858
|
-
|
|
1857
|
+
De > 0 ? /* @__PURE__ */ A(y, {
|
|
1859
1858
|
color: "error",
|
|
1860
1859
|
children: [
|
|
1861
1860
|
"校验失败 ",
|
|
1862
|
-
|
|
1861
|
+
De,
|
|
1863
1862
|
" 条"
|
|
1864
1863
|
]
|
|
1865
1864
|
}) : null,
|
|
1866
|
-
|
|
1865
|
+
Ee > 0 ? /* @__PURE__ */ A(y, {
|
|
1867
1866
|
color: "error",
|
|
1868
1867
|
children: [
|
|
1869
1868
|
"导入失败 ",
|
|
1870
|
-
|
|
1869
|
+
Ee,
|
|
1871
1870
|
" 条"
|
|
1872
1871
|
]
|
|
1873
1872
|
}) : null,
|
|
1874
1873
|
/* @__PURE__ */ k(y, {
|
|
1875
|
-
color:
|
|
1876
|
-
children:
|
|
1874
|
+
color: se.color,
|
|
1875
|
+
children: se.label
|
|
1877
1876
|
})
|
|
1878
1877
|
]
|
|
1879
1878
|
})]
|
|
1880
1879
|
}), /* @__PURE__ */ k(h, {
|
|
1881
|
-
percent:
|
|
1882
|
-
format: () =>
|
|
1883
|
-
status: sn(
|
|
1880
|
+
percent: Te,
|
|
1881
|
+
format: () => Ke(Te),
|
|
1882
|
+
status: sn(F),
|
|
1884
1883
|
size: "small"
|
|
1885
1884
|
})]
|
|
1886
1885
|
}) : a ? null : /* @__PURE__ */ A(u, {
|
|
@@ -1896,11 +1895,11 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1896
1895
|
}), /* @__PURE__ */ A(u, {
|
|
1897
1896
|
align: "center",
|
|
1898
1897
|
gap: 8,
|
|
1899
|
-
children: [
|
|
1898
|
+
children: [De > 0 ? /* @__PURE__ */ A(y, {
|
|
1900
1899
|
color: "error",
|
|
1901
1900
|
children: [
|
|
1902
1901
|
"校验失败 ",
|
|
1903
|
-
|
|
1902
|
+
De,
|
|
1904
1903
|
" 条"
|
|
1905
1904
|
]
|
|
1906
1905
|
}) : null, /* @__PURE__ */ k(y, { children: "待导入" })]
|
|
@@ -1959,7 +1958,7 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1959
1958
|
type: "secondary",
|
|
1960
1959
|
children: [
|
|
1961
1960
|
"筛选出 ",
|
|
1962
|
-
|
|
1961
|
+
_e.length,
|
|
1963
1962
|
" 条"
|
|
1964
1963
|
]
|
|
1965
1964
|
}) : null]
|
|
@@ -1969,11 +1968,11 @@ var mn = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: a, includedKeys
|
|
|
1969
1968
|
size: "middle",
|
|
1970
1969
|
tableLayout: "fixed",
|
|
1971
1970
|
virtual: !0,
|
|
1972
|
-
columns:
|
|
1973
|
-
dataSource:
|
|
1971
|
+
columns: Ce,
|
|
1972
|
+
dataSource: _e,
|
|
1974
1973
|
pagination: !1,
|
|
1975
1974
|
scroll: {
|
|
1976
|
-
x:
|
|
1975
|
+
x: we,
|
|
1977
1976
|
y: 520
|
|
1978
1977
|
},
|
|
1979
1978
|
locale: { emptyText: he ? "没有符合条件的行" : void 0 }
|
|
@@ -2009,14 +2008,29 @@ function vn(e, t, n) {
|
|
|
2009
2008
|
let r = {};
|
|
2010
2009
|
return t.forEach((t) => {
|
|
2011
2010
|
if (!n.includes(t.key)) return;
|
|
2012
|
-
let i =
|
|
2011
|
+
let i = G(t, e.values[t.key]), a = H(i.trim() === "" ? null : i, t);
|
|
2013
2012
|
if (!a.validateSuccess) throw Error(a.validateMessage);
|
|
2014
2013
|
r[t.key] = a.validateValue ?? null;
|
|
2015
2014
|
}), r;
|
|
2016
2015
|
}
|
|
2016
|
+
function yn(e, t, n) {
|
|
2017
|
+
return e.map((e, r) => {
|
|
2018
|
+
let i = {}, a = {};
|
|
2019
|
+
return t.forEach((t) => {
|
|
2020
|
+
if (!n.includes(t.key)) return;
|
|
2021
|
+
let r = G(t, e.values[t.key]), o = H(r.trim() === "" ? null : r, t);
|
|
2022
|
+
o.validateSuccess ? i[t.key] = he(t, o.validateValue ?? null) : (i[t.key] = e.values[t.key], a[t.key] = o.validateMessage);
|
|
2023
|
+
}), {
|
|
2024
|
+
...e,
|
|
2025
|
+
key: String(r),
|
|
2026
|
+
values: i,
|
|
2027
|
+
errors: a
|
|
2028
|
+
};
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
2017
2031
|
// src/components/ImportButton.tsx
|
|
2018
|
-
var
|
|
2019
|
-
function
|
|
2032
|
+
var bn = "缺少列: ";
|
|
2033
|
+
function xn(e) {
|
|
2020
2034
|
let t = Nt(e);
|
|
2021
2035
|
if (t && typeof t == "object") {
|
|
2022
2036
|
let e = t;
|
|
@@ -2029,8 +2043,8 @@ function bn(e) {
|
|
|
2029
2043
|
}
|
|
2030
2044
|
return Ft(e, "导入", "任务已暂停") ?? (e instanceof Error && e.message ? e.message : "导入失败, 任务已暂停");
|
|
2031
2045
|
}
|
|
2032
|
-
var
|
|
2033
|
-
let [f, p] = D(!1), [m, h] = D([]), [g, v] = Qt(), [y, x] = D("empty"), [S, C] = D(!1), [w, O] = D(!1), [j, M] = D([]), { modal: te, message: N } = c.useApp(), ne = E(null), P = T(() =>
|
|
2046
|
+
var Sn = ({ title: e, fieldSchemas: t, buttonText: n = "导入", batchSize: r = 20, importRows: i, beforeImport: a, afterImport: u, onModalClose: d }) => {
|
|
2047
|
+
let [f, p] = D(!1), [m, h] = D([]), [g, v] = Qt(), [y, x] = D("empty"), [S, C] = D(!1), [w, O] = D(!1), [j, M] = D([]), { modal: te, message: N } = c.useApp(), ne = E(null), P = T(() => oe(t), [t]), re = T(() => new Set([...j].filter((e) => P.some((t) => t.key === e))), [P, j]), ie = () => ne.current?.click(), ae = (e, t) => {
|
|
2034
2048
|
te.warning({
|
|
2035
2049
|
title: t ?? (e.missingTitles.length > 0 ? "文件表头不完整" : "文件检查未通过"),
|
|
2036
2050
|
width: 480,
|
|
@@ -2041,23 +2055,23 @@ var xn = ({ title: e, fieldSchemas: t, buttonText: n = "导入", batchSize: r =
|
|
|
2041
2055
|
closable: !0,
|
|
2042
2056
|
onOk: ie
|
|
2043
2057
|
});
|
|
2044
|
-
},
|
|
2058
|
+
}, F = async (e) => {
|
|
2045
2059
|
if (e.size > 20971520) N.error("文件大小超过 20MB, 请拆分后再导入");
|
|
2046
2060
|
else {
|
|
2047
2061
|
v(void 0), M([]), C(!0);
|
|
2048
2062
|
try {
|
|
2049
|
-
let { headerMessages: t, formulaMessages: n, rows: r, includedKeys: i } = await
|
|
2063
|
+
let { headerMessages: t, formulaMessages: n, rows: r, includedKeys: i } = await Re(e, P);
|
|
2050
2064
|
if (n.length > 0) {
|
|
2051
|
-
|
|
2065
|
+
ae({
|
|
2052
2066
|
missingTitles: [],
|
|
2053
2067
|
headerMessages: n
|
|
2054
2068
|
}, "文件里的公式还没有计算结果");
|
|
2055
2069
|
return;
|
|
2056
2070
|
}
|
|
2057
2071
|
if (t.length > 0) {
|
|
2058
|
-
|
|
2059
|
-
missingTitles: t.filter((e) => e.startsWith(
|
|
2060
|
-
headerMessages: t.filter((e) => !e.startsWith(
|
|
2072
|
+
ae({
|
|
2073
|
+
missingTitles: t.filter((e) => e.startsWith(bn)).map((e) => e.slice(5)),
|
|
2074
|
+
headerMessages: t.filter((e) => !e.startsWith(bn))
|
|
2061
2075
|
});
|
|
2062
2076
|
return;
|
|
2063
2077
|
}
|
|
@@ -2065,13 +2079,19 @@ var xn = ({ title: e, fieldSchemas: t, buttonText: n = "导入", batchSize: r =
|
|
|
2065
2079
|
N.error("文件里没有数据行");
|
|
2066
2080
|
return;
|
|
2067
2081
|
}
|
|
2082
|
+
let o = r;
|
|
2068
2083
|
try {
|
|
2069
|
-
await a?.(r);
|
|
2084
|
+
let e = await a?.(r);
|
|
2085
|
+
e && (o = yn(e, P, i));
|
|
2070
2086
|
} catch (e) {
|
|
2071
2087
|
N.error(e instanceof Error ? e.message : "导入已取消");
|
|
2072
2088
|
return;
|
|
2073
2089
|
}
|
|
2074
|
-
|
|
2090
|
+
if (o.length === 0) {
|
|
2091
|
+
N.error("没有可导入的数据");
|
|
2092
|
+
return;
|
|
2093
|
+
}
|
|
2094
|
+
M(i), x(`${e.name}-${Date.now()}`), h(o), p(!0);
|
|
2075
2095
|
} catch (e) {
|
|
2076
2096
|
console.error(`导入文件解析失败: ${e}`), N.error("导入文件解析失败, 请确认上传的是 Excel 文件");
|
|
2077
2097
|
} finally {
|
|
@@ -2101,7 +2121,7 @@ var xn = ({ title: e, fieldSchemas: t, buttonText: n = "导入", batchSize: r =
|
|
|
2101
2121
|
onClick: async () => {
|
|
2102
2122
|
O(!0);
|
|
2103
2123
|
try {
|
|
2104
|
-
await
|
|
2124
|
+
await Le(P, `${e}导入模板`);
|
|
2105
2125
|
} catch (e) {
|
|
2106
2126
|
console.error(`模板下载失败: ${e}`), N.error("模板下载失败");
|
|
2107
2127
|
} finally {
|
|
@@ -2119,7 +2139,7 @@ var xn = ({ title: e, fieldSchemas: t, buttonText: n = "导入", batchSize: r =
|
|
|
2119
2139
|
style: { display: "none" },
|
|
2120
2140
|
onChange: (e) => {
|
|
2121
2141
|
let t = e.target.files?.[0];
|
|
2122
|
-
e.target.value = "", t &&
|
|
2142
|
+
e.target.value = "", t && F(t);
|
|
2123
2143
|
}
|
|
2124
2144
|
}),
|
|
2125
2145
|
/* @__PURE__ */ k(mn, {
|
|
@@ -2131,7 +2151,7 @@ var xn = ({ title: e, fieldSchemas: t, buttonText: n = "导入", batchSize: r =
|
|
|
2131
2151
|
includedKeys: j,
|
|
2132
2152
|
onChangeCell: (e, t, n) => {
|
|
2133
2153
|
if (!j.includes(t.key)) return;
|
|
2134
|
-
let r =
|
|
2154
|
+
let r = G(t, n), i = H(r.trim() === "" ? null : r, t);
|
|
2135
2155
|
h((r) => r.map((r) => {
|
|
2136
2156
|
if (r.key !== e.key) return r;
|
|
2137
2157
|
let a = { ...r.errors };
|
|
@@ -2153,7 +2173,7 @@ var xn = ({ title: e, fieldSchemas: t, buttonText: n = "导入", batchSize: r =
|
|
|
2153
2173
|
}, i = {};
|
|
2154
2174
|
P.forEach((e) => {
|
|
2155
2175
|
if (!j.includes(e.key)) return;
|
|
2156
|
-
let t =
|
|
2176
|
+
let t = G(e, r[e.key]), n = H(t.trim() === "" ? null : t, e);
|
|
2157
2177
|
n.validateSuccess || (i[e.key] = n.validateMessage);
|
|
2158
2178
|
});
|
|
2159
2179
|
let a = {
|
|
@@ -2190,10 +2210,10 @@ var xn = ({ title: e, fieldSchemas: t, buttonText: n = "导入", batchSize: r =
|
|
|
2190
2210
|
importRows: async (e) => {
|
|
2191
2211
|
try {
|
|
2192
2212
|
let t = await i(e.map((e) => vn(e, P, j)));
|
|
2193
|
-
if (t.length !== e.length) throw new
|
|
2213
|
+
if (t.length !== e.length) throw new it("导入接口返回结果数量不正确, 任务已暂停");
|
|
2194
2214
|
return t.map((e) => _n(e, re));
|
|
2195
2215
|
} catch (e) {
|
|
2196
|
-
throw e instanceof
|
|
2216
|
+
throw e instanceof it ? e : new it(xn(e));
|
|
2197
2217
|
}
|
|
2198
2218
|
},
|
|
2199
2219
|
onFinished: u
|
|
@@ -2206,4 +2226,4 @@ var xn = ({ title: e, fieldSchemas: t, buttonText: n = "导入", batchSize: r =
|
|
|
2206
2226
|
}, y)
|
|
2207
2227
|
] });
|
|
2208
2228
|
};
|
|
2209
|
-
export { $t as ExportButton,
|
|
2229
|
+
export { $t as ExportButton, Sn as ImportButton, me as MAX_IMPORT_FILE_SIZE, F as MULTI_VALUE_SEPARATOR, Be as exportRowsToFile, oe as importableFields, I as joinMultiValues, Kt as resetTasks, L as splitMultiValues, ue as validateBooleanField, de as validateDateField, pe as validateDateTimeField, H as validateField, z as validateListField, V as validateMultipleChoiceField, le as validateNumberField, B as validateSingleChoiceField, R as validateTextField, fe as validateTimeField };
|