@svadmin/ui 0.130.0 → 0.131.1

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 (81) hide show
  1. package/dist/app.css +318 -0
  2. package/dist/app.theme.css +318 -0
  3. package/dist/components/AboutSettings.svelte +1 -1
  4. package/dist/components/AccessRevocationMatrix.svelte +425 -0
  5. package/dist/components/AccessRevocationMatrix.svelte.d.ts +27 -0
  6. package/dist/components/AudioVisualInspector.svelte +458 -0
  7. package/dist/components/AudioVisualInspector.svelte.d.ts +53 -0
  8. package/dist/components/AuditSnapshotCapture.svelte +328 -0
  9. package/dist/components/AuditSnapshotCapture.svelte.d.ts +28 -0
  10. package/dist/components/CannedResponsePicker.svelte +257 -0
  11. package/dist/components/CannedResponsePicker.svelte.d.ts +22 -0
  12. package/dist/components/ContentModerationCenter.svelte +166 -0
  13. package/dist/components/ContentModerationCenter.svelte.d.ts +11 -0
  14. package/dist/components/ContractClauseDiffViewer.svelte +566 -0
  15. package/dist/components/ContractClauseDiffViewer.svelte.d.ts +53 -0
  16. package/dist/components/DataImportPipeline.svelte +577 -0
  17. package/dist/components/DataImportPipeline.svelte.d.ts +35 -0
  18. package/dist/components/DataRetentionPolicyEditor.svelte +455 -0
  19. package/dist/components/DataRetentionPolicyEditor.svelte.d.ts +10 -0
  20. package/dist/components/ElectronicSealInspector.svelte +450 -0
  21. package/dist/components/ElectronicSealInspector.svelte.d.ts +72 -0
  22. package/dist/components/EmployeeOffboardingAuditor.svelte +405 -0
  23. package/dist/components/EmployeeOffboardingAuditor.svelte.d.ts +39 -0
  24. package/dist/components/FieldMappingBuilder.svelte +393 -0
  25. package/dist/components/FieldMappingBuilder.svelte.d.ts +39 -0
  26. package/dist/components/FilterBuilder.svelte +50 -34
  27. package/dist/components/FilterBuilder.svelte.d.ts +2 -0
  28. package/dist/components/GatewayRouteEditor.svelte +493 -0
  29. package/dist/components/GatewayRouteEditor.svelte.d.ts +34 -0
  30. package/dist/components/I18nStudio.svelte +635 -0
  31. package/dist/components/I18nStudio.svelte.d.ts +23 -0
  32. package/dist/components/IpAccessRuleEditor.svelte +290 -0
  33. package/dist/components/IpAccessRuleEditor.svelte.d.ts +19 -0
  34. package/dist/components/IpWhitelistDrawer.svelte +94 -0
  35. package/dist/components/IpWhitelistDrawer.svelte.d.ts +10 -0
  36. package/dist/components/MediaAuthenticityAuditCard.svelte +357 -0
  37. package/dist/components/MediaAuthenticityAuditCard.svelte.d.ts +64 -0
  38. package/dist/components/PrintDocument.svelte +95 -0
  39. package/dist/components/PrintDocument.svelte.d.ts +10 -0
  40. package/dist/components/PrintPreviewModal.svelte +52 -0
  41. package/dist/components/PrintPreviewModal.svelte.d.ts +11 -0
  42. package/dist/components/PrintTemplateDesigner.svelte +280 -0
  43. package/dist/components/PrintTemplateDesigner.svelte.d.ts +11 -0
  44. package/dist/components/RateLimitPolicyPanel.svelte +369 -0
  45. package/dist/components/RateLimitPolicyPanel.svelte.d.ts +29 -0
  46. package/dist/components/SensitiveWordAuditor.svelte +368 -0
  47. package/dist/components/SensitiveWordAuditor.svelte.d.ts +9 -0
  48. package/dist/components/ServiceDeskTicketCard.svelte +297 -0
  49. package/dist/components/ServiceDeskTicketCard.svelte.d.ts +52 -0
  50. package/dist/components/ShiftScheduler.svelte +490 -0
  51. package/dist/components/ShiftScheduler.svelte.d.ts +50 -0
  52. package/dist/components/SslCertificateMonitorCard.svelte +309 -0
  53. package/dist/components/SslCertificateMonitorCard.svelte.d.ts +30 -0
  54. package/dist/components/SsoConnectionStudio.svelte +784 -0
  55. package/dist/components/SsoConnectionStudio.svelte.d.ts +44 -0
  56. package/dist/components/SsoSpMetadataPanel.svelte +44 -0
  57. package/dist/components/SsoSpMetadataPanel.svelte.d.ts +8 -0
  58. package/dist/components/StepUpAuthModal.svelte +448 -0
  59. package/dist/components/StepUpAuthModal.svelte.d.ts +26 -0
  60. package/dist/components/TrafficTopologyInspector.svelte +361 -0
  61. package/dist/components/TrafficTopologyInspector.svelte.d.ts +43 -0
  62. package/dist/components/enterprise/filter-tree.js +1 -1
  63. package/dist/components/filter-i18n.d.ts +61 -0
  64. package/dist/components/filter-i18n.js +114 -0
  65. package/dist/components/ip-access-rules.d.ts +24 -0
  66. package/dist/components/ip-access-rules.js +110 -0
  67. package/dist/components/moderation-utils.d.ts +45 -0
  68. package/dist/components/moderation-utils.js +74 -0
  69. package/dist/components/print-document.d.ts +3 -0
  70. package/dist/components/print-document.js +65 -0
  71. package/dist/components/print-utils.d.ts +44 -0
  72. package/dist/components/print-utils.js +68 -0
  73. package/dist/components/retention-utils.d.ts +31 -0
  74. package/dist/components/retention-utils.js +38 -0
  75. package/dist/components/sso-connection-presets.d.ts +2 -0
  76. package/dist/components/sso-connection-presets.js +59 -0
  77. package/dist/components/ui/sheet/sheet.svelte +3 -1
  78. package/dist/components/ui/sheet/sheet.svelte.d.ts +1 -0
  79. package/dist/index.d.ts +29 -0
  80. package/dist/index.js +44 -0
  81. package/package.json +5 -4
