@svadmin/ui 0.119.0 → 0.121.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 (37) hide show
  1. package/dist/app.css +139 -0
  2. package/dist/app.theme.css +139 -0
  3. package/dist/components/AboutSettings.svelte +1 -1
  4. package/dist/components/Barcode.svelte +219 -0
  5. package/dist/components/Barcode.svelte.d.ts +15 -0
  6. package/dist/components/ContextMenu.svelte +268 -0
  7. package/dist/components/ContextMenu.svelte.d.ts +22 -0
  8. package/dist/components/JsonViewer.svelte +323 -0
  9. package/dist/components/JsonViewer.svelte.d.ts +20 -0
  10. package/dist/components/KpiCard.svelte +250 -0
  11. package/dist/components/KpiCard.svelte.d.ts +44 -0
  12. package/dist/components/NumberRoll.svelte +149 -0
  13. package/dist/components/NumberRoll.svelte.d.ts +17 -0
  14. package/dist/components/OtpInput.svelte +209 -0
  15. package/dist/components/OtpInput.svelte.d.ts +17 -0
  16. package/dist/components/RecordCompareModal.svelte +428 -0
  17. package/dist/components/RecordCompareModal.svelte.d.ts +42 -0
  18. package/dist/components/ResultPage.svelte +166 -0
  19. package/dist/components/ResultPage.svelte.d.ts +28 -0
  20. package/dist/components/SignaturePad.svelte +230 -66
  21. package/dist/components/SignaturePad.svelte.d.ts +6 -5
  22. package/dist/components/Tour.svelte +71 -13
  23. package/dist/components/Tour.svelte.d.ts +1 -1
  24. package/dist/components/TrendIndicator.svelte +21 -13
  25. package/dist/components/TrendIndicator.svelte.d.ts +4 -2
  26. package/dist/components/UnsavedChangesGuard.svelte +138 -0
  27. package/dist/components/UnsavedChangesGuard.svelte.d.ts +32 -0
  28. package/dist/components/VirtualList.svelte +165 -0
  29. package/dist/components/VirtualList.svelte.d.ts +43 -0
  30. package/dist/components/WatermarkContainer.svelte +196 -0
  31. package/dist/components/WatermarkContainer.svelte.d.ts +20 -0
  32. package/dist/components/useUnsavedChanges.d.svelte.ts +1 -0
  33. package/dist/components/useUnsavedChanges.svelte.d.ts +22 -0
  34. package/dist/components/useUnsavedChanges.svelte.js +105 -0
  35. package/dist/index.d.ts +30 -35
  36. package/dist/index.js +18 -2
  37. package/package.json +1 -1
