@svadmin/ui 0.129.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.
- package/dist/app.css +403 -0
- package/dist/app.theme.css +403 -0
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/AccessRevocationMatrix.svelte +425 -0
- package/dist/components/AccessRevocationMatrix.svelte.d.ts +27 -0
- package/dist/components/AudioVisualInspector.svelte +458 -0
- package/dist/components/AudioVisualInspector.svelte.d.ts +53 -0
- package/dist/components/AuditSnapshotCapture.svelte +328 -0
- package/dist/components/AuditSnapshotCapture.svelte.d.ts +28 -0
- package/dist/components/CannedResponsePicker.svelte +257 -0
- package/dist/components/CannedResponsePicker.svelte.d.ts +22 -0
- package/dist/components/ContentModerationCenter.svelte +166 -0
- package/dist/components/ContentModerationCenter.svelte.d.ts +11 -0
- package/dist/components/ContractClauseDiffViewer.svelte +566 -0
- package/dist/components/ContractClauseDiffViewer.svelte.d.ts +53 -0
- package/dist/components/DataImportPipeline.svelte +577 -0
- package/dist/components/DataImportPipeline.svelte.d.ts +35 -0
- package/dist/components/DataRetentionPolicyEditor.svelte +455 -0
- package/dist/components/DataRetentionPolicyEditor.svelte.d.ts +10 -0
- package/dist/components/ElectronicSealInspector.svelte +450 -0
- package/dist/components/ElectronicSealInspector.svelte.d.ts +72 -0
- package/dist/components/EmployeeOffboardingAuditor.svelte +405 -0
- package/dist/components/EmployeeOffboardingAuditor.svelte.d.ts +39 -0
- package/dist/components/FeatureFlagStudio.svelte +583 -0
- package/dist/components/FeatureFlagStudio.svelte.d.ts +12 -0
- package/dist/components/FieldMappingBuilder.svelte +393 -0
- package/dist/components/FieldMappingBuilder.svelte.d.ts +39 -0
- package/dist/components/GatewayRouteEditor.svelte +493 -0
- package/dist/components/GatewayRouteEditor.svelte.d.ts +34 -0
- package/dist/components/HotkeysHelpModal.svelte +286 -0
- package/dist/components/HotkeysHelpModal.svelte.d.ts +21 -0
- package/dist/components/I18nStudio.svelte +635 -0
- package/dist/components/I18nStudio.svelte.d.ts +23 -0
- package/dist/components/IpAccessRuleEditor.svelte +290 -0
- package/dist/components/IpAccessRuleEditor.svelte.d.ts +19 -0
- package/dist/components/IpWhitelistDrawer.svelte +94 -0
- package/dist/components/IpWhitelistDrawer.svelte.d.ts +10 -0
- package/dist/components/MediaAuthenticityAuditCard.svelte +357 -0
- package/dist/components/MediaAuthenticityAuditCard.svelte.d.ts +64 -0
- package/dist/components/MediaGallery.svelte +575 -0
- package/dist/components/MediaGallery.svelte.d.ts +34 -0
- package/dist/components/NotificationCenter.svelte +20 -1
- package/dist/components/NotificationCenter.svelte.d.ts +2 -0
- package/dist/components/NotificationDrawer.svelte +242 -0
- package/dist/components/NotificationDrawer.svelte.d.ts +40 -0
- package/dist/components/PrintDocument.svelte +95 -0
- package/dist/components/PrintDocument.svelte.d.ts +10 -0
- package/dist/components/PrintPreviewModal.svelte +52 -0
- package/dist/components/PrintPreviewModal.svelte.d.ts +11 -0
- package/dist/components/PrintTemplateDesigner.svelte +280 -0
- package/dist/components/PrintTemplateDesigner.svelte.d.ts +11 -0
- package/dist/components/RateLimitPolicyPanel.svelte +369 -0
- package/dist/components/RateLimitPolicyPanel.svelte.d.ts +29 -0
- package/dist/components/ResizableSplitter.svelte +246 -0
- package/dist/components/ResizableSplitter.svelte.d.ts +18 -0
- package/dist/components/SensitiveWordAuditor.svelte +368 -0
- package/dist/components/SensitiveWordAuditor.svelte.d.ts +9 -0
- package/dist/components/ServiceDeskTicketCard.svelte +297 -0
- package/dist/components/ServiceDeskTicketCard.svelte.d.ts +52 -0
- package/dist/components/ShiftScheduler.svelte +490 -0
- package/dist/components/ShiftScheduler.svelte.d.ts +50 -0
- package/dist/components/SslCertificateMonitorCard.svelte +309 -0
- package/dist/components/SslCertificateMonitorCard.svelte.d.ts +30 -0
- package/dist/components/SsoConnectionStudio.svelte +784 -0
- package/dist/components/SsoConnectionStudio.svelte.d.ts +44 -0
- package/dist/components/SsoSpMetadataPanel.svelte +44 -0
- package/dist/components/SsoSpMetadataPanel.svelte.d.ts +8 -0
- package/dist/components/StepUpAuthModal.svelte +448 -0
- package/dist/components/StepUpAuthModal.svelte.d.ts +26 -0
- package/dist/components/TrafficTopologyInspector.svelte +361 -0
- package/dist/components/TrafficTopologyInspector.svelte.d.ts +43 -0
- package/dist/components/ip-access-rules.d.ts +24 -0
- package/dist/components/ip-access-rules.js +110 -0
- package/dist/components/moderation-utils.d.ts +45 -0
- package/dist/components/moderation-utils.js +74 -0
- package/dist/components/print-document.d.ts +3 -0
- package/dist/components/print-document.js +65 -0
- package/dist/components/print-utils.d.ts +44 -0
- package/dist/components/print-utils.js +68 -0
- package/dist/components/retention-utils.d.ts +31 -0
- package/dist/components/retention-utils.js +38 -0
- package/dist/components/sso-connection-presets.d.ts +2 -0
- package/dist/components/sso-connection-presets.js +59 -0
- package/dist/components/ui/sheet/sheet.svelte +3 -1
- package/dist/components/ui/sheet/sheet.svelte.d.ts +1 -0
- package/dist/components/useFeatureFlag.d.svelte.ts +1 -0
- package/dist/components/useFeatureFlag.svelte.d.ts +45 -0
- package/dist/components/useFeatureFlag.svelte.js +94 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +53 -0
- package/package.json +5 -4
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { ArrowRight, Sparkles, AlertCircle, CheckCircle2, RotateCcw, Link2, Eye, EyeOff } from '@lucide/svelte';
|
|
3
|
+
import { cn } from '../utils.js';
|
|
4
|
+
|
|
5
|
+
export interface SourceField {
|
|
6
|
+
name: string;
|
|
7
|
+
label?: string | undefined;
|
|
8
|
+
sample?: unknown | undefined;
|
|
9
|
+
type?: 'string' | 'number' | 'boolean' | 'date' | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface TargetField {
|
|
13
|
+
name: string;
|
|
14
|
+
label: string;
|
|
15
|
+
required?: boolean | undefined;
|
|
16
|
+
type?: 'string' | 'number' | 'boolean' | 'date' | undefined;
|
|
17
|
+
description?: string | undefined;
|
|
18
|
+
defaultValue?: unknown | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type TransformType = 'direct' | 'uppercase' | 'lowercase' | 'trim' | 'number' | 'fallback';
|
|
22
|
+
|
|
23
|
+
export interface FieldMappingRule {
|
|
24
|
+
targetField: string;
|
|
25
|
+
sourceField?: string | undefined;
|
|
26
|
+
transform?: TransformType | undefined;
|
|
27
|
+
fallbackValue?: string | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface FieldMappingBuilderProps {
|
|
31
|
+
/** 外部源字段列表(如来自 CSV 表头或三方接口) */
|
|
32
|
+
sourceFields: SourceField[];
|
|
33
|
+
/** 本系统目标字段要求规范 */
|
|
34
|
+
targetFields: TargetField[];
|
|
35
|
+
/** 当前映射规则列表 */
|
|
36
|
+
value?: FieldMappingRule[] | undefined;
|
|
37
|
+
/** 选填源数据样本行,用于实时推演目标值 */
|
|
38
|
+
sourceSampleRows?: Record<string, unknown>[] | undefined;
|
|
39
|
+
/** 映射变更事件 */
|
|
40
|
+
onchange?: ((rules: FieldMappingRule[]) => void) | undefined;
|
|
41
|
+
/** 是否只读禁用 */
|
|
42
|
+
disabled?: boolean | undefined;
|
|
43
|
+
class?: string | undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let {
|
|
47
|
+
sourceFields = [],
|
|
48
|
+
targetFields = [],
|
|
49
|
+
value,
|
|
50
|
+
sourceSampleRows = [],
|
|
51
|
+
onchange,
|
|
52
|
+
disabled = false,
|
|
53
|
+
class: className = '',
|
|
54
|
+
}: FieldMappingBuilderProps = $props();
|
|
55
|
+
|
|
56
|
+
let internalRules = $state<FieldMappingRule[]>([]);
|
|
57
|
+
let showPreview = $state(false);
|
|
58
|
+
|
|
59
|
+
// 辅助函数:标准化字段名称以进行模糊智能识别
|
|
60
|
+
function normalizeKey(str: string): string {
|
|
61
|
+
return str.toLowerCase().replace(/[-_\s]/g, '');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 初始化或当 targetFields 变动时补充未包含的目标字段
|
|
65
|
+
$effect(() => {
|
|
66
|
+
if (value && value.length > 0) {
|
|
67
|
+
internalRules = [...value];
|
|
68
|
+
} else {
|
|
69
|
+
// 默认尝试一次自动匹配
|
|
70
|
+
internalRules = targetFields.map((tf) => {
|
|
71
|
+
const normTarget = normalizeKey(tf.name);
|
|
72
|
+
const normLabel = normalizeKey(tf.label);
|
|
73
|
+
const match = sourceFields.find((sf) => {
|
|
74
|
+
const normSource = normalizeKey(sf.name);
|
|
75
|
+
const normSourceLabel = sf.label ? normalizeKey(sf.label) : '';
|
|
76
|
+
return (
|
|
77
|
+
normSource === normTarget ||
|
|
78
|
+
normSource === normLabel ||
|
|
79
|
+
(normSourceLabel && normSourceLabel === normLabel) ||
|
|
80
|
+
normSource.includes(normTarget) ||
|
|
81
|
+
normTarget.includes(normSource)
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
targetField: tf.name,
|
|
87
|
+
sourceField: match ? match.name : undefined,
|
|
88
|
+
transform: 'direct',
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
function updateRule(targetFieldName: string, patch: Partial<FieldMappingRule>) {
|
|
95
|
+
if (disabled) return;
|
|
96
|
+
const next = internalRules.map((r) => {
|
|
97
|
+
if (r.targetField === targetFieldName) {
|
|
98
|
+
return { ...r, ...patch };
|
|
99
|
+
}
|
|
100
|
+
return r;
|
|
101
|
+
});
|
|
102
|
+
internalRules = next;
|
|
103
|
+
onchange?.(next);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function handleAutoMatch() {
|
|
107
|
+
if (disabled) return;
|
|
108
|
+
const next = targetFields.map((tf) => {
|
|
109
|
+
const normTarget = normalizeKey(tf.name);
|
|
110
|
+
const normLabel = normalizeKey(tf.label);
|
|
111
|
+
const match = sourceFields.find((sf) => {
|
|
112
|
+
const normSource = normalizeKey(sf.name);
|
|
113
|
+
const normSourceLabel = sf.label ? normalizeKey(sf.label) : '';
|
|
114
|
+
return (
|
|
115
|
+
normSource === normTarget ||
|
|
116
|
+
normSource === normLabel ||
|
|
117
|
+
(normSourceLabel && normSourceLabel === normLabel) ||
|
|
118
|
+
normSource.includes(normTarget) ||
|
|
119
|
+
normTarget.includes(normSource)
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
targetField: tf.name,
|
|
125
|
+
sourceField: match ? match.name : undefined,
|
|
126
|
+
transform: 'direct' as TransformType,
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
internalRules = next;
|
|
130
|
+
onchange?.(next);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function handleResetAll() {
|
|
134
|
+
if (disabled) return;
|
|
135
|
+
const next = targetFields.map((tf) => ({
|
|
136
|
+
targetField: tf.name,
|
|
137
|
+
sourceField: undefined,
|
|
138
|
+
transform: 'direct' as TransformType,
|
|
139
|
+
}));
|
|
140
|
+
internalRules = next;
|
|
141
|
+
onchange?.(next);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// 统计指标计算
|
|
145
|
+
const stats = $derived.by(() => {
|
|
146
|
+
let totalTargets = targetFields.length;
|
|
147
|
+
let mappedCount = 0;
|
|
148
|
+
let missingRequired = 0;
|
|
149
|
+
|
|
150
|
+
for (const tf of targetFields) {
|
|
151
|
+
const rule = internalRules.find((r) => r.targetField === tf.name);
|
|
152
|
+
const isMapped = Boolean(rule && (rule.sourceField || rule.fallbackValue));
|
|
153
|
+
if (isMapped) {
|
|
154
|
+
mappedCount += 1;
|
|
155
|
+
} else if (tf.required) {
|
|
156
|
+
missingRequired += 1;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const isValid = missingRequired === 0;
|
|
161
|
+
const percent = totalTargets > 0 ? Math.round((mappedCount / totalTargets) * 100) : 100;
|
|
162
|
+
|
|
163
|
+
return { totalTargets, mappedCount, missingRequired, isValid, percent };
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// 推演样本数据
|
|
167
|
+
const transformedSamples = $derived.by(() => {
|
|
168
|
+
if (sourceSampleRows.length === 0) return [];
|
|
169
|
+
return sourceSampleRows.slice(0, 3).map((row) => {
|
|
170
|
+
const result: Record<string, unknown> = {};
|
|
171
|
+
for (const tf of targetFields) {
|
|
172
|
+
const rule = internalRules.find((r) => r.targetField === tf.name);
|
|
173
|
+
let rawVal = rule && rule.sourceField ? row[rule.sourceField] : undefined;
|
|
174
|
+
|
|
175
|
+
if (rawVal === undefined || rawVal === null || rawVal === '') {
|
|
176
|
+
rawVal = rule?.fallbackValue ?? tf.defaultValue ?? '';
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (rule?.transform === 'uppercase' && typeof rawVal === 'string') {
|
|
180
|
+
rawVal = rawVal.toUpperCase();
|
|
181
|
+
} else if (rule?.transform === 'lowercase' && typeof rawVal === 'string') {
|
|
182
|
+
rawVal = rawVal.toLowerCase();
|
|
183
|
+
} else if (rule?.transform === 'trim' && typeof rawVal === 'string') {
|
|
184
|
+
rawVal = rawVal.trim();
|
|
185
|
+
} else if (rule?.transform === 'number') {
|
|
186
|
+
const num = Number(rawVal);
|
|
187
|
+
rawVal = isNaN(num) ? rawVal : num;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
result[tf.name] = rawVal;
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
</script>
|
|
196
|
+
|
|
197
|
+
<div
|
|
198
|
+
class={cn( 'rounded-xl border border-border/80 bg-card text-card-foreground shadow-sm transition-all',
|
|
199
|
+
className
|
|
200
|
+
)}
|
|
201
|
+
data-svadmin-component="FieldMappingBuilder"
|
|
202
|
+
>
|
|
203
|
+
<!-- 头部控制栏与状态摘要 -->
|
|
204
|
+
<div class="flex flex-wrap items-center justify-between gap-4 border-b border-border/60 p-4">
|
|
205
|
+
<div class="flex items-center gap-3">
|
|
206
|
+
<div class="flex h-9 w-9 items-center justify-center rounded-lg bg-primary/10 text-primary">
|
|
207
|
+
<Link2 class="h-5 w-5" />
|
|
208
|
+
</div>
|
|
209
|
+
<div>
|
|
210
|
+
<h3 class="text-sm font-semibold tracking-tight">字段映射与转换规则</h3>
|
|
211
|
+
<p class="text-xs text-muted-foreground">
|
|
212
|
+
将导入文件或三方源字段映射至本系统目标数据模型
|
|
213
|
+
</p>
|
|
214
|
+
</div>
|
|
215
|
+
</div>
|
|
216
|
+
|
|
217
|
+
<div class="flex items-center gap-2">
|
|
218
|
+
<!-- 映射完成度指示徽标 -->
|
|
219
|
+
<div
|
|
220
|
+
class={cn( 'flex items-center gap-1.5 rounded-full px-3 py-1 text-xs font-medium',
|
|
221
|
+
stats.isValid
|
|
222
|
+
? 'bg-success/10 text-success '
|
|
223
|
+
: 'bg-warning/10 text-warning '
|
|
224
|
+
)}
|
|
225
|
+
>
|
|
226
|
+
{#if stats.isValid}
|
|
227
|
+
<CheckCircle2 class="h-3.5 w-3.5" />
|
|
228
|
+
<span>必填字段均已映射 ({stats.mappedCount}/{stats.totalTargets})</span>
|
|
229
|
+
{:else}
|
|
230
|
+
<AlertCircle class="h-3.5 w-3.5" />
|
|
231
|
+
<span>尚有 {stats.missingRequired} 个必填项未映射</span>
|
|
232
|
+
{/if}
|
|
233
|
+
</div>
|
|
234
|
+
|
|
235
|
+
{#if sourceSampleRows.length > 0}
|
|
236
|
+
<button
|
|
237
|
+
type="button"
|
|
238
|
+
class="flex items-center gap-1 rounded-md border border-border bg-background px-2.5 py-1 text-xs text-foreground hover:bg-muted"
|
|
239
|
+
onclick={() => (showPreview = !showPreview)}
|
|
240
|
+
>
|
|
241
|
+
{#if showPreview}
|
|
242
|
+
<EyeOff class="h-3.5 w-3.5" />
|
|
243
|
+
<span>隐藏推演</span>
|
|
244
|
+
{:else}
|
|
245
|
+
<Eye class="h-3.5 w-3.5" />
|
|
246
|
+
<span>实时推演</span>
|
|
247
|
+
{/if}
|
|
248
|
+
</button>
|
|
249
|
+
{/if}
|
|
250
|
+
|
|
251
|
+
<button
|
|
252
|
+
type="button"
|
|
253
|
+
disabled={disabled}
|
|
254
|
+
class="flex items-center gap-1 rounded-md bg-primary/10 px-2.5 py-1 text-xs font-medium text-primary hover:bg-primary/20 disabled:opacity-50"
|
|
255
|
+
onclick={handleAutoMatch}
|
|
256
|
+
>
|
|
257
|
+
<Sparkles class="h-3.5 w-3.5" />
|
|
258
|
+
<span>智能自动匹配</span>
|
|
259
|
+
</button>
|
|
260
|
+
|
|
261
|
+
<button
|
|
262
|
+
type="button"
|
|
263
|
+
disabled={disabled}
|
|
264
|
+
class="flex items-center gap-1 rounded-md border border-border bg-background px-2.5 py-1 text-xs text-muted-foreground hover:bg-muted disabled:opacity-50"
|
|
265
|
+
onclick={handleResetAll}
|
|
266
|
+
title="清空全部映射"
|
|
267
|
+
>
|
|
268
|
+
<RotateCcw class="h-3.5 w-3.5" />
|
|
269
|
+
<span>重置</span>
|
|
270
|
+
</button>
|
|
271
|
+
</div>
|
|
272
|
+
</div>
|
|
273
|
+
|
|
274
|
+
<!-- 映射主列表 -->
|
|
275
|
+
<div class="divide-y divide-border/40">
|
|
276
|
+
<div class="grid grid-cols-12 gap-3 bg-muted/40 px-4 py-2 text-xs font-medium text-muted-foreground">
|
|
277
|
+
<div class="col-span-4">目标模型字段 (Target Schema)</div>
|
|
278
|
+
<div class="col-span-1 text-center">关联</div>
|
|
279
|
+
<div class="col-span-4">导入数据源字段 (Source Field)</div>
|
|
280
|
+
<div class="col-span-3">清洗与转换 (Transform)</div>
|
|
281
|
+
</div>
|
|
282
|
+
|
|
283
|
+
{#each targetFields as target (target.name)}
|
|
284
|
+
{@const rule = internalRules.find((r) => r.targetField === target.name)}
|
|
285
|
+
{@const isMapped = Boolean(rule && (rule.sourceField || rule.fallbackValue))}
|
|
286
|
+
{@const isMissingRequired = target.required && !isMapped}
|
|
287
|
+
|
|
288
|
+
<div
|
|
289
|
+
class={cn( 'grid grid-cols-12 items-center gap-3 px-4 py-3 text-sm transition-colors hover:bg-muted/30',
|
|
290
|
+
isMissingRequired ? 'bg-warning/5' : ''
|
|
291
|
+
)}
|
|
292
|
+
>
|
|
293
|
+
<!-- 目标字段描述 -->
|
|
294
|
+
<div class="col-span-4 flex flex-col gap-0.5">
|
|
295
|
+
<div class="flex items-center gap-1.5">
|
|
296
|
+
<span class="font-medium text-foreground">{target.label}</span>
|
|
297
|
+
<code class="rounded bg-muted px-1 py-0.5 text-[11px] text-muted-foreground">{target.name}</code>
|
|
298
|
+
{#if target.required}
|
|
299
|
+
<span class="rounded bg-destructive/10 px-1 py-0.2 text-[10px] font-semibold text-destructive">必填</span>
|
|
300
|
+
{/if}
|
|
301
|
+
</div>
|
|
302
|
+
{#if target.description}
|
|
303
|
+
<span class="text-xs text-muted-foreground">{target.description}</span>
|
|
304
|
+
{/if}
|
|
305
|
+
</div>
|
|
306
|
+
|
|
307
|
+
<!-- 连线指示箭头 -->
|
|
308
|
+
<div class="col-span-1 flex justify-center text-muted-foreground">
|
|
309
|
+
<ArrowRight class={cn('h-4 w-4', isMapped ? 'text-primary' : 'opacity-40')} />
|
|
310
|
+
</div>
|
|
311
|
+
|
|
312
|
+
<!-- 选择源字段 -->
|
|
313
|
+
<div class="col-span-4 flex items-center gap-2">
|
|
314
|
+
<select
|
|
315
|
+
disabled={disabled}
|
|
316
|
+
value={rule?.sourceField ?? ''}
|
|
317
|
+
onchange={(e) => updateRule(target.name, { sourceField: e.currentTarget.value || undefined })}
|
|
318
|
+
class={cn( 'svadmin-select h-9 text-xs',
|
|
319
|
+
isMissingRequired ? 'border-warning ring-1 ring-warning/30' : ''
|
|
320
|
+
)}
|
|
321
|
+
>
|
|
322
|
+
<option value="">-- 未映射 (使用空值或回退值) --</option>
|
|
323
|
+
{#each sourceFields as source (source.name)}
|
|
324
|
+
<option value={source.name}>
|
|
325
|
+
{source.label ? `${source.label} (${source.name})` : source.name}
|
|
326
|
+
</option>
|
|
327
|
+
{/each}
|
|
328
|
+
</select>
|
|
329
|
+
</div>
|
|
330
|
+
|
|
331
|
+
<!-- 转换选项与回退默认值 -->
|
|
332
|
+
<div class="col-span-3 flex items-center gap-2">
|
|
333
|
+
<select
|
|
334
|
+
disabled={disabled}
|
|
335
|
+
value={rule?.transform ?? 'direct'}
|
|
336
|
+
onchange={(e) => updateRule(target.name, { transform: e.currentTarget.value as TransformType })}
|
|
337
|
+
class="svadmin-select svadmin-select--inline h-9 w-28 text-xs"
|
|
338
|
+
>
|
|
339
|
+
<option value="direct">直接映射</option>
|
|
340
|
+
<option value="trim">去除前后空格</option>
|
|
341
|
+
<option value="uppercase">全大写</option>
|
|
342
|
+
<option value="lowercase">全小写</option>
|
|
343
|
+
<option value="number">转为数值</option>
|
|
344
|
+
<option value="fallback">固定回退值</option>
|
|
345
|
+
</select>
|
|
346
|
+
|
|
347
|
+
{#if rule?.transform === 'fallback' || !rule?.sourceField}
|
|
348
|
+
<input
|
|
349
|
+
type="text"
|
|
350
|
+
disabled={disabled}
|
|
351
|
+
placeholder="默认回退值"
|
|
352
|
+
value={rule?.fallbackValue ?? ''}
|
|
353
|
+
oninput={(e) => updateRule(target.name, { fallbackValue: e.currentTarget.value })}
|
|
354
|
+
class="h-9 min-w-0 flex-1 rounded-md border border-input bg-background px-2 py-1 text-xs text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
355
|
+
/>
|
|
356
|
+
{/if}
|
|
357
|
+
</div>
|
|
358
|
+
</div>
|
|
359
|
+
{/each}
|
|
360
|
+
</div>
|
|
361
|
+
|
|
362
|
+
<!-- 样本实时推演对比抽屉 -->
|
|
363
|
+
{#if showPreview && transformedSamples.length > 0}
|
|
364
|
+
<div class="border-t border-border/80 bg-muted/20 p-4">
|
|
365
|
+
<div class="mb-2 flex items-center justify-between">
|
|
366
|
+
<span class="text-xs font-semibold text-foreground">目标数据样本推演结果 (前 3 条)</span>
|
|
367
|
+
<span class="text-[11px] text-muted-foreground">根据当前映射及清洗规则实时计算</span>
|
|
368
|
+
</div>
|
|
369
|
+
<div class="overflow-x-auto rounded-lg border border-border/60 bg-background">
|
|
370
|
+
<table class="w-full text-left text-xs">
|
|
371
|
+
<thead class="border-b border-border/60 bg-muted/40 font-medium text-muted-foreground">
|
|
372
|
+
<tr>
|
|
373
|
+
{#each targetFields as target (target.name)}
|
|
374
|
+
<th class="px-3 py-2 whitespace-nowrap">{target.label}</th>
|
|
375
|
+
{/each}
|
|
376
|
+
</tr>
|
|
377
|
+
</thead>
|
|
378
|
+
<tbody class="divide-y divide-border/40">
|
|
379
|
+
{#each transformedSamples as sampleRow, sampleIndex (sampleIndex)}
|
|
380
|
+
<tr class="hover:bg-muted/30">
|
|
381
|
+
{#each targetFields as target (target.name)}
|
|
382
|
+
<td class="px-3 py-1.5 text-foreground whitespace-nowrap font-mono text-[11px]">
|
|
383
|
+
{String(sampleRow[target.name] ?? '-')}
|
|
384
|
+
</td>
|
|
385
|
+
{/each}
|
|
386
|
+
</tr>
|
|
387
|
+
{/each}
|
|
388
|
+
</tbody>
|
|
389
|
+
</table>
|
|
390
|
+
</div>
|
|
391
|
+
</div>
|
|
392
|
+
{/if}
|
|
393
|
+
</div>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface SourceField {
|
|
2
|
+
name: string;
|
|
3
|
+
label?: string | undefined;
|
|
4
|
+
sample?: unknown | undefined;
|
|
5
|
+
type?: 'string' | 'number' | 'boolean' | 'date' | undefined;
|
|
6
|
+
}
|
|
7
|
+
export interface TargetField {
|
|
8
|
+
name: string;
|
|
9
|
+
label: string;
|
|
10
|
+
required?: boolean | undefined;
|
|
11
|
+
type?: 'string' | 'number' | 'boolean' | 'date' | undefined;
|
|
12
|
+
description?: string | undefined;
|
|
13
|
+
defaultValue?: unknown | undefined;
|
|
14
|
+
}
|
|
15
|
+
export type TransformType = 'direct' | 'uppercase' | 'lowercase' | 'trim' | 'number' | 'fallback';
|
|
16
|
+
export interface FieldMappingRule {
|
|
17
|
+
targetField: string;
|
|
18
|
+
sourceField?: string | undefined;
|
|
19
|
+
transform?: TransformType | undefined;
|
|
20
|
+
fallbackValue?: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
export interface FieldMappingBuilderProps {
|
|
23
|
+
/** 外部源字段列表(如来自 CSV 表头或三方接口) */
|
|
24
|
+
sourceFields: SourceField[];
|
|
25
|
+
/** 本系统目标字段要求规范 */
|
|
26
|
+
targetFields: TargetField[];
|
|
27
|
+
/** 当前映射规则列表 */
|
|
28
|
+
value?: FieldMappingRule[] | undefined;
|
|
29
|
+
/** 选填源数据样本行,用于实时推演目标值 */
|
|
30
|
+
sourceSampleRows?: Record<string, unknown>[] | undefined;
|
|
31
|
+
/** 映射变更事件 */
|
|
32
|
+
onchange?: ((rules: FieldMappingRule[]) => void) | undefined;
|
|
33
|
+
/** 是否只读禁用 */
|
|
34
|
+
disabled?: boolean | undefined;
|
|
35
|
+
class?: string | undefined;
|
|
36
|
+
}
|
|
37
|
+
declare const FieldMappingBuilder: import("svelte").Component<FieldMappingBuilderProps, {}, "">;
|
|
38
|
+
type FieldMappingBuilder = ReturnType<typeof FieldMappingBuilder>;
|
|
39
|
+
export default FieldMappingBuilder;
|