@svadmin/ui 0.121.0 → 0.122.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 +204 -11
- package/dist/app.theme.css +204 -11
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/AnnouncementBanner.svelte +314 -0
- package/dist/components/AnnouncementBanner.svelte.d.ts +45 -0
- package/dist/components/AsyncExportModal.svelte +551 -0
- package/dist/components/AsyncExportModal.svelte.d.ts +50 -0
- package/dist/components/AudioFeedbackProvider.svelte +131 -0
- package/dist/components/AudioFeedbackProvider.svelte.d.ts +11 -0
- package/dist/components/AuditLogViewer.svelte +1 -1
- package/dist/components/CanvasAnnotation.svelte +1 -1
- package/dist/components/ColumnFilterBuilder.svelte +135 -0
- package/dist/components/ColumnFilterBuilder.svelte.d.ts +20 -0
- package/dist/components/ColumnSettings.svelte +1 -1
- package/dist/components/ColumnVisibilityDrawer.svelte +541 -0
- package/dist/components/ColumnVisibilityDrawer.svelte.d.ts +16 -0
- package/dist/components/ConcurrentConflictModal.svelte +7 -7
- package/dist/components/ConversionFunnel.svelte +154 -0
- package/dist/components/ConversionFunnel.svelte.d.ts +22 -0
- package/dist/components/CronExpressionBuilder.svelte +1 -1
- package/dist/components/DecisionTable.svelte +1 -1
- package/dist/components/DevTools.svelte +1 -1
- package/dist/components/DraggableRowTable.svelte +1 -1
- package/dist/components/DualApprovalGate.svelte +418 -0
- package/dist/components/DualApprovalGate.svelte.d.ts +39 -0
- package/dist/components/EditableTable.svelte +1 -1
- package/dist/components/ExcelImportWizard.svelte +2 -2
- package/dist/components/GlobalShortcuts.svelte +1 -1
- package/dist/components/ImageCropper.svelte +1 -1
- package/dist/components/ImportWizard.svelte +1 -1
- package/dist/components/JsonSchemaForm.svelte +1 -1
- package/dist/components/JsonViewer.svelte +11 -11
- package/dist/components/KeyboardShortcutsModal.svelte +362 -0
- package/dist/components/KeyboardShortcutsModal.svelte.d.ts +22 -0
- package/dist/components/KpiCard.svelte +5 -5
- package/dist/components/MasterDetailView.svelte +1 -1
- package/dist/components/MetricGrid.svelte +2 -2
- package/dist/components/MicroAppBridge.svelte +59 -0
- package/dist/components/MicroAppBridge.svelte.d.ts +11 -0
- package/dist/components/OfflineSyncBanner.svelte +1 -1
- package/dist/components/OrgChart.svelte +1 -1
- package/dist/components/OrgTreePicker.svelte +1 -1
- package/dist/components/OtpInput.svelte +5 -5
- package/dist/components/PdfDocumentViewer.svelte +2 -2
- package/dist/components/PivotDrilldownModal.svelte +6 -6
- package/dist/components/PivotTable.svelte +1 -1
- package/dist/components/PricingCard.svelte +1 -1
- package/dist/components/PricingTable.svelte +1 -1
- package/dist/components/PrintableBill.svelte +2 -2
- package/dist/components/PrintableReportLayout.svelte +259 -0
- package/dist/components/PrintableReportLayout.svelte.d.ts +32 -0
- package/dist/components/ProSkeleton.svelte +6 -6
- package/dist/components/ResultPage.svelte +2 -2
- package/dist/components/SafeDeleteConfirm.svelte +5 -5
- package/dist/components/SankeyChart.svelte +111 -0
- package/dist/components/SankeyChart.svelte.d.ts +22 -0
- package/dist/components/SchemaVisualModeler.svelte +336 -0
- package/dist/components/SchemaVisualModeler.svelte.d.ts +17 -0
- package/dist/components/SensitiveDataMask.svelte +81 -22
- package/dist/components/SensitiveDataMask.svelte.d.ts +15 -10
- package/dist/components/SessionTimeoutGuard.svelte +154 -0
- package/dist/components/SessionTimeoutGuard.svelte.d.ts +25 -0
- package/dist/components/SignaturePad.svelte +1 -1
- package/dist/components/SliderCaptcha.svelte +1 -1
- package/dist/components/SplitPaneLayout.svelte +1 -1
- package/dist/components/SpreadsheetView.svelte +1 -1
- package/dist/components/StepForm.svelte +1 -1
- package/dist/components/StepWizard.svelte +513 -0
- package/dist/components/StepWizard.svelte.d.ts +49 -0
- package/dist/components/TableClipboardManager.svelte +307 -0
- package/dist/components/TableClipboardManager.svelte.d.ts +13 -0
- package/dist/components/TaskCenter.svelte +9 -9
- package/dist/components/TextDiffViewer.svelte +613 -0
- package/dist/components/TextDiffViewer.svelte.d.ts +39 -0
- package/dist/components/TreeTransfer.svelte +1 -1
- package/dist/components/UnsavedChangesGuard.svelte +5 -5
- package/dist/components/UsageCard.svelte +1 -1
- package/dist/components/VersionDiffViewer.svelte +1 -1
- package/dist/components/VirtualTable.svelte +1 -1
- package/dist/components/VirtualTreeSelect.svelte +1 -1
- package/dist/components/WorkflowDesigner.svelte +3 -3
- package/dist/components/WorkflowProcessCard.svelte +1 -1
- package/dist/components/WorkflowStepper.svelte +250 -0
- package/dist/components/WorkflowStepper.svelte.d.ts +27 -0
- package/dist/components/charts/GaugeChart.svelte +1 -1
- package/dist/components/useAudioAlert.d.svelte.ts +1 -0
- package/dist/components/useAudioAlert.svelte.d.ts +13 -0
- package/dist/components/useAudioAlert.svelte.js +90 -0
- package/dist/components/useHotkeys.d.svelte.ts +1 -0
- package/dist/components/useHotkeys.svelte.d.ts +44 -0
- package/dist/components/useHotkeys.svelte.js +190 -0
- package/dist/components/useMicroAppEvent.d.svelte.ts +1 -0
- package/dist/components/useMicroAppEvent.svelte.d.ts +16 -0
- package/dist/components/useMicroAppEvent.svelte.js +61 -0
- package/dist/components/usePrintExport.d.svelte.ts +1 -0
- package/dist/components/usePrintExport.svelte.d.ts +11 -0
- package/dist/components/usePrintExport.svelte.js +45 -0
- package/dist/components/useSessionTimeout.d.svelte.ts +1 -0
- package/dist/components/useSessionTimeout.svelte.d.ts +28 -0
- package/dist/components/useSessionTimeout.svelte.js +182 -0
- package/dist/components/useTableClipboard.d.svelte.ts +1 -0
- package/dist/components/useTableClipboard.svelte.d.ts +28 -0
- package/dist/components/useTableClipboard.svelte.js +116 -0
- package/dist/index.d.ts +28 -9
- package/dist/index.js +35 -0
- package/package.json +1 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Filter, ArrowDown } from '@lucide/svelte';
|
|
3
|
+
import { useTranslation } from '@svadmin/core/i18n';
|
|
4
|
+
import { cn } from '../utils.js';
|
|
5
|
+
|
|
6
|
+
export interface FunnelStageItem {
|
|
7
|
+
id: string;
|
|
8
|
+
label: string;
|
|
9
|
+
value: number;
|
|
10
|
+
description?: string | undefined;
|
|
11
|
+
color?: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ConversionFunnelProps {
|
|
15
|
+
stages: FunnelStageItem[];
|
|
16
|
+
title?: string | undefined;
|
|
17
|
+
description?: string | undefined;
|
|
18
|
+
showPercentages?: boolean | undefined;
|
|
19
|
+
showDropoff?: boolean | undefined;
|
|
20
|
+
valuePrefix?: string | undefined;
|
|
21
|
+
valueSuffix?: string | undefined;
|
|
22
|
+
height?: number | undefined;
|
|
23
|
+
class?: string | undefined;
|
|
24
|
+
onSelectStage?: ((stage: FunnelStageItem) => void) | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let {
|
|
28
|
+
stages = [],
|
|
29
|
+
title,
|
|
30
|
+
description,
|
|
31
|
+
showPercentages = true,
|
|
32
|
+
showDropoff = true,
|
|
33
|
+
valuePrefix = '',
|
|
34
|
+
valueSuffix = '',
|
|
35
|
+
height = 360,
|
|
36
|
+
class: className = '',
|
|
37
|
+
onSelectStage,
|
|
38
|
+
}: ConversionFunnelProps = $props();
|
|
39
|
+
void height;
|
|
40
|
+
|
|
41
|
+
const i18n = useTranslation();
|
|
42
|
+
const chinese = $derived(i18n.locale.startsWith('zh'));
|
|
43
|
+
|
|
44
|
+
let hoveredStageId = $state<string | null>(null);
|
|
45
|
+
|
|
46
|
+
const maxValue = $derived(
|
|
47
|
+
stages.length > 0 ? Math.max(...stages.map((s) => s.value), 1) : 1,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const computedStages = $derived.by(() => {
|
|
51
|
+
return stages.map((stage, idx) => {
|
|
52
|
+
const prev = stages[idx - 1];
|
|
53
|
+
const rateFromTop = Math.round((stage.value / maxValue) * 100);
|
|
54
|
+
const dropoff = prev && prev.value > 0 ? Math.round(((prev.value - stage.value) / prev.value) * 100) : 0;
|
|
55
|
+
return {
|
|
56
|
+
...stage,
|
|
57
|
+
rateFromTop,
|
|
58
|
+
dropoff: Math.max(0, dropoff),
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const resolvedTitle = $derived(title ?? (chinese ? '业务链路转化漏斗' : 'Conversion Funnel'));
|
|
64
|
+
const resolvedDesc = $derived(
|
|
65
|
+
description ?? (chinese ? '各阶段用户留存、流失率与端到端绝对转化分析' : 'Stage-by-stage retention and drop-off rate metrics'),
|
|
66
|
+
);
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<div
|
|
70
|
+
data-svadmin-component="ConversionFunnel"
|
|
71
|
+
class={cn(
|
|
72
|
+
'w-full rounded-md border border-border bg-card text-card-foreground shadow-xs p-6 space-y-4',
|
|
73
|
+
className,
|
|
74
|
+
)}
|
|
75
|
+
>
|
|
76
|
+
<div class="flex items-center justify-between border-b border-border/60 pb-3">
|
|
77
|
+
<div class="flex items-center gap-2.5">
|
|
78
|
+
<div class="flex h-8 w-8 items-center justify-center rounded-sm bg-primary/10 text-primary border border-primary/20">
|
|
79
|
+
<Filter class="h-4 w-4" />
|
|
80
|
+
</div>
|
|
81
|
+
<div>
|
|
82
|
+
<h3 class="text-sm font-semibold text-foreground">{resolvedTitle}</h3>
|
|
83
|
+
<p class="text-xs text-muted-foreground">{resolvedDesc}</p>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
|
|
88
|
+
<!-- Funnel Visual Stack -->
|
|
89
|
+
<div class="space-y-2 py-2">
|
|
90
|
+
{#each computedStages as stage, idx (stage.id)}
|
|
91
|
+
{@const isHovered = hoveredStageId === stage.id}
|
|
92
|
+
{@const widthPct = Math.max(15, Math.min(100, (stage.value / maxValue) * 100))}
|
|
93
|
+
<div
|
|
94
|
+
class="group relative flex flex-col items-center"
|
|
95
|
+
onmouseenter={() => (hoveredStageId = stage.id)}
|
|
96
|
+
onmouseleave={() => (hoveredStageId = null)}
|
|
97
|
+
role="button"
|
|
98
|
+
tabindex="0"
|
|
99
|
+
onclick={() => onSelectStage?.(stage)}
|
|
100
|
+
onkeydown={(e) => e.key === 'Enter' && onSelectStage?.(stage)}
|
|
101
|
+
>
|
|
102
|
+
<!-- Funnel Bar Segment -->
|
|
103
|
+
<div
|
|
104
|
+
class={cn(
|
|
105
|
+
'relative flex h-14 items-center justify-between px-4 rounded-sm transition-all duration-200 cursor-pointer shadow-xs border',
|
|
106
|
+
isHovered ? 'ring-2 ring-primary border-primary scale-[1.01]' : 'border-border/80 hover:border-primary/50',
|
|
107
|
+
)}
|
|
108
|
+
style="width: {widthPct}%; background: {stage.color ?? 'var(--card)'};"
|
|
109
|
+
>
|
|
110
|
+
<div class="flex items-center gap-2 truncate">
|
|
111
|
+
<span class="flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-primary/15 text-primary text-xs font-bold">
|
|
112
|
+
{idx + 1}
|
|
113
|
+
</span>
|
|
114
|
+
<span class="text-xs font-semibold text-foreground truncate">{stage.label}</span>
|
|
115
|
+
</div>
|
|
116
|
+
|
|
117
|
+
<div class="flex items-center gap-3 shrink-0 font-mono text-xs">
|
|
118
|
+
<span class="font-bold text-foreground">
|
|
119
|
+
{valuePrefix}{stage.value.toLocaleString()}{valueSuffix}
|
|
120
|
+
</span>
|
|
121
|
+
{#if showPercentages}
|
|
122
|
+
<span class="rounded bg-primary/10 px-1.5 py-0.5 text-xs font-medium text-primary">
|
|
123
|
+
{stage.rateFromTop}%
|
|
124
|
+
</span>
|
|
125
|
+
{/if}
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<!-- Drop-off Transition Pill between stages -->
|
|
130
|
+
{#if idx < computedStages.length - 1 && showDropoff}
|
|
131
|
+
{@const nextStage = computedStages[idx + 1]}
|
|
132
|
+
{#if nextStage}
|
|
133
|
+
<div class="my-1 flex items-center gap-1.5 text-xs text-muted-foreground/80 font-mono">
|
|
134
|
+
<ArrowDown class="h-3 w-3 text-muted-foreground/60" />
|
|
135
|
+
<span class="text-destructive font-medium">-{nextStage.dropoff}% 流失</span>
|
|
136
|
+
<span>({valuePrefix}{(stage.value - nextStage.value).toLocaleString()})</span>
|
|
137
|
+
</div>
|
|
138
|
+
{/if}
|
|
139
|
+
{/if}
|
|
140
|
+
</div>
|
|
141
|
+
{/each}
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
<!-- Overall Summary Metrics Footer -->
|
|
145
|
+
{#if computedStages.length >= 2}
|
|
146
|
+
{@const firstVal = computedStages[0]?.value ?? 1}
|
|
147
|
+
{@const lastVal = computedStages[computedStages.length - 1]?.value ?? 0}
|
|
148
|
+
{@const endToEndRate = Math.round((lastVal / firstVal) * 100)}
|
|
149
|
+
<div class="flex items-center justify-between border-t border-border/60 pt-3 text-xs text-muted-foreground bg-muted/20 px-3 py-2 rounded-lg">
|
|
150
|
+
<span>{chinese ? '端到端综合留存转化率:' : 'End-to-End Overall Conversion:'}</span>
|
|
151
|
+
<span class="font-bold font-mono text-foreground">{endToEndRate}%</span>
|
|
152
|
+
</div>
|
|
153
|
+
{/if}
|
|
154
|
+
</div>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface FunnelStageItem {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
value: number;
|
|
5
|
+
description?: string | undefined;
|
|
6
|
+
color?: string | undefined;
|
|
7
|
+
}
|
|
8
|
+
export interface ConversionFunnelProps {
|
|
9
|
+
stages: FunnelStageItem[];
|
|
10
|
+
title?: string | undefined;
|
|
11
|
+
description?: string | undefined;
|
|
12
|
+
showPercentages?: boolean | undefined;
|
|
13
|
+
showDropoff?: boolean | undefined;
|
|
14
|
+
valuePrefix?: string | undefined;
|
|
15
|
+
valueSuffix?: string | undefined;
|
|
16
|
+
height?: number | undefined;
|
|
17
|
+
class?: string | undefined;
|
|
18
|
+
onSelectStage?: ((stage: FunnelStageItem) => void) | undefined;
|
|
19
|
+
}
|
|
20
|
+
declare const ConversionFunnel: import("svelte").Component<ConversionFunnelProps, {}, "">;
|
|
21
|
+
type ConversionFunnel = ReturnType<typeof ConversionFunnel>;
|
|
22
|
+
export default ConversionFunnel;
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
|
|
118
118
|
<div
|
|
119
119
|
data-svadmin-component="CronExpressionBuilder"
|
|
120
|
-
class={cn('rounded-
|
|
120
|
+
class={cn('rounded-md border border-border bg-card p-4 shadow-xs text-xs space-y-4 font-sans', className)}
|
|
121
121
|
>
|
|
122
122
|
<!-- Header: Cron Display & Copy -->
|
|
123
123
|
<div class="flex flex-wrap items-center justify-between gap-3 pb-3 border-b border-border/60">
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
}
|
|
123
123
|
</script>
|
|
124
124
|
|
|
125
|
-
<div class={cn('rounded-
|
|
125
|
+
<div class={cn('rounded-md border border-border bg-card p-4 shadow-xs text-xs space-y-4', className)}>
|
|
126
126
|
<!-- Header -->
|
|
127
127
|
<div class="flex flex-wrap items-center justify-between gap-2 pb-2 border-b border-border/60">
|
|
128
128
|
<div class="flex items-center gap-2">
|
|
@@ -533,7 +533,7 @@
|
|
|
533
533
|
|
|
534
534
|
{#if visible}
|
|
535
535
|
<div
|
|
536
|
-
class="fixed bottom-0 right-4 z-[9999] w-[560px] max-w-[95vw] rounded-t-
|
|
536
|
+
class="fixed bottom-0 right-4 z-[9999] w-[560px] max-w-[95vw] rounded-t-md border border-b-0 bg-card shadow-[var(--shadow-overlay)] text-[0.8125rem] overflow-hidden"
|
|
537
537
|
class:svadmin-devtools--collapsed-width={collapsed}
|
|
538
538
|
class:svadmin-devtools--collapsed-min-width={collapsed}
|
|
539
539
|
transition:fly={{ y: 400, duration: 300 }}
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
}
|
|
67
67
|
</script>
|
|
68
68
|
|
|
69
|
-
<div class={cn('w-full rounded-
|
|
69
|
+
<div class={cn('w-full rounded-md border border-border bg-card shadow-xs overflow-hidden text-xs', className)}>
|
|
70
70
|
<table class="w-full text-left border-collapse">
|
|
71
71
|
<thead class="bg-muted/40 font-semibold text-muted-foreground border-b border-border/60 select-none">
|
|
72
72
|
<tr>
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack, type Snippet } from 'svelte';
|
|
3
|
+
import {
|
|
4
|
+
ShieldCheck,
|
|
5
|
+
Users,
|
|
6
|
+
QrCode,
|
|
7
|
+
KeyRound,
|
|
8
|
+
AlertTriangle,
|
|
9
|
+
CheckCircle2,
|
|
10
|
+
XCircle,
|
|
11
|
+
Loader2,
|
|
12
|
+
Copy,
|
|
13
|
+
Check,
|
|
14
|
+
X,
|
|
15
|
+
} from '@lucide/svelte';
|
|
16
|
+
import { useTranslation } from '@svadmin/core/i18n';
|
|
17
|
+
import { cn } from '../utils.js';
|
|
18
|
+
import { Button } from './ui/button/index.js';
|
|
19
|
+
|
|
20
|
+
export type ApprovalMode = 'onsite' | 'remote';
|
|
21
|
+
|
|
22
|
+
export interface ReviewerVerificationPayload {
|
|
23
|
+
reviewerId: string;
|
|
24
|
+
reviewerName?: string | undefined;
|
|
25
|
+
reviewerRole: string;
|
|
26
|
+
secret: string;
|
|
27
|
+
actionTitle: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface DualApprovalAuditRecord {
|
|
31
|
+
actionId: string;
|
|
32
|
+
actionTitle: string;
|
|
33
|
+
initiator?: string | undefined;
|
|
34
|
+
reviewerId: string;
|
|
35
|
+
reviewerRole: string;
|
|
36
|
+
mode: ApprovalMode;
|
|
37
|
+
approvedAt: string;
|
|
38
|
+
auditHash: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface DualApprovalGateProps {
|
|
42
|
+
open?: boolean | undefined;
|
|
43
|
+
actionTitle: string;
|
|
44
|
+
actionDescription?: string | undefined;
|
|
45
|
+
actionPayload?: Record<string, unknown> | undefined;
|
|
46
|
+
requiredRole?: string | undefined;
|
|
47
|
+
defaultMode?: ApprovalMode | undefined;
|
|
48
|
+
allowModeSwitch?: boolean | undefined;
|
|
49
|
+
verifyReviewer?: ((payload: ReviewerVerificationPayload) => Promise<boolean | undefined> | boolean | undefined) | undefined;
|
|
50
|
+
onApproved?: ((record: DualApprovalAuditRecord) => void) | undefined;
|
|
51
|
+
onRejected?: ((reason?: string) => void) | undefined;
|
|
52
|
+
class?: string | undefined;
|
|
53
|
+
trigger?: Snippet<[{ openModal: () => void }]> | undefined;
|
|
54
|
+
children?: Snippet | undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let {
|
|
58
|
+
open = $bindable(false),
|
|
59
|
+
actionTitle,
|
|
60
|
+
actionDescription,
|
|
61
|
+
actionPayload,
|
|
62
|
+
requiredRole = '合规主管 / Supervisor Admin',
|
|
63
|
+
defaultMode = 'onsite',
|
|
64
|
+
allowModeSwitch = true,
|
|
65
|
+
verifyReviewer,
|
|
66
|
+
onApproved,
|
|
67
|
+
onRejected,
|
|
68
|
+
class: className = '',
|
|
69
|
+
trigger,
|
|
70
|
+
children,
|
|
71
|
+
}: DualApprovalGateProps = $props();
|
|
72
|
+
|
|
73
|
+
const i18n = useTranslation();
|
|
74
|
+
const chinese = $derived(i18n.locale.startsWith('zh'));
|
|
75
|
+
|
|
76
|
+
let activeMode = $state<ApprovalMode>(untrack(() => defaultMode));
|
|
77
|
+
let reviewerId = $state('');
|
|
78
|
+
let reviewerName = $state('');
|
|
79
|
+
let reviewerSecret = $state('');
|
|
80
|
+
let isVerifying = $state(false);
|
|
81
|
+
let errorMessage = $state<string | null>(null);
|
|
82
|
+
let isCopied = $state(false);
|
|
83
|
+
|
|
84
|
+
const actionId = $derived(`action-${Math.random().toString(36).slice(2, 9)}`);
|
|
85
|
+
const remoteReviewUrl = $derived(
|
|
86
|
+
typeof window !== 'undefined'
|
|
87
|
+
? `${window.location.origin}/approval/dual-review?id=${actionId}`
|
|
88
|
+
: `https://example.com/approval/dual-review?id=${actionId}`,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
function generateAuditHash(): string {
|
|
92
|
+
const raw = `${actionId}:${reviewerId}:${Date.now()}:${JSON.stringify(actionPayload ?? {})}`;
|
|
93
|
+
let hash = 0;
|
|
94
|
+
for (let i = 0; i < raw.length; i++) {
|
|
95
|
+
hash = (hash << 5) - hash + raw.charCodeAt(i);
|
|
96
|
+
hash |= 0;
|
|
97
|
+
}
|
|
98
|
+
return `SHA-${Math.abs(hash).toString(16).padStart(8, '0')}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function handleOnsiteSubmit() {
|
|
102
|
+
if (!reviewerId.trim() || !reviewerSecret.trim()) {
|
|
103
|
+
errorMessage = chinese ? '请完整填写复核人员工号与核验口令' : 'Please provide reviewer ID and authorization secret';
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
isVerifying = true;
|
|
108
|
+
errorMessage = null;
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
if (verifyReviewer) {
|
|
112
|
+
const passed = await verifyReviewer({
|
|
113
|
+
reviewerId: reviewerId.trim(),
|
|
114
|
+
reviewerName: reviewerName.trim() || undefined,
|
|
115
|
+
reviewerRole: requiredRole,
|
|
116
|
+
secret: reviewerSecret.trim(),
|
|
117
|
+
actionTitle,
|
|
118
|
+
});
|
|
119
|
+
if (passed === false) {
|
|
120
|
+
errorMessage = chinese ? '复核人鉴权未通过,请核对权限或密码' : 'Reviewer authorization failed';
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const auditRecord: DualApprovalAuditRecord = {
|
|
126
|
+
actionId,
|
|
127
|
+
actionTitle,
|
|
128
|
+
reviewerId: reviewerId.trim(),
|
|
129
|
+
reviewerRole: requiredRole,
|
|
130
|
+
mode: 'onsite',
|
|
131
|
+
approvedAt: new Date().toISOString(),
|
|
132
|
+
auditHash: generateAuditHash(),
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
open = false;
|
|
136
|
+
onApproved?.(auditRecord);
|
|
137
|
+
resetState();
|
|
138
|
+
} catch (err) {
|
|
139
|
+
errorMessage = err instanceof Error ? err.message : String(err);
|
|
140
|
+
} finally {
|
|
141
|
+
isVerifying = false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function handleCancel() {
|
|
146
|
+
open = false;
|
|
147
|
+
onRejected?.('User canceled dual approval flow');
|
|
148
|
+
resetState();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function resetState() {
|
|
152
|
+
reviewerId = '';
|
|
153
|
+
reviewerName = '';
|
|
154
|
+
reviewerSecret = '';
|
|
155
|
+
errorMessage = null;
|
|
156
|
+
isVerifying = false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function handleCopyLink() {
|
|
160
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard) {
|
|
161
|
+
await navigator.clipboard.writeText(remoteReviewUrl);
|
|
162
|
+
isCopied = true;
|
|
163
|
+
setTimeout(() => {
|
|
164
|
+
isCopied = false;
|
|
165
|
+
}, 1500);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const resolvedDesc = $derived(
|
|
170
|
+
actionDescription ??
|
|
171
|
+
(chinese
|
|
172
|
+
? '本操作涉及高危特权变更或资金资产,系统已开启双人双锁(Two-Person Rule)联签保护,须由第二位授权人员复核后方可执行。'
|
|
173
|
+
: 'This operation involves high-privilege changes. Dual-person approval (Two-Person Rule) is strictly required before execution.'),
|
|
174
|
+
);
|
|
175
|
+
</script>
|
|
176
|
+
|
|
177
|
+
{#if trigger}
|
|
178
|
+
{@render trigger({ openModal: () => (open = true) })}
|
|
179
|
+
{:else if children}
|
|
180
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
181
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
182
|
+
<div onclick={() => (open = true)} class="inline-block">
|
|
183
|
+
{@render children()}
|
|
184
|
+
</div>
|
|
185
|
+
{/if}
|
|
186
|
+
|
|
187
|
+
{#if open}
|
|
188
|
+
<div
|
|
189
|
+
role="dialog"
|
|
190
|
+
aria-modal="true"
|
|
191
|
+
aria-labelledby="dual-approval-title"
|
|
192
|
+
aria-describedby="dual-approval-desc"
|
|
193
|
+
data-svadmin-component="DualApprovalGate"
|
|
194
|
+
class="fixed inset-0 z-50 flex items-center justify-center p-4 bg-background/80 backdrop-blur-sm"
|
|
195
|
+
>
|
|
196
|
+
<!-- Modal Card -->
|
|
197
|
+
<div
|
|
198
|
+
class={cn(
|
|
199
|
+
'relative z-10 w-full max-w-lg rounded-md border border-border bg-card p-6 text-card-foreground shadow-[var(--shadow-overlay)] animate-in fade-in zoom-in-95 duration-150',
|
|
200
|
+
className,
|
|
201
|
+
)}
|
|
202
|
+
>
|
|
203
|
+
<!-- Header -->
|
|
204
|
+
<div class="flex items-start justify-between border-b border-border/60 pb-4">
|
|
205
|
+
<div class="flex items-center gap-3">
|
|
206
|
+
<div class="flex h-11 w-11 shrink-0 items-center justify-center rounded-sm bg-destructive/15 text-destructive border border-destructive/20">
|
|
207
|
+
<ShieldCheck class="h-6 w-6" />
|
|
208
|
+
</div>
|
|
209
|
+
<div>
|
|
210
|
+
<div class="inline-flex items-center gap-1.5 rounded-full bg-destructive/10 px-2 py-0.5 text-xs font-semibold text-destructive mb-1">
|
|
211
|
+
<AlertTriangle class="h-3 w-3" />
|
|
212
|
+
<span>{chinese ? '特权高危操作 · 双人双锁' : 'Two-Person Rule Required'}</span>
|
|
213
|
+
</div>
|
|
214
|
+
<h3 id="dual-approval-title" class="text-base font-bold text-foreground">
|
|
215
|
+
{actionTitle}
|
|
216
|
+
</h3>
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
|
|
220
|
+
<button
|
|
221
|
+
type="button"
|
|
222
|
+
onclick={handleCancel}
|
|
223
|
+
class="rounded-lg p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors"
|
|
224
|
+
aria-label="Close"
|
|
225
|
+
>
|
|
226
|
+
<X class="h-4 w-4" />
|
|
227
|
+
</button>
|
|
228
|
+
</div>
|
|
229
|
+
|
|
230
|
+
<!-- Description Banner -->
|
|
231
|
+
<p id="dual-approval-desc" class="text-xs text-muted-foreground leading-relaxed my-3">
|
|
232
|
+
{resolvedDesc}
|
|
233
|
+
</p>
|
|
234
|
+
|
|
235
|
+
<!-- Mode Switcher Tabs -->
|
|
236
|
+
{#if allowModeSwitch}
|
|
237
|
+
<div class="flex rounded-lg border border-border bg-muted/40 p-1 mb-4 text-xs">
|
|
238
|
+
<button
|
|
239
|
+
type="button"
|
|
240
|
+
onclick={() => (activeMode = 'onsite')}
|
|
241
|
+
class={cn(
|
|
242
|
+
'flex-1 flex items-center justify-center gap-1.5 py-1.5 rounded-md font-medium transition-all',
|
|
243
|
+
activeMode === 'onsite' ? 'bg-card text-foreground shadow-xs' : 'text-muted-foreground hover:text-foreground',
|
|
244
|
+
)}
|
|
245
|
+
>
|
|
246
|
+
<KeyRound class="h-3.5 w-3.5" />
|
|
247
|
+
<span>{chinese ? '当面同台复核' : 'Onsite Review'}</span>
|
|
248
|
+
</button>
|
|
249
|
+
<button
|
|
250
|
+
type="button"
|
|
251
|
+
onclick={() => (activeMode = 'remote')}
|
|
252
|
+
class={cn(
|
|
253
|
+
'flex-1 flex items-center justify-center gap-1.5 py-1.5 rounded-md font-medium transition-all',
|
|
254
|
+
activeMode === 'remote' ? 'bg-card text-foreground shadow-xs' : 'text-muted-foreground hover:text-foreground',
|
|
255
|
+
)}
|
|
256
|
+
>
|
|
257
|
+
<QrCode class="h-3.5 w-3.5" />
|
|
258
|
+
<span>{chinese ? '扫码/链接远程复核' : 'Remote QR Review'}</span>
|
|
259
|
+
</button>
|
|
260
|
+
</div>
|
|
261
|
+
{/if}
|
|
262
|
+
|
|
263
|
+
<!-- Error alert -->
|
|
264
|
+
{#if errorMessage}
|
|
265
|
+
<div role="alert" class="flex items-center gap-2 rounded-lg border border-destructive/30 bg-destructive/10 p-3 text-xs text-destructive mb-4">
|
|
266
|
+
<XCircle class="h-4 w-4 shrink-0" />
|
|
267
|
+
<span>{errorMessage}</span>
|
|
268
|
+
</div>
|
|
269
|
+
{/if}
|
|
270
|
+
|
|
271
|
+
{#if activeMode === 'onsite'}
|
|
272
|
+
<!-- Onsite Form -->
|
|
273
|
+
<div class="space-y-3.5 text-xs">
|
|
274
|
+
<div>
|
|
275
|
+
<label for="reviewer-role" class="block font-medium text-foreground mb-1">
|
|
276
|
+
{chinese ? '指定复核角色' : 'Required Role'}
|
|
277
|
+
</label>
|
|
278
|
+
<div id="reviewer-role" class="flex items-center gap-1.5 rounded-md border border-border bg-muted/30 px-3 py-1.5 text-muted-foreground font-mono">
|
|
279
|
+
<Users class="h-3.5 w-3.5 text-primary" />
|
|
280
|
+
<span>{requiredRole}</span>
|
|
281
|
+
</div>
|
|
282
|
+
</div>
|
|
283
|
+
|
|
284
|
+
<div class="grid grid-cols-2 gap-3">
|
|
285
|
+
<div>
|
|
286
|
+
<label for="reviewer-id" class="block font-medium text-foreground mb-1">
|
|
287
|
+
{chinese ? '复核人工号/账号 *' : 'Reviewer ID *'}
|
|
288
|
+
</label>
|
|
289
|
+
<input
|
|
290
|
+
id="reviewer-id"
|
|
291
|
+
type="text"
|
|
292
|
+
bind:value={reviewerId}
|
|
293
|
+
placeholder={chinese ? '例如: MGR-8801' : 'E.g. ADM-001'}
|
|
294
|
+
class="h-8.5 w-full rounded-md border border-input bg-background px-3 text-xs focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
295
|
+
/>
|
|
296
|
+
</div>
|
|
297
|
+
<div>
|
|
298
|
+
<label for="reviewer-name" class="block font-medium text-foreground mb-1">
|
|
299
|
+
{chinese ? '复核人姓名 (选填)' : 'Name (Optional)'}
|
|
300
|
+
</label>
|
|
301
|
+
<input
|
|
302
|
+
id="reviewer-name"
|
|
303
|
+
type="text"
|
|
304
|
+
bind:value={reviewerName}
|
|
305
|
+
placeholder={chinese ? '真实姓名' : 'Reviewer name'}
|
|
306
|
+
class="h-8.5 w-full rounded-md border border-input bg-background px-3 text-xs focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
307
|
+
/>
|
|
308
|
+
</div>
|
|
309
|
+
</div>
|
|
310
|
+
|
|
311
|
+
<div>
|
|
312
|
+
<label for="reviewer-secret" class="block font-medium text-foreground mb-1">
|
|
313
|
+
{chinese ? '复核人口令 / 动态 2FA 验证码 *' : 'Reviewer Password / 2FA OTP *'}
|
|
314
|
+
</label>
|
|
315
|
+
<input
|
|
316
|
+
id="reviewer-secret"
|
|
317
|
+
type="password"
|
|
318
|
+
bind:value={reviewerSecret}
|
|
319
|
+
placeholder={chinese ? '输入复核人独立认证口令' : 'Enter authorization secret'}
|
|
320
|
+
class="h-8.5 w-full rounded-md border border-input bg-background px-3 text-xs font-mono focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
321
|
+
/>
|
|
322
|
+
</div>
|
|
323
|
+
</div>
|
|
324
|
+
{:else}
|
|
325
|
+
<!-- Remote Review QR Code -->
|
|
326
|
+
<div class="flex flex-col items-center justify-center p-4 border border-dashed border-border rounded-md bg-muted/20 text-center space-y-3">
|
|
327
|
+
<div class="flex h-36 w-36 items-center justify-center rounded-sm bg-background border border-border shadow-xs text-xs text-muted-foreground p-3">
|
|
328
|
+
<div class="space-y-1 text-center">
|
|
329
|
+
<QrCode class="h-16 w-16 mx-auto text-primary/80" />
|
|
330
|
+
<div class="text-xs font-mono">{chinese ? '复核专属二维码' : 'Approval QR'}</div>
|
|
331
|
+
</div>
|
|
332
|
+
</div>
|
|
333
|
+
|
|
334
|
+
<div class="space-y-1 max-w-sm">
|
|
335
|
+
<p class="text-xs font-medium text-foreground">
|
|
336
|
+
{chinese ? '请联系主管使用移动端扫描上方二维码或点击链接复核' : 'Share link with supervisor to sign remotely'}
|
|
337
|
+
</p>
|
|
338
|
+
<div class="flex items-center gap-1.5 pt-1">
|
|
339
|
+
<input
|
|
340
|
+
readonly
|
|
341
|
+
value={remoteReviewUrl}
|
|
342
|
+
class="h-7 w-full rounded border border-border bg-background px-2 text-xs font-mono text-muted-foreground"
|
|
343
|
+
/>
|
|
344
|
+
<Button size="sm" variant="outline" class="h-7 px-2 shrink-0" onclick={handleCopyLink}>
|
|
345
|
+
{#if isCopied}
|
|
346
|
+
<Check class="h-3.5 w-3.5 text-success" />
|
|
347
|
+
{:else}
|
|
348
|
+
<Copy class="h-3.5 w-3.5" />
|
|
349
|
+
{/if}
|
|
350
|
+
</Button>
|
|
351
|
+
</div>
|
|
352
|
+
</div>
|
|
353
|
+
</div>
|
|
354
|
+
{/if}
|
|
355
|
+
|
|
356
|
+
<!-- Footer Actions -->
|
|
357
|
+
<div class="mt-6 flex items-center justify-between border-t border-border/60 pt-4">
|
|
358
|
+
<span class="text-xs text-muted-foreground font-mono">
|
|
359
|
+
ID: {actionId}
|
|
360
|
+
</span>
|
|
361
|
+
|
|
362
|
+
<div class="flex items-center gap-2">
|
|
363
|
+
<Button
|
|
364
|
+
type="button"
|
|
365
|
+
variant="ghost"
|
|
366
|
+
size="sm"
|
|
367
|
+
onclick={handleCancel}
|
|
368
|
+
disabled={isVerifying}
|
|
369
|
+
>
|
|
370
|
+
{chinese ? '放弃操作' : 'Cancel'}
|
|
371
|
+
</Button>
|
|
372
|
+
|
|
373
|
+
{#if activeMode === 'onsite'}
|
|
374
|
+
<Button
|
|
375
|
+
type="button"
|
|
376
|
+
size="sm"
|
|
377
|
+
onclick={handleOnsiteSubmit}
|
|
378
|
+
disabled={isVerifying || !reviewerId || !reviewerSecret}
|
|
379
|
+
class="gap-1.5 min-w-28 bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
|
380
|
+
>
|
|
381
|
+
{#if isVerifying}
|
|
382
|
+
<Loader2 class="h-3.5 w-3.5 animate-spin" />
|
|
383
|
+
<span>{chinese ? '联签核验中...' : 'Verifying...'}</span>
|
|
384
|
+
{:else}
|
|
385
|
+
<ShieldCheck class="h-3.5 w-3.5" />
|
|
386
|
+
<span>{chinese ? '确认双人联签' : 'Dual Approve'}</span>
|
|
387
|
+
{/if}
|
|
388
|
+
</Button>
|
|
389
|
+
{:else}
|
|
390
|
+
<Button
|
|
391
|
+
type="button"
|
|
392
|
+
size="sm"
|
|
393
|
+
onclick={() => {
|
|
394
|
+
// Simulate approval callback for remote mode demo
|
|
395
|
+
const auditRecord: DualApprovalAuditRecord = {
|
|
396
|
+
actionId,
|
|
397
|
+
actionTitle,
|
|
398
|
+
reviewerId: 'REMOTE-MGR',
|
|
399
|
+
reviewerRole: requiredRole,
|
|
400
|
+
mode: 'remote',
|
|
401
|
+
approvedAt: new Date().toISOString(),
|
|
402
|
+
auditHash: generateAuditHash(),
|
|
403
|
+
};
|
|
404
|
+
open = false;
|
|
405
|
+
onApproved?.(auditRecord);
|
|
406
|
+
resetState();
|
|
407
|
+
}}
|
|
408
|
+
class="gap-1.5"
|
|
409
|
+
>
|
|
410
|
+
<CheckCircle2 class="h-3.5 w-3.5 text-success" />
|
|
411
|
+
<span>{chinese ? '模拟远程复核通过' : 'Simulate Approved'}</span>
|
|
412
|
+
</Button>
|
|
413
|
+
{/if}
|
|
414
|
+
</div>
|
|
415
|
+
</div>
|
|
416
|
+
</div>
|
|
417
|
+
</div>
|
|
418
|
+
{/if}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
export type ApprovalMode = 'onsite' | 'remote';
|
|
3
|
+
export interface ReviewerVerificationPayload {
|
|
4
|
+
reviewerId: string;
|
|
5
|
+
reviewerName?: string | undefined;
|
|
6
|
+
reviewerRole: string;
|
|
7
|
+
secret: string;
|
|
8
|
+
actionTitle: string;
|
|
9
|
+
}
|
|
10
|
+
export interface DualApprovalAuditRecord {
|
|
11
|
+
actionId: string;
|
|
12
|
+
actionTitle: string;
|
|
13
|
+
initiator?: string | undefined;
|
|
14
|
+
reviewerId: string;
|
|
15
|
+
reviewerRole: string;
|
|
16
|
+
mode: ApprovalMode;
|
|
17
|
+
approvedAt: string;
|
|
18
|
+
auditHash: string;
|
|
19
|
+
}
|
|
20
|
+
export interface DualApprovalGateProps {
|
|
21
|
+
open?: boolean | undefined;
|
|
22
|
+
actionTitle: string;
|
|
23
|
+
actionDescription?: string | undefined;
|
|
24
|
+
actionPayload?: Record<string, unknown> | undefined;
|
|
25
|
+
requiredRole?: string | undefined;
|
|
26
|
+
defaultMode?: ApprovalMode | undefined;
|
|
27
|
+
allowModeSwitch?: boolean | undefined;
|
|
28
|
+
verifyReviewer?: ((payload: ReviewerVerificationPayload) => Promise<boolean | undefined> | boolean | undefined) | undefined;
|
|
29
|
+
onApproved?: ((record: DualApprovalAuditRecord) => void) | undefined;
|
|
30
|
+
onRejected?: ((reason?: string) => void) | undefined;
|
|
31
|
+
class?: string | undefined;
|
|
32
|
+
trigger?: Snippet<[{
|
|
33
|
+
openModal: () => void;
|
|
34
|
+
}]> | undefined;
|
|
35
|
+
children?: Snippet | undefined;
|
|
36
|
+
}
|
|
37
|
+
declare const DualApprovalGate: import("svelte").Component<DualApprovalGateProps, {}, "open">;
|
|
38
|
+
type DualApprovalGate = ReturnType<typeof DualApprovalGate>;
|
|
39
|
+
export default DualApprovalGate;
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
}
|
|
116
116
|
</script>
|
|
117
117
|
|
|
118
|
-
<div class={cn('space-y-3 rounded-
|
|
118
|
+
<div class={cn('space-y-3 rounded-md border border-border bg-card p-4 shadow-xs text-xs', className)}>
|
|
119
119
|
<div class="flex items-center justify-between gap-2 pb-2 border-b border-border/60">
|
|
120
120
|
<div class="font-semibold text-foreground">
|
|
121
121
|
Editable Grid <span class="text-muted-foreground font-normal">({rows.length} records)</span>
|