@svadmin/ui 0.130.0 → 0.131.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/app.css +301 -0
  2. package/dist/app.theme.css +301 -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/GatewayRouteEditor.svelte +493 -0
  27. package/dist/components/GatewayRouteEditor.svelte.d.ts +34 -0
  28. package/dist/components/I18nStudio.svelte +635 -0
  29. package/dist/components/I18nStudio.svelte.d.ts +23 -0
  30. package/dist/components/IpAccessRuleEditor.svelte +290 -0
  31. package/dist/components/IpAccessRuleEditor.svelte.d.ts +19 -0
  32. package/dist/components/IpWhitelistDrawer.svelte +94 -0
  33. package/dist/components/IpWhitelistDrawer.svelte.d.ts +10 -0
  34. package/dist/components/MediaAuthenticityAuditCard.svelte +357 -0
  35. package/dist/components/MediaAuthenticityAuditCard.svelte.d.ts +64 -0
  36. package/dist/components/PrintDocument.svelte +95 -0
  37. package/dist/components/PrintDocument.svelte.d.ts +10 -0
  38. package/dist/components/PrintPreviewModal.svelte +52 -0
  39. package/dist/components/PrintPreviewModal.svelte.d.ts +11 -0
  40. package/dist/components/PrintTemplateDesigner.svelte +280 -0
  41. package/dist/components/PrintTemplateDesigner.svelte.d.ts +11 -0
  42. package/dist/components/RateLimitPolicyPanel.svelte +369 -0
  43. package/dist/components/RateLimitPolicyPanel.svelte.d.ts +29 -0
  44. package/dist/components/SensitiveWordAuditor.svelte +368 -0
  45. package/dist/components/SensitiveWordAuditor.svelte.d.ts +9 -0
  46. package/dist/components/ServiceDeskTicketCard.svelte +297 -0
  47. package/dist/components/ServiceDeskTicketCard.svelte.d.ts +52 -0
  48. package/dist/components/ShiftScheduler.svelte +490 -0
  49. package/dist/components/ShiftScheduler.svelte.d.ts +50 -0
  50. package/dist/components/SslCertificateMonitorCard.svelte +309 -0
  51. package/dist/components/SslCertificateMonitorCard.svelte.d.ts +30 -0
  52. package/dist/components/SsoConnectionStudio.svelte +784 -0
  53. package/dist/components/SsoConnectionStudio.svelte.d.ts +44 -0
  54. package/dist/components/SsoSpMetadataPanel.svelte +44 -0
  55. package/dist/components/SsoSpMetadataPanel.svelte.d.ts +8 -0
  56. package/dist/components/StepUpAuthModal.svelte +448 -0
  57. package/dist/components/StepUpAuthModal.svelte.d.ts +26 -0
  58. package/dist/components/TrafficTopologyInspector.svelte +361 -0
  59. package/dist/components/TrafficTopologyInspector.svelte.d.ts +43 -0
  60. package/dist/components/ip-access-rules.d.ts +24 -0
  61. package/dist/components/ip-access-rules.js +110 -0
  62. package/dist/components/moderation-utils.d.ts +45 -0
  63. package/dist/components/moderation-utils.js +74 -0
  64. package/dist/components/print-document.d.ts +3 -0
  65. package/dist/components/print-document.js +65 -0
  66. package/dist/components/print-utils.d.ts +44 -0
  67. package/dist/components/print-utils.js +68 -0
  68. package/dist/components/retention-utils.d.ts +31 -0
  69. package/dist/components/retention-utils.js +38 -0
  70. package/dist/components/sso-connection-presets.d.ts +2 -0
  71. package/dist/components/sso-connection-presets.js +59 -0
  72. package/dist/components/ui/sheet/sheet.svelte +3 -1
  73. package/dist/components/ui/sheet/sheet.svelte.d.ts +1 -0
  74. package/dist/index.d.ts +29 -0
  75. package/dist/index.js +44 -0
  76. package/package.json +5 -4
