@svadmin/ui 0.129.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.
- package/dist/app.css +403 -0
- package/dist/app.theme.css +403 -0
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/AccessRevocationMatrix.svelte +425 -0
- package/dist/components/AccessRevocationMatrix.svelte.d.ts +27 -0
- package/dist/components/AudioVisualInspector.svelte +458 -0
- package/dist/components/AudioVisualInspector.svelte.d.ts +53 -0
- package/dist/components/AuditSnapshotCapture.svelte +328 -0
- package/dist/components/AuditSnapshotCapture.svelte.d.ts +28 -0
- package/dist/components/CannedResponsePicker.svelte +257 -0
- package/dist/components/CannedResponsePicker.svelte.d.ts +22 -0
- package/dist/components/ContentModerationCenter.svelte +166 -0
- package/dist/components/ContentModerationCenter.svelte.d.ts +11 -0
- package/dist/components/ContractClauseDiffViewer.svelte +566 -0
- package/dist/components/ContractClauseDiffViewer.svelte.d.ts +53 -0
- package/dist/components/DataImportPipeline.svelte +577 -0
- package/dist/components/DataImportPipeline.svelte.d.ts +35 -0
- package/dist/components/DataRetentionPolicyEditor.svelte +455 -0
- package/dist/components/DataRetentionPolicyEditor.svelte.d.ts +10 -0
- package/dist/components/ElectronicSealInspector.svelte +450 -0
- package/dist/components/ElectronicSealInspector.svelte.d.ts +72 -0
- package/dist/components/EmployeeOffboardingAuditor.svelte +405 -0
- package/dist/components/EmployeeOffboardingAuditor.svelte.d.ts +39 -0
- package/dist/components/FeatureFlagStudio.svelte +583 -0
- package/dist/components/FeatureFlagStudio.svelte.d.ts +12 -0
- package/dist/components/FieldMappingBuilder.svelte +393 -0
- package/dist/components/FieldMappingBuilder.svelte.d.ts +39 -0
- package/dist/components/GatewayRouteEditor.svelte +493 -0
- package/dist/components/GatewayRouteEditor.svelte.d.ts +34 -0
- package/dist/components/HotkeysHelpModal.svelte +286 -0
- package/dist/components/HotkeysHelpModal.svelte.d.ts +21 -0
- package/dist/components/I18nStudio.svelte +635 -0
- package/dist/components/I18nStudio.svelte.d.ts +23 -0
- package/dist/components/IpAccessRuleEditor.svelte +290 -0
- package/dist/components/IpAccessRuleEditor.svelte.d.ts +19 -0
- package/dist/components/IpWhitelistDrawer.svelte +94 -0
- package/dist/components/IpWhitelistDrawer.svelte.d.ts +10 -0
- package/dist/components/MediaAuthenticityAuditCard.svelte +357 -0
- package/dist/components/MediaAuthenticityAuditCard.svelte.d.ts +64 -0
- package/dist/components/MediaGallery.svelte +575 -0
- package/dist/components/MediaGallery.svelte.d.ts +34 -0
- package/dist/components/NotificationCenter.svelte +20 -1
- package/dist/components/NotificationCenter.svelte.d.ts +2 -0
- package/dist/components/NotificationDrawer.svelte +242 -0
- package/dist/components/NotificationDrawer.svelte.d.ts +40 -0
- package/dist/components/PrintDocument.svelte +95 -0
- package/dist/components/PrintDocument.svelte.d.ts +10 -0
- package/dist/components/PrintPreviewModal.svelte +52 -0
- package/dist/components/PrintPreviewModal.svelte.d.ts +11 -0
- package/dist/components/PrintTemplateDesigner.svelte +280 -0
- package/dist/components/PrintTemplateDesigner.svelte.d.ts +11 -0
- package/dist/components/RateLimitPolicyPanel.svelte +369 -0
- package/dist/components/RateLimitPolicyPanel.svelte.d.ts +29 -0
- package/dist/components/ResizableSplitter.svelte +246 -0
- package/dist/components/ResizableSplitter.svelte.d.ts +18 -0
- package/dist/components/SensitiveWordAuditor.svelte +368 -0
- package/dist/components/SensitiveWordAuditor.svelte.d.ts +9 -0
- package/dist/components/ServiceDeskTicketCard.svelte +297 -0
- package/dist/components/ServiceDeskTicketCard.svelte.d.ts +52 -0
- package/dist/components/ShiftScheduler.svelte +490 -0
- package/dist/components/ShiftScheduler.svelte.d.ts +50 -0
- package/dist/components/SslCertificateMonitorCard.svelte +309 -0
- package/dist/components/SslCertificateMonitorCard.svelte.d.ts +30 -0
- package/dist/components/SsoConnectionStudio.svelte +784 -0
- package/dist/components/SsoConnectionStudio.svelte.d.ts +44 -0
- package/dist/components/SsoSpMetadataPanel.svelte +44 -0
- package/dist/components/SsoSpMetadataPanel.svelte.d.ts +8 -0
- package/dist/components/StepUpAuthModal.svelte +448 -0
- package/dist/components/StepUpAuthModal.svelte.d.ts +26 -0
- package/dist/components/TrafficTopologyInspector.svelte +361 -0
- package/dist/components/TrafficTopologyInspector.svelte.d.ts +43 -0
- package/dist/components/ip-access-rules.d.ts +24 -0
- package/dist/components/ip-access-rules.js +110 -0
- package/dist/components/moderation-utils.d.ts +45 -0
- package/dist/components/moderation-utils.js +74 -0
- package/dist/components/print-document.d.ts +3 -0
- package/dist/components/print-document.js +65 -0
- package/dist/components/print-utils.d.ts +44 -0
- package/dist/components/print-utils.js +68 -0
- package/dist/components/retention-utils.d.ts +31 -0
- package/dist/components/retention-utils.js +38 -0
- package/dist/components/sso-connection-presets.d.ts +2 -0
- package/dist/components/sso-connection-presets.js +59 -0
- package/dist/components/ui/sheet/sheet.svelte +3 -1
- package/dist/components/ui/sheet/sheet.svelte.d.ts +1 -0
- package/dist/components/useFeatureFlag.d.svelte.ts +1 -0
- package/dist/components/useFeatureFlag.svelte.d.ts +45 -0
- package/dist/components/useFeatureFlag.svelte.js +94 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +53 -0
- package/package.json +5 -4
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onDestroy, untrack } from 'svelte';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
import {
|
|
5
|
+
Network,
|
|
6
|
+
Server,
|
|
7
|
+
ArrowRight,
|
|
8
|
+
RefreshCw
|
|
9
|
+
} from '@lucide/svelte';
|
|
10
|
+
import { cn } from '../utils.js';
|
|
11
|
+
|
|
12
|
+
export type TopologyNodeStatus = 'healthy' | 'warning' | 'critical' | 'bypassed';
|
|
13
|
+
export type TopologyNodeType = 'gateway' | 'service' | 'database' | 'cache' | 'external';
|
|
14
|
+
|
|
15
|
+
export interface TopologyNode {
|
|
16
|
+
id: string;
|
|
17
|
+
label: string;
|
|
18
|
+
type: TopologyNodeType;
|
|
19
|
+
status: TopologyNodeStatus;
|
|
20
|
+
region?: string;
|
|
21
|
+
qps: number;
|
|
22
|
+
latencyMsP99: number;
|
|
23
|
+
errorRatePercent: number;
|
|
24
|
+
activeInstances?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface TopologyEdge {
|
|
28
|
+
id: string;
|
|
29
|
+
from: string;
|
|
30
|
+
to: string;
|
|
31
|
+
protocol?: string; // 如 "gRPC", "HTTP/2", "TCP"
|
|
32
|
+
trafficPercentage?: number; // 流量分流比重 0~100%
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface TrafficTopologyInspectorProps {
|
|
36
|
+
/** 拓扑节点列表 */
|
|
37
|
+
nodes: TopologyNode[];
|
|
38
|
+
/** 节点间流量调用关系边 */
|
|
39
|
+
edges?: TopologyEdge[];
|
|
40
|
+
/** 标题 */
|
|
41
|
+
title?: string;
|
|
42
|
+
/** 是否只读(不可切换节点旁路切流) */
|
|
43
|
+
readonly?: boolean;
|
|
44
|
+
/** 节点旁路切流切换回调 */
|
|
45
|
+
onToggleBypass?: (nodeId: string, bypassed: boolean) => void;
|
|
46
|
+
/** 选中节点回调 */
|
|
47
|
+
onSelectNode?: (nodeId: string) => void;
|
|
48
|
+
/** 刷新拓扑数据回调 */
|
|
49
|
+
onRefresh?: () => void | Promise<void>;
|
|
50
|
+
/** 自定义操作插槽 */
|
|
51
|
+
actions?: Snippet | undefined;
|
|
52
|
+
class?: string | undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let {
|
|
56
|
+
nodes = [],
|
|
57
|
+
edges = [],
|
|
58
|
+
title = '多云微服务实时流量拓扑与链路监控',
|
|
59
|
+
readonly = false,
|
|
60
|
+
onToggleBypass,
|
|
61
|
+
onSelectNode,
|
|
62
|
+
onRefresh,
|
|
63
|
+
actions,
|
|
64
|
+
class: className = ''
|
|
65
|
+
}: TrafficTopologyInspectorProps = $props();
|
|
66
|
+
|
|
67
|
+
let selectedNodeId = $state<string | null>(untrack(() => nodes[0]?.id ?? null));
|
|
68
|
+
let isRefreshing = $state(false);
|
|
69
|
+
let refreshError = $state('');
|
|
70
|
+
let generation = 0;
|
|
71
|
+
let destroyed = false;
|
|
72
|
+
let observedRefresh = untrack(() => onRefresh);
|
|
73
|
+
$effect.pre(() => {
|
|
74
|
+
if (observedRefresh === onRefresh) return;
|
|
75
|
+
observedRefresh = onRefresh;
|
|
76
|
+
generation += 1;
|
|
77
|
+
isRefreshing = false;
|
|
78
|
+
refreshError = '';
|
|
79
|
+
});
|
|
80
|
+
onDestroy(() => { destroyed = true; generation += 1; });
|
|
81
|
+
|
|
82
|
+
async function handleRefresh() {
|
|
83
|
+
if (isRefreshing || !onRefresh || destroyed) return;
|
|
84
|
+
const current = ++generation;
|
|
85
|
+
const callback = onRefresh;
|
|
86
|
+
const isCurrent = () => !destroyed && current === generation && callback === onRefresh;
|
|
87
|
+
isRefreshing = true;
|
|
88
|
+
refreshError = '';
|
|
89
|
+
try {
|
|
90
|
+
await onRefresh();
|
|
91
|
+
} catch {
|
|
92
|
+
if (isCurrent()) refreshError = '拓扑刷新失败,请重试';
|
|
93
|
+
} finally {
|
|
94
|
+
if (isCurrent()) isRefreshing = false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function handleNodeClick(id: string) {
|
|
99
|
+
selectedNodeId = id;
|
|
100
|
+
onSelectNode?.(id);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function handleBypassToggle(node: TopologyNode) {
|
|
104
|
+
if (readonly) return;
|
|
105
|
+
const nextBypassed = node.status !== 'bypassed';
|
|
106
|
+
onToggleBypass?.(node.id, nextBypassed);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getNodeStatusBadge(status: TopologyNodeStatus) {
|
|
110
|
+
switch (status) {
|
|
111
|
+
case 'healthy':
|
|
112
|
+
return { label: '运行平稳', class: 'bg-success/15 text-success border-success/30 dark:text-success' };
|
|
113
|
+
case 'warning':
|
|
114
|
+
return { label: '延迟偏高', class: 'bg-warning/15 text-warning border-warning/30 dark:text-warning' };
|
|
115
|
+
case 'critical':
|
|
116
|
+
return { label: '异常告警', class: 'bg-destructive/15 text-destructive border-destructive/30 dark:text-destructive' };
|
|
117
|
+
default:
|
|
118
|
+
return { label: '已熔断旁路', class: 'bg-muted text-muted-foreground border-border' };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const selectedNode = $derived(nodes.find((n) => n.id === selectedNodeId) ?? nodes[0] ?? null);
|
|
123
|
+
|
|
124
|
+
const clusterMetrics = $derived.by(() => {
|
|
125
|
+
let totalQps = 0;
|
|
126
|
+
let healthyCount = 0;
|
|
127
|
+
let warningCount = 0;
|
|
128
|
+
let criticalCount = 0;
|
|
129
|
+
|
|
130
|
+
for (const n of nodes) {
|
|
131
|
+
totalQps += n.qps;
|
|
132
|
+
if (n.status === 'healthy') healthyCount++;
|
|
133
|
+
else if (n.status === 'warning') warningCount++;
|
|
134
|
+
else if (n.status === 'critical') criticalCount++;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return { totalQps, healthyCount, warningCount, criticalCount, totalNodes: nodes.length };
|
|
138
|
+
});
|
|
139
|
+
</script>
|
|
140
|
+
|
|
141
|
+
<div
|
|
142
|
+
class={cn(
|
|
143
|
+
'flex flex-col rounded-xl border border-border bg-card text-card-foreground shadow-sm overflow-hidden',
|
|
144
|
+
className
|
|
145
|
+
)}
|
|
146
|
+
data-svadmin-component="TrafficTopologyInspector"
|
|
147
|
+
>
|
|
148
|
+
<!-- 头部总览条 -->
|
|
149
|
+
<header class="flex flex-wrap items-center justify-between gap-3 border-b border-border bg-muted/30 px-5 py-4">
|
|
150
|
+
<div class="flex items-center gap-3">
|
|
151
|
+
<div class="flex h-10 w-10 items-center justify-center rounded-xl bg-primary/10 text-primary">
|
|
152
|
+
<Network class="h-5 w-5" />
|
|
153
|
+
</div>
|
|
154
|
+
<div>
|
|
155
|
+
<h3 class="text-sm font-semibold text-foreground">{title}</h3>
|
|
156
|
+
<p class="text-xs text-muted-foreground">微服务调用链吞吐量、响应延迟(p99)与动态旁路切流控制</p>
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
|
|
160
|
+
<div class="flex flex-wrap items-center gap-3 text-xs">
|
|
161
|
+
<div class="flex items-center gap-2 border-r border-border pr-3">
|
|
162
|
+
<span class="text-muted-foreground">全集群总 QPS:</span>
|
|
163
|
+
<strong class="font-mono text-sm text-foreground">{clusterMetrics.totalQps.toLocaleString()}</strong>
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
<div class="flex items-center gap-1.5">
|
|
167
|
+
<span class="flex h-2 w-2 rounded-full bg-success"></span>
|
|
168
|
+
<span>正常 {clusterMetrics.healthyCount}</span>
|
|
169
|
+
<span class="flex h-2 w-2 rounded-full bg-warning ml-1"></span>
|
|
170
|
+
<span>预警 {clusterMetrics.warningCount}</span>
|
|
171
|
+
<span class="flex h-2 w-2 rounded-full bg-destructive ml-1"></span>
|
|
172
|
+
<span>故障 {clusterMetrics.criticalCount}</span>
|
|
173
|
+
</div>
|
|
174
|
+
|
|
175
|
+
<button
|
|
176
|
+
type="button"
|
|
177
|
+
class="flex items-center gap-1 rounded-lg border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground transition-colors hover:bg-muted"
|
|
178
|
+
disabled={isRefreshing || !onRefresh}
|
|
179
|
+
onclick={handleRefresh}
|
|
180
|
+
>
|
|
181
|
+
<RefreshCw class={cn('h-3.5 w-3.5', isRefreshing && 'animate-spin text-primary')} />
|
|
182
|
+
刷新拓扑
|
|
183
|
+
</button>
|
|
184
|
+
|
|
185
|
+
{#if actions}
|
|
186
|
+
{@render actions()}
|
|
187
|
+
{/if}
|
|
188
|
+
</div>
|
|
189
|
+
</header>
|
|
190
|
+
{#if refreshError}<p role="alert" class="p-4 text-xs text-destructive">{refreshError}</p>{/if}
|
|
191
|
+
|
|
192
|
+
<!-- 拓扑工作区:主拓扑矩阵 + 节点详情抽屉 -->
|
|
193
|
+
<div class="grid grid-cols-1 divide-y divide-border lg:grid-cols-12 lg:divide-x lg:divide-y-0 text-xs">
|
|
194
|
+
<!-- 左侧:拓扑调用链路卡片群 (8 列) -->
|
|
195
|
+
<div class="flex flex-col gap-4 p-5 lg:col-span-8 bg-muted/10">
|
|
196
|
+
<div class="flex items-center justify-between text-muted-foreground">
|
|
197
|
+
<span class="font-semibold text-foreground">微服务拓扑节点矩阵 ({nodes.length})</span>
|
|
198
|
+
<span>点击节点查看链路详情或执行旁路熔断</span>
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
<!-- 节点网格卡片 -->
|
|
202
|
+
<div class="grid grid-cols-1 gap-3 sm:grid-cols-2">
|
|
203
|
+
{#each nodes as node (node.id)}
|
|
204
|
+
{@const statusBadge = getNodeStatusBadge(node.status)}
|
|
205
|
+
<div
|
|
206
|
+
class={cn(
|
|
207
|
+
'flex flex-col gap-2 rounded-xl border p-4 transition-all cursor-pointer shadow-xs',
|
|
208
|
+
selectedNodeId === node.id
|
|
209
|
+
? 'border-primary bg-primary/5 ring-1 ring-primary'
|
|
210
|
+
: 'border-border bg-card hover:border-primary/50'
|
|
211
|
+
)}
|
|
212
|
+
onclick={() => handleNodeClick(node.id)}
|
|
213
|
+
role="button"
|
|
214
|
+
tabindex="0"
|
|
215
|
+
onkeydown={(e) => {
|
|
216
|
+
if (e.key === 'Enter') handleNodeClick(node.id);
|
|
217
|
+
}}
|
|
218
|
+
>
|
|
219
|
+
<div class="flex items-start justify-between gap-2">
|
|
220
|
+
<div class="flex items-center gap-2">
|
|
221
|
+
<div class="flex h-7 w-7 items-center justify-center rounded-lg bg-muted text-foreground">
|
|
222
|
+
<Server class="h-4 w-4" />
|
|
223
|
+
</div>
|
|
224
|
+
<div>
|
|
225
|
+
<h4 class="font-bold text-foreground text-xs">{node.label}</h4>
|
|
226
|
+
{#if node.region}
|
|
227
|
+
<span class="text-[10px] text-muted-foreground">{node.region}</span>
|
|
228
|
+
{/if}
|
|
229
|
+
</div>
|
|
230
|
+
</div>
|
|
231
|
+
|
|
232
|
+
<span class={cn('rounded border px-1.5 py-0.2 text-[10px] font-semibold', statusBadge.class)}>
|
|
233
|
+
{statusBadge.label}
|
|
234
|
+
</span>
|
|
235
|
+
</div>
|
|
236
|
+
|
|
237
|
+
<!-- 指标列 -->
|
|
238
|
+
<div class="grid grid-cols-3 gap-1 pt-1 border-t border-border/60 text-muted-foreground text-[11px]">
|
|
239
|
+
<div>
|
|
240
|
+
<span>QPS</span>
|
|
241
|
+
<strong class="block font-mono text-foreground">{node.qps}</strong>
|
|
242
|
+
</div>
|
|
243
|
+
<div>
|
|
244
|
+
<span>p99 延迟</span>
|
|
245
|
+
<span class={cn('block font-mono font-medium', node.latencyMsP99 > 200 ? 'text-destructive' : 'text-foreground')}>
|
|
246
|
+
{node.latencyMsP99} ms
|
|
247
|
+
</span>
|
|
248
|
+
</div>
|
|
249
|
+
<div>
|
|
250
|
+
<span>错误率</span>
|
|
251
|
+
<span class={cn('block font-mono font-medium', node.errorRatePercent > 1 ? 'text-destructive' : 'text-foreground')}>
|
|
252
|
+
{node.errorRatePercent}%
|
|
253
|
+
</span>
|
|
254
|
+
</div>
|
|
255
|
+
</div>
|
|
256
|
+
</div>
|
|
257
|
+
{/each}
|
|
258
|
+
</div>
|
|
259
|
+
|
|
260
|
+
<!-- 节点间关系边示意流 -->
|
|
261
|
+
{#if edges.length > 0}
|
|
262
|
+
<div class="rounded-lg border border-border bg-card p-3 space-y-2">
|
|
263
|
+
<div class="font-semibold text-foreground text-[11px]">活跃调用链路流向 (Edges)</div>
|
|
264
|
+
<div class="flex flex-wrap gap-2">
|
|
265
|
+
{#each edges as edge (edge.id)}
|
|
266
|
+
<div class="flex items-center gap-1.5 rounded-md border border-border bg-muted/40 px-2.5 py-1 text-[11px] text-muted-foreground">
|
|
267
|
+
<span class="font-medium text-foreground">{edge.from}</span>
|
|
268
|
+
<ArrowRight class="h-3 w-3 text-muted-foreground" />
|
|
269
|
+
<span class="font-medium text-foreground">{edge.to}</span>
|
|
270
|
+
{#if edge.protocol}
|
|
271
|
+
<span class="rounded bg-muted px-1 font-mono text-[9px]">{edge.protocol}</span>
|
|
272
|
+
{/if}
|
|
273
|
+
{#if edge.trafficPercentage !== undefined}
|
|
274
|
+
<span class="text-primary font-mono text-[10px] font-semibold">{edge.trafficPercentage}%</span>
|
|
275
|
+
{/if}
|
|
276
|
+
</div>
|
|
277
|
+
{/each}
|
|
278
|
+
</div>
|
|
279
|
+
</div>
|
|
280
|
+
{/if}
|
|
281
|
+
</div>
|
|
282
|
+
|
|
283
|
+
<!-- 右侧:选中节点详情与旁路熔断控制 (4 列) -->
|
|
284
|
+
<div class="flex flex-col gap-4 p-5 lg:col-span-4 bg-card">
|
|
285
|
+
{#if selectedNode}
|
|
286
|
+
{@const statusBadge = getNodeStatusBadge(selectedNode.status)}
|
|
287
|
+
<div class="flex items-center justify-between border-b border-border pb-3">
|
|
288
|
+
<div>
|
|
289
|
+
<h4 class="text-sm font-bold text-foreground">{selectedNode.label}</h4>
|
|
290
|
+
<span class="text-muted-foreground text-[11px]">节点 ID: <code class="font-mono">{selectedNode.id}</code></span>
|
|
291
|
+
</div>
|
|
292
|
+
<span class={cn('rounded border px-2 py-0.5 text-xs font-semibold', statusBadge.class)}>
|
|
293
|
+
{statusBadge.label}
|
|
294
|
+
</span>
|
|
295
|
+
</div>
|
|
296
|
+
|
|
297
|
+
<!-- 详细指标 -->
|
|
298
|
+
<div class="flex flex-col gap-2.5 text-muted-foreground">
|
|
299
|
+
<div class="flex justify-between">
|
|
300
|
+
<span>服务类型:</span>
|
|
301
|
+
<span class="font-mono uppercase text-foreground">{selectedNode.type}</span>
|
|
302
|
+
</div>
|
|
303
|
+
{#if selectedNode.region}
|
|
304
|
+
<div class="flex justify-between">
|
|
305
|
+
<span>部署地域 / 可用区:</span>
|
|
306
|
+
<span class="text-foreground">{selectedNode.region}</span>
|
|
307
|
+
</div>
|
|
308
|
+
{/if}
|
|
309
|
+
{#if selectedNode.activeInstances}
|
|
310
|
+
<div class="flex justify-between">
|
|
311
|
+
<span>容器实例数 (Pods):</span>
|
|
312
|
+
<span class="font-mono text-foreground font-semibold">{selectedNode.activeInstances} 个</span>
|
|
313
|
+
</div>
|
|
314
|
+
{/if}
|
|
315
|
+
<div class="flex justify-between">
|
|
316
|
+
<span>实时流量吞吐:</span>
|
|
317
|
+
<span class="font-mono font-bold text-foreground">{selectedNode.qps} req/s</span>
|
|
318
|
+
</div>
|
|
319
|
+
<div class="flex justify-between">
|
|
320
|
+
<span>p99 端到端耗时:</span>
|
|
321
|
+
<span class="font-mono text-foreground">{selectedNode.latencyMsP99} ms</span>
|
|
322
|
+
</div>
|
|
323
|
+
<div class="flex justify-between">
|
|
324
|
+
<span>HTTP 5xx 异常率:</span>
|
|
325
|
+
<span class="font-mono text-foreground">{selectedNode.errorRatePercent}%</span>
|
|
326
|
+
</div>
|
|
327
|
+
</div>
|
|
328
|
+
|
|
329
|
+
<!-- 旁路切流与熔断控制箱 -->
|
|
330
|
+
<div class="mt-2 rounded-xl border border-border bg-muted/20 p-4 space-y-3">
|
|
331
|
+
<div class="flex items-center justify-between">
|
|
332
|
+
<div>
|
|
333
|
+
<span class="font-semibold text-foreground block">流量旁路熔断控制</span>
|
|
334
|
+
<span class="text-[11px] text-muted-foreground">
|
|
335
|
+
{selectedNode.status === 'bypassed' ? '该节点已被踢出路由池' : '节点正正常承接线上流量'}
|
|
336
|
+
</span>
|
|
337
|
+
</div>
|
|
338
|
+
{#if !readonly}
|
|
339
|
+
<button
|
|
340
|
+
type="button"
|
|
341
|
+
class={cn(
|
|
342
|
+
'rounded-lg px-3 py-1.5 font-medium transition-colors',
|
|
343
|
+
selectedNode.status === 'bypassed'
|
|
344
|
+
? 'bg-success text-background hover:bg-success'
|
|
345
|
+
: 'bg-destructive text-background hover:bg-destructive'
|
|
346
|
+
)}
|
|
347
|
+
onclick={() => selectedNode && handleBypassToggle(selectedNode)}
|
|
348
|
+
>
|
|
349
|
+
{selectedNode.status === 'bypassed' ? '恢复上线' : '一键熔断旁路'}
|
|
350
|
+
</button>
|
|
351
|
+
{/if}
|
|
352
|
+
</div>
|
|
353
|
+
</div>
|
|
354
|
+
{:else}
|
|
355
|
+
<div class="py-12 text-center text-muted-foreground">
|
|
356
|
+
请选择一个拓扑节点以查看监控详情
|
|
357
|
+
</div>
|
|
358
|
+
{/if}
|
|
359
|
+
</div>
|
|
360
|
+
</div>
|
|
361
|
+
</div>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export type TopologyNodeStatus = 'healthy' | 'warning' | 'critical' | 'bypassed';
|
|
3
|
+
export type TopologyNodeType = 'gateway' | 'service' | 'database' | 'cache' | 'external';
|
|
4
|
+
export interface TopologyNode {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
type: TopologyNodeType;
|
|
8
|
+
status: TopologyNodeStatus;
|
|
9
|
+
region?: string;
|
|
10
|
+
qps: number;
|
|
11
|
+
latencyMsP99: number;
|
|
12
|
+
errorRatePercent: number;
|
|
13
|
+
activeInstances?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface TopologyEdge {
|
|
16
|
+
id: string;
|
|
17
|
+
from: string;
|
|
18
|
+
to: string;
|
|
19
|
+
protocol?: string;
|
|
20
|
+
trafficPercentage?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface TrafficTopologyInspectorProps {
|
|
23
|
+
/** 拓扑节点列表 */
|
|
24
|
+
nodes: TopologyNode[];
|
|
25
|
+
/** 节点间流量调用关系边 */
|
|
26
|
+
edges?: TopologyEdge[];
|
|
27
|
+
/** 标题 */
|
|
28
|
+
title?: string;
|
|
29
|
+
/** 是否只读(不可切换节点旁路切流) */
|
|
30
|
+
readonly?: boolean;
|
|
31
|
+
/** 节点旁路切流切换回调 */
|
|
32
|
+
onToggleBypass?: (nodeId: string, bypassed: boolean) => void;
|
|
33
|
+
/** 选中节点回调 */
|
|
34
|
+
onSelectNode?: (nodeId: string) => void;
|
|
35
|
+
/** 刷新拓扑数据回调 */
|
|
36
|
+
onRefresh?: () => void | Promise<void>;
|
|
37
|
+
/** 自定义操作插槽 */
|
|
38
|
+
actions?: Snippet | undefined;
|
|
39
|
+
class?: string | undefined;
|
|
40
|
+
}
|
|
41
|
+
declare const TrafficTopologyInspector: import("svelte").Component<TrafficTopologyInspectorProps, {}, "">;
|
|
42
|
+
type TrafficTopologyInspector = ReturnType<typeof TrafficTopologyInspector>;
|
|
43
|
+
export default TrafficTopologyInspector;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type IpRuleType = 'SINGLE' | 'CIDR' | 'RANGE';
|
|
2
|
+
export type IpRuleAction = 'ALLOW' | 'DENY';
|
|
3
|
+
export type IpAccessMode = 'WHITELIST' | 'BLACKLIST';
|
|
4
|
+
export interface IpAccessRule {
|
|
5
|
+
id: string;
|
|
6
|
+
type: IpRuleType;
|
|
7
|
+
value: string;
|
|
8
|
+
action: IpRuleAction;
|
|
9
|
+
description?: string;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
startsAt?: string | null;
|
|
12
|
+
expiresAt?: string | null;
|
|
13
|
+
/** 仅保留宿主元数据;本地安全预览始终 DENY 优先。 */
|
|
14
|
+
priority?: number;
|
|
15
|
+
createdAt?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function validateIpRuleValue(type: IpRuleType, value: string): {
|
|
18
|
+
valid: boolean;
|
|
19
|
+
error?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function ruleTimingError(rule: Pick<IpAccessRule, 'startsAt' | 'expiresAt'>): string | null;
|
|
22
|
+
export declare function ipRuleState(rule: IpAccessRule, now: number): 'Disabled' | 'Invalid' | 'Scheduled' | 'Expired' | 'Active';
|
|
23
|
+
export declare function clientIpAllowed(rules: IpAccessRule[], mode: IpAccessMode, ip: string, now: number): boolean;
|
|
24
|
+
export declare function lockoutError(rules: IpAccessRule[], mode: IpAccessMode, ip: string, now: number): string | null;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Address4, Address6 } from 'ip-address';
|
|
2
|
+
const ipv4 = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
|
|
3
|
+
function parseAddress(address) {
|
|
4
|
+
if (ipv4.test(address))
|
|
5
|
+
return new Address4(address);
|
|
6
|
+
if (!address.includes(':') || /[/\s%[\]]/.test(address) || !Address6.isValid(address))
|
|
7
|
+
return null;
|
|
8
|
+
return new Address6(address);
|
|
9
|
+
}
|
|
10
|
+
function singleBounds(address) {
|
|
11
|
+
const parsed = parseAddress(address);
|
|
12
|
+
if (!parsed)
|
|
13
|
+
return null;
|
|
14
|
+
// 映射 IPv6 与普通 IPv4 必须使用同一比较域,防止同一连接绕过冲突检查。
|
|
15
|
+
const normalized = parsed instanceof Address6 && parsed.isMapped4() ? parsed.to4() : parsed;
|
|
16
|
+
return { family: normalized instanceof Address4 ? 4 : 6, first: normalized.bigInt(), last: normalized.bigInt() };
|
|
17
|
+
}
|
|
18
|
+
function cidrBounds(pattern) {
|
|
19
|
+
const parts = pattern.split('/');
|
|
20
|
+
const address = parts[0] ? parseAddress(parts[0]) : null;
|
|
21
|
+
if (parts.length !== 2 || !address || !/^(0|[1-9]\d*)$/.test(parts[1] ?? ''))
|
|
22
|
+
return null;
|
|
23
|
+
const prefix = Number(parts[1]);
|
|
24
|
+
const maximum = address instanceof Address4 ? 32 : 128;
|
|
25
|
+
if (prefix > maximum)
|
|
26
|
+
return null;
|
|
27
|
+
const subnet = address instanceof Address4 ? new Address4(pattern) : new Address6(pattern);
|
|
28
|
+
if (subnet instanceof Address6 && subnet.isMapped4() && prefix >= 96) {
|
|
29
|
+
const mapped = subnet.to4();
|
|
30
|
+
return { family: 4, first: mapped.startAddress().bigInt(), last: mapped.endAddress().bigInt() };
|
|
31
|
+
}
|
|
32
|
+
return { family: maximum === 32 ? 4 : 6, first: subnet.startAddress().bigInt(), last: subnet.endAddress().bigInt() };
|
|
33
|
+
}
|
|
34
|
+
function patternBounds(type, pattern) {
|
|
35
|
+
if (type === 'SINGLE')
|
|
36
|
+
return singleBounds(pattern);
|
|
37
|
+
if (type === 'CIDR')
|
|
38
|
+
return cidrBounds(pattern);
|
|
39
|
+
if (type !== 'RANGE')
|
|
40
|
+
return null;
|
|
41
|
+
const endpoints = pattern.split('-').map(endpoint => singleBounds(endpoint.trim()));
|
|
42
|
+
const [start, end] = endpoints;
|
|
43
|
+
if (endpoints.length !== 2 || !start || !end || start.family !== end.family || start.first > end.first)
|
|
44
|
+
return null;
|
|
45
|
+
return { family: start.family, first: start.first, last: end.first };
|
|
46
|
+
}
|
|
47
|
+
export function validateIpRuleValue(type, value) {
|
|
48
|
+
if (patternBounds(type, value.trim()))
|
|
49
|
+
return { valid: true };
|
|
50
|
+
return { valid: false, error: 'Enter a valid IP, decimal CIDR prefix, or ascending same-family IP range.' };
|
|
51
|
+
}
|
|
52
|
+
export function ruleTimingError(rule) {
|
|
53
|
+
const start = rule.startsAt == null ? null : Date.parse(rule.startsAt);
|
|
54
|
+
const end = rule.expiresAt == null ? null : Date.parse(rule.expiresAt);
|
|
55
|
+
if ((start !== null && !Number.isFinite(start)) || (end !== null && !Number.isFinite(end)))
|
|
56
|
+
return 'Invalid rule date.';
|
|
57
|
+
if (start !== null && end !== null && end <= start)
|
|
58
|
+
return 'Expiration must be after activation.';
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
export function ipRuleState(rule, now) {
|
|
62
|
+
if (!rule.enabled)
|
|
63
|
+
return 'Disabled';
|
|
64
|
+
if (ruleTimingError(rule) || !validateIpRuleValue(rule.type, rule.value).valid)
|
|
65
|
+
return 'Invalid';
|
|
66
|
+
if (rule.expiresAt != null && Date.parse(rule.expiresAt) <= now)
|
|
67
|
+
return 'Expired';
|
|
68
|
+
if (rule.startsAt != null && Date.parse(rule.startsAt) > now)
|
|
69
|
+
return 'Scheduled';
|
|
70
|
+
return 'Active';
|
|
71
|
+
}
|
|
72
|
+
function matchesAddress(bounds, address) {
|
|
73
|
+
if (bounds.family === address.family)
|
|
74
|
+
return bounds.first <= address.first && address.first <= bounds.last;
|
|
75
|
+
// IPv6 的 /0 等广域规则也必须覆盖 IPv4-mapped 连接。
|
|
76
|
+
if (bounds.family === 6 && address.family === 4) {
|
|
77
|
+
const mapped = new Address6(`::ffff:${Address4.fromBigInt(address.first).correctForm()}`).bigInt();
|
|
78
|
+
return bounds.first <= mapped && mapped <= bounds.last;
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
export function clientIpAllowed(rules, mode, ip, now) {
|
|
83
|
+
const address = singleBounds(ip.trim());
|
|
84
|
+
if (!address)
|
|
85
|
+
return false;
|
|
86
|
+
const matches = rules.filter(rule => {
|
|
87
|
+
const bounds = patternBounds(rule.type, rule.value.trim());
|
|
88
|
+
return bounds && ipRuleState(rule, now) === 'Active' && matchesAddress(bounds, address);
|
|
89
|
+
});
|
|
90
|
+
if (matches.some(rule => rule.action === 'DENY'))
|
|
91
|
+
return false;
|
|
92
|
+
return mode === 'BLACKLIST' || matches.some(rule => rule.action === 'ALLOW');
|
|
93
|
+
}
|
|
94
|
+
export function lockoutError(rules, mode, ip, now) {
|
|
95
|
+
if (!validateIpRuleValue('SINGLE', ip).valid)
|
|
96
|
+
return 'Resolve a valid server-observed client IP before changing this policy.';
|
|
97
|
+
if (rules.some(rule => !validateIpRuleValue(rule.type, rule.value).valid || ruleTimingError(rule)
|
|
98
|
+
|| !['ALLOW', 'DENY'].includes(rule.action)))
|
|
99
|
+
return 'Fix invalid rule patterns, actions or dates before saving the policy.';
|
|
100
|
+
if (new Set(rules.map(rule => rule.id)).size !== rules.length)
|
|
101
|
+
return 'Rule IDs must be unique.';
|
|
102
|
+
if (!clientIpAllowed(rules, mode, ip, now))
|
|
103
|
+
return 'This change would block your current IP. Keep an active ALLOW rule and remove conflicting DENY rules.';
|
|
104
|
+
// 只检查会改变策略的时刻,防止临时放行到期或未来 DENY 生效后误锁。
|
|
105
|
+
const boundaries = rules.flatMap(rule => [rule.startsAt, rule.expiresAt])
|
|
106
|
+
.filter((date) => date != null).map(date => Date.parse(date)).filter(time => Number.isFinite(time) && time > now);
|
|
107
|
+
return boundaries.some(time => !clientIpAllowed(rules, mode, ip, time))
|
|
108
|
+
? 'A scheduled rule or expiration would later block your current IP. Keep permanent access before saving.'
|
|
109
|
+
: null;
|
|
110
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type ModerationCategory = 'politics' | 'violence' | 'pornography' | 'spam' | 'custom';
|
|
2
|
+
export type ModerationAction = 'block' | 'mask' | 'review';
|
|
3
|
+
export type ModerationSeverity = 'critical' | 'high' | 'medium' | 'low';
|
|
4
|
+
export interface SensitiveWordItem {
|
|
5
|
+
id: string;
|
|
6
|
+
word: string;
|
|
7
|
+
category: ModerationCategory;
|
|
8
|
+
action: ModerationAction;
|
|
9
|
+
severity: ModerationSeverity;
|
|
10
|
+
replacement?: string;
|
|
11
|
+
enabled: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface ModerationMatch {
|
|
14
|
+
word: string;
|
|
15
|
+
category: ModerationCategory;
|
|
16
|
+
action: ModerationAction;
|
|
17
|
+
severity: ModerationSeverity;
|
|
18
|
+
index: number;
|
|
19
|
+
length: number;
|
|
20
|
+
replacement?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ModerationScanResult {
|
|
23
|
+
hasViolation: boolean;
|
|
24
|
+
blockRequired: boolean;
|
|
25
|
+
reviewRequired: boolean;
|
|
26
|
+
totalHits: number;
|
|
27
|
+
matches: ModerationMatch[];
|
|
28
|
+
maskedText: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ModerationTicket {
|
|
31
|
+
id: string;
|
|
32
|
+
title: string;
|
|
33
|
+
sourceModule: string;
|
|
34
|
+
author: string;
|
|
35
|
+
submittedAt: string;
|
|
36
|
+
rawContent: string;
|
|
37
|
+
status: 'pending' | 'approved' | 'rejected' | 'masked';
|
|
38
|
+
riskScore: number;
|
|
39
|
+
matches: ModerationMatch[];
|
|
40
|
+
}
|
|
41
|
+
export declare function maskModerationMatches(text: string, matches: ModerationMatch[]): string;
|
|
42
|
+
/**
|
|
43
|
+
* 扫描文本并根据敏感词库进行分词匹配与脱敏处理
|
|
44
|
+
*/
|
|
45
|
+
export declare function scanContent(text: string, dictionary: SensitiveWordItem[]): ModerationScanResult;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export function maskModerationMatches(text, matches) {
|
|
2
|
+
const regions = [];
|
|
3
|
+
for (const match of [...matches].sort((a, b) => a.index - b.index)) {
|
|
4
|
+
if (!Number.isInteger(match.index) || !Number.isInteger(match.length)
|
|
5
|
+
|| match.index < 0 || match.length < 1 || match.index + match.length > text.length) {
|
|
6
|
+
throw new RangeError('敏感词匹配位置无效');
|
|
7
|
+
}
|
|
8
|
+
const end = match.index + match.length;
|
|
9
|
+
const previous = regions.at(-1);
|
|
10
|
+
// 重叠命中覆盖原文区间的并集;相邻命中独立替换,不处理替换产物。
|
|
11
|
+
if (previous && match.index < previous.end) {
|
|
12
|
+
previous.end = Math.max(previous.end, end);
|
|
13
|
+
previous.replacement = '*'.repeat(previous.end - previous.start);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
regions.push({ start: match.index, end, replacement: match.replacement ?? '*'.repeat(match.length) });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
let cursor = 0;
|
|
20
|
+
let masked = '';
|
|
21
|
+
for (const region of regions) {
|
|
22
|
+
masked += text.slice(cursor, region.start) + region.replacement;
|
|
23
|
+
cursor = region.end;
|
|
24
|
+
}
|
|
25
|
+
return masked + text.slice(cursor);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 扫描文本并根据敏感词库进行分词匹配与脱敏处理
|
|
29
|
+
*/
|
|
30
|
+
export function scanContent(text, dictionary) {
|
|
31
|
+
if (!text) {
|
|
32
|
+
return {
|
|
33
|
+
hasViolation: false,
|
|
34
|
+
blockRequired: false,
|
|
35
|
+
reviewRequired: false,
|
|
36
|
+
totalHits: 0,
|
|
37
|
+
matches: [],
|
|
38
|
+
maskedText: '',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const activeWords = dictionary.filter(w => w.enabled);
|
|
42
|
+
const matches = [];
|
|
43
|
+
for (const item of activeWords) {
|
|
44
|
+
if (!item.word.trim())
|
|
45
|
+
continue;
|
|
46
|
+
const pattern = new RegExp(item.word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi');
|
|
47
|
+
let occurrence;
|
|
48
|
+
while ((occurrence = pattern.exec(text)) !== null) {
|
|
49
|
+
matches.push({
|
|
50
|
+
word: item.word,
|
|
51
|
+
category: item.category,
|
|
52
|
+
action: item.action,
|
|
53
|
+
severity: item.severity,
|
|
54
|
+
index: occurrence.index,
|
|
55
|
+
length: occurrence[0].length,
|
|
56
|
+
...(item.replacement ? { replacement: item.replacement } : {}),
|
|
57
|
+
});
|
|
58
|
+
pattern.lastIndex = occurrence.index + 1;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Sort matches by offset index
|
|
62
|
+
matches.sort((a, b) => a.index - b.index);
|
|
63
|
+
const maskedText = maskModerationMatches(text, matches);
|
|
64
|
+
const blockRequired = matches.some(m => m.action === 'block' || m.severity === 'critical');
|
|
65
|
+
const reviewRequired = matches.some(m => m.action === 'review' || m.severity === 'high');
|
|
66
|
+
return {
|
|
67
|
+
hasViolation: matches.length > 0,
|
|
68
|
+
blockRequired,
|
|
69
|
+
reviewRequired,
|
|
70
|
+
totalHits: matches.length,
|
|
71
|
+
matches,
|
|
72
|
+
maskedText,
|
|
73
|
+
};
|
|
74
|
+
}
|