@@ -0,0 +1,428 @@
1
+ <script lang="ts">
2
+ import { X, ArrowLeftRight, Check, Copy, Search, SlidersHorizontal } from '@lucide/svelte';
3
+ import { untrack } from 'svelte';
4
+ import { cn } from '../utils.js';
5
+
6
+ export interface CompareFieldConfig<T = Record<string, unknown>> {
7
+ key: string;
8
+ label: string;
9
+ category?: string | undefined;
10
+ formatter?: ((value: unknown, record: T) => string) | undefined;
11
+ highlightDiff?: boolean | undefined;
12
+ }
13
+
14
+ export interface RecordCompareModalProps {
15
+ /** Controlled open state */
16
+ open?: boolean | undefined;
17
+ /** Display title (default: 'Record Comparison' / '实体记录对比') */
18
+ title?: string | undefined;
19
+ /** Subtitle or description */
20
+ description?: string | undefined;
21
+ /** List of records to compare (2 to 5 records) */
22
+ records: Record<string, unknown>[];
23
+ /** Optional custom field definitions. If omitted, automatically inferred from record properties */
24
+ fields?: CompareFieldConfig[] | undefined;
25
+ /** Index of baseline/benchmark record (default: 0) */
26
+ benchmarkIndex?: number | undefined;
27
+ /** Initial filter state: only show rows with differences (default: false) */
28
+ defaultOnlyDiff?: boolean | undefined;
29
+ /** Initial filter state: hide identical rows (default: false) */
30
+ defaultHideIdentical?: boolean | undefined;
31
+ /** Record identifier key (default: 'id') */
32
+ recordIdKey?: string | undefined;
33
+ /** Record title/name key (default: 'title' || 'name' || 'id') */
34
+ recordTitleKey?: string | undefined;
35
+ /** Presentation mode: 'modal' (center overlay) or 'drawer' (slide from right) (default: 'modal') */
36
+ layout?: 'modal' | 'drawer' | undefined;
37
+ /** Allow syncing field value from benchmark to target record (default: true) */
38
+ allowSync?: boolean | undefined;
39
+ /** Additional CSS classes for modal container */
40
+ class?: string | undefined;
41
+ /** Callback when user closes the modal */
42
+ onclose?: (() => void) | undefined;
43
+ /** Callback when user clicks sync button from benchmark to target record */
44
+ onsync?: ((sourceRecord: Record<string, unknown>, targetRecord: Record<string, unknown>, fieldKey: string) => void) | undefined;
45
+ }
46
+
47
+ let {
48
+ open = $bindable(false),
49
+ title = 'Record Comparison',
50
+ description,
51
+ records = [],
52
+ fields,
53
+ benchmarkIndex = $bindable(0),
54
+ defaultOnlyDiff = false,
55
+ defaultHideIdentical = false,
56
+ recordIdKey = 'id',
57
+ recordTitleKey,
58
+ layout = 'modal',
59
+ allowSync = true,
60
+ class: className = '',
61
+ onclose,
62
+ onsync,
63
+ }: RecordCompareModalProps = $props();
64
+
65
+ let onlyDiff = $state(untrack(() => defaultOnlyDiff || defaultHideIdentical));
66
+ let highlightDiff = $state(true);
67
+ let searchQuery = $state('');
68
+ let copiedField = $state<string | null>(null);
69
+
70
+ // Inferred or provided field definitions
71
+ const effectiveFields = $derived.by<CompareFieldConfig[]>(() => {
72
+ if (fields && fields.length > 0) return fields;
73
+ if (records.length === 0) return [];
74
+
75
+ const keys = new Set<string>();
76
+ for (const rec of records) {
77
+ if (rec && typeof rec === 'object') {
78
+ for (const k of Object.keys(rec)) {
79
+ if (!k.startsWith('_') && k !== 'password' && k !== 'secret') {
80
+ keys.add(k);
81
+ }
82
+ }
83
+ }
84
+ }
85
+
86
+ return Array.from(keys).map((k) => ({
87
+ key: k,
88
+ label: k.replace(/_/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase()),
89
+ highlightDiff: true,
90
+ }));
91
+ });
92
+
93
+ // Benchmark record
94
+ const benchmarkRecord = $derived(records[benchmarkIndex] ?? records[0]);
95
+
96
+ // Check whether a specific field has different values across the provided records
97
+ function isFieldDifferent(fieldKey: string): boolean {
98
+ if (records.length < 2) return false;
99
+ const baseVal = JSON.stringify(benchmarkRecord?.[fieldKey] ?? null);
100
+ for (let i = 0; i < records.length; i++) {
101
+ if (i === benchmarkIndex) continue;
102
+ const curVal = JSON.stringify(records[i]?.[fieldKey] ?? null);
103
+ if (curVal !== baseVal) return true;
104
+ }
105
+ return false;
106
+ }
107
+
108
+ // Filtered rows
109
+ const visibleFields = $derived.by(() => {
110
+ return effectiveFields.filter((f) => {
111
+ // 1. Search text filter
112
+ if (searchQuery.trim()) {
113
+ const q = searchQuery.toLowerCase();
114
+ const matchesLabel = f.label.toLowerCase().includes(q);
115
+ const matchesKey = f.key.toLowerCase().includes(q);
116
+ if (!matchesLabel && !matchesKey) return false;
117
+ }
118
+
119
+ // 2. Diff filter
120
+ if (onlyDiff && !isFieldDifferent(f.key)) return false;
121
+
122
+ return true;
123
+ });
124
+ });
125
+
126
+ // Format value safely
127
+ function formatValue(field: CompareFieldConfig, record: Record<string, unknown> | undefined): string {
128
+ if (!record) return '—';
129
+ const val = record[field.key];
130
+ if (field.formatter) {
131
+ return field.formatter(val, record);
132
+ }
133
+ if (val === null || val === undefined) return '—';
134
+ if (typeof val === 'boolean') return val ? 'Yes' : 'No';
135
+ if (typeof val === 'object') {
136
+ try {
137
+ return JSON.stringify(val);
138
+ } catch {
139
+ return String(val);
140
+ }
141
+ }
142
+ return String(val);
143
+ }
144
+
145
+ function getRecordTitle(record: Record<string, unknown> | undefined, index: number): string {
146
+ if (!record) return `Record #${index + 1}`;
147
+ if (recordTitleKey && record[recordTitleKey]) {
148
+ return String(record[recordTitleKey]);
149
+ }
150
+ return (
151
+ (record['title'] as string | undefined) ??
152
+ (record['name'] as string | undefined) ??
153
+ (record['label'] as string | undefined) ??
154
+ (record[recordIdKey] as string | undefined) ??
155
+ `Record #${index + 1}`
156
+ );
157
+ }
158
+
159
+ function handleClose() {
160
+ open = false;
161
+ onclose?.();
162
+ }
163
+
164
+ function handleSync(targetRecord: Record<string, unknown>, fieldKey: string) {
165
+ if (!benchmarkRecord || !targetRecord) return;
166
+ onsync?.(benchmarkRecord, targetRecord, fieldKey);
167
+ copiedField = `${String(targetRecord[recordIdKey] ?? 'target')}_${fieldKey}`;
168
+ setTimeout(() => {
169
+ copiedField = null;
170
+ }, 1500);
171
+ }
172
+
173
+ function handleKeydown(e: KeyboardEvent) {
174
+ if (e.key === 'Escape' && open) {
175
+ handleClose();
176
+ }
177
+ }
178
+ </script>
179
+
180
+ <svelte:window onkeydown={handleKeydown} />
181
+
182
+ {#if open}
183
+ <div
184
+ role="dialog"
185
+ aria-modal="true"
186
+ aria-label={title}
187
+ data-svadmin-component="RecordCompareModal"
188
+ data-layout={layout}
189
+ class="fixed inset-0 z-50 flex items-center justify-center overflow-hidden"
190
+ >
191
+ <!-- Backdrop -->
192
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
193
+ <div
194
+ role="button"
195
+ tabindex="-1"
196
+ class="fixed inset-0 bg-background/80 backdrop-blur-sm transition-opacity"
197
+ onclick={handleClose}
198
+ aria-label="Close dialog"
199
+ ></div>
200
+
201
+ <!-- Container: Modal or Drawer -->
202
+ <div
203
+ class={cn(
204
+ 'relative z-50 flex flex-col border border-border bg-card text-card-foreground shadow-[var(--shadow-overlay)] transition-all',
205
+ layout === 'drawer'
206
+ ? 'fixed right-0 top-0 h-full w-full max-w-4xl rounded-none border-l'
207
+ : 'mx-4 my-6 h-[85vh] w-full max-w-5xl rounded-md',
208
+ className,
209
+ )}
210
+ >
211
+ <!-- Header -->
212
+ <div class="flex items-center justify-between border-b border-border px-6 py-3.5">
213
+ <div class="flex items-center gap-3">
214
+ <div class="flex h-8 w-8 items-center justify-center rounded-sm bg-primary/10 text-primary">
215
+ <ArrowLeftRight class="h-4 w-4" />
216
+ </div>
217
+ <div>
218
+ <h2 class="text-base font-semibold tracking-tight text-foreground">{title}</h2>
219
+ {#if description}
220
+ <p class="text-xs text-muted-foreground mt-0.5">{description}</p>
221
+ {/if}
222
+ </div>
223
+ </div>
224
+
225
+ <button
226
+ type="button"
227
+ onclick={handleClose}
228
+ class="flex h-8 w-8 items-center justify-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground transition-colors cursor-pointer"
229
+ aria-label="Close"
230
+ >
231
+ <X class="h-4 w-4" />
232
+ </button>
233
+ </div>
234
+
235
+ <!-- Controls & Filter Toolbar -->
236
+ <div class="flex flex-wrap items-center justify-between gap-3 border-b border-border bg-muted/30 px-6 py-2.5 text-xs">
237
+ <div class="flex items-center gap-2">
238
+ <div class="relative w-48 sm:w-64">
239
+ <Search class="absolute left-2.5 top-2.5 h-3.5 w-3.5 text-muted-foreground" />
240
+ <input
241
+ type="text"
242
+ bind:value={searchQuery}
243
+ placeholder="Filter attributes..."
244
+ class="h-8 w-full rounded-sm border border-input bg-background pl-8 pr-3 text-xs placeholder:text-muted-foreground focus:border-primary focus:outline-none"
245
+ />
246
+ </div>
247
+
248
+ <button
249
+ type="button"
250
+ onclick={() => (onlyDiff = !onlyDiff)}
251
+ class={cn(
252
+ 'h-8 inline-flex items-center gap-1.5 rounded-sm border px-3 text-xs font-medium transition-colors cursor-pointer',
253
+ onlyDiff
254
+ ? 'border-primary/40 bg-primary/10 text-primary font-medium'
255
+ : 'border-border bg-background text-muted-foreground hover:bg-muted hover:text-foreground',
256
+ )}
257
+ >
258
+ <SlidersHorizontal class="h-3.5 w-3.5" />
259
+ <span>Only Differences</span>
260
+ </button>
261
+ </div>
262
+
263
+ <div class="flex items-center gap-2 text-muted-foreground text-xs">
264
+ <span>Comparing <strong class="font-mono tabular-nums text-foreground">{records.length}</strong> records</span>
265
+ <span>•</span>
266
+ <span><strong class="font-mono tabular-nums text-foreground">{visibleFields.length}</strong> fields shown</span>
267
+ </div>
268
+ </div>
269
+
270
+ <!-- Comparison Matrix Table Area -->
271
+ <div class="flex-1 overflow-auto p-6">
272
+ {#if records.length < 2}
273
+ <div class="flex h-64 flex-col items-center justify-center text-center text-muted-foreground">
274
+ <ArrowLeftRight class="mb-3 h-8 w-8 text-muted-foreground/40" />
275
+ <p class="text-sm font-medium">Please select at least 2 records to compare.</p>
276
+ </div>
277
+ {:else if visibleFields.length === 0}
278
+ <div class="flex h-64 flex-col items-center justify-center text-center text-muted-foreground">
279
+ <p class="text-sm font-medium">No matching attributes found for the current filters.</p>
280
+ {#if onlyDiff}
281
+ <button
282
+ type="button"
283
+ onclick={() => {
284
+ onlyDiff = false;
285
+ searchQuery = '';
286
+ }}
287
+ class="mt-2 text-xs text-primary underline cursor-pointer"
288
+ >
289
+ Clear comparison filters
290
+ </button>
291
+ {/if}
292
+ </div>
293
+ {:else}
294
+ <div class="overflow-x-auto rounded-md border border-border bg-card">
295
+ <table class="w-full text-left text-xs border-collapse">
296
+ <!-- Table Header: Record Columns -->
297
+ <thead>
298
+ <tr class="h-10 border-b border-border bg-muted/60">
299
+ <!-- Attribute header -->
300
+ <th class="sticky left-0 z-20 w-44 bg-muted/95 p-3 text-xs font-semibold text-muted-foreground border-r border-border backdrop-blur-sm sm:w-56">
301
+ Attribute
302
+ </th>
303
+
304
+ <!-- Record Headers -->
305
+ {#each records as record, idx (record[recordIdKey] ?? idx)}
306
+ {@const isBenchmark = idx === benchmarkIndex}
307
+ <th class="min-w-[180px] p-3 text-xs font-semibold text-foreground border-l border-border">
308
+ <div class="flex flex-col gap-1">
309
+ <div class="flex items-center justify-between gap-1.5">
310
+ <span class="truncate font-medium text-foreground">
311
+ {getRecordTitle(record, idx)}
312
+ </span>
313
+ {#if isBenchmark}
314
+ <span class="inline-flex items-center rounded-sm bg-primary/10 text-primary border border-primary/20 px-1.5 py-0.5 text-xs font-medium">
315
+ Baseline
316
+ </span>
317
+ {:else}
318
+ <button
319
+ type="button"
320
+ onclick={() => (benchmarkIndex = idx)}
321
+ class="text-xs text-muted-foreground hover:text-primary transition-colors cursor-pointer"
322
+ title="Set as baseline for comparison"
323
+ >
324
+ Set Baseline
325
+ </button>
326
+ {/if}
327
+ </div>
328
+ <span class="font-mono text-xs text-muted-foreground tabular-nums">
329
+ ID: {record[recordIdKey] ?? `#${idx + 1}`}
330
+ </span>
331
+ </div>
332
+ </th>
333
+ {/each}
334
+ </tr>
335
+ </thead>
336
+
337
+ <!-- Table Body -->
338
+ <tbody class="divide-y divide-border">
339
+ {#each visibleFields as field (field.key)}
340
+ {@const isDiff = isFieldDifferent(field.key)}
341
+ <tr
342
+ class={cn(
343
+ 'transition-colors',
344
+ isDiff && highlightDiff ? 'bg-primary/[0.03] hover:bg-primary/[0.06]' : 'hover:bg-muted/40',
345
+ )}
346
+ >
347
+ <!-- Attribute label -->
348
+ <td class="sticky left-0 z-10 w-44 bg-card p-3 text-xs font-medium text-foreground border-r border-border backdrop-blur-sm sm:w-56">
349
+ <div class="flex items-center gap-1.5">
350
+ {#if isDiff && highlightDiff}
351
+ <span class="h-1.5 w-1.5 rounded-full bg-primary shrink-0" title="Different value across records"></span>
352
+ {/if}
353
+ <span class="truncate" title={field.label}>{field.label}</span>
354
+ </div>
355
+ {#if field.category}
356
+ <span class="text-xs text-muted-foreground">{field.category}</span>
357
+ {/if}
358
+ </td>
359
+
360
+ <!-- Values for each record -->
361
+ {#each records as record, idx (record[recordIdKey] ?? idx)}
362
+ {@const isBenchmark = idx === benchmarkIndex}
363
+ {@const formattedVal = formatValue(field, record)}
364
+ {@const baseVal = formatValue(field, benchmarkRecord)}
365
+ {@const cellDiff = !isBenchmark && formattedVal !== baseVal}
366
+ {@const cellCopied = copiedField === `${record[recordIdKey] ?? 'target'}_${field.key}`}
367
+
368
+ <td
369
+ class={cn(
370
+ 'p-3 border-l border-border font-mono text-xs tabular-nums transition-colors relative',
371
+ cellDiff && highlightDiff ? 'font-medium text-primary' : 'text-foreground',
372
+ )}
373
+ >
374
+ <div class="flex items-center justify-between gap-2">
375
+ <span class="truncate" title={formattedVal}>
376
+ {formattedVal}
377
+ </span>
378
+
379
+ <!-- Sync button from baseline to this record -->
380
+ {#if allowSync && !isBenchmark && cellDiff}
381
+ <button
382
+ type="button"
383
+ onclick={() => handleSync(record, field.key)}
384
+ class={cn(
385
+ 'inline-flex items-center gap-1 rounded-sm border px-2 py-0.5 text-xs transition-colors shrink-0 cursor-pointer',
386
+ cellCopied
387
+ ? 'border-success/30 bg-success/10 text-success'
388
+ : 'border-border bg-background text-muted-foreground hover:border-primary hover:text-primary hover:bg-primary/5',
389
+ )}
390
+ title="Sync value from baseline record"
391
+ >
392
+ {#if cellCopied}
393
+ <Check class="h-3 w-3 text-success" />
394
+ <span class="text-success font-sans">Synced</span>
395
+ {:else}
396
+ <Copy class="h-3 w-3" />
397
+ <span class="font-sans">Sync</span>
398
+ {/if}
399
+ </button>
400
+ {/if}
401
+ </div>
402
+ </td>
403
+ {/each}
404
+ </tr>
405
+ {/each}
406
+ </tbody>
407
+ </table>
408
+ </div>
409
+ {/if}
410
+ </div>
411
+
412
+ <!-- Footer -->
413
+ <div class="flex items-center justify-between border-t border-border px-6 py-3 bg-muted/20">
414
+ <span class="text-xs text-muted-foreground">
415
+ Baseline: <strong class="text-foreground">{getRecordTitle(benchmarkRecord, benchmarkIndex)}</strong>
416
+ </span>
417
+
418
+ <button
419
+ type="button"
420
+ onclick={handleClose}
421
+ class="h-8 rounded-sm border border-border bg-background px-4 text-xs font-medium text-foreground hover:bg-muted hover:border-border transition-colors cursor-pointer"
422
+ >
423
+ Close
424
+ </button>
425
+ </div>
426
+ </div>
427
+ </div>
428
+ {/if}
@@ -0,0 +1,42 @@
1
+ export interface CompareFieldConfig<T = Record<string, unknown>> {
2
+ key: string;
3
+ label: string;
4
+ category?: string | undefined;
5
+ formatter?: ((value: unknown, record: T) => string) | undefined;
6
+ highlightDiff?: boolean | undefined;
7
+ }
8
+ export interface RecordCompareModalProps {
9
+ /** Controlled open state */
10
+ open?: boolean | undefined;
11
+ /** Display title (default: 'Record Comparison' / '实体记录对比') */
12
+ title?: string | undefined;
13
+ /** Subtitle or description */
14
+ description?: string | undefined;
15
+ /** List of records to compare (2 to 5 records) */
16
+ records: Record<string, unknown>[];
17
+ /** Optional custom field definitions. If omitted, automatically inferred from record properties */
18
+ fields?: CompareFieldConfig[] | undefined;
19
+ /** Index of baseline/benchmark record (default: 0) */
20
+ benchmarkIndex?: number | undefined;
21
+ /** Initial filter state: only show rows with differences (default: false) */
22
+ defaultOnlyDiff?: boolean | undefined;
23
+ /** Initial filter state: hide identical rows (default: false) */
24
+ defaultHideIdentical?: boolean | undefined;
25
+ /** Record identifier key (default: 'id') */
26
+ recordIdKey?: string | undefined;
27
+ /** Record title/name key (default: 'title' || 'name' || 'id') */
28
+ recordTitleKey?: string | undefined;
29
+ /** Presentation mode: 'modal' (center overlay) or 'drawer' (slide from right) (default: 'modal') */
30
+ layout?: 'modal' | 'drawer' | undefined;
31
+ /** Allow syncing field value from benchmark to target record (default: true) */
32
+ allowSync?: boolean | undefined;
33
+ /** Additional CSS classes for modal container */
34
+ class?: string | undefined;
35
+ /** Callback when user closes the modal */
36
+ onclose?: (() => void) | undefined;
37
+ /** Callback when user clicks sync button from benchmark to target record */
38
+ onsync?: ((sourceRecord: Record<string, unknown>, targetRecord: Record<string, unknown>, fieldKey: string) => void) | undefined;
39
+ }
40
+ declare const RecordCompareModal: import("svelte").Component<RecordCompareModalProps, {}, "open" | "benchmarkIndex">;
41
+ type RecordCompareModal = ReturnType<typeof RecordCompareModal>;
42
+ export default RecordCompareModal;
@@ -0,0 +1,166 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import {
4
+ CheckCircle2,
5
+ XCircle,
6
+ AlertTriangle,
7
+ Clock,
8
+ ShieldAlert,
9
+ FileQuestion,
10
+ ServerCrash,
11
+ } from '@lucide/svelte';
12
+ import { Button } from './ui/button/index.js';
13
+ import { cn } from '../utils.js';
14
+
15
+ export type ResultStatus = 'success' | 'processing' | 'warning' | 'error' | '403' | '404' | '500';
16
+
17
+ export interface ResultPageProps {
18
+ /** 业务结果或异常状态类型,默认 'success' */
19
+ status?: ResultStatus | undefined;
20
+ /** 大号主标题,如 "订单提交成功" 或 "无权访问此页面" */
21
+ title: string;
22
+ /** 详细描述说明或提示信息 */
23
+ description?: string | undefined;
24
+ /** 主要操作按钮文案(如 "返回工作台"、"重新提交") */
25
+ primaryActionText?: string | undefined;
26
+ /** 主要操作按钮点击回调 */
27
+ onPrimaryAction?: (() => void) | undefined;
28
+ /** 次要操作按钮文案(如 "查看详情"、"返回上一页") */
29
+ secondaryActionText?: string | undefined;
30
+ /** 次要操作按钮点击回调 */
31
+ onSecondaryAction?: (() => void) | undefined;
32
+ /** 布局形态:'page'(页面级全宽居中)或 'card'(卡片容器内嵌),默认 'card' */
33
+ layout?: 'page' | 'card' | undefined;
34
+ /** 自定义操作按钮区域插槽 */
35
+ actions?: Snippet | undefined;
36
+ /** 关联业务信息或补充详情插槽(如订单明细卡片、审批人流水等) */
37
+ children?: Snippet | undefined;
38
+ class?: string | undefined;
39
+ }
40
+
41
+ let {
42
+ status = 'success',
43
+ title,
44
+ description,
45
+ primaryActionText,
46
+ onPrimaryAction,
47
+ secondaryActionText,
48
+ onSecondaryAction,
49
+ layout = 'card',
50
+ actions,
51
+ children,
52
+ class: className = '',
53
+ }: ResultPageProps = $props();
54
+
55
+ const statusTone = $derived.by(() => {
56
+ switch (status) {
57
+ case 'success':
58
+ return {
59
+ icon: CheckCircle2,
60
+ iconClass: 'text-success',
61
+ bgClass: 'bg-success/10 ring-success/20',
62
+ };
63
+ case 'processing':
64
+ return {
65
+ icon: Clock,
66
+ iconClass: 'text-primary',
67
+ bgClass: 'bg-primary/10 ring-primary/20',
68
+ };
69
+ case 'warning':
70
+ return {
71
+ icon: AlertTriangle,
72
+ iconClass: 'text-warning',
73
+ bgClass: 'bg-warning/10 ring-warning/20',
74
+ };
75
+ case 'error':
76
+ return {
77
+ icon: XCircle,
78
+ iconClass: 'text-destructive',
79
+ bgClass: 'bg-destructive/10 ring-destructive/20',
80
+ };
81
+ case '403':
82
+ return {
83
+ icon: ShieldAlert,
84
+ iconClass: 'text-warning',
85
+ bgClass: 'bg-warning/10 ring-warning/20',
86
+ };
87
+ case '404':
88
+ return {
89
+ icon: FileQuestion,
90
+ iconClass: 'text-muted-foreground',
91
+ bgClass: 'bg-muted ring-border',
92
+ };
93
+ case '500':
94
+ default:
95
+ return {
96
+ icon: ServerCrash,
97
+ iconClass: 'text-destructive',
98
+ bgClass: 'bg-destructive/10 ring-destructive/20',
99
+ };
100
+ }
101
+ });
102
+
103
+ const IconComp = $derived(statusTone.icon);
104
+ </script>
105
+
106
+ <div
107
+ data-svadmin-component="ResultPage"
108
+ data-status={status}
109
+ class={cn(
110
+ 'flex flex-col items-center justify-center text-center',
111
+ layout === 'page'
112
+ ? 'min-h-[50vh] py-16 px-4 w-full'
113
+ : 'rounded-xl border border-border bg-card p-8 md:p-12 shadow-xs w-full',
114
+ className
115
+ )}
116
+ >
117
+ <!-- Big Semantic Icon with Soft Halo Ring -->
118
+ <div class={cn('mb-6 flex h-20 w-20 items-center justify-center rounded-full ring-8', statusTone.bgClass)}>
119
+ <IconComp class={cn('h-10 w-10', statusTone.iconClass)} />
120
+ </div>
121
+
122
+ <!-- Title & Description -->
123
+ <h1 class="text-xl md:text-2xl font-bold tracking-tight text-foreground">
124
+ {title}
125
+ </h1>
126
+
127
+ {#if description}
128
+ <p class="mt-2.5 max-w-lg text-sm text-muted-foreground leading-relaxed">
129
+ {description}
130
+ </p>
131
+ {/if}
132
+
133
+ <!-- Action Buttons -->
134
+ {#if actions}
135
+ <div class="mt-7 flex flex-wrap items-center justify-center gap-3">
136
+ {@render actions()}
137
+ </div>
138
+ {:else if primaryActionText || secondaryActionText}
139
+ <div class="mt-7 flex flex-wrap items-center justify-center gap-3">
140
+ {#if primaryActionText}
141
+ <Button
142
+ class="min-w-28"
143
+ onclick={onPrimaryAction}
144
+ >
145
+ {primaryActionText}
146
+ </Button>
147
+ {/if}
148
+ {#if secondaryActionText}
149
+ <Button
150
+ variant="outline"
151
+ class="min-w-28"
152
+ onclick={onSecondaryAction}
153
+ >
154
+ {secondaryActionText}
155
+ </Button>
156
+ {/if}
157
+ </div>
158
+ {/if}
159
+
160
+ <!-- Related Business Information Slot -->
161
+ {#if children}
162
+ <div class="mt-8 w-full max-w-xl text-left rounded-lg border border-border/80 bg-muted/20 p-5 text-sm">
163
+ {@render children()}
164
+ </div>
165
+ {/if}
166
+ </div>
@@ -0,0 +1,28 @@
1
+ import type { Snippet } from 'svelte';
2
+ export type ResultStatus = 'success' | 'processing' | 'warning' | 'error' | '403' | '404' | '500';
3
+ export interface ResultPageProps {
4
+ /** 业务结果或异常状态类型,默认 'success' */
5
+ status?: ResultStatus | undefined;
6
+ /** 大号主标题,如 "订单提交成功" 或 "无权访问此页面" */
7
+ title: string;
8
+ /** 详细描述说明或提示信息 */
9
+ description?: string | undefined;
10
+ /** 主要操作按钮文案(如 "返回工作台"、"重新提交") */
11
+ primaryActionText?: string | undefined;
12
+ /** 主要操作按钮点击回调 */
13
+ onPrimaryAction?: (() => void) | undefined;
14
+ /** 次要操作按钮文案(如 "查看详情"、"返回上一页") */
15
+ secondaryActionText?: string | undefined;
16
+ /** 次要操作按钮点击回调 */
17
+ onSecondaryAction?: (() => void) | undefined;
18
+ /** 布局形态:'page'(页面级全宽居中)或 'card'(卡片容器内嵌),默认 'card' */
19
+ layout?: 'page' | 'card' | undefined;
20
+ /** 自定义操作按钮区域插槽 */
21
+ actions?: Snippet | undefined;
22
+ /** 关联业务信息或补充详情插槽(如订单明细卡片、审批人流水等) */
23
+ children?: Snippet | undefined;
24
+ class?: string | undefined;
25
+ }
26
+ declare const ResultPage: import("svelte").Component<ResultPageProps, {}, "">;
27
+ type ResultPage = ReturnType<typeof ResultPage>;
28
+ export default ResultPage;