@@ -0,0 +1,493 @@
1
+ <script lang="ts">
2
+ import { untrack } from 'svelte';
3
+ import {
4
+ Network,
5
+ Plus,
6
+ Trash2,
7
+ Check,
8
+ Play,
9
+ Split,
10
+ Sliders,
11
+ Server,
12
+ CheckCircle2,
13
+ XCircle,
14
+ } from '@lucide/svelte';
15
+
16
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD' | 'ALL';
17
+
18
+ export interface HeaderMatchRule {
19
+ id: string;
20
+ name: string;
21
+ value: string;
22
+ op: 'exact' | 'regex' | 'prefix';
23
+ }
24
+
25
+ export interface GatewayRouteConfig {
26
+ id: string;
27
+ name: string;
28
+ description?: string;
29
+ enabled: boolean;
30
+ pathPattern: string;
31
+ matchType: 'prefix' | 'exact' | 'regex';
32
+ methods: HttpMethod[];
33
+ headers: HeaderMatchRule[];
34
+ upstreamUrl: string;
35
+ stripPrefix: boolean;
36
+ rewritePrefix?: string;
37
+ canaryEnabled: boolean;
38
+ canaryUpstreamUrl?: string;
39
+ canaryWeight: number; // 0 to 100
40
+ }
41
+
42
+ interface Props {
43
+ route?: GatewayRouteConfig;
44
+ title?: string;
45
+ subtitle?: string;
46
+ onsave?: (route: GatewayRouteConfig) => void | Promise<void>;
47
+ ontest?: (testPath: string) => boolean | Promise<boolean>;
48
+ ondelete?: () => void;
49
+ }
50
+
51
+ const defaultRoute: GatewayRouteConfig = {
52
+ id: 'route-user-service-01',
53
+ name: '用户微服务核心路由规则',
54
+ description: '负责分发移动端与 Web 端用户档案、权限鉴权与组织架构调用',
55
+ enabled: true,
56
+ pathPattern: '/api/v1/users/**',
57
+ matchType: 'prefix',
58
+ methods: ['GET', 'POST', 'PUT', 'DELETE'],
59
+ headers: [
60
+ { id: 'h-1', name: 'X-Tenant-ID', value: 'tenant-*', op: 'prefix' },
61
+ ],
62
+ upstreamUrl: 'http://user-service-cluster.internal:8080',
63
+ stripPrefix: true,
64
+ rewritePrefix: '/internal/users',
65
+ canaryEnabled: true,
66
+ canaryUpstreamUrl: 'http://user-service-canary.internal:8080',
67
+ canaryWeight: 15,
68
+ };
69
+
70
+ let {
71
+ route = defaultRoute,
72
+ title = '微服务 API 网关路由编排',
73
+ subtitle = '配置端点路径匹配、目标微服务集群分发与金丝雀灰度流量分流',
74
+ onsave,
75
+ ontest,
76
+ ondelete,
77
+ }: Props = $props();
78
+
79
+ function copyRoute(value: GatewayRouteConfig): GatewayRouteConfig {
80
+ return { ...value, methods: [...value.methods], headers: value.headers.map((header) => ({ ...header })) };
81
+ }
82
+
83
+ let currentRoute = $state<GatewayRouteConfig>(untrack(() => copyRoute(route)));
84
+ let testInputPath = $state('/api/v1/users/profile');
85
+ let testResult = $state<{ matched: boolean; targetUpstream: string; message: string } | null>(null);
86
+ let isTesting = $state(false);
87
+ let savedSnapshot = $state<string | null>(null);
88
+ const saveSuccess = $derived(savedSnapshot !== null && savedSnapshot === JSON.stringify(currentRoute));
89
+ let isSaving = $state(false);
90
+ let saveError = $state('');
91
+
92
+ $effect(() => {
93
+ currentRoute = copyRoute(route);
94
+ testResult = null;
95
+ savedSnapshot = null;
96
+ saveError = '';
97
+ });
98
+
99
+ const availableMethods: HttpMethod[] = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'];
100
+
101
+ function toggleMethod(method: HttpMethod) {
102
+ if (currentRoute.methods.includes(method)) {
103
+ currentRoute.methods = currentRoute.methods.filter((m) => m !== method);
104
+ } else {
105
+ currentRoute.methods = [...currentRoute.methods, method];
106
+ }
107
+ }
108
+
109
+ function addHeaderRule() {
110
+ const newHeader: HeaderMatchRule = {
111
+ id: `h-${Date.now()}`,
112
+ name: '',
113
+ value: '',
114
+ op: 'exact',
115
+ };
116
+ currentRoute.headers = [...currentRoute.headers, newHeader];
117
+ }
118
+
119
+ function removeHeaderRule(id: string) {
120
+ currentRoute.headers = currentRoute.headers.filter((h) => h.id !== id);
121
+ }
122
+
123
+ async function handleTestMatch() {
124
+ if (isTesting) return;
125
+ isTesting = true;
126
+ testResult = null;
127
+ try {
128
+ if (ontest) {
129
+ const passed = await ontest(testInputPath);
130
+ testResult = {
131
+ matched: passed,
132
+ targetUpstream: passed ? currentRoute.upstreamUrl : '未命中规则',
133
+ message: passed ? '路径成功匹配规则,正常路由分发' : '路径未能命中当前路由匹配前缀',
134
+ };
135
+ } else {
136
+ // 内置简易正则 / 前缀推演
137
+ let matched = false;
138
+ if (currentRoute.matchType === 'prefix') {
139
+ const prefix = currentRoute.pathPattern.replace(/\/\*\*?$/, '');
140
+ matched = testInputPath.startsWith(prefix);
141
+ } else if (currentRoute.matchType === 'exact') {
142
+ matched = testInputPath === currentRoute.pathPattern;
143
+ } else {
144
+ matched = new RegExp(currentRoute.pathPattern).test(testInputPath);
145
+ }
146
+
147
+ testResult = {
148
+ matched,
149
+ targetUpstream: matched
150
+ ? currentRoute.canaryEnabled && currentRoute.canaryWeight > 0
151
+ ? `${currentRoute.upstreamUrl} (${100 - currentRoute.canaryWeight}%) / ${currentRoute.canaryUpstreamUrl || ''} (${currentRoute.canaryWeight}%)`
152
+ : currentRoute.upstreamUrl
153
+ : '无可用上游',
154
+ message: matched ? '测试路径与规则匹配成功!' : '路径未满足前缀或模式匹配要求',
155
+ };
156
+ }
157
+ } catch {
158
+ testResult = { matched: false, targetUpstream: '无可用上游', message: '路由测试失败,请检查路径规则或测试服务。' };
159
+ } finally {
160
+ isTesting = false;
161
+ }
162
+ }
163
+
164
+ async function handleSave() {
165
+ if (!onsave || isSaving) return;
166
+ isSaving = true;
167
+ savedSnapshot = null;
168
+ saveError = '';
169
+ try {
170
+ const payload = copyRoute(currentRoute);
171
+ const snapshot = JSON.stringify(payload);
172
+ await onsave(payload);
173
+ savedSnapshot = snapshot;
174
+ } catch {
175
+ saveError = '保存失败,请重试。';
176
+ } finally {
177
+ isSaving = false;
178
+ }
179
+ }
180
+ </script>
181
+
182
+ <div
183
+ class="relative rounded-xl border border-border bg-card p-6 shadow-lg transition-all"
184
+ data-svadmin-component="GatewayRouteEditor"
185
+ >
186
+ <!-- Header Title & Status -->
187
+ <div class="flex flex-wrap items-center justify-between gap-4 pb-5 border-b border-border">
188
+ <div class="flex items-center gap-3">
189
+ <div class="flex h-11 w-11 shrink-0 items-center justify-center rounded-xl bg-primary/10 text-primary border border-primary/20">
190
+ <Network class="h-6 w-6" />
191
+ </div>
192
+ <div>
193
+ <div class="flex items-center gap-2">
194
+ <h2 class="text-base font-semibold text-foreground tracking-tight">{title}</h2>
195
+ <span class="inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold
196
+ {currentRoute.enabled ? 'bg-success/15 text-success border border-success/30' : 'bg-muted text-muted-foreground'}">
197
+ {currentRoute.enabled ? '规则已生效' : '规则已禁用'}
198
+ </span>
199
+ </div>
200
+ <p class="text-xs text-muted-foreground">{subtitle}</p>
201
+ </div>
202
+ </div>
203
+
204
+ <div class="flex items-center gap-2">
205
+ <label class="relative inline-flex items-center cursor-pointer mr-2">
206
+ <input
207
+ type="checkbox"
208
+ class="sr-only peer"
209
+ checked={currentRoute.enabled}
210
+ onchange={(e) => currentRoute.enabled = (e.target as HTMLInputElement).checked}
211
+ />
212
+ <div class="w-9 h-5 bg-muted peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-background after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-background after:border-border after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-primary"></div>
213
+ <span class="ml-2 text-xs font-medium text-foreground">路由启用</span>
214
+ </label>
215
+
216
+ {#if ondelete}
217
+ <button
218
+ type="button"
219
+ class="inline-flex items-center gap-1 rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-1.5 text-xs font-medium text-destructive hover:bg-destructive/20 transition-colors"
220
+ onclick={ondelete}
221
+ >
222
+ <Trash2 class="h-3.5 w-3.5" />
223
+ <span>删除路由</span>
224
+ </button>
225
+ {/if}
226
+
227
+ <button
228
+ type="button"
229
+ class="inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow hover:bg-primary/90 transition-colors"
230
+ onclick={handleSave}
231
+ disabled={isSaving || !onsave}
232
+ >
233
+ {#if saveSuccess}
234
+ <Check class="h-3.5 w-3.5 text-primary-foreground" />
235
+ <span>已保存配置</span>
236
+ {:else}
237
+ <span>保存路由配置</span>
238
+ {/if}
239
+ </button>
240
+ </div>
241
+ </div>
242
+
243
+ {#if saveError}
244
+ <p role="alert" class="pt-3 text-xs text-destructive">{saveError}</p>
245
+ {/if}
246
+
247
+ <div class="grid grid-cols-1 lg:grid-cols-2 gap-6 pt-6">
248
+ <!-- Left Column: Match Rules -->
249
+ <div class="space-y-5">
250
+ <div class="flex items-center gap-2 text-sm font-semibold text-foreground">
251
+ <Sliders class="h-4 w-4 text-primary" />
252
+ <span>请求入口匹配条件</span>
253
+ </div>
254
+
255
+ <!-- Route Name & ID -->
256
+ <div class="grid grid-cols-2 gap-3 text-xs">
257
+ <div>
258
+ <label for="gateway-route-name" class="block font-medium text-muted-foreground mb-1">路由名称</label>
259
+ <input
260
+ id="gateway-route-name"
261
+ type="text"
262
+ class="w-full rounded-lg border border-input bg-background px-3 py-1.5 text-xs font-medium text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
263
+ bind:value={currentRoute.name}
264
+ />
265
+ </div>
266
+ <div>
267
+ <label for="gateway-route-id" class="block font-medium text-muted-foreground mb-1">路由唯一标识 (ID)</label>
268
+ <input
269
+ id="gateway-route-id"
270
+ type="text"
271
+ class="w-full rounded-lg border border-input bg-background px-3 py-1.5 text-xs font-mono text-muted-foreground"
272
+ bind:value={currentRoute.id}
273
+ />
274
+ </div>
275
+ </div>
276
+
277
+ <!-- Path Match Pattern -->
278
+ <div class="text-xs space-y-1.5">
279
+ <label for="gateway-path-pattern" class="block font-medium text-muted-foreground">路径匹配模式 (URI Pattern)</label>
280
+ <div class="flex gap-2">
281
+ <select
282
+ class="rounded-lg border border-input bg-background px-2.5 py-1.5 text-xs text-foreground focus:outline-none focus:ring-2 focus:ring-ring"
283
+ bind:value={currentRoute.matchType}
284
+ >
285
+ <option value="prefix">前缀匹配 (Prefix)</option>
286
+ <option value="exact">精确匹配 (Exact)</option>
287
+ <option value="regex">正则表达式 (Regex)</option>
288
+ </select>
289
+ <input
290
+ id="gateway-path-pattern"
291
+ type="text"
292
+ class="flex-1 rounded-lg border border-input bg-background px-3 py-1.5 text-xs font-mono text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
293
+ placeholder="/api/v1/resource/**"
294
+ bind:value={currentRoute.pathPattern}
295
+ />
296
+ </div>
297
+ </div>
298
+
299
+ <!-- HTTP Methods -->
300
+ <div class="text-xs space-y-2">
301
+ <span class="block font-medium text-muted-foreground">允许 HTTP 方法</span>
302
+ <div class="flex flex-wrap gap-1.5">
303
+ {#each availableMethods as method (method)}
304
+ <button
305
+ type="button"
306
+ class="rounded-md px-2.5 py-1 text-[11px] font-mono font-semibold transition-colors
307
+ {currentRoute.methods.includes(method)
308
+ ? 'bg-primary text-primary-foreground shadow-sm'
309
+ : 'bg-muted text-muted-foreground hover:bg-muted/80'}"
310
+ onclick={() => toggleMethod(method)}
311
+ >
312
+ {method}
313
+ </button>
314
+ {/each}
315
+ </div>
316
+ </div>
317
+
318
+ <!-- Header Matching Criteria -->
319
+ <div class="text-xs space-y-2">
320
+ <div class="flex items-center justify-between">
321
+ <span class="font-medium text-muted-foreground">请求头 Header 限制过滤</span>
322
+ <button
323
+ type="button"
324
+ class="inline-flex items-center gap-1 text-[11px] font-medium text-primary hover:underline"
325
+ onclick={addHeaderRule}
326
+ >
327
+ <Plus class="h-3 w-3" />
328
+ <span>添加 Header 规则</span>
329
+ </button>
330
+ </div>
331
+
332
+ {#if currentRoute.headers.length === 0}
333
+ <div class="rounded-lg border border-dashed border-border p-3 text-center text-muted-foreground">
334
+ 未配置 Header 限制,所有 HTTP Header 均放行
335
+ </div>
336
+ {:else}
337
+ <div class="space-y-2">
338
+ {#each currentRoute.headers as header (header.id)}
339
+ <div class="flex items-center gap-2">
340
+ <input
341
+ type="text"
342
+ placeholder="Header 键名 (如 X-Tenant-ID)"
343
+ class="flex-1 rounded-lg border border-input bg-background px-2.5 py-1 text-xs font-mono text-foreground focus:outline-none focus:ring-1 focus:ring-ring"
344
+ bind:value={header.name}
345
+ />
346
+ <input
347
+ type="text"
348
+ placeholder="匹配值"
349
+ class="flex-1 rounded-lg border border-input bg-background px-2.5 py-1 text-xs font-mono text-foreground focus:outline-none focus:ring-1 focus:ring-ring"
350
+ bind:value={header.value}
351
+ />
352
+ <button
353
+ type="button"
354
+ class="rounded p-1 text-muted-foreground hover:text-destructive transition-colors"
355
+ onclick={() => removeHeaderRule(header.id)}
356
+ aria-label="移除 Header 规则"
357
+ >
358
+ <Trash2 class="h-3.5 w-3.5" />
359
+ </button>
360
+ </div>
361
+ {/each}
362
+ </div>
363
+ {/if}
364
+ </div>
365
+ </div>
366
+
367
+ <!-- Right Column: Upstream & Canary Traffic -->
368
+ <div class="space-y-5">
369
+ <div class="flex items-center gap-2 text-sm font-semibold text-foreground">
370
+ <Server class="h-4 w-4 text-primary" />
371
+ <span>后端集群与金丝雀灰度分流</span>
372
+ </div>
373
+
374
+ <!-- Primary Upstream URL -->
375
+ <div class="text-xs space-y-1.5">
376
+ <label for="gateway-upstream-url" class="block font-medium text-muted-foreground">主目标上游集群 (Primary Target Upstream)</label>
377
+ <input
378
+ id="gateway-upstream-url"
379
+ type="text"
380
+ class="w-full rounded-lg border border-input bg-background px-3 py-1.5 text-xs font-mono text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
381
+ placeholder="http://service-cluster.internal:8080"
382
+ bind:value={currentRoute.upstreamUrl}
383
+ />
384
+ </div>
385
+
386
+ <!-- Path Rewrite & Strip Prefix -->
387
+ <div class="rounded-lg border border-border bg-muted/20 p-3.5 text-xs space-y-3">
388
+ <div class="flex items-center justify-between">
389
+ <span class="font-medium text-foreground">剥离路径前缀 (Strip Prefix)</span>
390
+ <input
391
+ type="checkbox"
392
+ class="h-4 w-4 rounded border-border text-primary focus:ring-ring"
393
+ bind:checked={currentRoute.stripPrefix}
394
+ />
395
+ </div>
396
+ <div>
397
+ <label for="gateway-rewrite-prefix" class="block text-muted-foreground mb-1">重写转发目标前缀 (Rewrite Path)</label>
398
+ <input
399
+ id="gateway-rewrite-prefix"
400
+ type="text"
401
+ class="w-full rounded-lg border border-input bg-background px-2.5 py-1 text-xs font-mono text-foreground focus:outline-none focus:ring-1 focus:ring-ring"
402
+ placeholder="/internal/service"
403
+ bind:value={currentRoute.rewritePrefix}
404
+ />
405
+ </div>
406
+ </div>
407
+
408
+ <!-- Canary / Gray Release Traffic Slider -->
409
+ <div class="rounded-lg border border-border bg-card p-4 text-xs space-y-3 shadow-sm">
410
+ <div class="flex items-center justify-between">
411
+ <div class="flex items-center gap-1.5 font-semibold text-foreground">
412
+ <Split class="h-3.5 w-3.5 text-primary" />
413
+ <span>金丝雀 (Canary) 灰度权重分配</span>
414
+ </div>
415
+ <input
416
+ type="checkbox"
417
+ class="h-4 w-4 rounded border-border text-primary focus:ring-ring"
418
+ bind:checked={currentRoute.canaryEnabled}
419
+ />
420
+ </div>
421
+
422
+ {#if currentRoute.canaryEnabled}
423
+ <div class="space-y-3 pt-1">
424
+ <div>
425
+ <label for="gateway-canary-url" class="block text-muted-foreground mb-1">灰度集群地址</label>
426
+ <input
427
+ id="gateway-canary-url"
428
+ type="text"
429
+ class="w-full rounded-lg border border-input bg-background px-2.5 py-1 text-xs font-mono text-foreground focus:outline-none focus:ring-1 focus:ring-ring"
430
+ placeholder="http://service-canary.internal:8080"
431
+ bind:value={currentRoute.canaryUpstreamUrl}
432
+ />
433
+ </div>
434
+
435
+ <div>
436
+ <div class="flex justify-between text-muted-foreground mb-1">
437
+ <span>稳定主版本: <strong class="text-foreground">{100 - currentRoute.canaryWeight}%</strong></span>
438
+ <span>金丝雀版本: <strong class="text-primary">{currentRoute.canaryWeight}%</strong></span>
439
+ </div>
440
+ <input
441
+ type="range"
442
+ min="0"
443
+ max="100"
444
+ step="5"
445
+ class="w-full accent-primary cursor-pointer"
446
+ bind:value={currentRoute.canaryWeight}
447
+ />
448
+ </div>
449
+ </div>
450
+ {/if}
451
+ </div>
452
+
453
+ <!-- Route Test Sandbox -->
454
+ <div class="rounded-lg border border-border bg-muted/30 p-3.5 text-xs space-y-2.5">
455
+ <span class="font-semibold text-foreground">路由规则沙箱测试 (Sandbox Matcher)</span>
456
+ <div class="flex gap-2">
457
+ <input
458
+ type="text"
459
+ class="flex-1 rounded-lg border border-input bg-background px-3 py-1.5 text-xs font-mono text-foreground focus:outline-none focus:ring-2 focus:ring-ring"
460
+ placeholder="/api/v1/users/123"
461
+ bind:value={testInputPath}
462
+ />
463
+ <button
464
+ type="button"
465
+ class="inline-flex items-center gap-1 rounded-lg bg-secondary px-3 py-1.5 text-xs font-medium text-secondary-foreground hover:bg-secondary/80 transition-colors"
466
+ onclick={handleTestMatch}
467
+ disabled={isTesting}
468
+ >
469
+ <Play class="h-3 w-3" />
470
+ <span>执行推演</span>
471
+ </button>
472
+ </div>
473
+
474
+ {#if testResult}
475
+ <div class="rounded-md p-2.5 text-xs border
476
+ {testResult.matched ? 'bg-success/10 border-success/30 text-success' : 'bg-destructive/10 border-destructive/30 text-destructive'}">
477
+ <div class="flex items-center gap-1.5 font-semibold">
478
+ {#if testResult.matched}
479
+ <CheckCircle2 class="h-3.5 w-3.5" />
480
+ {:else}
481
+ <XCircle class="h-3.5 w-3.5" />
482
+ {/if}
483
+ <span>{testResult.message}</span>
484
+ </div>
485
+ <div class="mt-1 font-mono text-[11px] opacity-90">
486
+ 目标集群:{testResult.targetUpstream}
487
+ </div>
488
+ </div>
489
+ {/if}
490
+ </div>
491
+ </div>
492
+ </div>
493
+ </div>
@@ -0,0 +1,34 @@
1
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD' | 'ALL';
2
+ export interface HeaderMatchRule {
3
+ id: string;
4
+ name: string;
5
+ value: string;
6
+ op: 'exact' | 'regex' | 'prefix';
7
+ }
8
+ export interface GatewayRouteConfig {
9
+ id: string;
10
+ name: string;
11
+ description?: string;
12
+ enabled: boolean;
13
+ pathPattern: string;
14
+ matchType: 'prefix' | 'exact' | 'regex';
15
+ methods: HttpMethod[];
16
+ headers: HeaderMatchRule[];
17
+ upstreamUrl: string;
18
+ stripPrefix: boolean;
19
+ rewritePrefix?: string;
20
+ canaryEnabled: boolean;
21
+ canaryUpstreamUrl?: string;
22
+ canaryWeight: number;
23
+ }
24
+ interface Props {
25
+ route?: GatewayRouteConfig;
26
+ title?: string;
27
+ subtitle?: string;
28
+ onsave?: (route: GatewayRouteConfig) => void | Promise<void>;
29
+ ontest?: (testPath: string) => boolean | Promise<boolean>;
30
+ ondelete?: () => void;
31
+ }
32
+ declare const GatewayRouteEditor: import("svelte").Component<Props, {}, "">;
33
+ type GatewayRouteEditor = ReturnType<typeof GatewayRouteEditor>;
34
+ export default GatewayRouteEditor;