@svadmin/ui 0.122.0 → 0.126.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 +581 -4
- package/dist/app.theme.css +581 -4
- package/dist/components/AbacPolicyMatrix.svelte +356 -0
- package/dist/components/AbacPolicyMatrix.svelte.d.ts +30 -0
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/ActionPalette.svelte +272 -0
- package/dist/components/ActionPalette.svelte.d.ts +23 -0
- package/dist/components/AdminCopilotWidget.svelte +316 -0
- package/dist/components/AdminCopilotWidget.svelte.d.ts +33 -0
- package/dist/components/AnnouncementBanner.svelte +12 -1
- package/dist/components/AnnouncementBanner.svelte.d.ts +4 -0
- package/dist/components/ApiPlayground.svelte +255 -0
- package/dist/components/ApiPlayground.svelte.d.ts +24 -0
- package/dist/components/ApiSettings.svelte +1 -1
- package/dist/components/AppearanceSettings.svelte +1 -1
- package/dist/components/ApprovalChainBuilder.svelte +262 -0
- package/dist/components/ApprovalChainBuilder.svelte.d.ts +20 -0
- package/dist/components/ApprovalTimeline.svelte +8 -1
- package/dist/components/AsyncExportModal.svelte +1 -1
- package/dist/components/AudioFeedbackProvider.svelte +1 -1
- package/dist/components/AuditLogDrawer.svelte +2 -2
- package/dist/components/AuditTrailInspector.svelte +448 -0
- package/dist/components/AuditTrailInspector.svelte.d.ts +44 -0
- package/dist/components/AutoTable.svelte +20 -1
- package/dist/components/AutoTable.svelte.d.ts +2 -0
- package/dist/components/BatchEditModal.svelte +266 -0
- package/dist/components/BatchEditModal.svelte.d.ts +27 -0
- package/dist/components/BillingInvoiceDrawer.svelte +206 -0
- package/dist/components/BillingInvoiceDrawer.svelte.d.ts +30 -0
- package/dist/components/ChartAnnotationOverlay.svelte +228 -0
- package/dist/components/ChartAnnotationOverlay.svelte.d.ts +21 -0
- package/dist/components/CheckCard.svelte +1 -1
- package/dist/components/ClusterTopologyGraph.svelte +317 -0
- package/dist/components/ClusterTopologyGraph.svelte.d.ts +31 -0
- package/dist/components/ColumnHeaderFilter.svelte +6 -6
- package/dist/components/ColumnMappingTable.svelte +174 -0
- package/dist/components/ColumnMappingTable.svelte.d.ts +23 -0
- package/dist/components/ConversionFunnel.svelte +1 -1
- package/dist/components/CursorListFooter.svelte +67 -0
- package/dist/components/CursorListFooter.svelte.d.ts +17 -0
- package/dist/components/DashboardGridLayout.svelte +309 -0
- package/dist/components/DashboardGridLayout.svelte.d.ts +30 -0
- package/dist/components/DashboardLayoutStorage.svelte +278 -0
- package/dist/components/DashboardLayoutStorage.svelte.d.ts +23 -0
- package/dist/components/DataFreshnessIndicator.svelte +149 -0
- package/dist/components/DataFreshnessIndicator.svelte.d.ts +20 -0
- package/dist/components/DataImportDropzone.svelte +215 -0
- package/dist/components/DataImportDropzone.svelte.d.ts +24 -0
- package/dist/components/DataLineageGraph.svelte +203 -0
- package/dist/components/DataLineageGraph.svelte.d.ts +26 -0
- package/dist/components/DataMaskPolicyEngine.svelte +291 -0
- package/dist/components/DataMaskPolicyEngine.svelte.d.ts +25 -0
- package/dist/components/DataScopeRuleEditor.svelte +142 -0
- package/dist/components/DataScopeRuleEditor.svelte.d.ts +19 -0
- package/dist/components/DataScreenContainer.svelte +160 -0
- package/dist/components/DataScreenContainer.svelte.d.ts +15 -0
- package/dist/components/DevTools.svelte +3 -3
- package/dist/components/DualApprovalGate.svelte +132 -65
- package/dist/components/DualApprovalGate.svelte.d.ts +20 -1
- package/dist/components/EditableTable.svelte +2 -2
- package/dist/components/ElectronicSealStamp.svelte +102 -0
- package/dist/components/ElectronicSealStamp.svelte.d.ts +14 -0
- package/dist/components/EnvVariableEditor.svelte +284 -0
- package/dist/components/EnvVariableEditor.svelte.d.ts +17 -0
- package/dist/components/ExcelImportWizard.svelte +2 -2
- package/dist/components/FeatureAnnouncementModal.svelte +173 -0
- package/dist/components/FeatureAnnouncementModal.svelte.d.ts +21 -0
- package/dist/components/FieldRenderer.svelte +1 -1
- package/dist/components/FilterTagBar.svelte +210 -0
- package/dist/components/FilterTagBar.svelte.d.ts +23 -0
- package/dist/components/FormulaField.svelte +149 -0
- package/dist/components/FormulaField.svelte.d.ts +18 -0
- package/dist/components/GeoScatterMap.svelte +225 -0
- package/dist/components/GeoScatterMap.svelte.d.ts +22 -0
- package/dist/components/HmacSignatureCalculator.svelte +199 -0
- package/dist/components/HmacSignatureCalculator.svelte.d.ts +10 -0
- package/dist/components/I18nLanguagePackEditor.svelte +208 -0
- package/dist/components/I18nLanguagePackEditor.svelte.d.ts +17 -0
- package/dist/components/ImportPreviewValidator.svelte +239 -0
- package/dist/components/ImportPreviewValidator.svelte.d.ts +26 -0
- package/dist/components/ImportWizard.svelte +2 -2
- package/dist/components/IncidentWarRoomDrawer.svelte +194 -0
- package/dist/components/IncidentWarRoomDrawer.svelte.d.ts +24 -0
- package/dist/components/InputGroup.svelte +133 -0
- package/dist/components/InputGroup.svelte.d.ts +16 -0
- package/dist/components/JsonSchemaForm.svelte +4 -4
- package/dist/components/LightFilter.svelte +2 -2
- package/dist/components/ListPagination.svelte +39 -3
- package/dist/components/LiveStreamLogViewer.svelte +185 -0
- package/dist/components/LiveStreamLogViewer.svelte.d.ts +21 -0
- package/dist/components/MasterSubTableDrawer.svelte +223 -0
- package/dist/components/MasterSubTableDrawer.svelte.d.ts +25 -0
- package/dist/components/MicroAppRouteSync.svelte +185 -0
- package/dist/components/MicroAppRouteSync.svelte.d.ts +12 -0
- package/dist/components/MicroAppSandbox.svelte +200 -0
- package/dist/components/MicroAppSandbox.svelte.d.ts +16 -0
- package/dist/components/MicroAppStateBusIndicator.svelte +159 -0
- package/dist/components/MicroAppStateBusIndicator.svelte.d.ts +12 -0
- package/dist/components/MockDataInterceptor.svelte +292 -0
- package/dist/components/MockDataInterceptor.svelte.d.ts +27 -0
- package/dist/components/OmnibarCommandPalette.svelte +320 -0
- package/dist/components/OmnibarCommandPalette.svelte.d.ts +27 -0
- package/dist/components/PageSkeleton.svelte +19 -5
- package/dist/components/PageSkeleton.svelte.d.ts +5 -3
- package/dist/components/PeriodComparisonCard.svelte +142 -0
- package/dist/components/PeriodComparisonCard.svelte.d.ts +16 -0
- package/dist/components/PermissionMatrix.svelte +1 -1
- package/dist/components/PermissionSimulator.svelte +319 -0
- package/dist/components/PermissionSimulator.svelte.d.ts +34 -0
- package/dist/components/PivotMatrix.svelte +271 -0
- package/dist/components/PivotMatrix.svelte.d.ts +32 -0
- package/dist/components/PlanUsageQuotaBar.svelte +154 -0
- package/dist/components/PlanUsageQuotaBar.svelte.d.ts +26 -0
- package/dist/components/Popconfirm.svelte +20 -8
- package/dist/components/Popconfirm.svelte.d.ts +3 -1
- package/dist/components/ProSkeleton.svelte +4 -0
- package/dist/components/ProSkeleton.svelte.d.ts +2 -0
- package/dist/components/QueryAiExplainer.svelte +148 -0
- package/dist/components/QueryAiExplainer.svelte.d.ts +16 -0
- package/dist/components/QueryBuilder.svelte +456 -0
- package/dist/components/QueryBuilder.svelte.d.ts +33 -0
- package/dist/components/Rate.svelte +19 -2
- package/dist/components/Result.svelte +36 -4
- package/dist/components/Result.svelte.d.ts +4 -2
- package/dist/components/RolePermissionComparator.svelte +273 -0
- package/dist/components/RolePermissionComparator.svelte.d.ts +28 -0
- package/dist/components/RuleExpressionBuilder.svelte +380 -0
- package/dist/components/RuleExpressionBuilder.svelte.d.ts +31 -0
- package/dist/components/ScheduledJobManager.svelte +225 -0
- package/dist/components/ScheduledJobManager.svelte.d.ts +23 -0
- package/dist/components/SchemaVisualModeler.svelte +2 -2
- package/dist/components/ScreenAntiLeakGuard.svelte +88 -0
- package/dist/components/ScreenAntiLeakGuard.svelte.d.ts +12 -0
- package/dist/components/SecureDataExporter.svelte +296 -0
- package/dist/components/SecureDataExporter.svelte.d.ts +29 -0
- package/dist/components/ServerStatusGrid.svelte +179 -0
- package/dist/components/ServerStatusGrid.svelte.d.ts +21 -0
- package/dist/components/SnapshotTimelineReplay.svelte +219 -0
- package/dist/components/SnapshotTimelineReplay.svelte.d.ts +19 -0
- package/dist/components/Spin.svelte +33 -11
- package/dist/components/Spin.svelte.d.ts +7 -4
- package/dist/components/SqlConsole.svelte +247 -0
- package/dist/components/SqlConsole.svelte.d.ts +20 -0
- package/dist/components/StepWizard.svelte +1 -1
- package/dist/components/Steps.svelte +44 -3
- package/dist/components/SystemCapacityForecastCard.svelte +132 -0
- package/dist/components/SystemCapacityForecastCard.svelte.d.ts +19 -0
- package/dist/components/SystemHealthCheckDashboard.svelte +306 -0
- package/dist/components/SystemHealthCheckDashboard.svelte.d.ts +24 -0
- package/dist/components/TableAggregationFooter.svelte +173 -0
- package/dist/components/TableAggregationFooter.svelte.d.ts +22 -0
- package/dist/components/TaskCenter.svelte +37 -29
- package/dist/components/TenantContextSwitcher.svelte +314 -0
- package/dist/components/TenantContextSwitcher.svelte.d.ts +35 -0
- package/dist/components/TenantQuotasMatrix.svelte +229 -0
- package/dist/components/TenantQuotasMatrix.svelte.d.ts +22 -0
- package/dist/components/ThemeSettingsDrawer.svelte +6 -14
- package/dist/components/ThreadedCommentDrawer.svelte +246 -0
- package/dist/components/ThreadedCommentDrawer.svelte.d.ts +26 -0
- package/dist/components/TierFeatureComparison.svelte +147 -0
- package/dist/components/TierFeatureComparison.svelte.d.ts +28 -0
- package/dist/components/Timeline.svelte +12 -3
- package/dist/components/Timeline.svelte.d.ts +2 -0
- package/dist/components/TreeTransferSelect.svelte +333 -0
- package/dist/components/TreeTransferSelect.svelte.d.ts +18 -0
- package/dist/components/VirtualCardGrid.svelte +180 -0
- package/dist/components/VirtualCardGrid.svelte.d.ts +65 -0
- package/dist/components/WebhookSimulator.svelte +263 -0
- package/dist/components/WebhookSimulator.svelte.d.ts +26 -0
- package/dist/components/WidgetContainer.svelte +204 -0
- package/dist/components/WidgetContainer.svelte.d.ts +31 -0
- package/dist/components/WorkflowExecutionTracker.svelte +131 -0
- package/dist/components/WorkflowExecutionTracker.svelte.d.ts +19 -0
- package/dist/components/WorkflowGraphDesigner.svelte +202 -0
- package/dist/components/WorkflowGraphDesigner.svelte.d.ts +24 -0
- package/dist/components/WorkflowNodeInspector.svelte +217 -0
- package/dist/components/WorkflowNodeInspector.svelte.d.ts +24 -0
- package/dist/components/WorkflowStepper.svelte +1 -1
- package/dist/components/list-i18n.d.ts +7 -0
- package/dist/components/list-i18n.js +14 -0
- package/dist/components/ui/badge/badge.svelte +3 -3
- package/dist/components/ui/button/button.svelte +3 -1
- package/dist/components/ui/button/button.svelte.d.ts +1 -0
- package/dist/components/ui/tooltip/tooltip-content.svelte +1 -1
- package/dist/components/useDynamicLocale.d.svelte.ts +1 -0
- package/dist/components/useDynamicLocale.svelte.d.ts +10 -0
- package/dist/components/useDynamicLocale.svelte.js +40 -0
- package/dist/components/useFormulaEngine.d.svelte.ts +1 -0
- package/dist/components/useFormulaEngine.svelte.d.ts +9 -0
- package/dist/components/useFormulaEngine.svelte.js +209 -0
- package/dist/components/useMicroAppState.d.svelte.ts +1 -0
- package/dist/components/useMicroAppState.svelte.d.ts +17 -0
- package/dist/components/useMicroAppState.svelte.js +38 -0
- package/dist/components/useStorageCache.d.svelte.ts +1 -0
- package/dist/components/useStorageCache.svelte.d.ts +49 -0
- package/dist/components/useStorageCache.svelte.js +229 -0
- package/dist/components.css +5 -1
- package/dist/index.d.ts +75 -3
- package/dist/index.js +118 -2
- package/package.json +4 -4
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
Layers,
|
|
4
|
+
RotateCcw,
|
|
5
|
+
ExternalLink,
|
|
6
|
+
AlertTriangle,
|
|
7
|
+
CheckCircle2,
|
|
8
|
+
Shield,
|
|
9
|
+
Activity,
|
|
10
|
+
Maximize2,
|
|
11
|
+
} from '@lucide/svelte';
|
|
12
|
+
import { cn } from '../utils.js';
|
|
13
|
+
import { Button } from './ui/button/index.js';
|
|
14
|
+
|
|
15
|
+
export interface MicroAppSandboxProps {
|
|
16
|
+
src?: string | undefined;
|
|
17
|
+
appName?: string | undefined;
|
|
18
|
+
appId?: string | undefined;
|
|
19
|
+
token?: string | undefined;
|
|
20
|
+
theme?: 'light' | 'dark' | 'system' | undefined;
|
|
21
|
+
locale?: string | undefined;
|
|
22
|
+
height?: string | number | undefined;
|
|
23
|
+
class?: string | undefined;
|
|
24
|
+
onLoad?: (() => void) | undefined;
|
|
25
|
+
onError?: ((error: string) => void) | undefined;
|
|
26
|
+
onReload?: (() => void) | undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let {
|
|
30
|
+
src = 'https://sub-bi.example.internal/embed',
|
|
31
|
+
appName = '企业商业智能 (BI) 报表子应用',
|
|
32
|
+
appId = 'app-bi-micro-01',
|
|
33
|
+
token = 'Bearer subapp-mock-jwt-token-9821',
|
|
34
|
+
theme = 'dark',
|
|
35
|
+
locale = 'zh-CN',
|
|
36
|
+
height = 420,
|
|
37
|
+
class: className = '',
|
|
38
|
+
onLoad,
|
|
39
|
+
onError,
|
|
40
|
+
onReload,
|
|
41
|
+
}: MicroAppSandboxProps = $props();
|
|
42
|
+
|
|
43
|
+
let status = $state<'loading' | 'ready' | 'error'>('ready');
|
|
44
|
+
let errorMessage = $state<string | null>(null);
|
|
45
|
+
let isFullscreen = $state(false);
|
|
46
|
+
|
|
47
|
+
function handleReload() {
|
|
48
|
+
status = 'loading';
|
|
49
|
+
errorMessage = null;
|
|
50
|
+
onReload?.();
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
status = 'ready';
|
|
53
|
+
onLoad?.();
|
|
54
|
+
}, 600);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function simulateCrash() {
|
|
58
|
+
status = 'error';
|
|
59
|
+
errorMessage = '子应用渲染进程未响应 (Script Execution Timeout / Error 502)';
|
|
60
|
+
onError?.(errorMessage);
|
|
61
|
+
}
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<div
|
|
65
|
+
class={cn(
|
|
66
|
+
'w-full rounded-2xl border border-border bg-card text-foreground shadow-sm flex flex-col overflow-hidden transition-all duration-200',
|
|
67
|
+
isFullscreen && 'fixed inset-4 z-50 shadow-2xl',
|
|
68
|
+
className
|
|
69
|
+
)}
|
|
70
|
+
data-svadmin-component="micro-app-sandbox"
|
|
71
|
+
>
|
|
72
|
+
<!-- 沙箱顶栏控制条 -->
|
|
73
|
+
<div class="px-4 py-3 border-b border-border bg-muted/20 flex flex-wrap items-center justify-between gap-3">
|
|
74
|
+
<div class="flex items-center gap-2.5 min-w-0">
|
|
75
|
+
<div class="flex items-center justify-center w-7 h-7 rounded-lg bg-primary/10 text-primary border border-primary/20 shrink-0">
|
|
76
|
+
<Layers class="w-4 h-4" />
|
|
77
|
+
</div>
|
|
78
|
+
|
|
79
|
+
<div class="flex flex-col min-w-0">
|
|
80
|
+
<div class="flex items-center gap-2">
|
|
81
|
+
<span class="text-xs font-semibold text-foreground truncate">{appName}</span>
|
|
82
|
+
<span class="text-[10px] font-mono px-1.5 py-0.2 rounded bg-muted text-muted-foreground border border-border shrink-0">
|
|
83
|
+
{appId}
|
|
84
|
+
</span>
|
|
85
|
+
</div>
|
|
86
|
+
<span class="text-[10px] text-muted-foreground truncate">
|
|
87
|
+
安全沙箱源: {src} · 语言: {locale} · 主题: {theme}
|
|
88
|
+
</span>
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
<!-- 运行状态指示与动作按钮 -->
|
|
93
|
+
<div class="flex items-center gap-2 shrink-0">
|
|
94
|
+
{#if status === 'ready'}
|
|
95
|
+
<span class="flex items-center gap-1 text-[11px] text-success font-medium px-2 py-0.5 rounded-full bg-success/10 border border-success/20">
|
|
96
|
+
<CheckCircle2 class="w-3 h-3" />
|
|
97
|
+
运行健康 (Mounted)
|
|
98
|
+
</span>
|
|
99
|
+
{:else if status === 'loading'}
|
|
100
|
+
<span class="flex items-center gap-1 text-[11px] text-info font-medium px-2 py-0.5 rounded-full bg-info/10 border border-info/20">
|
|
101
|
+
<Activity class="w-3 h-3 animate-spin" />
|
|
102
|
+
沙箱初始化...
|
|
103
|
+
</span>
|
|
104
|
+
{:else}
|
|
105
|
+
<span class="flex items-center gap-1 text-[11px] text-destructive font-medium px-2 py-0.5 rounded-full bg-destructive/10 border border-destructive/20">
|
|
106
|
+
<AlertTriangle class="w-3 h-3" />
|
|
107
|
+
沙箱异常拦截
|
|
108
|
+
</span>
|
|
109
|
+
{/if}
|
|
110
|
+
|
|
111
|
+
<div class="flex items-center gap-1 border-l border-border/60 pl-2">
|
|
112
|
+
<button
|
|
113
|
+
type="button"
|
|
114
|
+
class="p-1.5 rounded-lg text-muted-foreground hover:text-foreground hover:bg-muted transition-colors"
|
|
115
|
+
title="重新加载沙箱"
|
|
116
|
+
onclick={handleReload}
|
|
117
|
+
>
|
|
118
|
+
<RotateCcw class="w-3.5 h-3.5" />
|
|
119
|
+
</button>
|
|
120
|
+
|
|
121
|
+
<button
|
|
122
|
+
type="button"
|
|
123
|
+
class="p-1.5 rounded-lg text-muted-foreground hover:text-foreground hover:bg-muted transition-colors"
|
|
124
|
+
title={isFullscreen ? '退出全屏' : '全屏沙箱'}
|
|
125
|
+
onclick={() => (isFullscreen = !isFullscreen)}
|
|
126
|
+
>
|
|
127
|
+
<Maximize2 class="w-3.5 h-3.5" />
|
|
128
|
+
</button>
|
|
129
|
+
|
|
130
|
+
<a
|
|
131
|
+
href={src}
|
|
132
|
+
target="_blank"
|
|
133
|
+
rel="noopener noreferrer"
|
|
134
|
+
class="p-1.5 rounded-lg text-muted-foreground hover:text-foreground hover:bg-muted transition-colors"
|
|
135
|
+
title="独立窗口打开"
|
|
136
|
+
>
|
|
137
|
+
<ExternalLink class="w-3.5 h-3.5" />
|
|
138
|
+
</a>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
|
|
143
|
+
<!-- 沙箱主体视窗 -->
|
|
144
|
+
<div
|
|
145
|
+
class="relative w-full bg-muted/10 flex flex-col justify-center overflow-hidden"
|
|
146
|
+
style="height: {typeof height === 'number' ? `${height}px` : height};"
|
|
147
|
+
>
|
|
148
|
+
{#if status === 'loading'}
|
|
149
|
+
<!-- 加载过渡态骨架 -->
|
|
150
|
+
<div class="p-6 flex flex-col items-center justify-center gap-3 text-muted-foreground">
|
|
151
|
+
<Activity class="w-8 h-8 text-primary animate-spin" />
|
|
152
|
+
<div class="text-xs">正在向子应用注入登录令牌与安全样式表...</div>
|
|
153
|
+
</div>
|
|
154
|
+
{:else if status === 'error'}
|
|
155
|
+
<!-- 异常崩溃容灾降级面板 -->
|
|
156
|
+
<div class="p-8 flex flex-col items-center justify-center text-center max-w-md mx-auto gap-3">
|
|
157
|
+
<div class="w-12 h-12 rounded-2xl bg-destructive/10 text-destructive border border-destructive/20 flex items-center justify-center">
|
|
158
|
+
<AlertTriangle class="w-6 h-6" />
|
|
159
|
+
</div>
|
|
160
|
+
<div>
|
|
161
|
+
<h4 class="text-sm font-semibold text-foreground">子应用隔离拦截与崩溃保护</h4>
|
|
162
|
+
<p class="text-xs text-muted-foreground mt-1">{errorMessage}</p>
|
|
163
|
+
</div>
|
|
164
|
+
<div class="flex items-center gap-2 mt-2">
|
|
165
|
+
<Button variant="outline" size="sm" class="h-8 text-xs" onclick={handleReload}>
|
|
166
|
+
<RotateCcw class="w-3.5 h-3.5 mr-1" />
|
|
167
|
+
尝试自愈重启
|
|
168
|
+
</Button>
|
|
169
|
+
</div>
|
|
170
|
+
</div>
|
|
171
|
+
{:else}
|
|
172
|
+
<!-- 模拟/真实 沙箱视图 -->
|
|
173
|
+
<div class="w-full h-full p-4 flex flex-col justify-between">
|
|
174
|
+
<div class="p-4 rounded-xl border border-border bg-card flex flex-col gap-2">
|
|
175
|
+
<div class="flex items-center justify-between">
|
|
176
|
+
<span class="text-xs font-semibold text-foreground">微前端隔离沙箱运行时 (Shadow DOM / iframe Guard)</span>
|
|
177
|
+
<span class="text-[10px] text-muted-foreground font-mono">Token 已就绪: {token.slice(0, 16)}...</span>
|
|
178
|
+
</div>
|
|
179
|
+
<p class="text-[11px] text-muted-foreground leading-relaxed">
|
|
180
|
+
宿主与子应用已建立受信任的跨域事件通道。子应用的 CSS 样式与全局 window 作用域完全隔离,不污染宿主管理平台全局规范。
|
|
181
|
+
</p>
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
<div class="flex items-center justify-between text-[10px] text-muted-foreground pt-2 border-t border-border/40">
|
|
185
|
+
<span class="flex items-center gap-1">
|
|
186
|
+
<Shield class="w-3 h-3 text-primary" />
|
|
187
|
+
Sandbox Isolation Level: Strict (allow-scripts, allow-same-origin, allow-forms)
|
|
188
|
+
</span>
|
|
189
|
+
<button
|
|
190
|
+
type="button"
|
|
191
|
+
class="text-[10px] text-muted-foreground hover:text-destructive underline"
|
|
192
|
+
onclick={simulateCrash}
|
|
193
|
+
>
|
|
194
|
+
测试异常容灾兜底
|
|
195
|
+
</button>
|
|
196
|
+
</div>
|
|
197
|
+
</div>
|
|
198
|
+
{/if}
|
|
199
|
+
</div>
|
|
200
|
+
</div>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface MicroAppSandboxProps {
|
|
2
|
+
src?: string | undefined;
|
|
3
|
+
appName?: string | undefined;
|
|
4
|
+
appId?: string | undefined;
|
|
5
|
+
token?: string | undefined;
|
|
6
|
+
theme?: 'light' | 'dark' | 'system' | undefined;
|
|
7
|
+
locale?: string | undefined;
|
|
8
|
+
height?: string | number | undefined;
|
|
9
|
+
class?: string | undefined;
|
|
10
|
+
onLoad?: (() => void) | undefined;
|
|
11
|
+
onError?: ((error: string) => void) | undefined;
|
|
12
|
+
onReload?: (() => void) | undefined;
|
|
13
|
+
}
|
|
14
|
+
declare const MicroAppSandbox: import("svelte").Component<MicroAppSandboxProps, {}, "">;
|
|
15
|
+
type MicroAppSandbox = ReturnType<typeof MicroAppSandbox>;
|
|
16
|
+
export default MicroAppSandbox;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from 'svelte';
|
|
3
|
+
import {
|
|
4
|
+
Radio,
|
|
5
|
+
Send,
|
|
6
|
+
Activity,
|
|
7
|
+
CheckCircle2,
|
|
8
|
+
Trash2,
|
|
9
|
+
Share2,
|
|
10
|
+
} from '@lucide/svelte';
|
|
11
|
+
import { cn } from '../utils.js';
|
|
12
|
+
import { Button } from './ui/button/index.js';
|
|
13
|
+
import { useMicroAppState, type MicroAppStateMessage } from './useMicroAppState.svelte.js';
|
|
14
|
+
|
|
15
|
+
export interface MicroAppStateBusIndicatorProps {
|
|
16
|
+
channel?: string | undefined;
|
|
17
|
+
appId?: string | undefined;
|
|
18
|
+
title?: string | undefined;
|
|
19
|
+
description?: string | undefined;
|
|
20
|
+
class?: string | undefined;
|
|
21
|
+
onBroadcast?: ((msg: MicroAppStateMessage) => void) | undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let {
|
|
25
|
+
channel = 'svadmin_microapp_global_bus',
|
|
26
|
+
appId = 'host_admin_root',
|
|
27
|
+
title = '微前端全局响应式状态总线 (MicroApp State Bus)',
|
|
28
|
+
description = '跨技术栈父子应用双向状态同步、租户上下文广播与事件流转中枢',
|
|
29
|
+
class: className = '',
|
|
30
|
+
onBroadcast,
|
|
31
|
+
}: MicroAppStateBusIndicatorProps = $props();
|
|
32
|
+
|
|
33
|
+
const bus = useMicroAppState({ channel: untrack(() => channel), appId: untrack(() => appId) });
|
|
34
|
+
|
|
35
|
+
let broadcastType = $state('tenant:context:change');
|
|
36
|
+
let broadcastPayload = $state('{"tenantId": "tenant-east-02", "name": "华东大区创新科技中心"}');
|
|
37
|
+
|
|
38
|
+
function handleSend() {
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(broadcastPayload);
|
|
41
|
+
const msg = bus.broadcast(broadcastType, parsed);
|
|
42
|
+
onBroadcast?.(msg);
|
|
43
|
+
} catch {
|
|
44
|
+
const msg = bus.broadcast(broadcastType, broadcastPayload);
|
|
45
|
+
onBroadcast?.(msg);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function formatTime(ts: number) {
|
|
50
|
+
const d = new Date(ts);
|
|
51
|
+
return `${d.getHours().toString().padStart(2, '0')}:${d.getMinutes().toString().padStart(2, '0')}:${d.getSeconds().toString().padStart(2, '0')}`;
|
|
52
|
+
}
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<div
|
|
56
|
+
class={cn('w-full rounded-2xl border border-border bg-card text-foreground shadow-sm flex flex-col overflow-hidden', className)}
|
|
57
|
+
data-svadmin-component="micro-app-state-bus"
|
|
58
|
+
>
|
|
59
|
+
<!-- 头部控制栏 -->
|
|
60
|
+
<div class="p-5 border-b border-border bg-muted/10 flex flex-col md:flex-row md:items-center justify-between gap-4">
|
|
61
|
+
<div>
|
|
62
|
+
<div class="flex items-center gap-2">
|
|
63
|
+
<Radio class="w-5 h-5 text-primary" />
|
|
64
|
+
<h3 class="text-base font-semibold text-foreground tracking-tight">{title}</h3>
|
|
65
|
+
</div>
|
|
66
|
+
<p class="text-xs text-muted-foreground mt-1">{description}</p>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
<!-- 运行状态指示 -->
|
|
70
|
+
<div class="flex items-center gap-2">
|
|
71
|
+
<div class="flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-border bg-card text-xs">
|
|
72
|
+
<Share2 class="w-3.5 h-3.5 text-primary" />
|
|
73
|
+
<span class="text-muted-foreground">频道:</span>
|
|
74
|
+
<span class="font-mono font-medium text-foreground">{channel}</span>
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
<div class="flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-success/20 bg-success/10 text-xs">
|
|
78
|
+
<CheckCircle2 class="w-3.5 h-3.5 text-success" />
|
|
79
|
+
<span class="text-success font-medium">3 个子应用已连接</span>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
<!-- 广播发送工具栏 -->
|
|
85
|
+
<div class="p-4 border-b border-border bg-muted/20 flex flex-col sm:flex-row items-center gap-2.5">
|
|
86
|
+
<div class="w-full sm:w-56 shrink-0">
|
|
87
|
+
<input
|
|
88
|
+
type="text"
|
|
89
|
+
bind:value={broadcastType}
|
|
90
|
+
placeholder="事件类型 (e.g. auth:token:refresh)"
|
|
91
|
+
class="w-full px-3 py-1.5 text-xs font-mono rounded-lg border border-border bg-background text-foreground focus:outline-none focus:ring-1 focus:ring-primary"
|
|
92
|
+
/>
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<div class="w-full sm:flex-1">
|
|
96
|
+
<input
|
|
97
|
+
type="text"
|
|
98
|
+
bind:value={broadcastPayload}
|
|
99
|
+
placeholder="JSON 载荷 (Payload)"
|
|
100
|
+
class="w-full px-3 py-1.5 text-xs font-mono rounded-lg border border-border bg-background text-foreground focus:outline-none focus:ring-1 focus:ring-primary"
|
|
101
|
+
/>
|
|
102
|
+
</div>
|
|
103
|
+
|
|
104
|
+
<Button
|
|
105
|
+
variant="default"
|
|
106
|
+
size="sm"
|
|
107
|
+
class="h-8 gap-1.5 text-xs bg-primary text-primary-foreground shrink-0 w-full sm:w-auto"
|
|
108
|
+
onclick={handleSend}
|
|
109
|
+
>
|
|
110
|
+
<Send class="w-3.5 h-3.5" />
|
|
111
|
+
<span>广播状态变更</span>
|
|
112
|
+
</Button>
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
<!-- 最近接收到的跨应用状态消息流 -->
|
|
116
|
+
<div class="p-4 space-y-2">
|
|
117
|
+
<div class="flex items-center justify-between text-xs font-semibold text-foreground mb-1">
|
|
118
|
+
<div class="flex items-center gap-1.5">
|
|
119
|
+
<Activity class="w-4 h-4 text-primary" />
|
|
120
|
+
<span>跨端状态消息流 (Message Stream)</span>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
{#if bus.messages.length > 0}
|
|
124
|
+
<button
|
|
125
|
+
type="button"
|
|
126
|
+
class="flex items-center gap-1 text-[11px] text-muted-foreground hover:text-destructive"
|
|
127
|
+
onclick={() => bus.clearMessages()}
|
|
128
|
+
>
|
|
129
|
+
<Trash2 class="w-3 h-3" />
|
|
130
|
+
<span>清空流</span>
|
|
131
|
+
</button>
|
|
132
|
+
{/if}
|
|
133
|
+
</div>
|
|
134
|
+
|
|
135
|
+
<div class="space-y-2 max-h-60 overflow-y-auto">
|
|
136
|
+
{#if bus.messages.length === 0}
|
|
137
|
+
<div class="p-4 rounded-xl border border-dashed border-border bg-muted/10 text-center text-xs text-muted-foreground">
|
|
138
|
+
暂无跨端广播消息,点击上方按钮模拟向子应用广播全局状态
|
|
139
|
+
</div>
|
|
140
|
+
{:else}
|
|
141
|
+
{#each bus.messages as msg (msg.timestamp)}
|
|
142
|
+
<div class="p-2.5 rounded-xl border border-border bg-card flex flex-col gap-1 text-xs">
|
|
143
|
+
<div class="flex items-center justify-between">
|
|
144
|
+
<div class="flex items-center gap-2">
|
|
145
|
+
<span class="font-semibold text-primary font-mono">{msg.type}</span>
|
|
146
|
+
<span class="text-[10px] text-muted-foreground">来自: {msg.senderAppId}</span>
|
|
147
|
+
</div>
|
|
148
|
+
<span class="text-[10px] text-muted-foreground font-mono">
|
|
149
|
+
{formatTime(msg.timestamp)}
|
|
150
|
+
</span>
|
|
151
|
+
</div>
|
|
152
|
+
|
|
153
|
+
<pre class="p-2 rounded bg-muted/40 text-[11px] font-mono text-foreground overflow-x-auto">{JSON.stringify(msg.payload, null, 2)}</pre>
|
|
154
|
+
</div>
|
|
155
|
+
{/each}
|
|
156
|
+
{/if}
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type MicroAppStateMessage } from './useMicroAppState.svelte.js';
|
|
2
|
+
export interface MicroAppStateBusIndicatorProps {
|
|
3
|
+
channel?: string | undefined;
|
|
4
|
+
appId?: string | undefined;
|
|
5
|
+
title?: string | undefined;
|
|
6
|
+
description?: string | undefined;
|
|
7
|
+
class?: string | undefined;
|
|
8
|
+
onBroadcast?: ((msg: MicroAppStateMessage) => void) | undefined;
|
|
9
|
+
}
|
|
10
|
+
declare const MicroAppStateBusIndicator: import("svelte").Component<MicroAppStateBusIndicatorProps, {}, "">;
|
|
11
|
+
type MicroAppStateBusIndicator = ReturnType<typeof MicroAppStateBusIndicator>;
|
|
12
|
+
export default MicroAppStateBusIndicator;
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from 'svelte';
|
|
3
|
+
|
|
4
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
|
+
|
|
6
|
+
export interface MockRuleItem {
|
|
7
|
+
id: string;
|
|
8
|
+
endpoint: string;
|
|
9
|
+
method: HttpMethod;
|
|
10
|
+
status: number;
|
|
11
|
+
delayMs: number;
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
responseBody: string;
|
|
14
|
+
description?: string | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface MockDataInterceptorProps {
|
|
18
|
+
rules?: MockRuleItem[] | undefined;
|
|
19
|
+
isInterceptorActive?: boolean | undefined;
|
|
20
|
+
title?: string | undefined;
|
|
21
|
+
class?: string | undefined;
|
|
22
|
+
onToggleActive?: ((active: boolean) => void) | undefined;
|
|
23
|
+
onSaveRules?: ((rules: MockRuleItem[]) => void) | undefined;
|
|
24
|
+
onTestMock?: ((rule: MockRuleItem) => Promise<{ status: number; duration: number; data: unknown }>) | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const defaultRules: MockRuleItem[] = [
|
|
28
|
+
{
|
|
29
|
+
id: 'm1',
|
|
30
|
+
endpoint: '/api/v1/users/me',
|
|
31
|
+
method: 'GET',
|
|
32
|
+
status: 200,
|
|
33
|
+
delayMs: 80,
|
|
34
|
+
enabled: true,
|
|
35
|
+
responseBody: '{"id":"usr_01","name":"Demo Admin","role":"super_admin","permissions":["*"]}',
|
|
36
|
+
description: '当前登录用户信息与权限清单'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'm2',
|
|
40
|
+
endpoint: '/api/v1/billing/invoices',
|
|
41
|
+
method: 'GET',
|
|
42
|
+
status: 200,
|
|
43
|
+
delayMs: 150,
|
|
44
|
+
enabled: true,
|
|
45
|
+
responseBody: '{"invoices":[{"id":"inv_202611","amount":12800.00,"status":"paid"}]}',
|
|
46
|
+
description: '企业计费账单列表 Mock'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: 'm3',
|
|
50
|
+
endpoint: '/api/v1/orders/checkout',
|
|
51
|
+
method: 'POST',
|
|
52
|
+
status: 201,
|
|
53
|
+
delayMs: 300,
|
|
54
|
+
enabled: true,
|
|
55
|
+
responseBody: '{"order_id":"ord_88201","status":"created","trade_no":"tx_9981"}',
|
|
56
|
+
description: '模拟创建订单成功'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: 'm4',
|
|
60
|
+
endpoint: '/api/v1/payments/refund',
|
|
61
|
+
method: 'POST',
|
|
62
|
+
status: 500,
|
|
63
|
+
delayMs: 800,
|
|
64
|
+
enabled: false,
|
|
65
|
+
responseBody: '{"code":"GATEWAY_TIMEOUT","message":"第三方银行清算通道超时,已触发重试保护"}',
|
|
66
|
+
description: '支付退款故障注入 (500 熔断模拟)'
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
const {
|
|
71
|
+
rules = defaultRules,
|
|
72
|
+
isInterceptorActive = true,
|
|
73
|
+
title = '前端请求拦截与离线 Mock 沙箱控制台',
|
|
74
|
+
class: className = '',
|
|
75
|
+
onToggleActive = undefined,
|
|
76
|
+
onSaveRules = undefined,
|
|
77
|
+
onTestMock = undefined
|
|
78
|
+
}: MockDataInterceptorProps = $props();
|
|
79
|
+
|
|
80
|
+
let active = $state(untrack(() => isInterceptorActive));
|
|
81
|
+
let ruleList = $state<MockRuleItem[]>(untrack(() => [...rules]));
|
|
82
|
+
let selectedRuleId = $state<string>(untrack(() => rules[0]?.id ?? ''));
|
|
83
|
+
let isTesting = $state(false);
|
|
84
|
+
let testResponse = $state<unknown>(null);
|
|
85
|
+
let testStatus = $state<number | null>(null);
|
|
86
|
+
let testDuration = $state<number | null>(null);
|
|
87
|
+
|
|
88
|
+
const currentRule = $derived(
|
|
89
|
+
ruleList.find(r => r.id === selectedRuleId) ?? ruleList[0]
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
function toggleActive() {
|
|
93
|
+
active = !active;
|
|
94
|
+
onToggleActive?.(active);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function toggleRule(id: string) {
|
|
98
|
+
ruleList = ruleList.map(r => r.id === id ? { ...r, enabled: !r.enabled } : r);
|
|
99
|
+
onSaveRules?.(ruleList);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function runTest(rule: MockRuleItem) {
|
|
103
|
+
isTesting = true;
|
|
104
|
+
testStatus = null;
|
|
105
|
+
testDuration = null;
|
|
106
|
+
testResponse = null;
|
|
107
|
+
|
|
108
|
+
const start = Date.now();
|
|
109
|
+
try {
|
|
110
|
+
if (onTestMock) {
|
|
111
|
+
const res = await onTestMock(rule);
|
|
112
|
+
testStatus = res.status;
|
|
113
|
+
testDuration = res.duration;
|
|
114
|
+
testResponse = res.data;
|
|
115
|
+
} else {
|
|
116
|
+
await new Promise(resolve => setTimeout(resolve, Math.min(rule.delayMs, 600)));
|
|
117
|
+
testStatus = rule.status;
|
|
118
|
+
testDuration = Date.now() - start;
|
|
119
|
+
try {
|
|
120
|
+
testResponse = JSON.parse(rule.responseBody);
|
|
121
|
+
} catch {
|
|
122
|
+
testResponse = rule.responseBody;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} finally {
|
|
126
|
+
isTesting = false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function getMethodBadge(method: HttpMethod): string {
|
|
131
|
+
switch (method) {
|
|
132
|
+
case 'GET': return 'bg-info/10 text-info border-info/20';
|
|
133
|
+
case 'POST': return 'bg-success/10 text-success border-success/20';
|
|
134
|
+
case 'PUT': return 'bg-warning/10 text-warning border-warning/20';
|
|
135
|
+
case 'DELETE': return 'bg-destructive/10 text-destructive border-destructive/20';
|
|
136
|
+
case 'PATCH': return 'bg-primary/10 text-primary border-primary/20';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function getStatusCodeBadge(status: number): string {
|
|
141
|
+
if (status >= 200 && status < 300) return 'bg-success/10 text-success border-success/20';
|
|
142
|
+
if (status >= 400 && status < 500) return 'bg-warning/10 text-warning border-warning/20';
|
|
143
|
+
if (status >= 500) return 'bg-destructive/10 text-destructive border-destructive/20';
|
|
144
|
+
return 'bg-muted text-muted-foreground border-border';
|
|
145
|
+
}
|
|
146
|
+
</script>
|
|
147
|
+
|
|
148
|
+
<div
|
|
149
|
+
class="flex flex-col gap-4 rounded-lg border border-border bg-card p-4 text-card-foreground shadow-sm {className}"
|
|
150
|
+
data-svadmin-component="MockDataInterceptor"
|
|
151
|
+
>
|
|
152
|
+
<div class="flex flex-wrap items-center justify-between gap-3 border-b border-border pb-3">
|
|
153
|
+
<div class="flex items-center gap-2.5">
|
|
154
|
+
<div class="flex h-8 w-8 items-center justify-center rounded-md bg-primary/10 text-primary">
|
|
155
|
+
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
156
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4" />
|
|
157
|
+
</svg>
|
|
158
|
+
</div>
|
|
159
|
+
<div>
|
|
160
|
+
<h3 class="text-sm font-medium text-foreground">{title}</h3>
|
|
161
|
+
<p class="text-xs text-muted-foreground">脱离后端联调等待,支持自定义延迟注入与故障模拟</p>
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
|
|
165
|
+
<div class="flex items-center gap-3">
|
|
166
|
+
<div class="flex items-center gap-2">
|
|
167
|
+
<span class="text-xs font-medium {active ? 'text-success' : 'text-muted-foreground'}">
|
|
168
|
+
{active ? '● 拦截器运行中' : '○ 拦截器已停用'}
|
|
169
|
+
</span>
|
|
170
|
+
<button
|
|
171
|
+
type="button"
|
|
172
|
+
class="relative inline-flex h-5 w-9 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none {active ? 'bg-primary' : 'bg-muted'}"
|
|
173
|
+
onclick={toggleActive}
|
|
174
|
+
aria-label="Toggle Mock Interceptor"
|
|
175
|
+
>
|
|
176
|
+
<span
|
|
177
|
+
class="pointer-events-none inline-block h-4 w-4 transform rounded-full bg-background shadow ring-0 transition duration-200 ease-in-out {active ? 'translate-x-4' : 'translate-x-0'}"
|
|
178
|
+
></span>
|
|
179
|
+
</button>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
<div class="grid grid-cols-1 lg:grid-cols-3 gap-4">
|
|
185
|
+
<div class="lg:col-span-2 overflow-x-auto rounded-md border border-border">
|
|
186
|
+
<table class="w-full border-collapse text-left text-xs">
|
|
187
|
+
<thead>
|
|
188
|
+
<tr class="border-b border-border bg-muted/50 font-medium text-muted-foreground">
|
|
189
|
+
<th class="p-2.5">方法</th>
|
|
190
|
+
<th class="p-2.5">端点路径 (Endpoint)</th>
|
|
191
|
+
<th class="p-2.5">状态码</th>
|
|
192
|
+
<th class="p-2.5">延时</th>
|
|
193
|
+
<th class="p-2.5 text-center">启用</th>
|
|
194
|
+
<th class="p-2.5 text-right">操作</th>
|
|
195
|
+
</tr>
|
|
196
|
+
</thead>
|
|
197
|
+
<tbody class="divide-y divide-border">
|
|
198
|
+
{#each ruleList as rule (rule.id)}
|
|
199
|
+
<tr
|
|
200
|
+
class="hover:bg-muted/30 transition-colors cursor-pointer {selectedRuleId === rule.id ? 'bg-muted/40' : ''} {rule.enabled ? '' : 'opacity-50'}"
|
|
201
|
+
onclick={() => { selectedRuleId = rule.id; }}
|
|
202
|
+
>
|
|
203
|
+
<td class="p-2.5">
|
|
204
|
+
<span class="inline-flex rounded border px-1.5 py-0.5 text-[10px] font-bold {getMethodBadge(rule.method)}">
|
|
205
|
+
{rule.method}
|
|
206
|
+
</span>
|
|
207
|
+
</td>
|
|
208
|
+
<td class="p-2.5 font-mono text-foreground font-medium">
|
|
209
|
+
{rule.endpoint}
|
|
210
|
+
</td>
|
|
211
|
+
<td class="p-2.5">
|
|
212
|
+
<span class="inline-flex rounded border px-1.5 py-0.5 text-[10px] font-semibold {getStatusCodeBadge(rule.status)}">
|
|
213
|
+
{rule.status}
|
|
214
|
+
</span>
|
|
215
|
+
</td>
|
|
216
|
+
<td class="p-2.5 text-muted-foreground font-mono">
|
|
217
|
+
{rule.delayMs}ms
|
|
218
|
+
</td>
|
|
219
|
+
<td class="p-2.5 text-center" onclick={(e) => e.stopPropagation()}>
|
|
220
|
+
<input
|
|
221
|
+
type="checkbox"
|
|
222
|
+
checked={rule.enabled}
|
|
223
|
+
onchange={() => toggleRule(rule.id)}
|
|
224
|
+
class="h-4 w-4 rounded border-border text-primary focus:ring-ring cursor-pointer"
|
|
225
|
+
/>
|
|
226
|
+
</td>
|
|
227
|
+
<td class="p-2.5 text-right" onclick={(e) => e.stopPropagation()}>
|
|
228
|
+
<button
|
|
229
|
+
type="button"
|
|
230
|
+
class="rounded bg-primary/10 px-2 py-1 text-[11px] font-medium text-primary hover:bg-primary/20 transition-colors"
|
|
231
|
+
onclick={() => runTest(rule)}
|
|
232
|
+
>
|
|
233
|
+
测试
|
|
234
|
+
</button>
|
|
235
|
+
</td>
|
|
236
|
+
</tr>
|
|
237
|
+
{/each}
|
|
238
|
+
</tbody>
|
|
239
|
+
</table>
|
|
240
|
+
</div>
|
|
241
|
+
|
|
242
|
+
<div class="rounded-md border border-border bg-muted/20 p-3 flex flex-col gap-3">
|
|
243
|
+
<div class="flex items-center justify-between border-b border-border pb-2">
|
|
244
|
+
<span class="text-xs font-semibold text-foreground">Mock 响应载荷核验</span>
|
|
245
|
+
{#if currentRule}
|
|
246
|
+
<span class="rounded border px-1.5 py-0.5 text-[10px] font-mono {getMethodBadge(currentRule.method)}">
|
|
247
|
+
{currentRule.method}
|
|
248
|
+
</span>
|
|
249
|
+
{/if}
|
|
250
|
+
</div>
|
|
251
|
+
|
|
252
|
+
{#if currentRule}
|
|
253
|
+
<div class="flex flex-col gap-2">
|
|
254
|
+
<div class="flex items-center justify-between text-xs text-muted-foreground font-mono">
|
|
255
|
+
<span class="truncate max-w-[200px]">{currentRule.endpoint}</span>
|
|
256
|
+
<span>{currentRule.status} OK</span>
|
|
257
|
+
</div>
|
|
258
|
+
|
|
259
|
+
<div class="flex flex-col gap-1">
|
|
260
|
+
<span class="text-[11px] text-muted-foreground">预设 JSON 响应体:</span>
|
|
261
|
+
<pre class="rounded-md border border-border bg-card p-2 text-[11px] font-mono text-foreground overflow-x-auto max-h-[140px] leading-relaxed">
|
|
262
|
+
{currentRule.responseBody}
|
|
263
|
+
</pre>
|
|
264
|
+
</div>
|
|
265
|
+
|
|
266
|
+
<button
|
|
267
|
+
type="button"
|
|
268
|
+
disabled={isTesting}
|
|
269
|
+
class="w-full rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50"
|
|
270
|
+
onclick={() => runTest(currentRule)}
|
|
271
|
+
>
|
|
272
|
+
{isTesting ? '正在模拟请求与网络延迟...' : '立即发起模拟请求验证'}
|
|
273
|
+
</button>
|
|
274
|
+
|
|
275
|
+
{#if testStatus !== null}
|
|
276
|
+
<div class="mt-2 rounded-md border border-border bg-card p-2.5 flex flex-col gap-1.5 text-xs">
|
|
277
|
+
<div class="flex items-center justify-between">
|
|
278
|
+
<span class="font-medium text-foreground">模拟测试结果:</span>
|
|
279
|
+
<span class="rounded border px-1.5 py-0.5 text-[10px] font-semibold {getStatusCodeBadge(testStatus)}">
|
|
280
|
+
HTTP {testStatus} ({testDuration}ms)
|
|
281
|
+
</span>
|
|
282
|
+
</div>
|
|
283
|
+
<pre class="text-[10px] font-mono text-muted-foreground overflow-x-auto max-h-[100px]">
|
|
284
|
+
{typeof testResponse === 'object' ? JSON.stringify(testResponse, null, 2) : testResponse}
|
|
285
|
+
</pre>
|
|
286
|
+
</div>
|
|
287
|
+
{/if}
|
|
288
|
+
</div>
|
|
289
|
+
{/if}
|
|
290
|
+
</div>
|
|
291
|
+
</div>
|
|
292
|
+
</div>
|