@svadmin/ui 0.130.0 → 0.131.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.
Files changed (76) hide show
  1. package/dist/app.css +301 -0
  2. package/dist/app.theme.css +301 -0
  3. package/dist/components/AboutSettings.svelte +1 -1
  4. package/dist/components/AccessRevocationMatrix.svelte +425 -0
  5. package/dist/components/AccessRevocationMatrix.svelte.d.ts +27 -0
  6. package/dist/components/AudioVisualInspector.svelte +458 -0
  7. package/dist/components/AudioVisualInspector.svelte.d.ts +53 -0
  8. package/dist/components/AuditSnapshotCapture.svelte +328 -0
  9. package/dist/components/AuditSnapshotCapture.svelte.d.ts +28 -0
  10. package/dist/components/CannedResponsePicker.svelte +257 -0
  11. package/dist/components/CannedResponsePicker.svelte.d.ts +22 -0
  12. package/dist/components/ContentModerationCenter.svelte +166 -0
  13. package/dist/components/ContentModerationCenter.svelte.d.ts +11 -0
  14. package/dist/components/ContractClauseDiffViewer.svelte +566 -0
  15. package/dist/components/ContractClauseDiffViewer.svelte.d.ts +53 -0
  16. package/dist/components/DataImportPipeline.svelte +577 -0
  17. package/dist/components/DataImportPipeline.svelte.d.ts +35 -0
  18. package/dist/components/DataRetentionPolicyEditor.svelte +455 -0
  19. package/dist/components/DataRetentionPolicyEditor.svelte.d.ts +10 -0
  20. package/dist/components/ElectronicSealInspector.svelte +450 -0
  21. package/dist/components/ElectronicSealInspector.svelte.d.ts +72 -0
  22. package/dist/components/EmployeeOffboardingAuditor.svelte +405 -0
  23. package/dist/components/EmployeeOffboardingAuditor.svelte.d.ts +39 -0
  24. package/dist/components/FieldMappingBuilder.svelte +393 -0
  25. package/dist/components/FieldMappingBuilder.svelte.d.ts +39 -0
  26. package/dist/components/GatewayRouteEditor.svelte +493 -0
  27. package/dist/components/GatewayRouteEditor.svelte.d.ts +34 -0
  28. package/dist/components/I18nStudio.svelte +635 -0
  29. package/dist/components/I18nStudio.svelte.d.ts +23 -0
  30. package/dist/components/IpAccessRuleEditor.svelte +290 -0
  31. package/dist/components/IpAccessRuleEditor.svelte.d.ts +19 -0
  32. package/dist/components/IpWhitelistDrawer.svelte +94 -0
  33. package/dist/components/IpWhitelistDrawer.svelte.d.ts +10 -0
  34. package/dist/components/MediaAuthenticityAuditCard.svelte +357 -0
  35. package/dist/components/MediaAuthenticityAuditCard.svelte.d.ts +64 -0
  36. package/dist/components/PrintDocument.svelte +95 -0
  37. package/dist/components/PrintDocument.svelte.d.ts +10 -0
  38. package/dist/components/PrintPreviewModal.svelte +52 -0
  39. package/dist/components/PrintPreviewModal.svelte.d.ts +11 -0
  40. package/dist/components/PrintTemplateDesigner.svelte +280 -0
  41. package/dist/components/PrintTemplateDesigner.svelte.d.ts +11 -0
  42. package/dist/components/RateLimitPolicyPanel.svelte +369 -0
  43. package/dist/components/RateLimitPolicyPanel.svelte.d.ts +29 -0
  44. package/dist/components/SensitiveWordAuditor.svelte +368 -0
  45. package/dist/components/SensitiveWordAuditor.svelte.d.ts +9 -0
  46. package/dist/components/ServiceDeskTicketCard.svelte +297 -0
  47. package/dist/components/ServiceDeskTicketCard.svelte.d.ts +52 -0
  48. package/dist/components/ShiftScheduler.svelte +490 -0
  49. package/dist/components/ShiftScheduler.svelte.d.ts +50 -0
  50. package/dist/components/SslCertificateMonitorCard.svelte +309 -0
  51. package/dist/components/SslCertificateMonitorCard.svelte.d.ts +30 -0
  52. package/dist/components/SsoConnectionStudio.svelte +784 -0
  53. package/dist/components/SsoConnectionStudio.svelte.d.ts +44 -0
  54. package/dist/components/SsoSpMetadataPanel.svelte +44 -0
  55. package/dist/components/SsoSpMetadataPanel.svelte.d.ts +8 -0
  56. package/dist/components/StepUpAuthModal.svelte +448 -0
  57. package/dist/components/StepUpAuthModal.svelte.d.ts +26 -0
  58. package/dist/components/TrafficTopologyInspector.svelte +361 -0
  59. package/dist/components/TrafficTopologyInspector.svelte.d.ts +43 -0
  60. package/dist/components/ip-access-rules.d.ts +24 -0
  61. package/dist/components/ip-access-rules.js +110 -0
  62. package/dist/components/moderation-utils.d.ts +45 -0
  63. package/dist/components/moderation-utils.js +74 -0
  64. package/dist/components/print-document.d.ts +3 -0
  65. package/dist/components/print-document.js +65 -0
  66. package/dist/components/print-utils.d.ts +44 -0
  67. package/dist/components/print-utils.js +68 -0
  68. package/dist/components/retention-utils.d.ts +31 -0
  69. package/dist/components/retention-utils.js +38 -0
  70. package/dist/components/sso-connection-presets.d.ts +2 -0
  71. package/dist/components/sso-connection-presets.js +59 -0
  72. package/dist/components/ui/sheet/sheet.svelte +3 -1
  73. package/dist/components/ui/sheet/sheet.svelte.d.ts +1 -0
  74. package/dist/index.d.ts +29 -0
  75. package/dist/index.js +44 -0
  76. package/package.json +5 -4