@@ -0,0 +1,328 @@
1
+ <script lang="ts">
2
+ import {
3
+ ShieldCheck,
4
+ FileCheck2,
5
+ Copy,
6
+ Check,
7
+ Download,
8
+ Hash,
9
+ Clock,
10
+ User,
11
+ Building2,
12
+ Globe,
13
+ AlertCircle,
14
+ } from '@lucide/svelte';
15
+
16
+ export interface AuditSnapshotDiffItem {
17
+ field: string;
18
+ label?: string;
19
+ before?: unknown;
20
+ after?: unknown;
21
+ }
22
+
23
+ interface Props {
24
+ recordId?: string;
25
+ title?: string;
26
+ subtitle?: string;
27
+ operatorName?: string;
28
+ operatorId?: string;
29
+ tenantName?: string;
30
+ clientIp?: string;
31
+ actionType?: 'create' | 'update' | 'delete' | 'export' | 'privilege_grant' | string;
32
+ actionLabel?: string;
33
+ timestamp?: string;
34
+ hash?: string;
35
+ verified?: boolean;
36
+ watermarkText?: string;
37
+ changes?: AuditSnapshotDiffItem[];
38
+ rawPayload?: Record<string, unknown> | null;
39
+ onexport?: (format: 'png' | 'svg' | 'json') => void;
40
+ onverifyHash?: () => void;
41
+ }
42
+
43
+ let {
44
+ recordId = 'AUDIT-20261114-9982',
45
+ title = '不可篡改操作存证快照',
46
+ subtitle = '操作发生时自动触发数字取证,已通过区块链与 SHA-256 签名存证',
47
+ operatorName = '张三 (Zhang San)',
48
+ operatorId = 'EMP-88204',
49
+ tenantName = '上海总部 / 核心运营一区',
50
+ clientIp = '10.12.88.42',
51
+ actionType = 'privilege_grant',
52
+ actionLabel = '全局特权提升审批',
53
+ timestamp = '2026-11-14 22:45:10.824 CST',
54
+ hash = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
55
+ verified = true,
56
+ watermarkText,
57
+ changes = [
58
+ { field: 'role', label: '授权角色', before: 'viewer', after: 'super_admin' },
59
+ { field: 'scope', label: '管控边界', before: 'read_only', after: 'full_control' },
60
+ { field: 'ipWhitelist', label: '放行 IP', before: '192.168.1.0/24', after: '0.0.0.0/0' },
61
+ { field: 'mfaRequired', label: 'MFA 强制', before: false, after: true },
62
+ ],
63
+ rawPayload = null,
64
+ onexport,
65
+ onverifyHash,
66
+ }: Props = $props();
67
+
68
+ let copied = $state(false);
69
+ let activeTab = $state<'diff' | 'raw'>('diff');
70
+
71
+ let effectiveWatermark = $derived(
72
+ watermarkText || `${operatorName} [${operatorId}] ${clientIp} ${timestamp}`
73
+ );
74
+
75
+ function handleCopyHash() {
76
+ if (navigator?.clipboard?.writeText) {
77
+ navigator.clipboard.writeText(hash);
78
+ }
79
+ copied = true;
80
+ setTimeout(() => {
81
+ copied = false;
82
+ }, 2000);
83
+ }
84
+
85
+ function handleExport(format: 'png' | 'svg' | 'json') {
86
+ if (onexport) {
87
+ onexport(format);
88
+ }
89
+ }
90
+
91
+ function formatValue(val: unknown): string {
92
+ if (val === null || val === undefined) return '(空)';
93
+ if (typeof val === 'boolean') return val ? 'true' : 'false';
94
+ if (typeof val === 'object') return JSON.stringify(val);
95
+ return String(val);
96
+ }
97
+ </script>
98
+
99
+ <div
100
+ class="relative overflow-hidden rounded-xl border border-border bg-card shadow-lg transition-all"
101
+ data-svadmin-component="AuditSnapshotCapture"
102
+ >
103
+ <!-- Security Watermark Background Overlay -->
104
+ <div
105
+ class="pointer-events-none absolute inset-0 select-none overflow-hidden opacity-[0.035] dark:opacity-[0.05]"
106
+ aria-hidden="true"
107
+ >
108
+ <svg class="h-full w-full" xmlns="http://www.w3.org/2000/svg">
109
+ <defs>
110
+ <pattern
111
+ id="audit-watermark-pattern"
112
+ width="280"
113
+ height="140"
114
+ patternUnits="userSpaceOnUse"
115
+ patternTransform="rotate(-25)"
116
+ >
117
+ <text
118
+ x="20"
119
+ y="60"
120
+ font-size="11"
121
+ font-family="monospace"
122
+ fill="currentColor"
123
+ font-weight="bold"
124
+ >
125
+ {effectiveWatermark}
126
+ </text>
127
+ </pattern>
128
+ </defs>
129
+ <rect width="100%" height="100%" fill="url(#audit-watermark-pattern)" />
130
+ </svg>
131
+ </div>
132
+
133
+ <!-- Header Banner -->
134
+ <div class="relative flex flex-wrap items-center justify-between gap-4 border-b border-border bg-muted/30 p-5">
135
+ <div class="flex items-center gap-3">
136
+ <div class="flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary border border-primary/20">
137
+ <ShieldCheck class="h-5 w-5" />
138
+ </div>
139
+ <div>
140
+ <div class="flex items-center gap-2">
141
+ <h3 class="text-base font-semibold text-foreground tracking-tight">{title}</h3>
142
+ <span class="inline-flex items-center rounded-md bg-muted px-2 py-0.5 text-xs font-mono font-medium text-muted-foreground border border-border">
143
+ {recordId}
144
+ </span>
145
+ </div>
146
+ <p class="text-xs text-muted-foreground">{subtitle}</p>
147
+ </div>
148
+ </div>
149
+
150
+ <!-- Export Action Buttons -->
151
+ <div class="flex items-center gap-2">
152
+ <button
153
+ type="button"
154
+ class="inline-flex items-center gap-1.5 rounded-lg border border-input bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-muted transition-colors shadow-sm"
155
+ onclick={() => handleExport('png')}
156
+ aria-label="导出 PNG 快照"
157
+ >
158
+ <Download class="h-3.5 w-3.5 text-muted-foreground" />
159
+ <span>存证图片 (PNG)</span>
160
+ </button>
161
+ <button
162
+ type="button"
163
+ class="inline-flex items-center gap-1.5 rounded-lg border border-input bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-muted transition-colors shadow-sm"
164
+ onclick={() => handleExport('svg')}
165
+ aria-label="导出 SVG 矢量图"
166
+ >
167
+ <FileCheck2 class="h-3.5 w-3.5 text-muted-foreground" />
168
+ <span>矢量存证 (SVG)</span>
169
+ </button>
170
+ </div>
171
+ </div>
172
+
173
+ <!-- Cryptographic Hash & Validation Bar -->
174
+ <div class="relative flex flex-wrap items-center justify-between gap-3 border-b border-border bg-background px-5 py-3 text-xs">
175
+ <div class="flex items-center gap-2 min-w-0">
176
+ <Hash class="h-4 w-4 shrink-0 text-muted-foreground" />
177
+ <span class="text-muted-foreground shrink-0 font-medium">SHA-256 指纹:</span>
178
+ <span class="font-mono text-foreground font-semibold truncate select-all">{hash}</span>
179
+ <button
180
+ type="button"
181
+ class="shrink-0 rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors"
182
+ onclick={handleCopyHash}
183
+ title="复制哈希值"
184
+ aria-label="复制哈希值"
185
+ >
186
+ {#if copied}
187
+ <Check class="h-3.5 w-3.5 text-success" />
188
+ {:else}
189
+ <Copy class="h-3.5 w-3.5" />
190
+ {/if}
191
+ </button>
192
+ </div>
193
+
194
+ <div class="flex items-center gap-2 shrink-0">
195
+ {#if verified}
196
+ <span class="inline-flex items-center gap-1 rounded-full bg-success/15 px-2.5 py-0.5 text-[11px] font-semibold text-success border border-success/30">
197
+ <Check class="h-3 w-3 stroke-[3]" />
198
+ <span>存证验真通过</span>
199
+ </span>
200
+ {:else}
201
+ <span class="inline-flex items-center gap-1 rounded-full bg-warning/15 px-2.5 py-0.5 text-[11px] font-semibold text-warning border border-warning/30">
202
+ <AlertCircle class="h-3 w-3" />
203
+ <span>待复核锚定</span>
204
+ </span>
205
+ {/if}
206
+
207
+ {#if onverifyHash}
208
+ <button
209
+ type="button"
210
+ class="text-xs text-primary hover:underline font-medium ml-1"
211
+ onclick={onverifyHash}
212
+ >
213
+ 重新验签
214
+ </button>
215
+ {/if}
216
+ </div>
217
+ </div>
218
+
219
+ <!-- Metadata Attributes Grid -->
220
+ <div class="relative grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 p-5 bg-card border-b border-border text-xs">
221
+ <div class="flex items-start gap-2.5">
222
+ <User class="h-4 w-4 shrink-0 text-muted-foreground mt-0.5" />
223
+ <div>
224
+ <div class="text-muted-foreground font-medium">操作责任人</div>
225
+ <div class="font-semibold text-foreground mt-0.5">{operatorName}</div>
226
+ <div class="font-mono text-[11px] text-muted-foreground">{operatorId}</div>
227
+ </div>
228
+ </div>
229
+
230
+ <div class="flex items-start gap-2.5">
231
+ <Globe class="h-4 w-4 shrink-0 text-muted-foreground mt-0.5" />
232
+ <div>
233
+ <div class="text-muted-foreground font-medium">终端 IP 溯源</div>
234
+ <div class="font-mono font-semibold text-foreground mt-0.5">{clientIp}</div>
235
+ <div class="text-[11px] text-muted-foreground">通过内网安全网关审计</div>
236
+ </div>
237
+ </div>
238
+
239
+ <div class="flex items-start gap-2.5">
240
+ <Building2 class="h-4 w-4 shrink-0 text-muted-foreground mt-0.5" />
241
+ <div>
242
+ <div class="text-muted-foreground font-medium">归属租户 / 部门</div>
243
+ <div class="font-medium text-foreground mt-0.5 truncate">{tenantName}</div>
244
+ </div>
245
+ </div>
246
+
247
+ <div class="flex items-start gap-2.5">
248
+ <Clock class="h-4 w-4 shrink-0 text-muted-foreground mt-0.5" />
249
+ <div>
250
+ <div class="text-muted-foreground font-medium">存证时间戳 (毫秒级)</div>
251
+ <div class="font-mono font-medium text-foreground mt-0.5">{timestamp}</div>
252
+ </div>
253
+ </div>
254
+ </div>
255
+
256
+ <!-- Changes Differential View & Payload Switcher -->
257
+ <div class="relative p-5">
258
+ <div class="flex items-center justify-between mb-3">
259
+ <div class="flex items-center gap-2">
260
+ <button
261
+ type="button"
262
+ class="px-3 py-1 text-xs font-semibold rounded-lg transition-colors
263
+ {activeTab === 'diff' ? 'bg-primary text-primary-foreground shadow-sm' : 'bg-muted text-muted-foreground hover:text-foreground'}"
264
+ onclick={() => activeTab = 'diff'}
265
+ >
266
+ 变更字段 Diff 对比 ({changes.length})
267
+ </button>
268
+ {#if rawPayload}
269
+ <button
270
+ type="button"
271
+ class="px-3 py-1 text-xs font-semibold rounded-lg transition-colors
272
+ {activeTab === 'raw' ? 'bg-primary text-primary-foreground shadow-sm' : 'bg-muted text-muted-foreground hover:text-foreground'}"
273
+ onclick={() => activeTab = 'raw'}
274
+ >
275
+ 原始 Payload (JSON)
276
+ </button>
277
+ {/if}
278
+ </div>
279
+
280
+ <span class="inline-flex items-center rounded-md px-2 py-0.5 text-xs font-medium
281
+ {actionType === 'delete' || actionType === 'privilege_grant' ? 'bg-destructive/15 text-destructive border border-destructive/20' :
282
+ actionType === 'update' ? 'bg-warning/15 text-warning border border-warning/20' :
283
+ 'bg-success/15 text-success border border-success/20'}">
284
+ {actionLabel || actionType}
285
+ </span>
286
+ </div>
287
+
288
+ {#if activeTab === 'diff'}
289
+ <div class="overflow-x-auto rounded-lg border border-border">
290
+ <table class="w-full text-left text-xs border-collapse">
291
+ <thead>
292
+ <tr class="bg-muted/50 border-b border-border text-muted-foreground font-semibold">
293
+ <th class="py-2.5 px-4 w-1/4">字段属性</th>
294
+ <th class="py-2.5 px-4 w-3/8">变更前 (Before)</th>
295
+ <th class="py-2.5 px-4 w-3/8">变更后 (After)</th>
296
+ </tr>
297
+ </thead>
298
+ <tbody class="divide-y divide-border">
299
+ {#each changes as item (item.field)}
300
+ <tr class="hover:bg-muted/30 transition-colors">
301
+ <td class="py-2 px-4 font-mono font-medium text-foreground">
302
+ <div>{item.field}</div>
303
+ {#if item.label}
304
+ <div class="text-[11px] text-muted-foreground font-sans">{item.label}</div>
305
+ {/if}
306
+ </td>
307
+ <td class="py-2 px-4 font-mono text-muted-foreground line-through opacity-75">
308
+ {formatValue(item.before)}
309
+ </td>
310
+ <td class="py-2 px-4 font-mono font-semibold text-foreground bg-primary/5">
311
+ {formatValue(item.after)}
312
+ </td>
313
+ </tr>
314
+ {/each}
315
+ </tbody>
316
+ </table>
317
+ </div>
318
+ {:else if rawPayload}
319
+ <pre class="overflow-x-auto rounded-lg border border-border bg-muted/40 p-4 font-mono text-xs text-foreground max-h-64">{JSON.stringify(rawPayload, null, 2)}</pre>
320
+ {/if}
321
+ </div>
322
+
323
+ <!-- Bottom Legal Guarantee Footnote -->
324
+ <div class="relative flex items-center justify-between border-t border-border bg-muted/20 px-5 py-2.5 text-[11px] text-muted-foreground">
325
+ <span>数字签名符合 ISO/IEC 27001 与公安部等保三级合规要求</span>
326
+ <span class="font-mono">Secure Hash Algorithm 256-bit</span>
327
+ </div>
328
+ </div>
@@ -0,0 +1,28 @@
1
+ export interface AuditSnapshotDiffItem {
2
+ field: string;
3
+ label?: string;
4
+ before?: unknown;
5
+ after?: unknown;
6
+ }
7
+ interface Props {
8
+ recordId?: string;
9
+ title?: string;
10
+ subtitle?: string;
11
+ operatorName?: string;
12
+ operatorId?: string;
13
+ tenantName?: string;
14
+ clientIp?: string;
15
+ actionType?: 'create' | 'update' | 'delete' | 'export' | 'privilege_grant' | string;
16
+ actionLabel?: string;
17
+ timestamp?: string;
18
+ hash?: string;
19
+ verified?: boolean;
20
+ watermarkText?: string;
21
+ changes?: AuditSnapshotDiffItem[];
22
+ rawPayload?: Record<string, unknown> | null;
23
+ onexport?: (format: 'png' | 'svg' | 'json') => void;
24
+ onverifyHash?: () => void;
25
+ }
26
+ declare const AuditSnapshotCapture: import("svelte").Component<Props, {}, "">;
27
+ type AuditSnapshotCapture = ReturnType<typeof AuditSnapshotCapture>;
28
+ export default AuditSnapshotCapture;
@@ -0,0 +1,257 @@
1
+ <script lang="ts">
2
+ import { untrack } from 'svelte';
3
+ import {
4
+ MessageSquare,
5
+ Search,
6
+ Variable,
7
+ Send,
8
+ } from '@lucide/svelte';
9
+ import { cn } from '../utils.js';
10
+
11
+ export interface CannedTemplate {
12
+ id: string;
13
+ title: string;
14
+ category: string;
15
+ content: string;
16
+ shortcut?: string | undefined;
17
+ tags?: string[] | undefined;
18
+ }
19
+
20
+ export interface CannedResponsePickerProps {
21
+ /** 预设话术模版列表 */
22
+ templates: CannedTemplate[];
23
+ /** 外部注入的上下文变量,如 { customer_name: '张三', ticket_id: 'TCK-8848' } */
24
+ contextVariables?: Record<string, string> | undefined;
25
+ /** 选定话术后的回填回调 */
26
+ onselect?: ((renderedText: string, template: CannedTemplate) => void) | undefined;
27
+ /** 是否紧凑模式 */
28
+ compact?: boolean | undefined;
29
+ class?: string | undefined;
30
+ }
31
+
32
+ let {
33
+ templates = [],
34
+ contextVariables = {},
35
+ onselect,
36
+ compact = false,
37
+ class: className = '',
38
+ }: CannedResponsePickerProps = $props();
39
+
40
+ let searchQuery = $state('');
41
+ let selectedCategory = $state<string>('all');
42
+ // Seeded from the initial prop; selection owns the value afterwards.
43
+ let activeTemplateId = $state<string>(untrack(() => templates[0]?.id ?? ''));
44
+ let variableOverrides = $state<Record<string, string>>({});
45
+
46
+ // 提取分类列表
47
+ const categories = $derived.by(() => {
48
+ const set = new Set<string>();
49
+ templates.forEach((t) => {
50
+ if (t.category) set.add(t.category);
51
+ });
52
+ return ['all', ...Array.from(set)];
53
+ });
54
+
55
+ // 过滤后的模版列表
56
+ const filteredTemplates = $derived.by(() => {
57
+ const q = searchQuery.trim().toLowerCase();
58
+ return templates.filter((t) => {
59
+ const matchCat = selectedCategory === 'all' || t.category === selectedCategory;
60
+ const matchQuery =
61
+ !q ||
62
+ t.title.toLowerCase().includes(q) ||
63
+ t.content.toLowerCase().includes(q) ||
64
+ (t.shortcut && t.shortcut.toLowerCase().includes(q));
65
+ return matchCat && matchQuery;
66
+ });
67
+ });
68
+
69
+ // 当前选中的模版
70
+ const currentTemplate = $derived.by(() => {
71
+ return templates.find((t) => t.id === activeTemplateId) ?? filteredTemplates[0];
72
+ });
73
+
74
+ // 解析当前模版中所有的 {{placeholder}} 变量
75
+ const templatePlaceholders = $derived.by<string[]>(() => {
76
+ if (!currentTemplate) return [];
77
+ const matches = currentTemplate.content.matchAll(/\{\{([a-zA-Z0-9_-]+)\}\}/g);
78
+ const set = new Set<string>();
79
+ for (const m of matches) {
80
+ if (m[1]) set.add(m[1]);
81
+ }
82
+ return Array.from(set);
83
+ });
84
+
85
+ // 实时推演替换后的最终文本
86
+ const renderedContent = $derived.by<string>(() => {
87
+ if (!currentTemplate) return '';
88
+ let text = currentTemplate.content;
89
+ templatePlaceholders.forEach((key) => {
90
+ const val = variableOverrides[key] ?? contextVariables[key] ?? `{{${key}}}`;
91
+ text = text.replaceAll(`{{${key}}}`, val);
92
+ });
93
+ return text;
94
+ });
95
+
96
+ function handleSelect() {
97
+ if (!currentTemplate) return;
98
+ onselect?.(renderedContent, currentTemplate);
99
+ }
100
+ </script>
101
+
102
+ <div
103
+ class={cn(
104
+ 'flex flex-col rounded-xl border border-border/80 bg-card text-card-foreground shadow-sm transition-all',
105
+ className
106
+ )}
107
+ data-svadmin-component="CannedResponsePicker"
108
+ data-compact={compact ? 'true' : undefined}
109
+ >
110
+ <!-- 头部搜索与检索控制栏 -->
111
+ <div class="border-b border-border/60 p-4">
112
+ <div class="flex items-center gap-2 mb-3">
113
+ <div class="flex h-8 w-8 items-center justify-center rounded-lg bg-primary/10 text-primary">
114
+ <MessageSquare class="h-4 w-4" />
115
+ </div>
116
+ <div>
117
+ <h3 class="text-sm font-semibold tracking-tight">快捷客服与工单回复模版</h3>
118
+ <p class="text-xs text-muted-foreground">内置智能变量替换与一键回填工单流转台</p>
119
+ </div>
120
+ </div>
121
+
122
+ <!-- 搜索输入框 -->
123
+ <div class="relative">
124
+ <Search class="absolute left-3 top-2.5 h-4 w-4 text-muted-foreground" />
125
+ <input
126
+ type="text"
127
+ bind:value={searchQuery}
128
+ placeholder="搜索快捷模版标题、正文关键词或快捷指令 (如 /hello)..."
129
+ class="h-9 w-full rounded-md border border-input bg-background pl-9 pr-3 text-xs text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
130
+ />
131
+ </div>
132
+
133
+ <!-- 分类横向滚动标签栏 -->
134
+ <div class="mt-3 flex items-center gap-1.5 overflow-x-auto pb-1 text-xs">
135
+ {#each categories as cat (cat)}
136
+ <button
137
+ type="button"
138
+ class={cn(
139
+ 'whitespace-nowrap rounded-full px-2.5 py-0.5 font-medium transition-colors',
140
+ selectedCategory === cat
141
+ ? 'bg-primary text-primary-foreground'
142
+ : 'bg-muted text-muted-foreground hover:bg-muted/80 hover:text-foreground'
143
+ )}
144
+ onclick={() => (selectedCategory = cat)}
145
+ >
146
+ {cat === 'all' ? '全部分类' : cat}
147
+ </button>
148
+ {/each}
149
+ </div>
150
+ </div>
151
+
152
+ <!-- 主体双栏展示:左侧列表,右侧变量调整与推演预览 -->
153
+ <div class="grid grid-cols-1 divide-y divide-border/60 sm:grid-cols-12 sm:divide-x sm:divide-y-0">
154
+ <!-- 左侧模版列表 (5列) -->
155
+ <div class="sm:col-span-5 max-h-80 overflow-y-auto divide-y divide-border/40 p-2">
156
+ {#if filteredTemplates.length === 0}
157
+ <div class="py-8 text-center text-xs text-muted-foreground">
158
+ 暂未找到匹配的话术模版
159
+ </div>
160
+ {:else}
161
+ {#each filteredTemplates as t (t.id)}
162
+ <button
163
+ type="button"
164
+ class={cn(
165
+ 'flex w-full flex-col gap-1 rounded-lg p-2.5 text-left text-xs transition-colors',
166
+ currentTemplate?.id === t.id
167
+ ? 'bg-primary/10 text-primary'
168
+ : 'text-foreground hover:bg-muted/40'
169
+ )}
170
+ onclick={() => (activeTemplateId = t.id)}
171
+ >
172
+ <div class="flex items-center justify-between">
173
+ <span class="font-semibold">{t.title}</span>
174
+ {#if t.shortcut}
175
+ <code class="rounded bg-muted px-1.5 py-0.2 font-mono text-[10px] text-muted-foreground">
176
+ {t.shortcut}
177
+ </code>
178
+ {/if}
179
+ </div>
180
+ <p class="line-clamp-2 text-[11px] text-muted-foreground">
181
+ {t.content}
182
+ </p>
183
+ </button>
184
+ {/each}
185
+ {/if}
186
+ </div>
187
+
188
+ <!-- 右侧变量填报与实时推演 (7列) -->
189
+ <div class="sm:col-span-7 flex flex-col justify-between p-4">
190
+ {#if currentTemplate}
191
+ <div class="space-y-3">
192
+ <div class="flex items-center justify-between border-b border-border/40 pb-2">
193
+ <span class="text-xs font-semibold text-foreground">
194
+ {currentTemplate.title}
195
+ </span>
196
+ <span class="rounded bg-muted px-2 py-0.5 text-[10px] text-muted-foreground">
197
+ {currentTemplate.category}
198
+ </span>
199
+ </div>
200
+
201
+ <!-- 动态占位符配置项 -->
202
+ {#if templatePlaceholders.length > 0}
203
+ <div class="rounded-lg border border-border/60 bg-muted/20 p-2.5">
204
+ <div class="mb-2 flex items-center gap-1.5 text-[11px] font-medium text-foreground">
205
+ <Variable class="h-3.5 w-3.5 text-primary" />
206
+ <span>动态参数智能注入 ({templatePlaceholders.length})</span>
207
+ </div>
208
+ <div class="grid grid-cols-2 gap-2">
209
+ {#each templatePlaceholders as ph (ph)}
210
+ <div>
211
+ <label for={`var-input-${ph}`} class="text-[10px] text-muted-foreground block mb-0.5">
212
+ {ph}
213
+ </label>
214
+ <input
215
+ id={`var-input-${ph}`}
216
+ type="text"
217
+ placeholder={contextVariables[ph] ?? '填入替换值'}
218
+ value={variableOverrides[ph] ?? contextVariables[ph] ?? ''}
219
+ oninput={(e) => (variableOverrides[ph] = e.currentTarget.value)}
220
+ class="h-7 w-full rounded border border-input bg-background px-2 text-[11px] text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
221
+ />
222
+ </div>
223
+ {/each}
224
+ </div>
225
+ </div>
226
+ {/if}
227
+
228
+ <!-- 渲染后正文推演预览 -->
229
+ <div>
230
+ <span class="text-[11px] font-medium text-muted-foreground block mb-1">
231
+ 推演最终发送文本:
232
+ </span>
233
+ <div class="rounded-lg border border-border/60 bg-background p-3 text-xs leading-relaxed text-foreground whitespace-pre-wrap font-sans">
234
+ {renderedContent}
235
+ </div>
236
+ </div>
237
+ </div>
238
+
239
+ <!-- 底部确定回填按钮 -->
240
+ <div class="mt-4 flex items-center justify-end gap-2 border-t border-border/40 pt-3">
241
+ <button
242
+ type="button"
243
+ class="flex items-center gap-1.5 rounded-md bg-primary px-3.5 py-1.5 text-xs font-medium text-primary-foreground shadow hover:bg-primary/90"
244
+ onclick={handleSelect}
245
+ >
246
+ <Send class="h-3.5 w-3.5" />
247
+ <span>选用此模版并填入</span>
248
+ </button>
249
+ </div>
250
+ {:else}
251
+ <div class="flex h-full items-center justify-center text-xs text-muted-foreground">
252
+ 请从左侧选择话术模版
253
+ </div>
254
+ {/if}
255
+ </div>
256
+ </div>
257
+ </div>
@@ -0,0 +1,22 @@
1
+ export interface CannedTemplate {
2
+ id: string;
3
+ title: string;
4
+ category: string;
5
+ content: string;
6
+ shortcut?: string | undefined;
7
+ tags?: string[] | undefined;
8
+ }
9
+ export interface CannedResponsePickerProps {
10
+ /** 预设话术模版列表 */
11
+ templates: CannedTemplate[];
12
+ /** 外部注入的上下文变量,如 { customer_name: '张三', ticket_id: 'TCK-8848' } */
13
+ contextVariables?: Record<string, string> | undefined;
14
+ /** 选定话术后的回填回调 */
15
+ onselect?: ((renderedText: string, template: CannedTemplate) => void) | undefined;
16
+ /** 是否紧凑模式 */
17
+ compact?: boolean | undefined;
18
+ class?: string | undefined;
19
+ }
20
+ declare const CannedResponsePicker: import("svelte").Component<CannedResponsePickerProps, {}, "">;
21
+ type CannedResponsePicker = ReturnType<typeof CannedResponsePicker>;
22
+ export default CannedResponsePicker;