@svadmin/ui 0.122.0 → 0.125.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 (165) hide show
  1. package/dist/app.css +561 -4
  2. package/dist/app.theme.css +561 -4
  3. package/dist/components/AbacPolicyMatrix.svelte +356 -0
  4. package/dist/components/AbacPolicyMatrix.svelte.d.ts +30 -0
  5. package/dist/components/AboutSettings.svelte +1 -1
  6. package/dist/components/ActionPalette.svelte +272 -0
  7. package/dist/components/ActionPalette.svelte.d.ts +23 -0
  8. package/dist/components/AdminCopilotWidget.svelte +316 -0
  9. package/dist/components/AdminCopilotWidget.svelte.d.ts +33 -0
  10. package/dist/components/AnnouncementBanner.svelte +12 -1
  11. package/dist/components/AnnouncementBanner.svelte.d.ts +4 -0
  12. package/dist/components/ApiPlayground.svelte +255 -0
  13. package/dist/components/ApiPlayground.svelte.d.ts +24 -0
  14. package/dist/components/ApprovalChainBuilder.svelte +262 -0
  15. package/dist/components/ApprovalChainBuilder.svelte.d.ts +20 -0
  16. package/dist/components/ApprovalTimeline.svelte +8 -1
  17. package/dist/components/AsyncExportModal.svelte +1 -1
  18. package/dist/components/AudioFeedbackProvider.svelte +1 -1
  19. package/dist/components/AuditTrailInspector.svelte +448 -0
  20. package/dist/components/AuditTrailInspector.svelte.d.ts +44 -0
  21. package/dist/components/BatchEditModal.svelte +266 -0
  22. package/dist/components/BatchEditModal.svelte.d.ts +27 -0
  23. package/dist/components/BillingInvoiceDrawer.svelte +206 -0
  24. package/dist/components/BillingInvoiceDrawer.svelte.d.ts +30 -0
  25. package/dist/components/ChartAnnotationOverlay.svelte +228 -0
  26. package/dist/components/ChartAnnotationOverlay.svelte.d.ts +21 -0
  27. package/dist/components/ClusterTopologyGraph.svelte +317 -0
  28. package/dist/components/ClusterTopologyGraph.svelte.d.ts +31 -0
  29. package/dist/components/ColumnMappingTable.svelte +174 -0
  30. package/dist/components/ColumnMappingTable.svelte.d.ts +23 -0
  31. package/dist/components/ConversionFunnel.svelte +1 -1
  32. package/dist/components/CursorListFooter.svelte +67 -0
  33. package/dist/components/CursorListFooter.svelte.d.ts +17 -0
  34. package/dist/components/DashboardGridLayout.svelte +309 -0
  35. package/dist/components/DashboardGridLayout.svelte.d.ts +30 -0
  36. package/dist/components/DashboardLayoutStorage.svelte +278 -0
  37. package/dist/components/DashboardLayoutStorage.svelte.d.ts +23 -0
  38. package/dist/components/DataFreshnessIndicator.svelte +149 -0
  39. package/dist/components/DataFreshnessIndicator.svelte.d.ts +20 -0
  40. package/dist/components/DataImportDropzone.svelte +215 -0
  41. package/dist/components/DataImportDropzone.svelte.d.ts +24 -0
  42. package/dist/components/DataLineageGraph.svelte +203 -0
  43. package/dist/components/DataLineageGraph.svelte.d.ts +26 -0
  44. package/dist/components/DataMaskPolicyEngine.svelte +291 -0
  45. package/dist/components/DataMaskPolicyEngine.svelte.d.ts +25 -0
  46. package/dist/components/DataScopeRuleEditor.svelte +142 -0
  47. package/dist/components/DataScopeRuleEditor.svelte.d.ts +19 -0
  48. package/dist/components/DataScreenContainer.svelte +160 -0
  49. package/dist/components/DataScreenContainer.svelte.d.ts +15 -0
  50. package/dist/components/DevTools.svelte +3 -3
  51. package/dist/components/DualApprovalGate.svelte +132 -65
  52. package/dist/components/DualApprovalGate.svelte.d.ts +20 -1
  53. package/dist/components/ElectronicSealStamp.svelte +102 -0
  54. package/dist/components/ElectronicSealStamp.svelte.d.ts +14 -0
  55. package/dist/components/EnvVariableEditor.svelte +284 -0
  56. package/dist/components/EnvVariableEditor.svelte.d.ts +17 -0
  57. package/dist/components/FeatureAnnouncementModal.svelte +173 -0
  58. package/dist/components/FeatureAnnouncementModal.svelte.d.ts +21 -0
  59. package/dist/components/FilterTagBar.svelte +210 -0
  60. package/dist/components/FilterTagBar.svelte.d.ts +23 -0
  61. package/dist/components/FormulaField.svelte +149 -0
  62. package/dist/components/FormulaField.svelte.d.ts +18 -0
  63. package/dist/components/GeoScatterMap.svelte +225 -0
  64. package/dist/components/GeoScatterMap.svelte.d.ts +22 -0
  65. package/dist/components/HmacSignatureCalculator.svelte +199 -0
  66. package/dist/components/HmacSignatureCalculator.svelte.d.ts +10 -0
  67. package/dist/components/I18nLanguagePackEditor.svelte +208 -0
  68. package/dist/components/I18nLanguagePackEditor.svelte.d.ts +17 -0
  69. package/dist/components/ImportPreviewValidator.svelte +239 -0
  70. package/dist/components/ImportPreviewValidator.svelte.d.ts +26 -0
  71. package/dist/components/IncidentWarRoomDrawer.svelte +194 -0
  72. package/dist/components/IncidentWarRoomDrawer.svelte.d.ts +24 -0
  73. package/dist/components/JsonSchemaForm.svelte +4 -4
  74. package/dist/components/ListPagination.svelte +39 -3
  75. package/dist/components/LiveStreamLogViewer.svelte +185 -0
  76. package/dist/components/LiveStreamLogViewer.svelte.d.ts +21 -0
  77. package/dist/components/MasterSubTableDrawer.svelte +223 -0
  78. package/dist/components/MasterSubTableDrawer.svelte.d.ts +25 -0
  79. package/dist/components/MockDataInterceptor.svelte +292 -0
  80. package/dist/components/MockDataInterceptor.svelte.d.ts +27 -0
  81. package/dist/components/OmnibarCommandPalette.svelte +320 -0
  82. package/dist/components/OmnibarCommandPalette.svelte.d.ts +27 -0
  83. package/dist/components/PageSkeleton.svelte +19 -5
  84. package/dist/components/PageSkeleton.svelte.d.ts +5 -3
  85. package/dist/components/PeriodComparisonCard.svelte +142 -0
  86. package/dist/components/PeriodComparisonCard.svelte.d.ts +16 -0
  87. package/dist/components/PermissionSimulator.svelte +319 -0
  88. package/dist/components/PermissionSimulator.svelte.d.ts +34 -0
  89. package/dist/components/PivotMatrix.svelte +271 -0
  90. package/dist/components/PivotMatrix.svelte.d.ts +32 -0
  91. package/dist/components/PlanUsageQuotaBar.svelte +154 -0
  92. package/dist/components/PlanUsageQuotaBar.svelte.d.ts +26 -0
  93. package/dist/components/Popconfirm.svelte +20 -8
  94. package/dist/components/Popconfirm.svelte.d.ts +3 -1
  95. package/dist/components/ProSkeleton.svelte +4 -0
  96. package/dist/components/ProSkeleton.svelte.d.ts +2 -0
  97. package/dist/components/QueryAiExplainer.svelte +148 -0
  98. package/dist/components/QueryAiExplainer.svelte.d.ts +16 -0
  99. package/dist/components/QueryBuilder.svelte +456 -0
  100. package/dist/components/QueryBuilder.svelte.d.ts +33 -0
  101. package/dist/components/RolePermissionComparator.svelte +273 -0
  102. package/dist/components/RolePermissionComparator.svelte.d.ts +28 -0
  103. package/dist/components/RuleExpressionBuilder.svelte +380 -0
  104. package/dist/components/RuleExpressionBuilder.svelte.d.ts +31 -0
  105. package/dist/components/ScheduledJobManager.svelte +225 -0
  106. package/dist/components/ScheduledJobManager.svelte.d.ts +23 -0
  107. package/dist/components/ScreenAntiLeakGuard.svelte +88 -0
  108. package/dist/components/ScreenAntiLeakGuard.svelte.d.ts +12 -0
  109. package/dist/components/SecureDataExporter.svelte +296 -0
  110. package/dist/components/SecureDataExporter.svelte.d.ts +29 -0
  111. package/dist/components/ServerStatusGrid.svelte +179 -0
  112. package/dist/components/ServerStatusGrid.svelte.d.ts +21 -0
  113. package/dist/components/SnapshotTimelineReplay.svelte +219 -0
  114. package/dist/components/SnapshotTimelineReplay.svelte.d.ts +19 -0
  115. package/dist/components/SqlConsole.svelte +247 -0
  116. package/dist/components/SqlConsole.svelte.d.ts +20 -0
  117. package/dist/components/StepWizard.svelte +1 -1
  118. package/dist/components/SystemCapacityForecastCard.svelte +132 -0
  119. package/dist/components/SystemCapacityForecastCard.svelte.d.ts +19 -0
  120. package/dist/components/SystemHealthCheckDashboard.svelte +306 -0
  121. package/dist/components/SystemHealthCheckDashboard.svelte.d.ts +24 -0
  122. package/dist/components/TableAggregationFooter.svelte +173 -0
  123. package/dist/components/TableAggregationFooter.svelte.d.ts +22 -0
  124. package/dist/components/TaskCenter.svelte +37 -29
  125. package/dist/components/TenantContextSwitcher.svelte +314 -0
  126. package/dist/components/TenantContextSwitcher.svelte.d.ts +35 -0
  127. package/dist/components/TenantQuotasMatrix.svelte +229 -0
  128. package/dist/components/TenantQuotasMatrix.svelte.d.ts +22 -0
  129. package/dist/components/ThreadedCommentDrawer.svelte +246 -0
  130. package/dist/components/ThreadedCommentDrawer.svelte.d.ts +26 -0
  131. package/dist/components/TierFeatureComparison.svelte +147 -0
  132. package/dist/components/TierFeatureComparison.svelte.d.ts +28 -0
  133. package/dist/components/TreeTransferSelect.svelte +333 -0
  134. package/dist/components/TreeTransferSelect.svelte.d.ts +18 -0
  135. package/dist/components/VirtualCardGrid.svelte +180 -0
  136. package/dist/components/VirtualCardGrid.svelte.d.ts +65 -0
  137. package/dist/components/WebhookSimulator.svelte +263 -0
  138. package/dist/components/WebhookSimulator.svelte.d.ts +26 -0
  139. package/dist/components/WidgetContainer.svelte +204 -0
  140. package/dist/components/WidgetContainer.svelte.d.ts +31 -0
  141. package/dist/components/WorkflowExecutionTracker.svelte +131 -0
  142. package/dist/components/WorkflowExecutionTracker.svelte.d.ts +19 -0
  143. package/dist/components/WorkflowGraphDesigner.svelte +202 -0
  144. package/dist/components/WorkflowGraphDesigner.svelte.d.ts +24 -0
  145. package/dist/components/WorkflowNodeInspector.svelte +217 -0
  146. package/dist/components/WorkflowNodeInspector.svelte.d.ts +24 -0
  147. package/dist/components/WorkflowStepper.svelte +1 -1
  148. package/dist/components/list-i18n.d.ts +7 -0
  149. package/dist/components/list-i18n.js +14 -0
  150. package/dist/components/ui/button/button.svelte +3 -1
  151. package/dist/components/ui/button/button.svelte.d.ts +1 -0
  152. package/dist/components/ui/tooltip/tooltip-content.svelte +1 -1
  153. package/dist/components/useDynamicLocale.d.svelte.ts +1 -0
  154. package/dist/components/useDynamicLocale.svelte.d.ts +10 -0
  155. package/dist/components/useDynamicLocale.svelte.js +40 -0
  156. package/dist/components/useFormulaEngine.d.svelte.ts +1 -0
  157. package/dist/components/useFormulaEngine.svelte.d.ts +9 -0
  158. package/dist/components/useFormulaEngine.svelte.js +209 -0
  159. package/dist/components/useStorageCache.d.svelte.ts +1 -0
  160. package/dist/components/useStorageCache.svelte.d.ts +49 -0
  161. package/dist/components/useStorageCache.svelte.js +229 -0
  162. package/dist/components.css +1 -1
  163. package/dist/index.d.ts +69 -3
  164. package/dist/index.js +112 -2
  165. package/package.json +4 -4