@@ -0,0 +1,577 @@
1
+ <script lang="ts">
2
+ import {
3
+ UploadCloud,
4
+ ArrowRight,
5
+ ArrowLeft,
6
+ CheckCircle2,
7
+ AlertCircle,
8
+ RotateCcw,
9
+ Trash2,
10
+ Play,
11
+ Check,
12
+ Loader2,
13
+ } from '@lucide/svelte';
14
+ import { cn } from '../utils.js';
15
+ import { parseImportRows } from '@svadmin/core';
16
+ import FieldMappingBuilder, {
17
+ type SourceField,
18
+ type TargetField,
19
+ type FieldMappingRule,
20
+ } from './FieldMappingBuilder.svelte';
21
+
22
+ export interface ValidationRule {
23
+ field: string;
24
+ required?: boolean | undefined;
25
+ pattern?: RegExp | undefined;
26
+ customValidator?: ((value: unknown, row: Record<string, unknown>) => string | null | undefined) | undefined;
27
+ errorMessage?: string | undefined;
28
+ }
29
+
30
+ export interface PipelineValidationError {
31
+ rowIndex: number;
32
+ field: string;
33
+ message: string;
34
+ }
35
+
36
+ export interface DataImportPipelineProps {
37
+ /** 目标系统数据结构 */
38
+ targetFields: TargetField[];
39
+ /** 校验规则列表 */
40
+ validationRules?: ValidationRule[] | undefined;
41
+ /** 外部直接传入的初始原始数据行(可选) */
42
+ initialRows?: Record<string, unknown>[] | undefined;
43
+ /** 业务模块标题,如 "用户档案导入" */
44
+ title?: string | undefined;
45
+ /** 最终提交导入回调 */
46
+ onimport?: ((validRows: Record<string, unknown>[]) => Promise<{ successCount: number; failCount: number }> | { successCount: number; failCount: number }) | undefined;
47
+ class?: string | undefined;
48
+ }
49
+
50
+ let {
51
+ targetFields = [],
52
+ validationRules = [],
53
+ initialRows = [],
54
+ title = '批量数据智能导入流水线',
55
+ onimport,
56
+ class: className = '',
57
+ }: DataImportPipelineProps = $props();
58
+
59
+ // 当前进行到的步骤:1: 数据录入, 2: 字段映射, 3: 质检纠错, 4: 导入结果
60
+ let currentStep = $state<1 | 2 | 3 | 4>(1);
61
+
62
+ // 原始导入数据与解析后的源字段
63
+ let rawRows = $state<Record<string, unknown>[]>([]);
64
+ let pasteContent = $state('');
65
+ let isParsing = $state(false);
66
+ let pipelineError = $state('');
67
+
68
+ // 映射规则
69
+ let mappingRules = $state<FieldMappingRule[]>([]);
70
+
71
+ $effect(() => {
72
+ if (initialRows.length > 0 && rawRows.length === 0) {
73
+ rawRows = [...initialRows];
74
+ currentStep = 2;
75
+ }
76
+ });
77
+
78
+ // 纠错阶段筛选状态:'all' | 'errors' | 'valid'
79
+ let errorFilter = $state<'all' | 'errors' | 'valid'>('all');
80
+
81
+ // 导入执行态
82
+ let isImporting = $state(false);
83
+ let importProgress = $state(0);
84
+ let importResult = $state<{ successCount: number; failCount: number } | null>(null);
85
+
86
+ // 解析源字段
87
+ const parsedSourceFields = $derived.by<SourceField[]>(() => {
88
+ if (rawRows.length === 0) return [];
89
+ const first = rawRows[0];
90
+ if (!first) return [];
91
+ return Object.keys(first).map((k) => ({
92
+ name: k,
93
+ label: k,
94
+ sample: first[k],
95
+ }));
96
+ });
97
+
98
+ function parseCsvText(text: string) {
99
+ pipelineError = '';
100
+ isParsing = true;
101
+ try {
102
+ const rows = parseImportRows(text, 'pasted.csv', 'csv');
103
+ if (rows.length === 0) {
104
+ pipelineError = 'CSV 至少需要一条数据记录';
105
+ return;
106
+ }
107
+ rawRows = rows;
108
+ currentStep = 2;
109
+ } catch {
110
+ pipelineError = 'CSV 解析失败,请检查引号、列名、列数与导入大小';
111
+ } finally {
112
+ isParsing = false;
113
+ }
114
+ }
115
+
116
+ // 根据当前映射规则计算转换后的规范数据行
117
+ const mappedRows = $derived.by<Record<string, unknown>[]>(() => {
118
+ return rawRows.map((rawRow) => {
119
+ const result: Record<string, unknown> = {};
120
+ for (const tf of targetFields) {
121
+ const rule = mappingRules.find((r) => r.targetField === tf.name);
122
+ let val = rule && rule.sourceField ? rawRow[rule.sourceField] : rawRow[tf.name];
123
+
124
+ if (val === undefined || val === null || val === '') {
125
+ val = rule?.fallbackValue ?? tf.defaultValue ?? '';
126
+ }
127
+
128
+ if (rule?.transform === 'uppercase' && typeof val === 'string') {
129
+ val = val.toUpperCase();
130
+ } else if (rule?.transform === 'lowercase' && typeof val === 'string') {
131
+ val = val.toLowerCase();
132
+ } else if (rule?.transform === 'trim' && typeof val === 'string') {
133
+ val = val.trim();
134
+ } else if (rule?.transform === 'number') {
135
+ const num = Number(val);
136
+ val = isNaN(num) ? val : num;
137
+ }
138
+
139
+ result[tf.name] = val;
140
+ }
141
+ return result;
142
+ });
143
+ });
144
+
145
+ // 就地纠错:数据修改
146
+ function updateCell(rowIndex: number, field: string, nextValue: unknown) {
147
+ const next = [...rawRows];
148
+ const currentRow = next[rowIndex];
149
+ if (!currentRow) return;
150
+
151
+ // 查找映射对应的源字段
152
+ const rule = mappingRules.find((r) => r.targetField === field);
153
+ const sourceKey = rule?.sourceField ?? field;
154
+
155
+ next[rowIndex] = {
156
+ ...currentRow,
157
+ [sourceKey]: nextValue,
158
+ };
159
+ rawRows = next;
160
+ }
161
+
162
+ // 剔除单行
163
+ function removeRow(rowIndex: number) {
164
+ rawRows = rawRows.filter((_, idx) => idx !== rowIndex);
165
+ }
166
+
167
+ // 质检校验计算
168
+ const validationErrors = $derived.by<PipelineValidationError[]>(() => {
169
+ const errors: PipelineValidationError[] = [];
170
+ mappedRows.forEach((row, rowIndex) => {
171
+ // 1. 目标必填项校验
172
+ targetFields.forEach((tf) => {
173
+ if (tf.required) {
174
+ const val = row[tf.name];
175
+ if (val === undefined || val === null || val === '') {
176
+ errors.push({
177
+ rowIndex,
178
+ field: tf.name,
179
+ message: `${tf.label}为必填字段,不能为空`,
180
+ });
181
+ }
182
+ }
183
+ });
184
+
185
+ // 2. 外部校验规则
186
+ validationRules.forEach((rule) => {
187
+ const val = row[rule.field];
188
+ if (rule.required && (val === undefined || val === null || val === '')) {
189
+ errors.push({
190
+ rowIndex,
191
+ field: rule.field,
192
+ message: rule.errorMessage || `${rule.field} 不能为空`,
193
+ });
194
+ }
195
+ if (rule.pattern && typeof val === 'string' && !rule.pattern.test(val)) {
196
+ errors.push({
197
+ rowIndex,
198
+ field: rule.field,
199
+ message: rule.errorMessage || `${rule.field} 格式校验未通过`,
200
+ });
201
+ }
202
+ if (rule.customValidator) {
203
+ const err = rule.customValidator(val, row);
204
+ if (err) {
205
+ errors.push({
206
+ rowIndex,
207
+ field: rule.field,
208
+ message: err,
209
+ });
210
+ }
211
+ }
212
+ });
213
+ });
214
+ return errors;
215
+ });
216
+
217
+ // 行错误索引快速映射
218
+ const rowErrorMap = $derived.by(() => {
219
+ const map = new Map<number, PipelineValidationError[]>();
220
+ validationErrors.forEach((err) => {
221
+ const list = map.get(err.rowIndex) || [];
222
+ list.push(err);
223
+ map.set(err.rowIndex, list);
224
+ });
225
+ return map;
226
+ });
227
+
228
+ // 过滤后的显示行
229
+ const displayRowsWithIndex = $derived.by(() => {
230
+ return mappedRows
231
+ .map((row, index) => ({ row, index, errors: rowErrorMap.get(index) || [] }))
232
+ .filter((item) => {
233
+ if (errorFilter === 'errors') return item.errors.length > 0;
234
+ if (errorFilter === 'valid') return item.errors.length === 0;
235
+ return true;
236
+ });
237
+ });
238
+
239
+ // 批量导入处理
240
+ async function handleExecuteImport() {
241
+ if (isImporting || !onimport || rowErrorMap.size > 0) return;
242
+ pipelineError = '';
243
+ importResult = null;
244
+ isImporting = true;
245
+ importProgress = 10;
246
+ currentStep = 4;
247
+
248
+ // 过滤出完全合规的数据行
249
+ const validRows = mappedRows.filter((_, idx) => !rowErrorMap.has(idx));
250
+
251
+ try {
252
+ importProgress = 40;
253
+ importResult = await onimport(validRows);
254
+ importProgress = 100;
255
+ } catch {
256
+ pipelineError = '导入失败,请核实服务端结果后重试';
257
+ currentStep = 3;
258
+ } finally {
259
+ isImporting = false;
260
+ }
261
+ }
262
+
263
+ function handleResetPipeline() {
264
+ rawRows = [];
265
+ pasteContent = '';
266
+ mappingRules = [];
267
+ importResult = null;
268
+ pipelineError = '';
269
+ currentStep = 1;
270
+ }
271
+ </script>
272
+
273
+ <div
274
+ class={cn( 'flex flex-col rounded-xl border border-border/80 bg-card text-card-foreground shadow-sm transition-all',
275
+ className
276
+ )}
277
+ data-svadmin-component="DataImportPipeline"
278
+ >
279
+ {#if pipelineError}<p role="alert" class="p-4 text-sm text-destructive">{pipelineError}</p>{/if}
280
+ <!-- 顶部主标题与步骤条 -->
281
+ <div class="border-b border-border/60 p-5">
282
+ <div class="flex flex-wrap items-center justify-between gap-4">
283
+ <div>
284
+ <h2 class="text-base font-semibold tracking-tight">{title}</h2>
285
+ <p class="text-xs text-muted-foreground">企业级多阶段批量数据导入、字段映射与行内纠错清洗</p>
286
+ </div>
287
+
288
+ <!-- 步骤指示器 -->
289
+ <nav aria-label="导入进度步骤" class="flex items-center gap-2">
290
+ {#each [
291
+ { step: 1, label: '数据源录入' },
292
+ { step: 2, label: '字段映射' },
293
+ { step: 3, label: '质检纠错' },
294
+ { step: 4, label: '批量入库' },
295
+ ] as s (s.step)}
296
+ <div class="flex items-center gap-2">
297
+ <div
298
+ class={cn( 'flex h-6 w-6 items-center justify-center rounded-full text-xs font-semibold transition-colors',
299
+ currentStep === s.step
300
+ ? 'bg-primary text-primary-foreground'
301
+ : currentStep > s.step
302
+ ? 'bg-success/10 text-success '
303
+ : 'bg-muted text-muted-foreground'
304
+ )}
305
+ >
306
+ {#if currentStep > s.step}
307
+ <Check class="h-3.5 w-3.5" />
308
+ {:else}
309
+ {s.step}
310
+ {/if}
311
+ </div>
312
+ <span
313
+ class={cn( 'text-xs font-medium',
314
+ currentStep === s.step ? 'text-foreground' : 'text-muted-foreground'
315
+ )}
316
+ >
317
+ {s.label}
318
+ </span>
319
+ {#if s.step < 4}
320
+ <div class="h-px w-4 bg-border"></div>
321
+ {/if}
322
+ </div>
323
+ {/each}
324
+ </nav>
325
+ </div>
326
+ </div>
327
+
328
+ <!-- 步骤 1: 数据录入与解析 -->
329
+ {#if currentStep === 1}
330
+ <div class="p-6">
331
+ <div class="rounded-lg border-2 border-dashed border-border/80 p-8 text-center transition-colors hover:border-primary/50">
332
+ <UploadCloud class="mx-auto h-10 w-10 text-muted-foreground" />
333
+ <h3 class="mt-3 text-sm font-semibold">粘贴 CSV 文本或选择文件</h3>
334
+ <p class="mt-1 text-xs text-muted-foreground">首行为列名(逗号分隔),支持大批量结构化数据解析</p>
335
+
336
+ <div class="mx-auto mt-4 max-w-lg">
337
+ <textarea
338
+ bind:value={pasteContent}
339
+ rows={5}
340
+ placeholder="示例:&#10;name,email,age&#10;张三,zhangsan@example.com,28&#10;李四,invalid-email,32"
341
+ class="w-full rounded-md border border-input bg-background p-3 text-xs font-mono text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
342
+ ></textarea>
343
+ </div>
344
+
345
+ <div class="mt-4 flex justify-center gap-3">
346
+ <button
347
+ type="button"
348
+ disabled={!pasteContent.trim() || isParsing}
349
+ class="flex items-center gap-2 rounded-md bg-primary px-4 py-2 text-xs font-medium text-primary-foreground shadow transition-colors hover:bg-primary/90 disabled:opacity-50"
350
+ onclick={() => parseCsvText(pasteContent)}
351
+ >
352
+ <span>开始解析</span>
353
+ <ArrowRight class="h-4 w-4" />
354
+ </button>
355
+ </div>
356
+ </div>
357
+ </div>
358
+ {/if}
359
+
360
+ <!-- 步骤 2: 字段映射 -->
361
+ {#if currentStep === 2}
362
+ <div class="p-6">
363
+ <FieldMappingBuilder
364
+ sourceFields={parsedSourceFields}
365
+ {targetFields}
366
+ sourceSampleRows={rawRows}
367
+ onchange={(rules) => (mappingRules = rules)}
368
+ />
369
+
370
+ <div class="mt-6 flex items-center justify-between border-t border-border/60 pt-4">
371
+ <button
372
+ type="button"
373
+ class="flex items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs text-foreground hover:bg-muted"
374
+ onclick={() => (currentStep = 1)}
375
+ >
376
+ <ArrowLeft class="h-3.5 w-3.5" />
377
+ <span>返回上一步</span>
378
+ </button>
379
+
380
+ <button
381
+ type="button"
382
+ class="flex items-center gap-1.5 rounded-md bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow hover:bg-primary/90"
383
+ onclick={() => (currentStep = 3)}
384
+ >
385
+ <span>进入数据质检与纠错 ({rawRows.length} 条)</span>
386
+ <ArrowRight class="h-3.5 w-3.5" />
387
+ </button>
388
+ </div>
389
+ </div>
390
+ {/if}
391
+
392
+ <!-- 步骤 3: 质检与行内就地纠错 -->
393
+ {#if currentStep === 3}
394
+ <div class="p-6">
395
+ <!-- 质检统计看板 -->
396
+ <div class="mb-4 grid grid-cols-1 gap-4 sm:grid-cols-4">
397
+ <div class="rounded-lg border border-border/60 bg-muted/20 p-3">
398
+ <span class="text-xs text-muted-foreground">总导入记录</span>
399
+ <p class="text-xl font-bold text-foreground">{rawRows.length}</p>
400
+ </div>
401
+ <div class="rounded-lg border border-border/60 bg-success/5 p-3">
402
+ <span class="text-xs text-success ">合规有效记录</span>
403
+ <p class="text-xl font-bold text-success ">
404
+ {rawRows.length - rowErrorMap.size}
405
+ </p>
406
+ </div>
407
+ <div class="rounded-lg border border-border/60 bg-warning/5 p-3">
408
+ <span class="text-xs text-warning ">存在校验异常</span>
409
+ <p class="text-xl font-bold text-warning ">{rowErrorMap.size}</p>
410
+ </div>
411
+ <div class="rounded-lg border border-border/60 bg-muted/20 p-3">
412
+ <span class="text-xs text-muted-foreground">错误总项数</span>
413
+ <p class="text-xl font-bold text-foreground">{validationErrors.length}</p>
414
+ </div>
415
+ </div>
416
+
417
+ <!-- 筛选与批量操作栏 -->
418
+ <div class="mb-3 flex flex-wrap items-center justify-between gap-3">
419
+ <div class="flex items-center gap-1 rounded-lg border border-border bg-background p-1 text-xs">
420
+ <button
421
+ type="button"
422
+ class={cn( 'rounded px-2.5 py-1 transition-colors',
423
+ errorFilter === 'all' ? 'bg-primary text-primary-foreground' : 'text-muted-foreground hover:bg-muted'
424
+ )}
425
+ onclick={() => (errorFilter = 'all')}
426
+ >
427
+ 全部 ({mappedRows.length})
428
+ </button>
429
+ <button
430
+ type="button"
431
+ class={cn( 'rounded px-2.5 py-1 transition-colors',
432
+ errorFilter === 'errors' ? 'bg-warning text-warning-foreground' : 'text-muted-foreground hover:bg-muted'
433
+ )}
434
+ onclick={() => (errorFilter = 'errors')}
435
+ >
436
+ 仅看异常 ({rowErrorMap.size})
437
+ </button>
438
+ <button
439
+ type="button"
440
+ class={cn( 'rounded px-2.5 py-1 transition-colors',
441
+ errorFilter === 'valid' ? 'bg-success text-success-foreground' : 'text-muted-foreground hover:bg-muted'
442
+ )}
443
+ onclick={() => (errorFilter = 'valid')}
444
+ >
445
+ 仅看合规 ({rawRows.length - rowErrorMap.size})
446
+ </button>
447
+ </div>
448
+
449
+ <span class="text-xs text-muted-foreground">提示:点击单元格即可直接就地纠错编辑</span>
450
+ </div>
451
+
452
+ <!-- 行内纠错可编辑表格 -->
453
+ <div class="max-h-96 overflow-auto rounded-lg border border-border/80 bg-background">
454
+ <table class="w-full text-left text-xs">
455
+ <thead class="sticky top-0 z-10 border-b border-border/60 bg-muted/80 font-medium text-muted-foreground backdrop-blur">
456
+ <tr>
457
+ <th class="px-3 py-2 text-center w-12">#</th>
458
+ <th class="px-3 py-2 w-16">状态</th>
459
+ {#each targetFields as target (target.name)}
460
+ <th class="px-3 py-2 whitespace-nowrap">{target.label}</th>
461
+ {/each}
462
+ <th class="px-3 py-2 text-center w-16">操作</th>
463
+ </tr>
464
+ </thead>
465
+ <tbody class="divide-y divide-border/40 font-mono">
466
+ {#each displayRowsWithIndex as item (item.index)}
467
+ {@const hasErr = item.errors.length > 0}
468
+ <tr class={cn('hover:bg-muted/30 transition-colors', hasErr ? 'bg-warning/5' : '')}>
469
+ <td class="px-3 py-2 text-center text-muted-foreground">{item.index + 1}</td>
470
+ <td class="px-3 py-2">
471
+ {#if hasErr}
472
+ <span class="inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] text-warning " title={item.errors.map((e) => e.message).join('; ')}>
473
+ <AlertCircle class="h-3 w-3" />
474
+ <span>{item.errors.length}</span>
475
+ </span>
476
+ {:else}
477
+ <span class="inline-flex items-center rounded bg-success/10 p-0.5 text-success ">
478
+ <CheckCircle2 class="h-3.5 w-3.5" />
479
+ </span>
480
+ {/if}
481
+ </td>
482
+
483
+ {#each targetFields as target (target.name)}
484
+ {@const cellErr = item.errors.find((e) => e.field === target.name)}
485
+ <td class="px-2 py-1">
486
+ <input
487
+ type="text"
488
+ value={String(item.row[target.name] ?? '')}
489
+ oninput={(e) => updateCell(item.index, target.name, e.currentTarget.value)}
490
+ class={cn( 'h-8 w-full rounded border bg-transparent px-2 text-xs transition-colors focus-visible:outline-none focus-visible:ring-1',
491
+ cellErr
492
+ ? 'border-warning/80 bg-warning/10 text-warning focus-visible:ring-warning'
493
+ : 'border-transparent hover:border-input focus-visible:border-input focus-visible:ring-ring'
494
+ )}
495
+ title={cellErr ? cellErr.message : undefined}
496
+ />
497
+ </td>
498
+ {/each}
499
+
500
+ <td class="px-3 py-2 text-center">
501
+ <button
502
+ type="button"
503
+ class="rounded p-1 text-muted-foreground hover:bg-destructive/10 hover:text-destructive"
504
+ onclick={() => removeRow(item.index)}
505
+ title="从导入列表剔除此行"
506
+ >
507
+ <Trash2 class="h-3.5 w-3.5" />
508
+ </button>
509
+ </td>
510
+ </tr>
511
+ {/each}
512
+ </tbody>
513
+ </table>
514
+ </div>
515
+
516
+ <!-- 底部控制按钮 -->
517
+ <div class="mt-6 flex items-center justify-between border-t border-border/60 pt-4">
518
+ <button
519
+ type="button"
520
+ class="flex items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs text-foreground hover:bg-muted"
521
+ onclick={() => (currentStep = 2)}
522
+ >
523
+ <ArrowLeft class="h-3.5 w-3.5" />
524
+ <span>返回字段映射</span>
525
+ </button>
526
+
527
+ <button
528
+ type="button"
529
+ disabled={rowErrorMap.size > 0 || !onimport || isImporting}
530
+ class="flex items-center gap-2 rounded-md bg-primary px-4 py-2 text-xs font-medium text-primary-foreground shadow hover:bg-primary/90 disabled:opacity-50"
531
+ onclick={handleExecuteImport}
532
+ >
533
+ <Play class="h-3.5 w-3.5" />
534
+ <span>确认导入全部合规数据 ({rawRows.length - rowErrorMap.size} 条)</span>
535
+ </button>
536
+ </div>
537
+ </div>
538
+ {/if}
539
+
540
+ <!-- 步骤 4: 批量入库状态与汇总结果 -->
541
+ {#if currentStep === 4}
542
+ <div class="p-8 text-center">
543
+ {#if isImporting}
544
+ <Loader2 class="mx-auto h-10 w-10 animate-spin text-primary" />
545
+ <h3 class="mt-4 text-sm font-semibold">正在批量同步导入数据...</h3>
546
+ <p class="mt-1 text-xs text-muted-foreground">处理中,请稍候不要关闭页面</p>
547
+ <div class="mx-auto mt-4 max-w-xs">
548
+ <div class="h-2 w-full overflow-hidden rounded-full bg-muted">
549
+ <div class="h-full bg-primary transition-all duration-300" style="width: {importProgress}%"></div>
550
+ </div>
551
+ </div>
552
+ {:else if importResult}
553
+ <div class="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-success/10 text-success ">
554
+ <CheckCircle2 class="h-6 w-6" />
555
+ </div>
556
+ <h3 class="mt-4 text-base font-semibold">批量数据导入完成</h3>
557
+ <p class="mt-1 text-xs text-muted-foreground">
558
+ 成功入库 <span class="font-bold text-success ">{importResult.successCount}</span> 条数据
559
+ {#if importResult.failCount > 0}
560
+ ,未导入/被剔除 <span class="font-bold text-warning ">{importResult.failCount}</span> 条
561
+ {/if}
562
+ </p>
563
+
564
+ <div class="mt-6 flex justify-center gap-3">
565
+ <button
566
+ type="button"
567
+ class="flex items-center gap-1.5 rounded-md border border-border bg-background px-4 py-2 text-xs font-medium text-foreground hover:bg-muted"
568
+ onclick={handleResetPipeline}
569
+ >
570
+ <RotateCcw class="h-3.5 w-3.5" />
571
+ <span>发起新的批量导入</span>
572
+ </button>
573
+ </div>
574
+ {/if}
575
+ </div>
576
+ {/if}
577
+ </div>
@@ -0,0 +1,35 @@
1
+ import { type TargetField } from './FieldMappingBuilder.svelte';
2
+ export interface ValidationRule {
3
+ field: string;
4
+ required?: boolean | undefined;
5
+ pattern?: RegExp | undefined;
6
+ customValidator?: ((value: unknown, row: Record<string, unknown>) => string | null | undefined) | undefined;
7
+ errorMessage?: string | undefined;
8
+ }
9
+ export interface PipelineValidationError {
10
+ rowIndex: number;
11
+ field: string;
12
+ message: string;
13
+ }
14
+ export interface DataImportPipelineProps {
15
+ /** 目标系统数据结构 */
16
+ targetFields: TargetField[];
17
+ /** 校验规则列表 */
18
+ validationRules?: ValidationRule[] | undefined;
19
+ /** 外部直接传入的初始原始数据行(可选) */
20
+ initialRows?: Record<string, unknown>[] | undefined;
21
+ /** 业务模块标题,如 "用户档案导入" */
22
+ title?: string | undefined;
23
+ /** 最终提交导入回调 */
24
+ onimport?: ((validRows: Record<string, unknown>[]) => Promise<{
25
+ successCount: number;
26
+ failCount: number;
27
+ }> | {
28
+ successCount: number;
29
+ failCount: number;
30
+ }) | undefined;
31
+ class?: string | undefined;
32
+ }
33
+ declare const DataImportPipeline: import("svelte").Component<DataImportPipelineProps, {}, "">;
34
+ type DataImportPipeline = ReturnType<typeof DataImportPipeline>;
35
+ export default DataImportPipeline;