antd-import-export 0.0.0-stage → 1.0.0

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,1598 @@
1
+ import { S as e, _ as t, b as n, c as r, d as i, f as a, g as o, h as s, i as c, l, m as u, p as d, s as f, t as ee, u as te, v as p, x as ne, y as re } from "./worksheet-BEUkpIL-.js";
2
+ import m from "dayjs";
3
+ import * as h from "comlink";
4
+ import { saveAs as g } from "file-saver";
5
+ import { createExcelWorker as ie } from "./core/excel/worker-url.js";
6
+ import { useCallback as _, useEffect as v, useMemo as y, useRef as b, useState as x, useSyncExternalStore as S } from "react";
7
+ import { DeleteOutlined as ae, DownloadOutlined as C, FileOutlined as oe, UploadOutlined as se } from "@ant-design/icons";
8
+ import { App as w, Button as T, Flex as E, Input as ce, InputNumber as le, Modal as ue, Popover as de, Progress as fe, Select as D, Space as pe, Table as me, Tag as O, Tooltip as he, Typography as k, message as A, theme as ge } from "antd";
9
+ import { Fragment as j, jsx as M, jsxs as N } from "react/jsx-runtime";
10
+ // src/core/schema/index.ts
11
+ function P(e) {
12
+ return e.filter((e) => e.importable !== !1);
13
+ }
14
+ // src/core/excel/importRow.ts
15
+ function _e(e, t, n) {
16
+ let r = {};
17
+ return t.forEach((t) => {
18
+ if (!n.includes(t.key)) return;
19
+ let i = c(t, e.values[t.key]), a = d(i.trim() === "" ? null : i, t);
20
+ if (!a.validateSuccess) throw Error(a.validateMessage);
21
+ r[t.key] = a.validateValue ?? null;
22
+ }), r;
23
+ }
24
+ // src/core/excel/runtime.ts
25
+ var F = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
26
+ async function I(e, t) {
27
+ let n = ie();
28
+ if (t?.aborted) throw n.terminate(), new DOMException("任务已取消", "AbortError");
29
+ let r = h.wrap(n), i;
30
+ try {
31
+ return await new Promise((a, o) => {
32
+ i = () => {
33
+ n.terminate(), o(new DOMException("任务已取消", "AbortError"));
34
+ }, t?.addEventListener("abort", i, { once: !0 }), e(r).then(a, o);
35
+ });
36
+ } finally {
37
+ i && t?.removeEventListener("abort", i), n.terminate();
38
+ }
39
+ }
40
+ async function L(e, t, n) {
41
+ let r = await I((n) => n.buildExportExcel(e, t), n);
42
+ return new Blob([r], { type: F });
43
+ }
44
+ async function R(e, t, n) {
45
+ let r = await L(e, t);
46
+ return g(r, `${n}.xlsx`), r;
47
+ }
48
+ async function ve(e, t) {
49
+ let n = await I((t) => t.buildImportTemplate(e));
50
+ g(new Blob([n], { type: F }), `${t}.xlsx`);
51
+ }
52
+ function z(e, t) {
53
+ return I((n) => n.parseImportFile(e, t));
54
+ }
55
+ // src/core/httpError.ts
56
+ function ye(e) {
57
+ let t = e;
58
+ return t !== null && (t.isAxiosError === !0 || t.response !== void 0);
59
+ }
60
+ function B(e) {
61
+ let t = e?.response?.status;
62
+ return typeof t == "number" ? t : void 0;
63
+ }
64
+ function be(e) {
65
+ return e?.response?.data;
66
+ }
67
+ // src/core/taskManager.ts
68
+ var V = class extends Error {
69
+ constructor(e) {
70
+ super(e), this.name = "ImportPauseError";
71
+ }
72
+ }, xe = 100, H = { tasks: [] }, Se = /* @__PURE__ */ new Set(), U = /* @__PURE__ */ new Map(), W = /* @__PURE__ */ new Map(), G = /* @__PURE__ */ new Map();
73
+ function K() {
74
+ H = { ...H }, Se.forEach((e) => e());
75
+ }
76
+ function Ce(e) {
77
+ return Se.add(e), () => {
78
+ Se.delete(e);
79
+ };
80
+ }
81
+ function q(e) {
82
+ return Ce(e);
83
+ }
84
+ function we() {
85
+ return H.tasks;
86
+ }
87
+ function Te() {
88
+ return `task-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
89
+ }
90
+ function J(e) {
91
+ return H.tasks.find((t) => t.id === e);
92
+ }
93
+ function Y(e, t) {
94
+ let n = !1, r = H.tasks.map((r) => r.id === e ? (n = !0, {
95
+ ...r,
96
+ ...t
97
+ }) : r);
98
+ n && (H = {
99
+ ...H,
100
+ tasks: r
101
+ }, K());
102
+ }
103
+ function Ee(e, t) {
104
+ let n = J(e), r = Date.now();
105
+ return [...n?.samples ?? [], {
106
+ time: r,
107
+ processed: t
108
+ }].filter((e) => r - e.time <= 15e3).slice(-20);
109
+ }
110
+ var De = 100, X = /* @__PURE__ */ new Set(), Z = null;
111
+ function Oe(e, t, n) {
112
+ let r = W.get(e);
113
+ r && (r.rowStates[t] = {
114
+ ...r.rowStates[t],
115
+ ...n
116
+ }, ke(e));
117
+ }
118
+ function ke(e) {
119
+ X.add(e), Z === null && (Z = setTimeout(() => {
120
+ Z = null;
121
+ let e = [...X];
122
+ X.clear(), e.forEach(Ae);
123
+ }, De));
124
+ }
125
+ function Q(e) {
126
+ X.delete(e);
127
+ }
128
+ function $(e, t) {
129
+ return {
130
+ processed: t.processed,
131
+ total: je(t),
132
+ successCount: t.successCount,
133
+ failureCount: t.failures.length,
134
+ validationFailedCount: t.validationFailedCount,
135
+ failures: t.failures,
136
+ rowStates: t.rowStates,
137
+ samples: Ee(e, t.processed)
138
+ };
139
+ }
140
+ function Ae(e) {
141
+ let t = W.get(e);
142
+ t && J(e) && Y(e, $(e, t));
143
+ }
144
+ function je(e) {
145
+ return e.options.rows.length - e.deletedIndexes.size;
146
+ }
147
+ async function Me(e, t, n) {
148
+ let { options: r } = t;
149
+ t.controller = n, t.cancelRequested = !1;
150
+ try {
151
+ for (; !t.cancelRequested;) {
152
+ let i = t.cursorId === void 0 ? {} : { cursor_id: t.cursorId }, a = await r.fetchPage(i, n.signal);
153
+ if (n.signal.aborted) throw new DOMException("任务已取消", "AbortError");
154
+ if (t.total = a.count, a.results.length === 0) break;
155
+ t.rows = t.rows.concat(a.results);
156
+ let o = t.rows.length;
157
+ Y(e, {
158
+ total: t.total,
159
+ processed: o,
160
+ samples: Ee(e, o)
161
+ });
162
+ let s = a.results[a.results.length - 1]?.id;
163
+ if (typeof s != "number") throw Error("导出数据缺少 id");
164
+ t.cursorId = s;
165
+ }
166
+ if (t.cancelRequested) {
167
+ Y(e, {
168
+ status: "canceled",
169
+ pausing: !1,
170
+ canceling: !1,
171
+ finalizing: !1
172
+ });
173
+ return;
174
+ }
175
+ if (t.rows.length === 0) throw Error("没有可导出的数据");
176
+ Y(e, { finalizing: !0 });
177
+ let i = await L(t.rows, r.fieldSchemas, n.signal);
178
+ if (n.signal.aborted) throw new DOMException("任务已取消", "AbortError");
179
+ try {
180
+ g(i, `${r.fileName}.xlsx`);
181
+ } catch (e) {
182
+ console.error(`自动下载失败: ${e}`);
183
+ }
184
+ Y(e, {
185
+ status: "completed",
186
+ pausing: !1,
187
+ finalizing: !1,
188
+ canceling: !1,
189
+ total: t.rows.length,
190
+ processed: t.rows.length,
191
+ blob: i
192
+ });
193
+ } catch (t) {
194
+ if (n.signal.aborted) {
195
+ Y(e, {
196
+ status: "canceled",
197
+ pausing: !1,
198
+ finalizing: !1,
199
+ canceling: !1
200
+ });
201
+ return;
202
+ }
203
+ Y(e, {
204
+ status: "failed",
205
+ pausing: !1,
206
+ finalizing: !1,
207
+ canceling: !1,
208
+ errorMessage: Ne(t)
209
+ });
210
+ } finally {
211
+ t.controller = null;
212
+ }
213
+ }
214
+ function Ne(e) {
215
+ if (!ye(e)) return e instanceof Error ? e.message : "导出失败";
216
+ let t = B(e);
217
+ return t === void 0 ? "网络异常, 导出失败" : t === 401 ? "登录已过期, 导出失败" : t === 403 ? "没有导出权限, 导出失败" : t === 404 ? "导出接口不存在, 导出失败" : t === 400 ? "导出参数错误, 导出失败" : t >= 500 ? "服务器错误, 导出失败" : "导出失败";
218
+ }
219
+ function Pe(e) {
220
+ return `导入完成: 成功 ${e.successCount} 条, 失败 ${e.failures.length} 条`;
221
+ }
222
+ async function Fe(e, t, n) {
223
+ let r = t.options.rows.length;
224
+ if (t.controller = n, t.pauseRequested = !1, t.cancelRequested = !1, t.cycleFailureCount = 0, r === 0) {
225
+ Y(e, {
226
+ status: "failed",
227
+ pausing: !1,
228
+ errorMessage: "没有可导入的数据"
229
+ }), t.options.onFinished?.();
230
+ return;
231
+ }
232
+ Y(e, {
233
+ ...$(e, t),
234
+ status: "running",
235
+ samples: [{
236
+ time: Date.now(),
237
+ processed: t.processed
238
+ }]
239
+ });
240
+ let i = Math.min(Math.max(t.options.batchSize ?? 20, 1), 200), a = Math.min(Math.max(t.options.concurrency ?? 3, 1), 5), o = () => {
241
+ let n = [];
242
+ for (; n.length < i;) {
243
+ let i = t.nextIndex;
244
+ if (t.nextIndex += 1, i >= r) break;
245
+ t.deletedIndexes.has(i) || J(e)?.rowStates?.[i]?.status !== "completed" && (t.skippedIndexes.has(i) || n.push(i));
246
+ }
247
+ return n;
248
+ }, s = async () => {
249
+ for (;;) {
250
+ if (n.signal.aborted || t.pauseRequested || t.cancelRequested) return;
251
+ let r = o();
252
+ if (r.length === 0) return;
253
+ r.forEach((t) => {
254
+ Oe(e, t, {
255
+ status: "running",
256
+ message: void 0,
257
+ fieldErrors: void 0
258
+ });
259
+ });
260
+ try {
261
+ let i = r.map((e) => t.options.rows[e]), a = await t.options.importRows(i, n.signal);
262
+ if (n.signal.aborted) return;
263
+ if (a.length !== r.length) throw new V("导入接口返回结果数量不正确, 任务已暂停");
264
+ a.forEach((n, i) => {
265
+ let a = r[i], o = t.options.rows[a];
266
+ n.success ? (t.successCount += 1, Oe(e, a, {
267
+ status: "completed",
268
+ fieldErrors: void 0
269
+ })) : (t.failures.push({
270
+ index: a,
271
+ rowNumber: o.rowNumber,
272
+ message: n.message ?? "导入失败",
273
+ fieldErrors: n.fieldErrors
274
+ }), Oe(e, a, {
275
+ status: "failed",
276
+ message: n.message,
277
+ fieldErrors: n.fieldErrors
278
+ }), t.cycleFailureCount += 1, t.cycleFailureCount > xe && (t.pauseRequested = !0));
279
+ });
280
+ } catch (i) {
281
+ if (n.signal.aborted) return;
282
+ let a = i instanceof V, o = i instanceof Error ? i.message : "导入失败";
283
+ r.forEach((n) => {
284
+ t.failures.push({
285
+ index: n,
286
+ rowNumber: t.options.rows[n].rowNumber,
287
+ message: o
288
+ }), Oe(e, n, {
289
+ status: "failed",
290
+ message: o
291
+ }), t.cycleFailureCount += 1;
292
+ }), a ? (t.pauseRequested = !0, n.abort()) : t.cycleFailureCount > xe && (t.pauseRequested = !0);
293
+ } finally {
294
+ t.processed += r.length, ke(e);
295
+ }
296
+ }
297
+ }, c = Math.min(a, Math.max(1, r));
298
+ if (await Promise.all(Array.from({ length: c }, () => s())), t.controller = null, !J(e)) return;
299
+ if (t.cancelRequested) {
300
+ Q(e), t.rowStates = t.rowStates.map((e) => e.status === "queued" || e.status === "running" ? { status: "canceled" } : e), Y(e, {
301
+ ...$(e, t),
302
+ status: "canceled",
303
+ pausing: !1,
304
+ canceling: !1
305
+ }), t.options.onFinished?.();
306
+ return;
307
+ }
308
+ if (t.pauseRequested && n.signal.aborted) {
309
+ Q(e), t.rowStates = t.rowStates.map((e) => e.status === "running" ? {
310
+ status: "queued",
311
+ validationErrors: e.validationErrors
312
+ } : e), Y(e, {
313
+ ...$(e, t),
314
+ status: "paused",
315
+ pausing: !1,
316
+ errorMessage: t.failures.length > 0 ? `累计失败 ${t.failures.length} 条, 任务已暂停, 可继续导入` : void 0
317
+ }), t.options.onFinished?.();
318
+ return;
319
+ }
320
+ if (n.signal.aborted) {
321
+ Q(e), t.rowStates = t.rowStates.map((e) => e.status === "queued" || e.status === "running" ? { status: "canceled" } : e), Y(e, {
322
+ ...$(e, t),
323
+ status: "canceled",
324
+ pausing: !1,
325
+ canceling: !1
326
+ }), t.options.onFinished?.();
327
+ return;
328
+ }
329
+ if (t.pauseRequested && t.nextIndex < r) {
330
+ Q(e), Y(e, {
331
+ ...$(e, t),
332
+ status: "paused",
333
+ pausing: !1,
334
+ errorMessage: t.failures.length > 0 ? `累计失败 ${t.failures.length} 条, 任务已暂停, 可继续导入` : void 0
335
+ }), t.options.onFinished?.();
336
+ return;
337
+ }
338
+ if (t.failures.length > 0) {
339
+ Q(e), Y(e, {
340
+ ...$(e, t),
341
+ status: "paused",
342
+ pausing: !1,
343
+ errorMessage: Pe(t)
344
+ }), t.options.onFinished?.();
345
+ return;
346
+ }
347
+ let l = [...t.skippedIndexes].filter((e) => !t.deletedIndexes.has(e)).length;
348
+ l > 0 ? (Q(e), Y(e, {
349
+ ...$(e, t),
350
+ status: "paused",
351
+ pausing: !1,
352
+ errorMessage: `有 ${l} 条校验失败数据待修复`
353
+ }), t.options.onFinished?.()) : (Q(e), Y(e, {
354
+ ...$(e, t),
355
+ status: "completed",
356
+ pausing: !1
357
+ }), t.options.onFinished?.());
358
+ }
359
+ function Ie(e, t) {
360
+ let n = new AbortController();
361
+ G.set(e, n), Me(e, t, n).finally(() => {
362
+ G.delete(e), U.delete(e);
363
+ });
364
+ }
365
+ function Le(e, t) {
366
+ let n = new AbortController();
367
+ G.set(e, n), Fe(e, t, n).finally(() => {
368
+ G.delete(e), X.delete(e), J(e)?.status !== "paused" && W.delete(e);
369
+ });
370
+ }
371
+ function Re(e) {
372
+ let t = Te(), n = {
373
+ id: t,
374
+ type: "export",
375
+ title: e.title,
376
+ status: "running",
377
+ total: 0,
378
+ processed: 0,
379
+ fileName: e.fileName,
380
+ samples: []
381
+ };
382
+ H = {
383
+ ...H,
384
+ tasks: [...H.tasks, n]
385
+ };
386
+ let r = {
387
+ options: e,
388
+ rows: [],
389
+ total: 0,
390
+ cancelRequested: !1,
391
+ controller: null
392
+ };
393
+ return U.set(t, r), K(), Ie(t, r), t;
394
+ }
395
+ function ze(e) {
396
+ let t = Te(), n = e.rows.map((e) => ({
397
+ status: "queued",
398
+ validationErrors: Object.keys(e.errors).length > 0 ? e.errors : void 0
399
+ })), r = new Set(e.rows.flatMap((e, t) => Object.keys(e.errors).length > 0 ? [t] : [])), i = r.size, a = {
400
+ id: t,
401
+ type: "import",
402
+ title: e.title,
403
+ status: "running",
404
+ total: e.rows.length,
405
+ processed: 0,
406
+ canceling: !1,
407
+ successCount: 0,
408
+ failureCount: 0,
409
+ validationFailedCount: i,
410
+ rowStates: n,
411
+ failures: [],
412
+ samples: []
413
+ };
414
+ H = {
415
+ ...H,
416
+ tasks: [...H.tasks, a]
417
+ };
418
+ let o = {
419
+ options: e,
420
+ nextIndex: 0,
421
+ processed: 0,
422
+ successCount: 0,
423
+ failures: [],
424
+ rowStates: n,
425
+ validationFailedCount: i,
426
+ pauseRequested: !1,
427
+ cancelRequested: !1,
428
+ deletedIndexes: /* @__PURE__ */ new Set(),
429
+ skippedIndexes: r,
430
+ cycleFailureCount: 0,
431
+ controller: null
432
+ };
433
+ return W.set(t, o), K(), Le(t, o), t;
434
+ }
435
+ function Be(e) {
436
+ let t = J(e);
437
+ if (!t || t.type !== "import" || t.status !== "paused") return;
438
+ let n = W.get(e);
439
+ if (!n) return;
440
+ let r = n.rowStates.filter((e) => e.status === "completed").length, i = n.rowStates.map((e) => e.status === "completed" || e.status === "deleted" ? e : {
441
+ status: "queued",
442
+ validationErrors: e.validationErrors
443
+ }), a = i.filter((e) => e.validationErrors && Object.keys(e.validationErrors).length > 0).length;
444
+ 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, {
445
+ status: "running",
446
+ pausing: !1,
447
+ canceling: !1,
448
+ processed: r,
449
+ successCount: r,
450
+ failureCount: 0,
451
+ validationFailedCount: a,
452
+ failures: [],
453
+ rowStates: i,
454
+ errorMessage: void 0
455
+ }), Le(e, n);
456
+ }
457
+ function Ve(e) {
458
+ let t = J(e);
459
+ if (!t || t.type !== "import" || t.status !== "running" || t.canceling) return;
460
+ let n = W.get(e);
461
+ n && (n.pauseRequested = !0, Y(e, { pausing: !0 }));
462
+ }
463
+ function He(e, t, n) {
464
+ let r = J(e), i = W.get(e);
465
+ if (!r || r.type !== "import" || r.status !== "paused" && r.status !== "failed" || !i) return;
466
+ let a = r.rowStates?.[t]?.status;
467
+ (a === "queued" || a === "failed") && (i.options.rows[t] = n);
468
+ }
469
+ function Ue(e, t, n) {
470
+ let r = J(e), i = W.get(e);
471
+ if (!r || r.type !== "import" || !i || r.status !== "paused" && r.status !== "failed") return;
472
+ let a = Object.keys(n).length > 0, o = i.rowStates[t]?.validationErrors, s = !!(o && Object.keys(o).length > 0);
473
+ a ? (i.skippedIndexes.add(t), s || (i.validationFailedCount += 1)) : (i.skippedIndexes.delete(t), s && --i.validationFailedCount), i.rowStates[t] = {
474
+ ...i.rowStates[t],
475
+ validationErrors: a ? n : void 0
476
+ }, i.options.rows[t] = {
477
+ ...i.options.rows[t],
478
+ errors: n
479
+ }, Y(e, {
480
+ validationFailedCount: i.validationFailedCount,
481
+ rowStates: i.rowStates
482
+ });
483
+ }
484
+ function We(e, t) {
485
+ let n = J(e), r = W.get(e);
486
+ n && n.type === "import" && n.status === "paused" && r && (t.forEach((e) => {
487
+ let t = r.rowStates[e];
488
+ t?.status === "queued" && (t.validationErrors && Object.keys(t.validationErrors).length > 0 && --r.validationFailedCount, r.deletedIndexes.add(e), r.rowStates[e] = {
489
+ status: "deleted",
490
+ fieldErrors: void 0
491
+ });
492
+ }), Y(e, {
493
+ total: je(r),
494
+ validationFailedCount: r.validationFailedCount,
495
+ rowStates: r.rowStates
496
+ }));
497
+ }
498
+ function Ge(e, t, n) {
499
+ let r = J(e)?.rowStates?.[t];
500
+ if (!r?.fieldErrors?.some((e) => n in e)) return;
501
+ let i = r.fieldErrors.filter((e) => !(n in e));
502
+ Oe(e, t, {
503
+ ...r,
504
+ fieldErrors: i.length > 0 ? i : void 0
505
+ });
506
+ }
507
+ function Ke(e) {
508
+ let t = J(e);
509
+ if (!t) return;
510
+ if (t.status === "paused") {
511
+ Y(e, {
512
+ status: "canceled",
513
+ pausing: !1,
514
+ canceling: !1,
515
+ rowStates: (t.rowStates ?? []).map((e) => e.status === "queued" || e.status === "running" ? { status: "canceled" } : e)
516
+ }), W.delete(e), X.delete(e);
517
+ return;
518
+ }
519
+ if (t.status !== "running") return;
520
+ if (t.type === "export") {
521
+ if (t.canceling) return;
522
+ let n = U.get(e);
523
+ if (!n) return;
524
+ n.cancelRequested = !0, n.controller?.abort(), Y(e, { canceling: !0 });
525
+ return;
526
+ }
527
+ if (t.canceling) return;
528
+ let n = W.get(e);
529
+ n && (n.cancelRequested = !0, Y(e, { canceling: !0 }));
530
+ }
531
+ function qe(e) {
532
+ let t = J(e);
533
+ t && (t.status === "running" && G.get(e)?.abort(), U.delete(e), W.delete(e), X.delete(e), H = {
534
+ ...H,
535
+ tasks: H.tasks.filter((t) => t.id !== e)
536
+ }, K());
537
+ }
538
+ function Je(e, t) {
539
+ try {
540
+ return g(e, `${t}.xlsx`), !0;
541
+ } catch (e) {
542
+ return console.error(`下载失败: ${e}`), !1;
543
+ }
544
+ }
545
+ function Ye(e) {
546
+ let t = J(e);
547
+ return t?.type !== "export" || !t.blob || !t.fileName ? !1 : Je(t.blob, t.fileName);
548
+ }
549
+ function Xe() {
550
+ G.forEach((e) => e.abort()), G.clear(), U.clear(), W.clear(), X.clear(), Z !== null && (clearTimeout(Z), Z = null), H = { tasks: [] }, K();
551
+ }
552
+ function Ze(e) {
553
+ if (e.status !== "running" || e.total <= 0) return null;
554
+ let t = Math.max(0, e.total - (e.validationFailedCount ?? 0) - e.processed);
555
+ if (t === 0) return 0;
556
+ if (e.samples.length < 2) return null;
557
+ let n = e.samples[0], r = e.samples[e.samples.length - 1], i = (r.time - n.time) / 1e3, a = r.processed - n.processed;
558
+ return i <= 0 || a <= 0 ? null : t / (a / i);
559
+ }
560
+ function Qe(e) {
561
+ return e.type === "import" ? e.successCount === void 0 ? e.rowStates?.filter((e) => e.status === "completed").length ?? e.processed : e.successCount : e.processed;
562
+ }
563
+ function $e(e) {
564
+ return e.total <= 0 ? 0 : Math.min(100, Qe(e) / e.total * 100);
565
+ }
566
+ function et(e) {
567
+ let t = $e(e);
568
+ return t >= 100 ? 100 : Math.trunc(t * 10) / 10;
569
+ }
570
+ function tt(e) {
571
+ return `${(Math.trunc(e * 10) / 10).toFixed(1)}%`;
572
+ }
573
+ function nt(e) {
574
+ if (e === null) return "计算中...";
575
+ let t = Math.ceil(e);
576
+ return t < 60 ? `约 ${t} 秒` : `约 ${Math.floor(t / 60)} 分 ${t % 60} 秒`;
577
+ }
578
+ // src/react/useTaskDetail.ts
579
+ function rt(e) {
580
+ let t = _(() => e ? we().find((t) => t.id === e) : void 0, [e]);
581
+ return S(q, t);
582
+ }
583
+ // src/components/BatchExportButton.tsx
584
+ var it = ({ title: e, fieldSchemas: t, selectedRows: n, disabled: r }) => {
585
+ let [i, a] = x(!1);
586
+ return /* @__PURE__ */ M(T, {
587
+ type: "default",
588
+ icon: /* @__PURE__ */ M(C, {}),
589
+ loading: i,
590
+ disabled: r ?? n.length === 0,
591
+ onClick: async () => {
592
+ if (n.length === 0) return;
593
+ if (n.length > 2e4) {
594
+ A.error(`导出数据 ${n.length.toLocaleString()} 条,超过上限 ${f} 条,请分批导出`);
595
+ return;
596
+ }
597
+ let r = `${e}_${m().format("YYYYMMDDHHmmss")}`;
598
+ a(!0);
599
+ try {
600
+ await R(n, t, r), A.success("导出成功");
601
+ } catch (e) {
602
+ console.error(`导出失败: ${e}`), A.error("导出失败");
603
+ } finally {
604
+ a(!1);
605
+ }
606
+ },
607
+ children: "批量导出"
608
+ });
609
+ };
610
+ // src/components/ExportTaskModal.tsx
611
+ function at(e) {
612
+ if (e.canceling) return "正在取消";
613
+ if (e.finalizing) return "正在生成文件";
614
+ switch (e.status) {
615
+ case "running": return "进行中";
616
+ case "paused": return "已暂停";
617
+ case "completed": return "已完成";
618
+ case "failed": return "失败";
619
+ case "canceled": return "已取消";
620
+ }
621
+ }
622
+ function ot(e) {
623
+ if (e.canceling) return "warning";
624
+ if (e.finalizing) return "processing";
625
+ }
626
+ function st(e) {
627
+ switch (e.status) {
628
+ case "failed": return "exception";
629
+ case "completed": return "success";
630
+ default: return "normal";
631
+ }
632
+ }
633
+ var ct = ({ taskId: e, onClose: t }) => {
634
+ let n = rt(e), { message: r } = w.useApp();
635
+ if (!n) return null;
636
+ let i = n.status === "completed" || n.status === "failed" || n.status === "canceled", a = et(n), o = () => {
637
+ qe(n.id), t();
638
+ }, s = () => {
639
+ Ye(n.id) || r.error("文件不存在");
640
+ }, c = at(n);
641
+ return /* @__PURE__ */ M(ue, {
642
+ title: "导出任务",
643
+ open: !0,
644
+ maskClosable: !1,
645
+ closable: i,
646
+ keyboard: i,
647
+ onCancel: () => {
648
+ i && o();
649
+ },
650
+ footer: i ? /* @__PURE__ */ N(E, {
651
+ justify: "flex-end",
652
+ gap: 8,
653
+ children: [n.status === "completed" ? /* @__PURE__ */ M(T, {
654
+ onClick: s,
655
+ children: "重新下载"
656
+ }) : null, /* @__PURE__ */ M(T, {
657
+ type: "primary",
658
+ onClick: o,
659
+ children: "关闭"
660
+ })]
661
+ }) : /* @__PURE__ */ M(E, {
662
+ justify: "flex-end",
663
+ children: /* @__PURE__ */ M(T, {
664
+ danger: !0,
665
+ loading: n.canceling,
666
+ disabled: n.canceling,
667
+ onClick: () => Ke(n.id),
668
+ children: n.canceling ? "取消中" : "取消任务"
669
+ })
670
+ }),
671
+ children: /* @__PURE__ */ N(E, {
672
+ vertical: !0,
673
+ gap: 12,
674
+ children: [
675
+ /* @__PURE__ */ N(E, {
676
+ justify: "space-between",
677
+ align: "center",
678
+ gap: 12,
679
+ children: [/* @__PURE__ */ M(k.Text, {
680
+ strong: !0,
681
+ ellipsis: !0,
682
+ children: n.title
683
+ }), /* @__PURE__ */ M(O, {
684
+ color: ot(n),
685
+ children: c
686
+ })]
687
+ }),
688
+ /* @__PURE__ */ M(fe, {
689
+ percent: a,
690
+ format: () => tt(a),
691
+ status: st(n),
692
+ size: "small"
693
+ }),
694
+ /* @__PURE__ */ N(E, {
695
+ justify: "space-between",
696
+ children: [
697
+ /* @__PURE__ */ N(k.Text, {
698
+ type: "secondary",
699
+ children: [
700
+ "已导出 ",
701
+ Qe(n).toLocaleString(),
702
+ " / 总数 ",
703
+ n.total > 0 ? n.total.toLocaleString() : "--"
704
+ ]
705
+ }),
706
+ n.finalizing ? /* @__PURE__ */ M(k.Text, {
707
+ type: "secondary",
708
+ children: "正在生成文件..."
709
+ }) : null,
710
+ n.canceling ? /* @__PURE__ */ M(k.Text, {
711
+ type: "secondary",
712
+ children: "正在取消..."
713
+ }) : null
714
+ ]
715
+ }),
716
+ n.errorMessage ? /* @__PURE__ */ M(k.Text, {
717
+ type: "danger",
718
+ children: n.errorMessage
719
+ }) : null
720
+ ]
721
+ })
722
+ });
723
+ }, lt = ({ title: e, buttonText: t = "导出", fieldSchemas: n, filters: r, totalCount: i, disabled: a, fetchPage: o }) => {
724
+ let { message: s } = w.useApp(), [c, l] = x(), u = b(void 0);
725
+ return v(() => {
726
+ u.current = c;
727
+ }, [c]), v(() => () => {
728
+ u.current && qe(u.current);
729
+ }, []), /* @__PURE__ */ N(j, { children: [/* @__PURE__ */ M(he, {
730
+ title: "导出 Excel",
731
+ children: /* @__PURE__ */ M(T, {
732
+ type: "default",
733
+ icon: /* @__PURE__ */ M(C, {}),
734
+ disabled: a,
735
+ onClick: () => {
736
+ if (i === 0) {
737
+ s.error("没有可导出的数据");
738
+ return;
739
+ }
740
+ if (i > 2e4) {
741
+ s.error(`导出数据共 ${i.toLocaleString()} 条, 超过上限 ${f} 条, 请缩小筛选范围后分批导出`);
742
+ return;
743
+ }
744
+ let t = `${e}_${m().format("YYYYMMDDHHmmss")}`;
745
+ l(Re({
746
+ title: `${e}导出`,
747
+ fileName: t,
748
+ fieldSchemas: n,
749
+ fetchPage: (e, t) => o({
750
+ ...r,
751
+ ...e
752
+ }, t)
753
+ }));
754
+ },
755
+ children: t
756
+ })
757
+ }), c ? /* @__PURE__ */ M(ct, {
758
+ taskId: c,
759
+ onClose: () => l(void 0)
760
+ }) : null] });
761
+ }, { Text: ut } = k, dt = ({ missingTitles: e, headerMessages: t }) => /* @__PURE__ */ N(E, {
762
+ vertical: !0,
763
+ gap: 4,
764
+ children: [e.length > 0 ? /* @__PURE__ */ M(ut, { children: `缺少必填列: ${e.join(", ")}` }) : null, t.map((e, t) => /* @__PURE__ */ M(ut, { children: e }, t))]
765
+ });
766
+ // src/react/useDebouncedValue.ts
767
+ function ft(e, t) {
768
+ let [n, r] = x(e);
769
+ return v(() => {
770
+ let n = setTimeout(() => r(e), t);
771
+ return () => clearTimeout(n);
772
+ }, [e, t]), n;
773
+ }
774
+ // src/react/useThrottledValue.ts
775
+ function pt(e, t) {
776
+ let [n, r] = x(e), i = b(e), a = b(0), o = b(null);
777
+ return i.current = e, v(() => {
778
+ let n = Date.now() - a.current;
779
+ n >= t ? (a.current = Date.now(), r(e)) : o.current === null && (o.current = setTimeout(() => {
780
+ o.current = null, a.current = Date.now(), r(i.current);
781
+ }, t - n));
782
+ }, [e, t]), v(() => () => {
783
+ o.current !== null && clearTimeout(o.current);
784
+ }, []), n;
785
+ }
786
+ // src/components/ImportPreviewModal.tsx
787
+ function mt(e) {
788
+ return e == null || e === "" ? "" : Array.isArray(e) ? ne(e) : String(e);
789
+ }
790
+ var ht = ({ field: e, record: t, disabled: n, onChange: r, onSave: i }) => {
791
+ let { token: a } = ge.useToken(), [o, s] = x(!1), [c, l] = x(!1), u = t.values[e.key];
792
+ if (o && !n) return e.type === "boolean" ? /* @__PURE__ */ M(D, {
793
+ autoFocus: !0,
794
+ open: !0,
795
+ size: "small",
796
+ style: { width: "100%" },
797
+ value: typeof u == "string" ? u : void 0,
798
+ options: [{
799
+ value: e.property.true_label,
800
+ label: e.property.true_label
801
+ }, {
802
+ value: e.property.false_label,
803
+ label: e.property.false_label
804
+ }],
805
+ onChange: (e) => {
806
+ r(e), i(e), s(!1);
807
+ },
808
+ onBlur: () => s(!1)
809
+ }) : e.type === "single_choice" ? /* @__PURE__ */ M(D, {
810
+ autoFocus: !0,
811
+ open: !0,
812
+ size: "small",
813
+ style: { width: "100%" },
814
+ value: typeof u == "string" ? u : void 0,
815
+ options: Object.keys(e.property.option_map).map((e) => ({
816
+ value: e,
817
+ label: e
818
+ })),
819
+ onChange: (e) => {
820
+ r(e), i(e), s(!1);
821
+ },
822
+ onBlur: () => s(!1)
823
+ }) : e.type === "multiple_choice" ? /* @__PURE__ */ M(D, {
824
+ autoFocus: !0,
825
+ open: !0,
826
+ mode: "multiple",
827
+ size: "small",
828
+ style: { width: "100%" },
829
+ value: Array.isArray(u) ? u : [],
830
+ options: Object.keys(e.property.option_map).map((e) => ({
831
+ value: e,
832
+ label: e
833
+ })),
834
+ onChange: r,
835
+ onBlur: () => {
836
+ s(!1), i(u);
837
+ }
838
+ }) : e.type === "number" ? /* @__PURE__ */ M(le, {
839
+ autoFocus: !0,
840
+ size: "small",
841
+ style: { width: "100%" },
842
+ value: typeof u == "number" || typeof u == "string" ? u : void 0,
843
+ onChange: r,
844
+ onBlur: () => {
845
+ s(!1), i(u);
846
+ },
847
+ onPressEnter: () => {
848
+ s(!1), i(u);
849
+ }
850
+ }) : /* @__PURE__ */ M(ce, {
851
+ autoFocus: !0,
852
+ size: "small",
853
+ value: typeof u == "string" ? u : "",
854
+ placeholder: e.type === "list" ? "多个值用分号分隔(中英文均可)" : void 0,
855
+ onChange: (e) => r(e.target.value),
856
+ onBlur: () => {
857
+ s(!1), i(u);
858
+ },
859
+ onPressEnter: () => {
860
+ s(!1), i(u);
861
+ }
862
+ });
863
+ let d = mt(u);
864
+ return /* @__PURE__ */ M("div", {
865
+ title: d || void 0,
866
+ style: {
867
+ height: 24,
868
+ boxSizing: "border-box",
869
+ display: "flex",
870
+ alignItems: "center",
871
+ minWidth: 0,
872
+ padding: "0 7px",
873
+ lineHeight: "22px",
874
+ whiteSpace: "nowrap",
875
+ overflow: "hidden",
876
+ border: `1px solid ${c && !n ? a.colorBorder : "transparent"}`,
877
+ borderRadius: a.borderRadiusSM,
878
+ cursor: n ? "default" : "text"
879
+ },
880
+ onMouseEnter: () => l(!0),
881
+ onMouseLeave: () => l(!1),
882
+ onClick: () => {
883
+ n || s(!0);
884
+ },
885
+ children: /* @__PURE__ */ M("span", {
886
+ style: {
887
+ minWidth: 0,
888
+ overflow: "hidden",
889
+ textOverflow: "ellipsis",
890
+ whiteSpace: "nowrap"
891
+ },
892
+ children: d
893
+ })
894
+ });
895
+ };
896
+ function gt(e) {
897
+ if (e.canceling) return {
898
+ label: "正在取消",
899
+ color: "warning"
900
+ };
901
+ switch (e.status) {
902
+ case "running": return {
903
+ label: "进行中",
904
+ color: "processing"
905
+ };
906
+ case "paused": return {
907
+ label: "已暂停",
908
+ color: "warning"
909
+ };
910
+ case "completed": return {
911
+ label: "已完成",
912
+ color: "success"
913
+ };
914
+ case "failed": return {
915
+ label: "失败",
916
+ color: "error"
917
+ };
918
+ case "canceled": return {
919
+ label: "已取消",
920
+ color: "warning"
921
+ };
922
+ }
923
+ }
924
+ function _t(e, t) {
925
+ if (e.canceling) return "正在取消...";
926
+ switch (e.status) {
927
+ case "running": return `预计剩余 ${nt(t)}`;
928
+ default: return null;
929
+ }
930
+ }
931
+ function vt(e) {
932
+ switch (e.status) {
933
+ case "failed": return "exception";
934
+ case "completed": return "success";
935
+ default: return "normal";
936
+ }
937
+ }
938
+ var yt = {
939
+ valid: {
940
+ label: "已校验",
941
+ color: "success"
942
+ },
943
+ invalid: {
944
+ label: "校验失败",
945
+ color: "error"
946
+ }
947
+ }, bt = {
948
+ pending: {
949
+ label: "待导入",
950
+ color: "default"
951
+ },
952
+ running: {
953
+ label: "进行中",
954
+ color: "processing"
955
+ },
956
+ completed: {
957
+ label: "已完成",
958
+ color: "success"
959
+ },
960
+ failed: {
961
+ label: "导入失败",
962
+ color: "error"
963
+ },
964
+ canceled: {
965
+ label: "已取消",
966
+ color: "warning"
967
+ }
968
+ };
969
+ function xt(e) {
970
+ return Object.keys(e.errors).length > 0 ? "invalid" : "valid";
971
+ }
972
+ function St(e, t, n) {
973
+ if (!t || e.taskIndex === void 0) return "pending";
974
+ switch (n?.rowStates?.[e.taskIndex]?.status) {
975
+ case "running": return "running";
976
+ case "completed": return "completed";
977
+ case "failed": return "failed";
978
+ case "canceled": return "canceled";
979
+ default: return "pending";
980
+ }
981
+ }
982
+ var Ct = ({ open: e, title: t, fieldSchemas: n, rows: r, taskId: i, includedKeys: a, onChangeCell: o, onSaveCell: s, onDelete: c, onConfirm: l, onClose: u }) => {
983
+ let [d, f] = x("all"), [ee, te] = x("all"), [p, ne] = x(""), re = ft(p, 300), m = () => {
984
+ f("all"), te("all"), ne("");
985
+ }, h = rt(i), [g, ie] = x(), _ = y(() => new Set(a), [a]), v = n.filter((e) => _.has(e.key));
986
+ h && h !== g && ie(h);
987
+ let b = h ?? (g?.id === i ? g : void 0), S = b ? gt(b) : void 0, C = !!(b && b.status !== "completed" && b.status !== "failed" && b.status !== "canceled"), oe = pt(b?.status === "running" ? Ze(b) : null, 1e3), se = b ? _t(b, oe) : null, w = (e) => e.taskIndex === void 0 ? void 0 : b?.rowStates?.[e.taskIndex], le = !(!h || h.status !== "failed" && h.status !== "paused"), pe = (e) => {
988
+ if (!i) return !0;
989
+ let t = w(e)?.status;
990
+ return le && (t === "queued" || t === "failed") ? !0 : le && e.taskIndex === void 0 && Object.keys(e.errors).length > 0;
991
+ }, he = (e) => !i || h?.status === "paused" && w(e)?.status === "queued", A = y(() => ["valid", "invalid"].map((e) => ({
992
+ value: e,
993
+ label: yt[e].label
994
+ })), []), ge = y(() => [
995
+ "pending",
996
+ "running",
997
+ "completed",
998
+ "failed",
999
+ "canceled"
1000
+ ].map((e) => ({
1001
+ value: e,
1002
+ label: bt[e].label
1003
+ })), []), P = b?.status === "running", _e = P ? "" : re, F = !P && d !== "all" && A.some((e) => e.value === d) ? d : "all", I = !P && ee !== "all" && ge.some((e) => e.value === ee) ? ee : "all", L = F !== "all" || _e.trim() !== "", R = I !== "all", ve = L || R, z = y(() => {
1004
+ if (!L) return r;
1005
+ let e = _e.trim().toLowerCase();
1006
+ return r.filter((t) => F !== "all" && xt(t) !== F ? !1 : !e || Object.values(t.values).some((t) => (Array.isArray(t) ? t.join(" ") : String(t ?? "")).toLowerCase().includes(e)));
1007
+ }, [
1008
+ r,
1009
+ F,
1010
+ _e,
1011
+ L
1012
+ ]), ye = pt(b, 300), B = R ? ye : void 0, be = y(() => R ? z.filter((e) => St(e, i, B) === I) : i && b ? z.slice() : z, [
1013
+ z,
1014
+ I,
1015
+ R,
1016
+ B,
1017
+ b,
1018
+ i
1019
+ ]), V = (e) => {
1020
+ let t = Object.entries(e.errors);
1021
+ return /* @__PURE__ */ M(E, {
1022
+ vertical: !0,
1023
+ gap: 4,
1024
+ style: { maxWidth: 320 },
1025
+ children: t.map(([e, t]) => {
1026
+ let r = n.find((t) => t.key === e)?.title ?? e;
1027
+ return /* @__PURE__ */ N(k.Text, { children: [
1028
+ /* @__PURE__ */ M(k.Text, {
1029
+ strong: !0,
1030
+ children: r
1031
+ }),
1032
+ ": ",
1033
+ t
1034
+ ] }, e);
1035
+ })
1036
+ });
1037
+ }, xe = (e) => {
1038
+ let t = xt(e), n = yt[t];
1039
+ return t === "invalid" ? /* @__PURE__ */ M(de, {
1040
+ trigger: "hover",
1041
+ placement: "topRight",
1042
+ title: "错误信息",
1043
+ content: V(e),
1044
+ children: /* @__PURE__ */ M(O, {
1045
+ color: n.color,
1046
+ children: n.label
1047
+ })
1048
+ }) : /* @__PURE__ */ M(O, {
1049
+ color: n.color,
1050
+ children: n.label
1051
+ });
1052
+ }, H = (e) => {
1053
+ let t = w(e), r = t?.fieldErrors ?? [], i = t?.message;
1054
+ if (r.length === 0) return /* @__PURE__ */ M(k.Text, { children: i ?? "导入失败" });
1055
+ let a = /* @__PURE__ */ new Map();
1056
+ r.forEach((e) => {
1057
+ 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) ?? [];
1058
+ o.push(r), a.set(i, o);
1059
+ });
1060
+ let o = [...a.entries()], s = o.slice(0, 3), c = o.length - s.length;
1061
+ return /* @__PURE__ */ N(E, {
1062
+ vertical: !0,
1063
+ gap: 8,
1064
+ style: { maxWidth: 360 },
1065
+ children: [
1066
+ i ? /* @__PURE__ */ M(k.Text, { children: i }) : null,
1067
+ s.map(([e, t]) => /* @__PURE__ */ N(E, {
1068
+ vertical: !0,
1069
+ gap: 2,
1070
+ children: [/* @__PURE__ */ M(k.Text, {
1071
+ strong: !0,
1072
+ children: e
1073
+ }), t.map((e, t) => /* @__PURE__ */ N(k.Text, { children: ["• ", e] }, t))]
1074
+ }, e)),
1075
+ c > 0 ? /* @__PURE__ */ N(k.Text, {
1076
+ type: "secondary",
1077
+ children: [
1078
+ "还有 ",
1079
+ c,
1080
+ " 个字段错误"
1081
+ ]
1082
+ }) : null
1083
+ ]
1084
+ });
1085
+ }, Se = (e) => {
1086
+ let t = St(e, i, b), n = bt[t];
1087
+ if (t === "failed") {
1088
+ let t = w(e), r = (t?.fieldErrors?.length ?? 0) + +!!t?.message, i = r > 0 ? `导入失败(${r})` : n.label;
1089
+ return /* @__PURE__ */ M(de, {
1090
+ trigger: "hover",
1091
+ placement: "topRight",
1092
+ title: "错误信息",
1093
+ content: H(e),
1094
+ children: /* @__PURE__ */ M(O, {
1095
+ color: n.color,
1096
+ children: i
1097
+ })
1098
+ });
1099
+ }
1100
+ return /* @__PURE__ */ M(O, {
1101
+ color: n.color,
1102
+ children: n.label
1103
+ });
1104
+ }, U = (e) => /* @__PURE__ */ M(T, {
1105
+ type: "primary",
1106
+ danger: !0,
1107
+ size: "small",
1108
+ disabled: !he(e),
1109
+ icon: /* @__PURE__ */ M(ae, {}),
1110
+ onClick: () => {
1111
+ c(e), h && e.taskIndex !== void 0 && We(h.id, [e.taskIndex]);
1112
+ },
1113
+ children: "删除"
1114
+ }), W = [
1115
+ {
1116
+ key: "rowNumber",
1117
+ title: "行号",
1118
+ dataIndex: "rowNumber",
1119
+ width: 60,
1120
+ fixed: "left"
1121
+ },
1122
+ ...v.map((e) => ({
1123
+ key: e.key,
1124
+ title: e.title,
1125
+ dataIndex: e.key,
1126
+ width: 160,
1127
+ render: (t, n) => /* @__PURE__ */ M(ht, {
1128
+ field: e,
1129
+ record: n,
1130
+ disabled: !pe(n),
1131
+ onChange: (t) => o(n, e, t),
1132
+ onSave: (t) => s(n, e, t)
1133
+ })
1134
+ })),
1135
+ {
1136
+ key: "dataStatus",
1137
+ title: "数据状态",
1138
+ width: 100,
1139
+ fixed: "right",
1140
+ render: (e, t) => xe(t)
1141
+ },
1142
+ {
1143
+ key: "importStatus",
1144
+ title: "导入状态",
1145
+ width: 110,
1146
+ fixed: "right",
1147
+ render: (e, t) => Se(t)
1148
+ },
1149
+ {
1150
+ key: "action",
1151
+ title: "操作",
1152
+ width: 80,
1153
+ fixed: "right",
1154
+ render: (e, t) => U(t)
1155
+ }
1156
+ ], G = Math.max(1200, 60 + v.length * 160 + 100 + 110 + 80), K = b && b.total > 0 ? et(b) : 0, Ce = b?.failureCount ?? b?.failures?.length ?? 0, q = b?.validationFailedCount ?? r.filter((e) => Object.keys(e.errors).length > 0).length, we = r.filter((e) => Object.keys(e.errors).length > 0).length, Te = r.length > 0 && we === r.length;
1157
+ return /* @__PURE__ */ M(j, { children: /* @__PURE__ */ N(ue, {
1158
+ title: i ? `${t}导入` : `${t}导入预览`,
1159
+ open: e,
1160
+ width: "min(1400px, 96vw)",
1161
+ maskClosable: !1,
1162
+ closable: !1,
1163
+ keyboard: !1,
1164
+ onCancel: () => {
1165
+ C || u();
1166
+ },
1167
+ footer: (() => {
1168
+ if (!i) return /* @__PURE__ */ N(E, {
1169
+ justify: "space-between",
1170
+ align: "center",
1171
+ gap: 8,
1172
+ wrap: !0,
1173
+ children: [/* @__PURE__ */ M("span", { children: r.length > 0 && we > 0 ? /* @__PURE__ */ M(k.Text, {
1174
+ type: Te ? "danger" : "secondary",
1175
+ children: Te ? "全部行校验失败, 请先修正后再导入" : `有 ${we} 行校验失败, 不会导入`
1176
+ }) : null }), /* @__PURE__ */ N(E, {
1177
+ gap: 8,
1178
+ children: [/* @__PURE__ */ M(T, {
1179
+ onClick: u,
1180
+ children: "取消"
1181
+ }), /* @__PURE__ */ M(T, {
1182
+ type: "primary",
1183
+ disabled: r.length === 0 || Te,
1184
+ onClick: () => {
1185
+ m(), l();
1186
+ },
1187
+ children: "开始导入"
1188
+ })]
1189
+ })]
1190
+ });
1191
+ if (!h || !b) return /* @__PURE__ */ M(E, {
1192
+ justify: "flex-end",
1193
+ children: /* @__PURE__ */ M(T, {
1194
+ onClick: u,
1195
+ children: "关闭"
1196
+ })
1197
+ });
1198
+ let e = b.status === "running", t = b.status === "paused";
1199
+ return /* @__PURE__ */ N(E, {
1200
+ justify: "flex-end",
1201
+ gap: 8,
1202
+ children: [
1203
+ e ? /* @__PURE__ */ N(j, { children: [/* @__PURE__ */ M(T, {
1204
+ danger: !0,
1205
+ loading: b.canceling,
1206
+ disabled: b.canceling,
1207
+ onClick: () => Ke(b.id),
1208
+ children: b.canceling ? "取消中" : "取消任务"
1209
+ }), /* @__PURE__ */ M(T, {
1210
+ loading: b.pausing,
1211
+ disabled: b.canceling,
1212
+ onClick: () => Ve(b.id),
1213
+ children: "暂停"
1214
+ })] }) : null,
1215
+ t ? /* @__PURE__ */ N(j, { children: [/* @__PURE__ */ M(T, {
1216
+ danger: !0,
1217
+ onClick: () => Ke(b.id),
1218
+ children: "取消任务"
1219
+ }), /* @__PURE__ */ M(T, {
1220
+ type: "primary",
1221
+ onClick: () => {
1222
+ m(), Be(b.id);
1223
+ },
1224
+ children: "继续导入"
1225
+ })] }) : null,
1226
+ !e && !t ? /* @__PURE__ */ M(T, {
1227
+ type: "primary",
1228
+ onClick: u,
1229
+ children: "关闭"
1230
+ }) : null
1231
+ ]
1232
+ });
1233
+ })(),
1234
+ children: [
1235
+ b && S ? /* @__PURE__ */ N(E, {
1236
+ vertical: !0,
1237
+ gap: 4,
1238
+ style: { marginBottom: 12 },
1239
+ children: [/* @__PURE__ */ N(E, {
1240
+ justify: "space-between",
1241
+ align: "center",
1242
+ children: [/* @__PURE__ */ N(k.Text, {
1243
+ type: "secondary",
1244
+ children: [
1245
+ "已导入 ",
1246
+ Qe(b).toLocaleString(),
1247
+ " / 总数 ",
1248
+ b.total.toLocaleString()
1249
+ ]
1250
+ }), /* @__PURE__ */ N(E, {
1251
+ align: "center",
1252
+ gap: 8,
1253
+ children: [
1254
+ se ? /* @__PURE__ */ M(k.Text, {
1255
+ type: "secondary",
1256
+ children: se
1257
+ }) : null,
1258
+ q > 0 ? /* @__PURE__ */ N(O, {
1259
+ color: "error",
1260
+ children: [
1261
+ "校验失败 ",
1262
+ q,
1263
+ " 条"
1264
+ ]
1265
+ }) : null,
1266
+ Ce > 0 ? /* @__PURE__ */ N(O, {
1267
+ color: "error",
1268
+ children: [
1269
+ "导入失败 ",
1270
+ Ce,
1271
+ " 条"
1272
+ ]
1273
+ }) : null,
1274
+ /* @__PURE__ */ M(O, {
1275
+ color: S.color,
1276
+ children: S.label
1277
+ })
1278
+ ]
1279
+ })]
1280
+ }), /* @__PURE__ */ M(fe, {
1281
+ percent: K,
1282
+ format: () => tt(K),
1283
+ status: vt(b),
1284
+ size: "small"
1285
+ })]
1286
+ }) : i ? null : /* @__PURE__ */ N(E, {
1287
+ vertical: !0,
1288
+ gap: 4,
1289
+ style: { marginBottom: 12 },
1290
+ children: [/* @__PURE__ */ N(E, {
1291
+ justify: "space-between",
1292
+ align: "center",
1293
+ children: [/* @__PURE__ */ N(k.Text, {
1294
+ type: "secondary",
1295
+ children: ["总数 ", r.length.toLocaleString()]
1296
+ }), /* @__PURE__ */ N(E, {
1297
+ align: "center",
1298
+ gap: 8,
1299
+ children: [q > 0 ? /* @__PURE__ */ N(O, {
1300
+ color: "error",
1301
+ children: [
1302
+ "校验失败 ",
1303
+ q,
1304
+ " 条"
1305
+ ]
1306
+ }) : null, /* @__PURE__ */ M(O, { children: "待导入" })]
1307
+ })]
1308
+ }), /* @__PURE__ */ M(fe, {
1309
+ percent: 0,
1310
+ format: () => "0.0%",
1311
+ size: "small"
1312
+ })]
1313
+ }),
1314
+ /* @__PURE__ */ N(E, {
1315
+ justify: "space-between",
1316
+ align: "center",
1317
+ gap: 8,
1318
+ wrap: !0,
1319
+ style: { marginBottom: 8 },
1320
+ children: [/* @__PURE__ */ N(E, {
1321
+ align: "center",
1322
+ gap: 8,
1323
+ wrap: !0,
1324
+ children: [
1325
+ /* @__PURE__ */ M(ce, {
1326
+ allowClear: !0,
1327
+ disabled: P,
1328
+ placeholder: "搜索所有字段",
1329
+ value: P ? "" : p,
1330
+ style: { width: 260 },
1331
+ onChange: (e) => {
1332
+ ne(e.target.value);
1333
+ }
1334
+ }),
1335
+ /* @__PURE__ */ M(D, {
1336
+ allowClear: !0,
1337
+ disabled: P,
1338
+ placeholder: "数据状态",
1339
+ value: F === "all" ? void 0 : F,
1340
+ options: A,
1341
+ style: { width: 140 },
1342
+ onChange: (e) => {
1343
+ f(e ?? "all");
1344
+ }
1345
+ }),
1346
+ /* @__PURE__ */ M(D, {
1347
+ allowClear: !0,
1348
+ disabled: P,
1349
+ placeholder: "导入状态",
1350
+ value: I === "all" ? void 0 : I,
1351
+ options: ge,
1352
+ style: { width: 140 },
1353
+ onChange: (e) => {
1354
+ te(e ?? "all");
1355
+ }
1356
+ })
1357
+ ]
1358
+ }), ve ? /* @__PURE__ */ N(k.Text, {
1359
+ type: "secondary",
1360
+ children: [
1361
+ "筛选出 ",
1362
+ be.length,
1363
+ " 条"
1364
+ ]
1365
+ }) : null]
1366
+ }),
1367
+ /* @__PURE__ */ M(me, {
1368
+ rowKey: "key",
1369
+ size: "middle",
1370
+ tableLayout: "fixed",
1371
+ virtual: !0,
1372
+ columns: W,
1373
+ dataSource: be,
1374
+ pagination: !1,
1375
+ scroll: {
1376
+ x: G,
1377
+ y: 520
1378
+ },
1379
+ locale: { emptyText: ve ? "没有符合条件的行" : void 0 }
1380
+ })
1381
+ ]
1382
+ }) });
1383
+ }, wt = "缺少列: ", Tt = [
1384
+ /期望为一个包含物件的列表/,
1385
+ /expected a list/i,
1386
+ /得到的类型是/,
1387
+ /not a list/i
1388
+ ];
1389
+ function Et(e) {
1390
+ return Tt.some((t) => t.test(e)) ? "数据格式不正确, 请检查导入内容" : e;
1391
+ }
1392
+ function Dt(e) {
1393
+ if (Object.keys(e).length === 0) return { success: !0 };
1394
+ let t = [], n;
1395
+ return Object.entries(e).forEach(([e, r]) => {
1396
+ let i = Array.isArray(r) ? r : [r];
1397
+ e === "detail" || e === "non_field_errors" ? n = i.map((e) => Et(String(e))).join("; ") : i.forEach((n) => t.push({ [e]: Et(String(n)) }));
1398
+ }), {
1399
+ success: !1,
1400
+ ...n ? { message: n } : {},
1401
+ ...t.length > 0 ? { fieldErrors: t } : {}
1402
+ };
1403
+ }
1404
+ function Ot(e) {
1405
+ if (!ye(e)) return "导入失败, 任务已暂停";
1406
+ let t = B(e);
1407
+ return t === void 0 ? "网络异常, 任务已暂停" : t === 401 ? "登录已过期, 任务已暂停" : t === 403 ? "没有导入权限, 任务已暂停" : t === 404 ? "导入接口不存在, 任务已暂停" : t === 400 ? "请求参数错误, 任务已暂停" : t >= 500 ? "服务器错误, 任务已暂停" : "导入失败, 任务已暂停";
1408
+ }
1409
+ function kt(e) {
1410
+ let t = be(e);
1411
+ if (t && typeof t == "object") {
1412
+ let e = t;
1413
+ if (typeof e.detail == "string") return e.detail;
1414
+ let n = Object.entries(e)[0];
1415
+ if (n) {
1416
+ let [e, t] = n, r = Array.isArray(t) ? t[0] : t;
1417
+ return `${e}: ${String(r)}`;
1418
+ }
1419
+ }
1420
+ return "导入数据校验失败";
1421
+ }
1422
+ var At = ({ title: e, fieldSchemas: t, importRows: n, onImported: r }) => {
1423
+ let [i, a] = x(!1), [o, s] = x([]), [l, u] = x(), [f, ee] = x("empty"), [te, p] = x(!1), [ne, re] = x(!1), [m, h] = x([]), { modal: g } = w.useApp(), ie = b(null), _ = b(void 0), S = y(() => P(t), [t]);
1424
+ v(() => {
1425
+ _.current = l;
1426
+ }, [l]), v(() => () => {
1427
+ _.current && qe(_.current);
1428
+ }, []);
1429
+ let ae = () => ie.current?.click(), C = (e, t) => {
1430
+ g.warning({
1431
+ title: t ?? (e.missingTitles.length > 0 ? "文件表头不完整" : "文件检查未通过"),
1432
+ width: 480,
1433
+ content: /* @__PURE__ */ M(dt, { ...e }),
1434
+ okCancel: !0,
1435
+ okText: "重新选择文件",
1436
+ cancelText: "关闭",
1437
+ closable: !0,
1438
+ onOk: ae
1439
+ });
1440
+ }, E = async (e) => {
1441
+ if (e.size > 20971520) A.error("文件大小超过 20MB, 请拆分后再导入");
1442
+ else {
1443
+ u(void 0), h([]), p(!0);
1444
+ try {
1445
+ let { headerMessages: t, formulaMessages: n, rows: r, includedKeys: i } = await z(e, S);
1446
+ if (n.length > 0) {
1447
+ C({
1448
+ missingTitles: [],
1449
+ headerMessages: n
1450
+ }, "文件里的公式还没有计算结果");
1451
+ return;
1452
+ }
1453
+ if (t.length > 0) {
1454
+ C({
1455
+ missingTitles: t.filter((e) => e.startsWith(wt)).map((e) => e.slice(5)),
1456
+ headerMessages: t.filter((e) => !e.startsWith(wt))
1457
+ });
1458
+ return;
1459
+ }
1460
+ if (r.length === 0) {
1461
+ A.error("文件里没有数据行");
1462
+ return;
1463
+ }
1464
+ h(i), ee(`${e.name}-${Date.now()}`), s(r), a(!0);
1465
+ } catch (e) {
1466
+ console.error(`导入文件解析失败: ${e}`), A.error("导入文件解析失败, 请确认上传的是 Excel 文件");
1467
+ } finally {
1468
+ p(!1);
1469
+ }
1470
+ }
1471
+ };
1472
+ return /* @__PURE__ */ N(j, { children: [
1473
+ /* @__PURE__ */ N(pe.Compact, {
1474
+ block: !0,
1475
+ children: [/* @__PURE__ */ M(he, {
1476
+ title: "Excel 导入",
1477
+ children: /* @__PURE__ */ M(T, {
1478
+ type: "default",
1479
+ icon: /* @__PURE__ */ M(se, {}),
1480
+ loading: te,
1481
+ disabled: te,
1482
+ onClick: ae,
1483
+ children: "导入"
1484
+ })
1485
+ }), /* @__PURE__ */ M(he, {
1486
+ title: "Excel 导入模板",
1487
+ children: /* @__PURE__ */ M(T, {
1488
+ type: "default",
1489
+ icon: /* @__PURE__ */ M(oe, {}),
1490
+ loading: ne,
1491
+ onClick: async () => {
1492
+ re(!0);
1493
+ try {
1494
+ await ve(S, `${e}导入模板`);
1495
+ } catch (e) {
1496
+ console.error(`模板下载失败: ${e}`), A.error("模板下载失败");
1497
+ } finally {
1498
+ re(!1);
1499
+ }
1500
+ },
1501
+ children: "下载模板"
1502
+ })
1503
+ })]
1504
+ }),
1505
+ /* @__PURE__ */ M("input", {
1506
+ ref: ie,
1507
+ type: "file",
1508
+ accept: ".xlsx",
1509
+ style: { display: "none" },
1510
+ onChange: (e) => {
1511
+ let t = e.target.files?.[0];
1512
+ e.target.value = "", t && E(t);
1513
+ }
1514
+ }),
1515
+ /* @__PURE__ */ M(Ct, {
1516
+ open: i,
1517
+ title: e,
1518
+ fieldSchemas: S,
1519
+ rows: o,
1520
+ taskId: l,
1521
+ includedKeys: m,
1522
+ onChangeCell: (e, t, n) => {
1523
+ if (!m.includes(t.key)) return;
1524
+ let r = c(t, n), i = d(r.trim() === "" ? null : r, t);
1525
+ s((r) => r.map((r) => {
1526
+ if (r.key !== e.key) return r;
1527
+ let a = { ...r.errors };
1528
+ return i.validateSuccess ? delete a[t.key] : a[t.key] = i.validateMessage, {
1529
+ ...r,
1530
+ values: {
1531
+ ...r.values,
1532
+ [t.key]: n
1533
+ },
1534
+ errors: a
1535
+ };
1536
+ }));
1537
+ },
1538
+ onSaveCell: (e, t, n) => {
1539
+ if (!m.includes(t.key)) return;
1540
+ let r = {
1541
+ ...e.values,
1542
+ [t.key]: n
1543
+ }, i = {};
1544
+ S.forEach((e) => {
1545
+ if (!m.includes(e.key)) return;
1546
+ let t = c(e, r[e.key]), n = d(t.trim() === "" ? null : t, e);
1547
+ n.validateSuccess || (i[e.key] = n.validateMessage);
1548
+ });
1549
+ let a = {
1550
+ ...e,
1551
+ values: r,
1552
+ errors: i
1553
+ };
1554
+ s((t) => t.map((t) => t.key === e.key ? a : t)), l && e.taskIndex !== void 0 && (Ge(l, e.taskIndex, t.key), Ue(l, e.taskIndex, i), He(l, e.taskIndex, a));
1555
+ },
1556
+ onDelete: (e) => {
1557
+ s((t) => t.filter((t) => t.key !== e.key));
1558
+ },
1559
+ onConfirm: () => {
1560
+ let t = o;
1561
+ if (t.length === 0) {
1562
+ A.error("没有可导入的数据");
1563
+ return;
1564
+ }
1565
+ if (t.every((e) => Object.keys(e.errors).length > 0)) {
1566
+ A.error("所有行都有校验错误, 请先修正后再导入");
1567
+ return;
1568
+ }
1569
+ let i = t.map((e, t) => ({
1570
+ ...e,
1571
+ taskIndex: t
1572
+ }));
1573
+ s(i);
1574
+ let a = ze({
1575
+ title: `${e}导入`,
1576
+ rows: i,
1577
+ fieldSchemas: S,
1578
+ includedKeys: m,
1579
+ importRows: async (e, t) => {
1580
+ try {
1581
+ let r = await n(e.map((e) => _e(e, S, m)), t);
1582
+ if (r.length !== e.length) throw new V("导入接口返回结果数量不正确, 任务已暂停");
1583
+ return r.map(Dt);
1584
+ } catch (e) {
1585
+ throw t.aborted || e instanceof V ? e : B(e) === 422 ? Error(kt(e)) : new V(Ot(e));
1586
+ }
1587
+ },
1588
+ onFinished: r
1589
+ });
1590
+ u(a);
1591
+ },
1592
+ onClose: () => {
1593
+ l && qe(l), a(!1), u(void 0), s([]), h([]);
1594
+ }
1595
+ }, f)
1596
+ ] });
1597
+ };
1598
+ export { it as BatchExportButton, lt as ExcelExportButton, At as ExcelImportButton, ct as ExportTaskModal, V as ImportPauseError, f as MAX_EXPORT_ROWS, r as MAX_IMPORT_FILE_SIZE, l as MAX_IMPORT_ROWS, n as MULTI_VALUE_SEPARATOR, ee as autoAdjustColumnWidths, L as buildExportBlob, _e as buildImportPayload, Ke as cancelTask, Ge as clearImportRowFieldError, Be as continueTask, We as deleteImportRows, qe as dismissTask, ve as downloadImportTemplate, Ye as downloadTask, Re as enqueueExport, ze as enqueueImport, R as exportExcel, tt as formatTaskPercent, nt as formatTaskRemainingSeconds, et as getTaskDisplayPercent, Ze as getTaskRemainingSeconds, Qe as getTaskSuccessCount, we as getTasksSnapshot, P as importableFields, ne as joinMultiValues, z as parseImportFile, Ve as pauseTask, Xe as resetTasks, Ue as setImportRowValidation, e as splitMultiValues, q as subscribeTasks, He as updateImportRowData, rt as useTaskDetail, te as validateBooleanField, i as validateDateField, a as validateDateTimeField, d as validateField, u as validateListField, s as validateMultipleChoiceField, o as validateNumberField, t as validateSingleChoiceField, p as validateTextField, re as validateTimeField };