@@ -0,0 +1,273 @@
1
+ <script lang="ts">
2
+ import {
3
+ ShieldAlert,
4
+ AlertOctagon,
5
+ ArrowRight,
6
+ Save,
7
+ Check,
8
+ X,
9
+ } from '@lucide/svelte';
10
+ import { useTranslation } from '@svadmin/core/i18n';
11
+ import { cn } from '../utils.js';
12
+ import { Button } from './ui/button/index.js';
13
+
14
+ export type CrudAction = 'read' | 'create' | 'update' | 'delete' | 'export';
15
+
16
+ export interface ResourcePermissionDiff {
17
+ resource: string;
18
+ resourceLabel: string;
19
+ action: CrudAction;
20
+ previousAllowed: boolean;
21
+ currentAllowed: boolean;
22
+ isHighRisk?: boolean | undefined;
23
+ }
24
+
25
+ export interface PermissionChangeAuditPayload {
26
+ roleId: string;
27
+ roleName: string;
28
+ approvalTicket: string;
29
+ modifiedItems: ResourcePermissionDiff[];
30
+ confirmedAt: string;
31
+ }
32
+
33
+ export interface RolePermissionComparatorProps {
34
+ roleId: string;
35
+ roleName: string;
36
+ changes?: ResourcePermissionDiff[] | undefined;
37
+ title?: string | undefined;
38
+ description?: string | undefined;
39
+ class?: string | undefined;
40
+ onConfirmChanges?: ((payload: PermissionChangeAuditPayload) => void | Promise<void>) | undefined;
41
+ }
42
+
43
+ let {
44
+ roleId = 'finance_auditor',
45
+ roleName = '财务审核专员',
46
+ changes = [
47
+ { resource: 'financial_ledger', resourceLabel: '财务账目明细', action: 'export', previousAllowed: false, currentAllowed: true, isHighRisk: true },
48
+ { resource: 'financial_ledger', resourceLabel: '财务账目明细', action: 'delete', previousAllowed: false, currentAllowed: true, isHighRisk: true },
49
+ { resource: 'customer_contact', resourceLabel: '客户联系方式', action: 'read', previousAllowed: true, currentAllowed: true },
50
+ { resource: 'customer_contact', resourceLabel: '客户联系方式', action: 'update', previousAllowed: false, currentAllowed: true },
51
+ ],
52
+ title,
53
+ description,
54
+ class: className = '',
55
+ onConfirmChanges,
56
+ }: RolePermissionComparatorProps = $props();
57
+
58
+ const i18n = useTranslation();
59
+ const chinese = $derived(i18n.locale.startsWith('zh'));
60
+
61
+ let approvalTicket = $state('');
62
+ let isSaving = $state(false);
63
+ let isSaved = $state(false);
64
+
65
+ const modifiedChanges = $derived(
66
+ changes.filter((c) => c.previousAllowed !== c.currentAllowed),
67
+ );
68
+
69
+ const highRiskChanges = $derived(
70
+ modifiedChanges.filter((c) => c.isHighRisk && c.currentAllowed && !c.previousAllowed),
71
+ );
72
+
73
+ async function handleConfirm() {
74
+ if (!approvalTicket.trim() || isSaving) return;
75
+ isSaving = true;
76
+
77
+ try {
78
+ const payload: PermissionChangeAuditPayload = {
79
+ roleId,
80
+ roleName,
81
+ approvalTicket: approvalTicket.trim(),
82
+ modifiedItems: modifiedChanges,
83
+ confirmedAt: new Date().toISOString(),
84
+ };
85
+
86
+ await onConfirmChanges?.(payload);
87
+ isSaved = true;
88
+ setTimeout(() => {
89
+ isSaved = false;
90
+ }, 1500);
91
+ } finally {
92
+ isSaving = false;
93
+ }
94
+ }
95
+
96
+ const actionLabels: Record<CrudAction, string> = {
97
+ read: '读取 (Read)',
98
+ create: '创建 (Create)',
99
+ update: '编辑 (Update)',
100
+ delete: '删除 (Delete)',
101
+ export: '导出 (Export)',
102
+ };
103
+
104
+ const resolvedTitle = $derived(title ?? (chinese ? '角色权限变更高危审计与差异比对' : 'Role Permission Diff Comparator'));
105
+ const resolvedDesc = $derived(
106
+ description ?? (chinese ? '调整前后权限矩阵并排红绿差异审计,自动标红高危特权提权' : 'Audit permission matrix modifications before commit'),
107
+ );
108
+ </script>
109
+
110
+ <div
111
+ data-svadmin-component="RolePermissionComparator"
112
+ class={cn(
113
+ 'w-full rounded-2xl border border-border bg-card text-card-foreground shadow-xs p-6 space-y-4 flex flex-col text-xs',
114
+ className,
115
+ )}
116
+ >
117
+ <!-- Header Bar -->
118
+ <div class="flex items-center justify-between border-b border-border/70 pb-4">
119
+ <div class="flex items-center gap-2.5">
120
+ <div class="flex h-9 w-9 items-center justify-center rounded-xl bg-destructive/10 text-destructive border border-destructive/20">
121
+ <ShieldAlert class="h-5 w-5" />
122
+ </div>
123
+ <div>
124
+ <h3 class="text-base font-semibold text-foreground">{resolvedTitle}</h3>
125
+ <p class="text-xs text-muted-foreground">{resolvedDesc}</p>
126
+ </div>
127
+ </div>
128
+
129
+ <!-- Role Name Badge -->
130
+ <div class="flex items-center gap-2 font-mono text-[11px]">
131
+ <span class="rounded bg-muted px-2 py-0.5 font-bold text-foreground">
132
+ {roleName} ({roleId})
133
+ </span>
134
+ <span class="rounded-full bg-primary/10 px-2 py-0.5 text-primary font-bold">
135
+ {modifiedChanges.length} {chinese ? '项权限变更' : 'modifications'}
136
+ </span>
137
+ </div>
138
+ </div>
139
+
140
+ <!-- High Risk Escalation Warning -->
141
+ {#if highRiskChanges.length > 0}
142
+ <div role="alert" class="flex items-start gap-3 rounded-xl border border-destructive/30 bg-destructive/10 p-3.5 text-destructive text-xs">
143
+ <AlertOctagon class="h-5 w-5 shrink-0 mt-0.5" />
144
+ <div class="space-y-1">
145
+ <div class="font-bold">{chinese ? '高危越权/特权提权预警 (Privilege Escalation Alert)' : 'High Risk Permission Escalation Detected'}</div>
146
+ <p class="text-[11px] leading-relaxed text-destructive/90">
147
+ {chinese
148
+ ? `本次变更为该角色新增了 ${highRiskChanges.length} 项敏感高危权限 (如财务删除、数据全量导出)。请核实合规授权流程。`
149
+ : `Granting ${highRiskChanges.length} sensitive high-risk permissions. Approval ticket required.`}
150
+ </p>
151
+ </div>
152
+ </div>
153
+ {/if}
154
+
155
+ <!-- Differences Table -->
156
+ <div class="rounded-xl border border-border overflow-hidden">
157
+ <table class="w-full text-left text-xs border-collapse">
158
+ <thead class="bg-muted/40 border-b border-border text-muted-foreground font-semibold">
159
+ <tr>
160
+ <th class="p-3 w-52">{chinese ? '业务资源' : 'Resource'}</th>
161
+ <th class="p-3 w-36">{chinese ? '操作动作' : 'Action'}</th>
162
+ <th class="p-3 w-32 text-center">{chinese ? '变更前权限' : 'Prior Allowed'}</th>
163
+ <th class="p-3 w-10 text-center"></th>
164
+ <th class="p-3 w-32 text-center">{chinese ? '拟变更权限' : 'New Allowed'}</th>
165
+ <th class="p-3">{chinese ? '安全评估' : 'Risk Assessment'}</th>
166
+ </tr>
167
+ </thead>
168
+ <tbody class="divide-y divide-border/60">
169
+ {#each changes as item (item.resource + item.action)}
170
+ {@const isAdded = !item.previousAllowed && item.currentAllowed}
171
+ {@const isRevoked = item.previousAllowed && !item.currentAllowed}
172
+ {@const isUnchanged = item.previousAllowed === item.currentAllowed}
173
+ <tr class={cn('hover:bg-muted/20', isAdded && 'bg-success/5', isRevoked && 'bg-destructive/5')}>
174
+ <!-- Resource -->
175
+ <td class="p-3 font-semibold text-foreground">
176
+ {item.resourceLabel}
177
+ <span class="block font-mono text-[10px] text-muted-foreground font-normal">{item.resource}</span>
178
+ </td>
179
+
180
+ <!-- Action -->
181
+ <td class="p-3 font-mono text-muted-foreground">
182
+ {actionLabels[item.action] ?? item.action}
183
+ </td>
184
+
185
+ <!-- Prior -->
186
+ <td class="p-3 text-center">
187
+ {#if item.previousAllowed}
188
+ <span class="inline-flex items-center gap-1 rounded bg-muted px-2 py-0.5 text-[11px] font-mono font-medium text-foreground">
189
+ <Check class="h-3 w-3 text-success" />
190
+ <span>允许</span>
191
+ </span>
192
+ {:else}
193
+ <span class="inline-flex items-center gap-1 rounded bg-muted/60 px-2 py-0.5 text-[11px] font-mono text-muted-foreground">
194
+ <X class="h-3 w-3" />
195
+ <span>拒绝</span>
196
+ </span>
197
+ {/if}
198
+ </td>
199
+
200
+ <!-- Arrow -->
201
+ <td class="p-3 text-center text-muted-foreground">
202
+ {#if !isUnchanged}
203
+ <ArrowRight class="h-3.5 w-3.5 mx-auto" />
204
+ {/if}
205
+ </td>
206
+
207
+ <!-- Current -->
208
+ <td class="p-3 text-center">
209
+ {#if item.currentAllowed}
210
+ <span class={cn('inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-mono font-bold', isAdded ? 'bg-success/15 text-success' : 'bg-muted text-foreground')}>
211
+ <Check class="h-3 w-3" />
212
+ <span>允许</span>
213
+ </span>
214
+ {:else}
215
+ <span class={cn('inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-mono', isRevoked ? 'bg-destructive/15 text-destructive font-bold' : 'bg-muted/60 text-muted-foreground')}>
216
+ <X class="h-3 w-3" />
217
+ <span>拒绝</span>
218
+ </span>
219
+ {/if}
220
+ </td>
221
+
222
+ <!-- Risk note -->
223
+ <td class="p-3">
224
+ {#if item.isHighRisk && isAdded}
225
+ <span class="rounded bg-destructive/15 px-2 py-0.5 text-[10px] font-bold text-destructive">
226
+ ⚠️ 高危特权提权
227
+ </span>
228
+ {:else if isAdded}
229
+ <span class="text-success font-medium text-[11px]">+ 新增授权</span>
230
+ {:else if isRevoked}
231
+ <span class="text-destructive font-medium text-[11px]">- 权限收回</span>
232
+ {:else}
233
+ <span class="text-muted-foreground text-[11px]">无变动</span>
234
+ {/if}
235
+ </td>
236
+ </tr>
237
+ {/each}
238
+ </tbody>
239
+ </table>
240
+ </div>
241
+
242
+ <!-- Mandatory Ticket & Commit Footer -->
243
+ <div class="flex flex-wrap items-center justify-between gap-4 border-t border-border/70 pt-4 bg-muted/10 p-3 rounded-xl">
244
+ <div class="flex items-center gap-2 flex-1 min-w-64">
245
+ <label for="approval-ticket-input" class="font-bold text-foreground whitespace-nowrap">
246
+ {chinese ? '审批工单号 (必填) *' : 'Approval Ticket *'}
247
+ </label>
248
+ <input
249
+ id="approval-ticket-input"
250
+ type="text"
251
+ bind:value={approvalTicket}
252
+ placeholder={chinese ? '例如: TICKET-SEC-2026-902' : 'E.g. SEC-001'}
253
+ class="h-8 max-w-xs flex-1 rounded-md border border-input bg-background px-2.5 font-mono text-xs text-foreground focus-visible:outline-none"
254
+ />
255
+ </div>
256
+
257
+ <Button
258
+ type="button"
259
+ size="sm"
260
+ disabled={!approvalTicket.trim() || isSaving || modifiedChanges.length === 0}
261
+ onclick={handleConfirm}
262
+ class="gap-1.5 min-w-32 bg-destructive text-destructive-foreground hover:bg-destructive/90"
263
+ >
264
+ {#if isSaved}
265
+ <Check class="h-3.5 w-3.5 text-white" />
266
+ <span>{chinese ? '已确认并签署' : 'Confirmed'}</span>
267
+ {:else}
268
+ <Save class="h-3.5 w-3.5" />
269
+ <span>{chinese ? '确认并签署变更' : 'Audit & Confirm'}</span>
270
+ {/if}
271
+ </Button>
272
+ </div>
273
+ </div>
@@ -0,0 +1,28 @@
1
+ export type CrudAction = 'read' | 'create' | 'update' | 'delete' | 'export';
2
+ export interface ResourcePermissionDiff {
3
+ resource: string;
4
+ resourceLabel: string;
5
+ action: CrudAction;
6
+ previousAllowed: boolean;
7
+ currentAllowed: boolean;
8
+ isHighRisk?: boolean | undefined;
9
+ }
10
+ export interface PermissionChangeAuditPayload {
11
+ roleId: string;
12
+ roleName: string;
13
+ approvalTicket: string;
14
+ modifiedItems: ResourcePermissionDiff[];
15
+ confirmedAt: string;
16
+ }
17
+ export interface RolePermissionComparatorProps {
18
+ roleId: string;
19
+ roleName: string;
20
+ changes?: ResourcePermissionDiff[] | undefined;
21
+ title?: string | undefined;
22
+ description?: string | undefined;
23
+ class?: string | undefined;
24
+ onConfirmChanges?: ((payload: PermissionChangeAuditPayload) => void | Promise<void>) | undefined;
25
+ }
26
+ declare const RolePermissionComparator: import("svelte").Component<RolePermissionComparatorProps, {}, "">;
27
+ type RolePermissionComparator = ReturnType<typeof RolePermissionComparator>;
28
+ export default RolePermissionComparator;
@@ -0,0 +1,380 @@
1
+ <script lang="ts">
2
+ import {
3
+ Network,
4
+ Plus,
5
+ Trash2,
6
+ Check,
7
+ Copy,
8
+ Code,
9
+ } from '@lucide/svelte';
10
+ import { untrack } from 'svelte';
11
+ import { useTranslation } from '@svadmin/core/i18n';
12
+ import { cn } from '../utils.js';
13
+ import { Button } from './ui/button/index.js';
14
+
15
+ export type RuleOperator =
16
+ | 'eq'
17
+ | 'ne'
18
+ | 'gt'
19
+ | 'gte'
20
+ | 'lt'
21
+ | 'lte'
22
+ | 'in'
23
+ | 'contains'
24
+ | 'regex';
25
+
26
+ export interface RuleFieldOption {
27
+ key: string;
28
+ label: string;
29
+ type?: ('string' | 'number' | 'boolean' | 'date') | undefined;
30
+ }
31
+
32
+ export interface RuleLeafNode {
33
+ id: string;
34
+ type: 'leaf';
35
+ field: string;
36
+ operator: RuleOperator;
37
+ value: string;
38
+ }
39
+
40
+ export interface RuleGroupNode {
41
+ id: string;
42
+ type: 'group';
43
+ combinator: 'and' | 'or';
44
+ not?: boolean | undefined;
45
+ children: Array<RuleGroupNode | RuleLeafNode>;
46
+ }
47
+
48
+ export interface RuleExpressionBuilderProps {
49
+ fields?: RuleFieldOption[] | undefined;
50
+ rootGroup?: RuleGroupNode | undefined;
51
+ title?: string | undefined;
52
+ description?: string | undefined;
53
+ class?: string | undefined;
54
+ onChange?: ((root: RuleGroupNode, naturalText: string) => void) | undefined;
55
+ }
56
+
57
+ let {
58
+ fields = [
59
+ { key: 'order.amount', label: '订单金额', type: 'number' },
60
+ { key: 'user.level', label: '会员等级', type: 'string' },
61
+ { key: 'user.riskScore', label: '风险评分', type: 'number' },
62
+ { key: 'order.status', label: '订单状态', type: 'string' },
63
+ ],
64
+ rootGroup: initialRoot = {
65
+ id: 'root',
66
+ type: 'group',
67
+ combinator: 'and',
68
+ not: false,
69
+ children: [
70
+ { id: 'r1', type: 'leaf', field: 'order.amount', operator: 'gt', value: '5000' },
71
+ { id: 'r2', type: 'leaf', field: 'user.level', operator: 'in', value: 'VIP, SVIP' },
72
+ ],
73
+ },
74
+ title,
75
+ description,
76
+ class: className = '',
77
+ onChange,
78
+ }: RuleExpressionBuilderProps = $props();
79
+
80
+ const i18n = useTranslation();
81
+ const chinese = $derived(i18n.locale.startsWith('zh'));
82
+
83
+ let root = $state<RuleGroupNode>(untrack(() => JSON.parse(JSON.stringify(initialRoot))));
84
+ let isCopied = $state(false);
85
+
86
+ function nextNodeId(): string {
87
+ return `node-${Math.random().toString(36).slice(2, 7)}`;
88
+ }
89
+
90
+ function addLeaf(group: RuleGroupNode) {
91
+ const firstField = fields[0]?.key ?? 'field';
92
+ group.children = [
93
+ ...group.children,
94
+ {
95
+ id: nextNodeId(),
96
+ type: 'leaf',
97
+ field: firstField,
98
+ operator: 'eq',
99
+ value: '',
100
+ },
101
+ ];
102
+ notify();
103
+ }
104
+
105
+ function addSubGroup(group: RuleGroupNode) {
106
+ const firstField = fields[0]?.key ?? 'field';
107
+ group.children = [
108
+ ...group.children,
109
+ {
110
+ id: nextNodeId(),
111
+ type: 'group',
112
+ combinator: 'or',
113
+ not: false,
114
+ children: [
115
+ {
116
+ id: nextNodeId(),
117
+ type: 'leaf',
118
+ field: firstField,
119
+ operator: 'eq',
120
+ value: '',
121
+ },
122
+ ],
123
+ },
124
+ ];
125
+ notify();
126
+ }
127
+
128
+ function removeChild(group: RuleGroupNode, childId: string) {
129
+ group.children = group.children.filter((c) => c.id !== childId);
130
+ notify();
131
+ }
132
+
133
+ function formatNaturalLanguage(node: RuleGroupNode | RuleLeafNode): string {
134
+ if (node.type === 'leaf') {
135
+ const fieldDef = fields.find((f) => f.key === node.field);
136
+ const label = fieldDef?.label ?? node.field;
137
+ const opMap: Record<RuleOperator, string> = {
138
+ eq: '=',
139
+ ne: '≠',
140
+ gt: '>',
141
+ gte: '≥',
142
+ lt: '<',
143
+ lte: '≤',
144
+ in: 'in',
145
+ contains: '包含',
146
+ regex: '正则匹配',
147
+ };
148
+ return `${label} ${opMap[node.operator]} '${node.value}'`;
149
+ }
150
+
151
+ const subExprs = node.children.map(formatNaturalLanguage).filter(Boolean);
152
+ if (subExprs.length === 0) return '';
153
+ const joiner = node.combinator === 'and' ? (chinese ? ' 且 ' : ' AND ') : (chinese ? ' 或 ' : ' OR ');
154
+ const combined = subExprs.join(joiner);
155
+ const wrapped = `(${combined})`;
156
+ return node.not ? (chinese ? `非 ${wrapped}` : `NOT ${wrapped}`) : wrapped;
157
+ }
158
+
159
+ const naturalExpression = $derived(formatNaturalLanguage(root));
160
+
161
+ function notify() {
162
+ onChange?.(root, naturalExpression);
163
+ }
164
+
165
+ async function handleCopyAST() {
166
+ if (typeof navigator !== 'undefined' && navigator.clipboard) {
167
+ await navigator.clipboard.writeText(JSON.stringify(root, null, 2));
168
+ isCopied = true;
169
+ setTimeout(() => {
170
+ isCopied = false;
171
+ }, 1500);
172
+ }
173
+ }
174
+
175
+ const resolvedTitle = $derived(title ?? (chinese ? '风控与业务流规则表达式设计器' : 'Rule Expression Builder'));
176
+ const resolvedDesc = $derived(
177
+ description ??
178
+ (chinese
179
+ ? '多层级复合布尔逻辑编排,支持嵌套条件组与动态 AST 编译导出'
180
+ : 'Construct composite boolean logic trees with nested groups and AST compiler'),
181
+ );
182
+ </script>
183
+
184
+ <div
185
+ data-svadmin-component="RuleExpressionBuilder"
186
+ class={cn(
187
+ 'w-full rounded-md border border-border bg-card text-card-foreground shadow-xs p-6 space-y-4',
188
+ className,
189
+ )}
190
+ >
191
+ <!-- Header Bar -->
192
+ <div class="flex items-center justify-between border-b border-border/70 pb-4">
193
+ <div class="flex items-center gap-3">
194
+ <div class="flex h-9 w-9 items-center justify-center rounded-sm bg-primary/10 text-primary border border-primary/20">
195
+ <Network class="h-5 w-5" />
196
+ </div>
197
+ <div>
198
+ <h3 class="text-base font-semibold text-foreground">{resolvedTitle}</h3>
199
+ <p class="text-xs text-muted-foreground">{resolvedDesc}</p>
200
+ </div>
201
+ </div>
202
+
203
+ <Button
204
+ type="button"
205
+ variant="outline"
206
+ size="sm"
207
+ onclick={handleCopyAST}
208
+ class="gap-1.5 text-xs font-mono"
209
+ >
210
+ {#if isCopied}
211
+ <Check class="h-3.5 w-3.5 text-success" />
212
+ <span>{chinese ? '已复制 AST' : 'Copied AST'}</span>
213
+ {:else}
214
+ <Copy class="h-3.5 w-3.5" />
215
+ <span>{chinese ? '复制 JSON AST' : 'Copy AST'}</span>
216
+ {/if}
217
+ </Button>
218
+ </div>
219
+
220
+ <!-- Natural Language Expression Preview -->
221
+ <div class="flex items-center gap-2 rounded-md border border-border/80 bg-muted/30 px-4 py-2.5 text-xs">
222
+ <Code class="h-4 w-4 text-primary shrink-0" />
223
+ <span class="font-medium text-muted-foreground shrink-0">{chinese ? '表达式解析:' : 'Expression:'}</span>
224
+ <span class="font-mono text-foreground font-semibold truncate">{naturalExpression || (chinese ? '空规则' : 'Empty rule')}</span>
225
+ </div>
226
+
227
+ <!-- Root Group Canvas -->
228
+ <div class="rounded-md border border-primary/30 bg-primary/5 p-4 space-y-3">
229
+ <!-- Group Header Controls -->
230
+ <div class="flex items-center justify-between">
231
+ <div class="flex items-center gap-2 text-xs">
232
+ <span class="font-bold text-primary">{chinese ? '满足以下' : 'Match'}</span>
233
+ <select
234
+ bind:value={root.combinator}
235
+ onchange={notify}
236
+ class="h-7 rounded border border-input bg-background px-2 text-xs font-semibold text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
237
+ >
238
+ <option value="and">{chinese ? '全部条件 (AND)' : 'ALL conditions (AND)'}</option>
239
+ <option value="or">{chinese ? '任一条件 (OR)' : 'ANY condition (OR)'}</option>
240
+ </select>
241
+ <label class="inline-flex items-center gap-1 cursor-pointer select-none ml-2">
242
+ <input type="checkbox" bind:checked={root.not} onchange={notify} />
243
+ <span class="text-muted-foreground">{chinese ? '取反 (NOT)' : 'Invert (NOT)'}</span>
244
+ </label>
245
+ </div>
246
+
247
+ <div class="flex items-center gap-1.5">
248
+ <Button type="button" variant="outline" size="sm" class="h-7 text-xs gap-1" onclick={() => addLeaf(root)}>
249
+ <Plus class="h-3.5 w-3.5" />
250
+ <span>{chinese ? '添加规则' : 'Add Rule'}</span>
251
+ </Button>
252
+ <Button type="button" variant="outline" size="sm" class="h-7 text-xs gap-1" onclick={() => addSubGroup(root)}>
253
+ <Plus class="h-3.5 w-3.5" />
254
+ <span>{chinese ? '添加子组' : 'Add Group'}</span>
255
+ </Button>
256
+ </div>
257
+ </div>
258
+
259
+ <!-- Children Nodes -->
260
+ <div class="space-y-2 pt-1 pl-3 border-l-2 border-primary/40">
261
+ {#each root.children as child (child.id)}
262
+ {#if child.type === 'leaf'}
263
+ <div class="flex items-center gap-2 rounded-lg border border-border bg-card p-2 text-xs shadow-2xs">
264
+ <!-- Field select -->
265
+ <select
266
+ bind:value={child.field}
267
+ onchange={notify}
268
+ class="h-7 rounded border border-input bg-background px-2 text-xs font-medium focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
269
+ >
270
+ {#each fields as f (f.key)}
271
+ <option value={f.key}>{f.label} ({f.key})</option>
272
+ {/each}
273
+ </select>
274
+
275
+ <!-- Operator select -->
276
+ <select
277
+ bind:value={child.operator}
278
+ onchange={notify}
279
+ class="h-7 rounded border border-input bg-background px-2 text-xs font-mono font-medium focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
280
+ >
281
+ <option value="eq">=</option>
282
+ <option value="ne">≠</option>
283
+ <option value="gt">&gt;</option>
284
+ <option value="gte">&ge;</option>
285
+ <option value="lt">&lt;</option>
286
+ <option value="lte">&le;</option>
287
+ <option value="in">in</option>
288
+ <option value="contains">contains</option>
289
+ <option value="regex">regex</option>
290
+ </select>
291
+
292
+ <!-- Value input -->
293
+ <input
294
+ type="text"
295
+ bind:value={child.value}
296
+ oninput={notify}
297
+ placeholder={chinese ? '输入比较值...' : 'Value...'}
298
+ class="h-7 flex-1 rounded border border-input bg-background px-2 text-xs font-mono focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
299
+ />
300
+
301
+ <!-- Remove Button -->
302
+ <button
303
+ type="button"
304
+ onclick={() => removeChild(root, child.id)}
305
+ class="rounded p-1 text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors"
306
+ aria-label="Remove rule"
307
+ >
308
+ <Trash2 class="h-3.5 w-3.5" />
309
+ </button>
310
+ </div>
311
+ {:else}
312
+ <!-- SubGroup Container -->
313
+ <div class="rounded-md border border-warning/40 bg-warning/5 p-3 space-y-2">
314
+ <div class="flex items-center justify-between text-xs">
315
+ <div class="flex items-center gap-2">
316
+ <span class="font-bold text-warning">{chinese ? '子条件组' : 'Subgroup'}</span>
317
+ <select
318
+ bind:value={child.combinator}
319
+ onchange={notify}
320
+ class="h-6 rounded border border-input bg-background px-1.5 text-xs text-foreground"
321
+ >
322
+ <option value="and">AND</option>
323
+ <option value="or">OR</option>
324
+ </select>
325
+ </div>
326
+
327
+ <div class="flex items-center gap-1">
328
+ <Button type="button" variant="outline" size="sm" class="h-6 text-[11px] px-2" onclick={() => addLeaf(child)}>
329
+ + {chinese ? '规则' : 'Rule'}
330
+ </Button>
331
+ <button
332
+ type="button"
333
+ onclick={() => removeChild(root, child.id)}
334
+ class="rounded p-1 text-muted-foreground hover:text-destructive hover:bg-destructive/10"
335
+ aria-label="Remove subgroup"
336
+ >
337
+ <Trash2 class="h-3.5 w-3.5" />
338
+ </button>
339
+ </div>
340
+ </div>
341
+
342
+ <div class="space-y-1.5 pl-2 border-l border-warning/40">
343
+ {#each child.children as subChild (subChild.id)}
344
+ {#if subChild.type === 'leaf'}
345
+ <div class="flex items-center gap-2 rounded border border-border bg-card p-1.5 text-xs">
346
+ <select bind:value={subChild.field} onchange={notify} class="h-6 text-xs bg-background border rounded px-1">
347
+ {#each fields as f (f.key)}
348
+ <option value={f.key}>{f.label}</option>
349
+ {/each}
350
+ </select>
351
+ <select bind:value={subChild.operator} onchange={notify} class="h-6 text-xs bg-background border rounded px-1">
352
+ <option value="eq">=</option>
353
+ <option value="gt">&gt;</option>
354
+ <option value="lt">&lt;</option>
355
+ <option value="in">in</option>
356
+ </select>
357
+ <input
358
+ type="text"
359
+ bind:value={subChild.value}
360
+ oninput={notify}
361
+ class="h-6 flex-1 text-xs bg-background border rounded px-1.5 font-mono"
362
+ />
363
+ <button
364
+ type="button"
365
+ onclick={() => removeChild(child, subChild.id)}
366
+ class="rounded p-1 text-muted-foreground hover:text-destructive"
367
+ aria-label="Remove rule"
368
+ >
369
+ <Trash2 class="h-3 w-3" />
370
+ </button>
371
+ </div>
372
+ {/if}
373
+ {/each}
374
+ </div>
375
+ </div>
376
+ {/if}
377
+ {/each}
378
+ </div>
379
+ </div>
380
+ </div>