@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,23 @@
|
|
|
1
|
+
export interface PaletteActionItem {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
category?: string | undefined;
|
|
5
|
+
shortcut?: string | undefined;
|
|
6
|
+
description?: string | undefined;
|
|
7
|
+
danger?: boolean | undefined;
|
|
8
|
+
requiresParam?: boolean | undefined;
|
|
9
|
+
paramPlaceholder?: string | undefined;
|
|
10
|
+
handler?: ((selectedRecords: Record<string, unknown>[], param?: string) => void | Promise<void>) | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface ActionPaletteProps {
|
|
13
|
+
open?: boolean | undefined;
|
|
14
|
+
selectedRecords?: Record<string, unknown>[] | undefined;
|
|
15
|
+
actions?: PaletteActionItem[] | undefined;
|
|
16
|
+
placeholder?: string | undefined;
|
|
17
|
+
class?: string | undefined;
|
|
18
|
+
onExecuteAction?: ((actionId: string, param?: string) => void) | undefined;
|
|
19
|
+
onClose?: (() => void) | undefined;
|
|
20
|
+
}
|
|
21
|
+
declare const ActionPalette: import("svelte").Component<ActionPaletteProps, {}, "open">;
|
|
22
|
+
type ActionPalette = ReturnType<typeof ActionPalette>;
|
|
23
|
+
export default ActionPalette;
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from 'svelte';
|
|
3
|
+
import { Sparkles, X, Send, Bot, User, Check, ArrowRight, Loader2 } from '@lucide/svelte';
|
|
4
|
+
import { cn } from '../utils.js';
|
|
5
|
+
|
|
6
|
+
export interface CopilotFilterSuggestion {
|
|
7
|
+
field: string;
|
|
8
|
+
operator: string;
|
|
9
|
+
value: string | number;
|
|
10
|
+
label: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface CopilotMessage {
|
|
14
|
+
id: string;
|
|
15
|
+
role: 'user' | 'assistant' | 'system';
|
|
16
|
+
content: string;
|
|
17
|
+
suggestedFilter?: CopilotFilterSuggestion | undefined;
|
|
18
|
+
timestamp?: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AdminCopilotWidgetProps {
|
|
22
|
+
/** 浮窗卡片主标题 */
|
|
23
|
+
title?: string | undefined;
|
|
24
|
+
/** 机器人助手名称,默认 "SVAdmin Copilot" */
|
|
25
|
+
botName?: string | undefined;
|
|
26
|
+
/** 输入框占位提示文本 */
|
|
27
|
+
placeholder?: string | undefined;
|
|
28
|
+
/** 快捷预设提示词气泡列表 */
|
|
29
|
+
suggestedPrompts?: string[] | undefined;
|
|
30
|
+
/** 是否默认展开浮窗 */
|
|
31
|
+
defaultOpen?: boolean | undefined;
|
|
32
|
+
/** 点击应用推荐筛选条件到当前页面的回调 */
|
|
33
|
+
onapplyfilter?: ((filter: CopilotFilterSuggestion) => void) | undefined;
|
|
34
|
+
/** 发送提问消息回调,支持返回回复文本或完整消息对象 */
|
|
35
|
+
onsendmessage?: ((query: string) => Promise<string | CopilotMessage> | string | CopilotMessage) | undefined;
|
|
36
|
+
class?: string | undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let {
|
|
40
|
+
title = '智能业务表格副驾驶',
|
|
41
|
+
botName = 'SVAdmin Copilot',
|
|
42
|
+
placeholder = '输入自然语言,例如:“筛选华东大区大额已支付订单”...',
|
|
43
|
+
suggestedPrompts = [
|
|
44
|
+
'筛选出本周华东大区大额订单',
|
|
45
|
+
'有哪些高危待复核的异常单据?',
|
|
46
|
+
'帮我汇总当月各团队销售达成率',
|
|
47
|
+
],
|
|
48
|
+
defaultOpen = false,
|
|
49
|
+
onapplyfilter,
|
|
50
|
+
onsendmessage,
|
|
51
|
+
class: className = '',
|
|
52
|
+
}: AdminCopilotWidgetProps = $props();
|
|
53
|
+
|
|
54
|
+
let isOpen = $state(untrack(() => defaultOpen));
|
|
55
|
+
let inputQuery = $state('');
|
|
56
|
+
let isThinking = $state(false);
|
|
57
|
+
let appliedFilterIds = $state<string[]>([]);
|
|
58
|
+
|
|
59
|
+
let messages = $state<CopilotMessage[]>([
|
|
60
|
+
{
|
|
61
|
+
id: 'msg-init',
|
|
62
|
+
role: 'assistant',
|
|
63
|
+
content: '您好!我是您的智能数据副驾驶。您可以随时向我询问报表洞察,或用自然语言让我帮您直接过滤表格数据。',
|
|
64
|
+
timestamp: '刚刚',
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
function makeId(): string {
|
|
69
|
+
return Math.random().toString(36).substring(2, 9);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function handleSend() {
|
|
73
|
+
const q = inputQuery.trim();
|
|
74
|
+
if (!q || isThinking) return;
|
|
75
|
+
|
|
76
|
+
const userMsg: CopilotMessage = {
|
|
77
|
+
id: makeId(),
|
|
78
|
+
role: 'user',
|
|
79
|
+
content: q,
|
|
80
|
+
timestamp: '刚刚',
|
|
81
|
+
};
|
|
82
|
+
messages = [...messages, userMsg];
|
|
83
|
+
inputQuery = '';
|
|
84
|
+
isThinking = true;
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
if (onsendmessage) {
|
|
88
|
+
const resp = await onsendmessage(q);
|
|
89
|
+
if (typeof resp === 'string') {
|
|
90
|
+
messages = [
|
|
91
|
+
...messages,
|
|
92
|
+
{ id: makeId(), role: 'assistant', content: resp, timestamp: '刚刚' },
|
|
93
|
+
];
|
|
94
|
+
} else {
|
|
95
|
+
messages = [...messages, resp];
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
// Built-in intelligent simulation with auto filter extraction
|
|
99
|
+
await new Promise((r) => setTimeout(r, 650));
|
|
100
|
+
let replyContent = `已为您检索并分析关于“${q}”的数据记录。`;
|
|
101
|
+
let filterSuggestion: CopilotFilterSuggestion | undefined;
|
|
102
|
+
|
|
103
|
+
if (q.includes('华东') || q.includes('大额') || q.includes('筛选') || q.includes('订单')) {
|
|
104
|
+
replyContent = `已根据您的指令分析业务规则:建议对当前表格应用复合过滤【所属大区 = 华东大区 且 订单金额 >= ¥50,000】。`;
|
|
105
|
+
filterSuggestion = {
|
|
106
|
+
field: 'region',
|
|
107
|
+
operator: '=',
|
|
108
|
+
value: '华东大区',
|
|
109
|
+
label: '大区 = 华东大区 (大额)',
|
|
110
|
+
};
|
|
111
|
+
} else if (q.includes('高危') || q.includes('异常')) {
|
|
112
|
+
replyContent = `已定位到高危审计日志:建议对表格应用【风险级别 = HIGH】过滤。`;
|
|
113
|
+
filterSuggestion = {
|
|
114
|
+
field: 'risk_level',
|
|
115
|
+
operator: '=',
|
|
116
|
+
value: 'HIGH',
|
|
117
|
+
label: '风险等级 = HIGH',
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
messages = [
|
|
122
|
+
...messages,
|
|
123
|
+
{
|
|
124
|
+
id: makeId(),
|
|
125
|
+
role: 'assistant',
|
|
126
|
+
content: replyContent,
|
|
127
|
+
suggestedFilter: filterSuggestion,
|
|
128
|
+
timestamp: '刚刚',
|
|
129
|
+
},
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
} catch {
|
|
133
|
+
messages = [
|
|
134
|
+
...messages,
|
|
135
|
+
{
|
|
136
|
+
id: makeId(),
|
|
137
|
+
role: 'assistant',
|
|
138
|
+
content: '连接智能副驾驶引擎出现波动,请稍后重试。',
|
|
139
|
+
timestamp: '刚刚',
|
|
140
|
+
},
|
|
141
|
+
];
|
|
142
|
+
} finally {
|
|
143
|
+
isThinking = false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function applyFilter(msgId: string, filter: CopilotFilterSuggestion) {
|
|
148
|
+
appliedFilterIds = [...appliedFilterIds, msgId];
|
|
149
|
+
onapplyfilter?.(filter);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function handlePromptClick(p: string) {
|
|
153
|
+
inputQuery = p;
|
|
154
|
+
handleSend();
|
|
155
|
+
}
|
|
156
|
+
</script>
|
|
157
|
+
|
|
158
|
+
<div
|
|
159
|
+
class={cn('fixed bottom-6 right-6 z-50 font-sans select-none', className)}
|
|
160
|
+
data-svadmin-component="AdminCopilotWidget"
|
|
161
|
+
data-open={isOpen ? 'true' : 'false'}
|
|
162
|
+
>
|
|
163
|
+
{#if !isOpen}
|
|
164
|
+
<!-- Floating Circular Action Trigger Button -->
|
|
165
|
+
<button
|
|
166
|
+
type="button"
|
|
167
|
+
class="h-12 w-12 rounded-full bg-primary text-primary-foreground shadow-lg hover:shadow-xl hover:scale-105 active:scale-95 transition-all flex items-center justify-center cursor-pointer relative group"
|
|
168
|
+
onclick={() => (isOpen = true)}
|
|
169
|
+
aria-label="Open AI Copilot"
|
|
170
|
+
>
|
|
171
|
+
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-primary opacity-30"></span>
|
|
172
|
+
<Sparkles class="h-6 w-6 relative z-10 transition-transform group-hover:rotate-12" />
|
|
173
|
+
</button>
|
|
174
|
+
{:else}
|
|
175
|
+
<!-- Open Window Card -->
|
|
176
|
+
<div
|
|
177
|
+
class="w-[380px] sm:w-[420px] h-[520px] max-h-[85vh] rounded-2xl border border-border bg-card text-card-foreground shadow-2xl flex flex-col overflow-hidden animate-in fade-in zoom-in-95 duration-200"
|
|
178
|
+
>
|
|
179
|
+
<!-- Header -->
|
|
180
|
+
<header class="flex items-center justify-between border-b border-border px-4 py-3 bg-muted/30 shrink-0">
|
|
181
|
+
<div class="flex items-center gap-2">
|
|
182
|
+
<div class="h-7 w-7 rounded-lg bg-primary/10 text-primary flex items-center justify-center">
|
|
183
|
+
<Sparkles class="h-4 w-4" />
|
|
184
|
+
</div>
|
|
185
|
+
<div>
|
|
186
|
+
<h3 class="font-bold text-xs text-foreground flex items-center gap-1.5">
|
|
187
|
+
<span>{botName}</span>
|
|
188
|
+
<span class="h-1.5 w-1.5 rounded-full bg-success"></span>
|
|
189
|
+
</h3>
|
|
190
|
+
<p class="text-[10px] text-muted-foreground">{title}</p>
|
|
191
|
+
</div>
|
|
192
|
+
</div>
|
|
193
|
+
|
|
194
|
+
<button
|
|
195
|
+
type="button"
|
|
196
|
+
class="rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors cursor-pointer"
|
|
197
|
+
onclick={() => (isOpen = false)}
|
|
198
|
+
aria-label="Close Copilot"
|
|
199
|
+
>
|
|
200
|
+
<X class="h-4 w-4" />
|
|
201
|
+
</button>
|
|
202
|
+
</header>
|
|
203
|
+
|
|
204
|
+
<!-- Messages Body -->
|
|
205
|
+
<div class="flex-1 overflow-y-auto p-4 space-y-3.5 text-xs">
|
|
206
|
+
{#each messages as msg (msg.id)}
|
|
207
|
+
<div class={cn('flex gap-2.5 items-start', msg.role === 'user' ? 'flex-row-reverse' : 'flex-row')}>
|
|
208
|
+
<div
|
|
209
|
+
class={cn(
|
|
210
|
+
'h-6 w-6 rounded-full flex items-center justify-center shrink-0 text-xs',
|
|
211
|
+
msg.role === 'user'
|
|
212
|
+
? 'bg-primary text-primary-foreground'
|
|
213
|
+
: 'bg-muted text-muted-foreground border border-border'
|
|
214
|
+
)}
|
|
215
|
+
>
|
|
216
|
+
{#if msg.role === 'user'}
|
|
217
|
+
<User class="h-3.5 w-3.5" />
|
|
218
|
+
{:else}
|
|
219
|
+
<Bot class="h-3.5 w-3.5 text-primary" />
|
|
220
|
+
{/if}
|
|
221
|
+
</div>
|
|
222
|
+
|
|
223
|
+
<div class={cn('space-y-1.5 max-w-[82%]', msg.role === 'user' ? 'items-end' : 'items-start')}>
|
|
224
|
+
<div
|
|
225
|
+
class={cn(
|
|
226
|
+
'p-3 rounded-2xl text-xs leading-relaxed',
|
|
227
|
+
msg.role === 'user'
|
|
228
|
+
? 'bg-primary text-primary-foreground rounded-tr-none'
|
|
229
|
+
: 'bg-muted/40 border border-border/80 text-foreground rounded-tl-none shadow-2xs'
|
|
230
|
+
)}
|
|
231
|
+
>
|
|
232
|
+
<p class="whitespace-pre-wrap">{msg.content}</p>
|
|
233
|
+
</div>
|
|
234
|
+
|
|
235
|
+
<!-- Suggested Filter Card Action -->
|
|
236
|
+
{#if msg.suggestedFilter}
|
|
237
|
+
{@const isApplied = appliedFilterIds.includes(msg.id)}
|
|
238
|
+
<div class="rounded-lg border border-primary/30 bg-primary/5 p-2.5 space-y-1.5 text-[11px] font-mono">
|
|
239
|
+
<span class="text-muted-foreground font-sans block text-[10px]">💡 识别到表格筛选条件:</span>
|
|
240
|
+
<div class="font-bold text-primary truncate">
|
|
241
|
+
{msg.suggestedFilter.label}
|
|
242
|
+
</div>
|
|
243
|
+
<button
|
|
244
|
+
type="button"
|
|
245
|
+
class={cn(
|
|
246
|
+
'inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-sans font-semibold transition-all cursor-pointer shadow-2xs',
|
|
247
|
+
isApplied
|
|
248
|
+
? 'bg-success/10 text-success border border-success/30 cursor-default'
|
|
249
|
+
: 'bg-primary text-primary-foreground hover:opacity-90'
|
|
250
|
+
)}
|
|
251
|
+
onclick={() => !isApplied && msg.suggestedFilter && applyFilter(msg.id, msg.suggestedFilter)}
|
|
252
|
+
disabled={isApplied}
|
|
253
|
+
>
|
|
254
|
+
{#if isApplied}
|
|
255
|
+
<Check class="h-3 w-3" />
|
|
256
|
+
<span>已应用到当前表格</span>
|
|
257
|
+
{:else}
|
|
258
|
+
<ArrowRight class="h-3 w-3" />
|
|
259
|
+
<span>一键应用此筛选</span>
|
|
260
|
+
{/if}
|
|
261
|
+
</button>
|
|
262
|
+
</div>
|
|
263
|
+
{/if}
|
|
264
|
+
</div>
|
|
265
|
+
</div>
|
|
266
|
+
{/each}
|
|
267
|
+
|
|
268
|
+
{#if isThinking}
|
|
269
|
+
<div class="flex items-center gap-2 text-xs text-muted-foreground p-2 rounded-lg bg-muted/20 w-fit">
|
|
270
|
+
<Loader2 class="h-3.5 w-3.5 animate-spin text-primary" />
|
|
271
|
+
<span class="font-mono text-[11px]">正在解析业务意图并检索数据...</span>
|
|
272
|
+
</div>
|
|
273
|
+
{/if}
|
|
274
|
+
</div>
|
|
275
|
+
|
|
276
|
+
<!-- Suggested Quick Prompts -->
|
|
277
|
+
{#if messages.length <= 3 && suggestedPrompts.length > 0}
|
|
278
|
+
<div class="px-4 py-2 border-t border-border/60 bg-muted/10 flex flex-wrap gap-1.5 shrink-0">
|
|
279
|
+
{#each suggestedPrompts as prompt (prompt)}
|
|
280
|
+
<button
|
|
281
|
+
type="button"
|
|
282
|
+
class="rounded-full border border-border bg-background px-2.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground hover:border-primary/40 transition-colors cursor-pointer truncate max-w-[280px]"
|
|
283
|
+
onclick={() => handlePromptClick(prompt)}
|
|
284
|
+
>
|
|
285
|
+
{prompt}
|
|
286
|
+
</button>
|
|
287
|
+
{/each}
|
|
288
|
+
</div>
|
|
289
|
+
{/if}
|
|
290
|
+
|
|
291
|
+
<!-- Input Footer -->
|
|
292
|
+
<footer class="p-3 border-t border-border bg-background shrink-0">
|
|
293
|
+
<form
|
|
294
|
+
class="flex items-center gap-1.5 rounded-xl border border-input bg-muted/20 px-3 py-1.5 focus-within:ring-2 focus-within:ring-primary/40 focus-within:bg-background transition-all"
|
|
295
|
+
onsubmit={(e) => { e.preventDefault(); handleSend(); }}
|
|
296
|
+
>
|
|
297
|
+
<input
|
|
298
|
+
type="text"
|
|
299
|
+
class="w-full bg-transparent text-xs text-foreground outline-none placeholder:text-muted-foreground"
|
|
300
|
+
bind:value={inputQuery}
|
|
301
|
+
{placeholder}
|
|
302
|
+
disabled={isThinking}
|
|
303
|
+
/>
|
|
304
|
+
<button
|
|
305
|
+
type="submit"
|
|
306
|
+
class="rounded-lg p-1.5 bg-primary text-primary-foreground hover:opacity-90 disabled:opacity-40 transition-opacity cursor-pointer shrink-0"
|
|
307
|
+
disabled={!inputQuery.trim() || isThinking}
|
|
308
|
+
aria-label="Send query"
|
|
309
|
+
>
|
|
310
|
+
<Send class="h-3.5 w-3.5" />
|
|
311
|
+
</button>
|
|
312
|
+
</form>
|
|
313
|
+
</footer>
|
|
314
|
+
</div>
|
|
315
|
+
{/if}
|
|
316
|
+
</div>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface CopilotFilterSuggestion {
|
|
2
|
+
field: string;
|
|
3
|
+
operator: string;
|
|
4
|
+
value: string | number;
|
|
5
|
+
label: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CopilotMessage {
|
|
8
|
+
id: string;
|
|
9
|
+
role: 'user' | 'assistant' | 'system';
|
|
10
|
+
content: string;
|
|
11
|
+
suggestedFilter?: CopilotFilterSuggestion | undefined;
|
|
12
|
+
timestamp?: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface AdminCopilotWidgetProps {
|
|
15
|
+
/** 浮窗卡片主标题 */
|
|
16
|
+
title?: string | undefined;
|
|
17
|
+
/** 机器人助手名称,默认 "SVAdmin Copilot" */
|
|
18
|
+
botName?: string | undefined;
|
|
19
|
+
/** 输入框占位提示文本 */
|
|
20
|
+
placeholder?: string | undefined;
|
|
21
|
+
/** 快捷预设提示词气泡列表 */
|
|
22
|
+
suggestedPrompts?: string[] | undefined;
|
|
23
|
+
/** 是否默认展开浮窗 */
|
|
24
|
+
defaultOpen?: boolean | undefined;
|
|
25
|
+
/** 点击应用推荐筛选条件到当前页面的回调 */
|
|
26
|
+
onapplyfilter?: ((filter: CopilotFilterSuggestion) => void) | undefined;
|
|
27
|
+
/** 发送提问消息回调,支持返回回复文本或完整消息对象 */
|
|
28
|
+
onsendmessage?: ((query: string) => Promise<string | CopilotMessage> | string | CopilotMessage) | undefined;
|
|
29
|
+
class?: string | undefined;
|
|
30
|
+
}
|
|
31
|
+
declare const AdminCopilotWidget: import("svelte").Component<AdminCopilotWidgetProps, {}, "">;
|
|
32
|
+
type AdminCopilotWidget = ReturnType<typeof AdminCopilotWidget>;
|
|
33
|
+
export default AdminCopilotWidget;
|
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
items?: AnnouncementItem[] | undefined;
|
|
29
29
|
/** 严重级别/色彩语义,默认 'warning' */
|
|
30
30
|
tone?: 'info' | 'warning' | 'error' | 'success' | undefined;
|
|
31
|
+
/** 屏幕阅读器播报策略;未指定时由 blocking 推导 */
|
|
32
|
+
live?: 'off' | 'polite' | 'assertive' | undefined;
|
|
33
|
+
/** 是否阻断当前任务;非阻断提示应设置为 false */
|
|
34
|
+
blocking?: boolean | undefined;
|
|
31
35
|
/** 维护/停服倒计时目标时间,自动计算并展示倒计时 */
|
|
32
36
|
countdownTo?: Date | string | number | undefined;
|
|
33
37
|
/** 倒计时前缀文案,默认 "距系统维护还剩: " */
|
|
@@ -59,6 +63,8 @@
|
|
|
59
63
|
message,
|
|
60
64
|
items,
|
|
61
65
|
tone = 'warning',
|
|
66
|
+
live,
|
|
67
|
+
blocking = true,
|
|
62
68
|
countdownTo,
|
|
63
69
|
countdownPrefix = '距系统维护还剩: ',
|
|
64
70
|
oncountdownend,
|
|
@@ -99,6 +105,8 @@
|
|
|
99
105
|
return activeItem?.tone ?? tone;
|
|
100
106
|
});
|
|
101
107
|
|
|
108
|
+
const liveMode = $derived(live ?? (blocking ? 'assertive' : 'polite'));
|
|
109
|
+
|
|
102
110
|
const toneStyle = $derived.by(() => {
|
|
103
111
|
switch (currentTone) {
|
|
104
112
|
case 'info':
|
|
@@ -225,7 +233,10 @@
|
|
|
225
233
|
className
|
|
226
234
|
)}
|
|
227
235
|
data-svadmin-component="AnnouncementBanner"
|
|
228
|
-
|
|
236
|
+
data-svadmin-blocking={blocking}
|
|
237
|
+
aria-live={liveMode}
|
|
238
|
+
aria-atomic="true"
|
|
239
|
+
role={liveMode === 'assertive' ? 'alert' : undefined}
|
|
229
240
|
onmouseenter={() => (isPaused = true)}
|
|
230
241
|
onmouseleave={() => (isPaused = false)}
|
|
231
242
|
>
|
|
@@ -14,6 +14,10 @@ export interface AnnouncementBannerProps {
|
|
|
14
14
|
items?: AnnouncementItem[] | undefined;
|
|
15
15
|
/** 严重级别/色彩语义,默认 'warning' */
|
|
16
16
|
tone?: 'info' | 'warning' | 'error' | 'success' | undefined;
|
|
17
|
+
/** 屏幕阅读器播报策略;未指定时由 blocking 推导 */
|
|
18
|
+
live?: 'off' | 'polite' | 'assertive' | undefined;
|
|
19
|
+
/** 是否阻断当前任务;非阻断提示应设置为 false */
|
|
20
|
+
blocking?: boolean | undefined;
|
|
17
21
|
/** 维护/停服倒计时目标时间,自动计算并展示倒计时 */
|
|
18
22
|
countdownTo?: Date | string | number | undefined;
|
|
19
23
|
/** 倒计时前缀文案,默认 "距系统维护还剩: " */
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from 'svelte';
|
|
3
|
+
import { Terminal, Play, Copy, Check, CheckCircle2, AlertCircle, Loader2 } from '@lucide/svelte';
|
|
4
|
+
import { cn } from '../utils.js';
|
|
5
|
+
|
|
6
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
7
|
+
|
|
8
|
+
export interface ApiResponse {
|
|
9
|
+
status: number;
|
|
10
|
+
durationMs: number;
|
|
11
|
+
sizeBytes?: number | undefined;
|
|
12
|
+
data?: unknown | undefined;
|
|
13
|
+
error?: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ApiPlaygroundProps {
|
|
17
|
+
defaultMethod?: HttpMethod | undefined;
|
|
18
|
+
defaultUrl?: string | undefined;
|
|
19
|
+
defaultHeaders?: Record<string, string> | undefined;
|
|
20
|
+
defaultBody?: string | undefined;
|
|
21
|
+
onrequest?: ((req: {
|
|
22
|
+
method: HttpMethod;
|
|
23
|
+
url: string;
|
|
24
|
+
headers: Record<string, string>;
|
|
25
|
+
body?: string | undefined;
|
|
26
|
+
}) => Promise<ApiResponse> | ApiResponse) | undefined;
|
|
27
|
+
class?: string | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
defaultMethod = 'GET',
|
|
32
|
+
defaultUrl = '/api/v1/users?limit=10',
|
|
33
|
+
defaultHeaders = { 'Content-Type': 'application/json', Authorization: 'Bearer sk_live_demo' },
|
|
34
|
+
defaultBody = '',
|
|
35
|
+
onrequest,
|
|
36
|
+
class: className = '',
|
|
37
|
+
}: ApiPlaygroundProps = $props();
|
|
38
|
+
|
|
39
|
+
let method = $state<HttpMethod>(untrack(() => defaultMethod));
|
|
40
|
+
let url = $state(untrack(() => defaultUrl));
|
|
41
|
+
let requestBody = $state(untrack(() => defaultBody));
|
|
42
|
+
let isExecuting = $state(false);
|
|
43
|
+
let responseResult = $state<ApiResponse | null>(null);
|
|
44
|
+
let isCurlCopied = $state(false);
|
|
45
|
+
|
|
46
|
+
const generatedCurl = $derived.by(() => {
|
|
47
|
+
const parts = [`curl -X ${method} "${url}"`];
|
|
48
|
+
for (const [k, v] of Object.entries(defaultHeaders)) {
|
|
49
|
+
parts.push(`-H "${k}: ${v}"`);
|
|
50
|
+
}
|
|
51
|
+
if (['POST', 'PUT', 'PATCH'].includes(method) && requestBody.trim()) {
|
|
52
|
+
parts.push(`-d '${requestBody.trim()}'`);
|
|
53
|
+
}
|
|
54
|
+
return parts.join(' \\\n ');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
async function copyCurl() {
|
|
58
|
+
if (typeof navigator === 'undefined' || !navigator.clipboard) return;
|
|
59
|
+
try {
|
|
60
|
+
await navigator.clipboard.writeText(generatedCurl);
|
|
61
|
+
isCurlCopied = true;
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
isCurlCopied = false;
|
|
64
|
+
}, 1500);
|
|
65
|
+
} catch {
|
|
66
|
+
// Ignore
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function executeRequest() {
|
|
71
|
+
if (!url.trim() || isExecuting) return;
|
|
72
|
+
isExecuting = true;
|
|
73
|
+
responseResult = null;
|
|
74
|
+
const startTime = Date.now();
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
if (onrequest) {
|
|
78
|
+
responseResult = await onrequest({
|
|
79
|
+
method,
|
|
80
|
+
url: url.trim(),
|
|
81
|
+
headers: defaultHeaders,
|
|
82
|
+
body: requestBody || undefined,
|
|
83
|
+
});
|
|
84
|
+
} else {
|
|
85
|
+
// Built-in mock response
|
|
86
|
+
await new Promise((r) => setTimeout(r, 380));
|
|
87
|
+
responseResult = {
|
|
88
|
+
status: 200,
|
|
89
|
+
durationMs: Date.now() - startTime,
|
|
90
|
+
sizeBytes: 1420,
|
|
91
|
+
data: {
|
|
92
|
+
success: true,
|
|
93
|
+
items: [
|
|
94
|
+
{ id: 1, name: 'Alice', role: 'admin' },
|
|
95
|
+
{ id: 2, name: 'Bob', role: 'operator' },
|
|
96
|
+
],
|
|
97
|
+
total: 2,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
} catch (err: unknown) {
|
|
102
|
+
responseResult = {
|
|
103
|
+
status: 500,
|
|
104
|
+
durationMs: Date.now() - startTime,
|
|
105
|
+
error: err instanceof Error ? err.message : '接口调用异常中断',
|
|
106
|
+
};
|
|
107
|
+
} finally {
|
|
108
|
+
isExecuting = false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function getMethodTone(m: HttpMethod) {
|
|
113
|
+
switch (m) {
|
|
114
|
+
case 'GET':
|
|
115
|
+
return 'text-primary bg-primary/10 border-primary/30';
|
|
116
|
+
case 'POST':
|
|
117
|
+
return 'text-success bg-success/10 border-success/30';
|
|
118
|
+
case 'PUT':
|
|
119
|
+
case 'PATCH':
|
|
120
|
+
return 'text-warning bg-warning/10 border-warning/30';
|
|
121
|
+
case 'DELETE':
|
|
122
|
+
return 'text-destructive bg-destructive/10 border-destructive/30';
|
|
123
|
+
default:
|
|
124
|
+
return 'text-foreground bg-muted border-border';
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
</script>
|
|
128
|
+
|
|
129
|
+
<div
|
|
130
|
+
class={cn('rounded-md border border-border bg-card p-5 text-card-foreground shadow-xs space-y-4', className)}
|
|
131
|
+
data-svadmin-component="ApiPlayground"
|
|
132
|
+
>
|
|
133
|
+
<header class="flex items-center justify-between border-b border-border pb-3">
|
|
134
|
+
<div class="flex items-center gap-2">
|
|
135
|
+
<Terminal class="h-4 w-4 text-primary" />
|
|
136
|
+
<h3 class="font-bold text-sm text-foreground">API 快捷调试工作台</h3>
|
|
137
|
+
</div>
|
|
138
|
+
<span class="text-xs font-mono text-muted-foreground">内嵌式接口探针</span>
|
|
139
|
+
</header>
|
|
140
|
+
|
|
141
|
+
<!-- URL Request Bar -->
|
|
142
|
+
<div class="flex items-center gap-2 text-xs font-mono">
|
|
143
|
+
<!-- Method Selector -->
|
|
144
|
+
<select
|
|
145
|
+
class={cn('svadmin-select svadmin-select--inline font-bold cursor-pointer', getMethodTone(method))}
|
|
146
|
+
bind:value={method}
|
|
147
|
+
disabled={isExecuting}
|
|
148
|
+
>
|
|
149
|
+
<option value="GET">GET</option>
|
|
150
|
+
<option value="POST">POST</option>
|
|
151
|
+
<option value="PUT">PUT</option>
|
|
152
|
+
<option value="PATCH">PATCH</option>
|
|
153
|
+
<option value="DELETE">DELETE</option>
|
|
154
|
+
</select>
|
|
155
|
+
|
|
156
|
+
<!-- URL Input -->
|
|
157
|
+
<input
|
|
158
|
+
type="text"
|
|
159
|
+
class="flex-1 rounded-md border border-input bg-background px-3 py-1.5 text-xs text-foreground outline-none focus:ring-1 focus:ring-primary"
|
|
160
|
+
bind:value={url}
|
|
161
|
+
placeholder="/api/v1/..."
|
|
162
|
+
disabled={isExecuting}
|
|
163
|
+
/>
|
|
164
|
+
|
|
165
|
+
<!-- Send Button -->
|
|
166
|
+
<button
|
|
167
|
+
type="button"
|
|
168
|
+
class="inline-flex items-center gap-1.5 rounded-md bg-primary px-4 py-1.5 font-semibold text-primary-foreground hover:opacity-90 transition-opacity cursor-pointer disabled:opacity-50"
|
|
169
|
+
onclick={executeRequest}
|
|
170
|
+
disabled={isExecuting || !url.trim()}
|
|
171
|
+
>
|
|
172
|
+
{#if isExecuting}
|
|
173
|
+
<Loader2 class="h-3.5 w-3.5 animate-spin" />
|
|
174
|
+
<span>请求中...</span>
|
|
175
|
+
{:else}
|
|
176
|
+
<Play class="h-3.5 w-3.5 fill-current" />
|
|
177
|
+
<span>发送请求</span>
|
|
178
|
+
{/if}
|
|
179
|
+
</button>
|
|
180
|
+
</div>
|
|
181
|
+
|
|
182
|
+
<!-- Request Body (for POST/PUT/PATCH) -->
|
|
183
|
+
{#if ['POST', 'PUT', 'PATCH'].includes(method)}
|
|
184
|
+
<div class="space-y-1 text-xs">
|
|
185
|
+
<label for="api-request-body" class="block font-medium text-foreground font-mono">
|
|
186
|
+
请求正文 (Request Body JSON)
|
|
187
|
+
</label>
|
|
188
|
+
<textarea
|
|
189
|
+
id="api-request-body"
|
|
190
|
+
class="w-full h-24 rounded-md border border-input bg-background p-3 font-mono text-xs leading-relaxed text-foreground outline-none focus:ring-1 focus:ring-primary"
|
|
191
|
+
bind:value={requestBody}
|
|
192
|
+
placeholder="输入 JSON 正文..."
|
|
193
|
+
></textarea>
|
|
194
|
+
</div>
|
|
195
|
+
{/if}
|
|
196
|
+
|
|
197
|
+
<!-- Generated cURL preview box -->
|
|
198
|
+
<div class="rounded-md border border-border bg-muted/20 p-3 space-y-2 text-xs font-mono">
|
|
199
|
+
<div class="flex items-center justify-between text-muted-foreground">
|
|
200
|
+
<span class="font-bold text-foreground">一键生成标准终端 cURL 命令</span>
|
|
201
|
+
<button
|
|
202
|
+
type="button"
|
|
203
|
+
class="inline-flex items-center gap-1 text-primary hover:underline cursor-pointer"
|
|
204
|
+
onclick={copyCurl}
|
|
205
|
+
>
|
|
206
|
+
{#if isCurlCopied}
|
|
207
|
+
<Check class="h-3 w-3 text-success" />
|
|
208
|
+
<span class="text-success font-semibold">已复制 cURL</span>
|
|
209
|
+
{:else}
|
|
210
|
+
<Copy class="h-3 w-3" />
|
|
211
|
+
<span>复制 cURL</span>
|
|
212
|
+
{/if}
|
|
213
|
+
</button>
|
|
214
|
+
</div>
|
|
215
|
+
<pre class="rounded border border-border bg-card p-2 text-foreground whitespace-pre-wrap select-all"><code>{generatedCurl}</code></pre>
|
|
216
|
+
</div>
|
|
217
|
+
|
|
218
|
+
<!-- Response Section -->
|
|
219
|
+
{#if responseResult}
|
|
220
|
+
<div class="rounded-md border border-border bg-card p-4 space-y-3 text-xs font-mono">
|
|
221
|
+
<div class="flex items-center justify-between border-b border-border pb-2">
|
|
222
|
+
<div class="flex items-center gap-2">
|
|
223
|
+
{#if responseResult.status >= 200 && responseResult.status < 300}
|
|
224
|
+
<span class="font-bold text-success flex items-center gap-1">
|
|
225
|
+
<CheckCircle2 class="h-3.5 w-3.5" />
|
|
226
|
+
HTTP {responseResult.status} OK
|
|
227
|
+
</span>
|
|
228
|
+
{:else}
|
|
229
|
+
<span class="font-bold text-destructive flex items-center gap-1">
|
|
230
|
+
<AlertCircle class="h-3.5 w-3.5" />
|
|
231
|
+
HTTP {responseResult.status} ERROR
|
|
232
|
+
</span>
|
|
233
|
+
{/if}
|
|
234
|
+
</div>
|
|
235
|
+
<div class="flex items-center gap-3 text-muted-foreground">
|
|
236
|
+
<span>耗时: <strong>{responseResult.durationMs}ms</strong></span>
|
|
237
|
+
{#if responseResult.sizeBytes}
|
|
238
|
+
<span>大小: <strong>{responseResult.sizeBytes} B</strong></span>
|
|
239
|
+
{/if}
|
|
240
|
+
</div>
|
|
241
|
+
</div>
|
|
242
|
+
|
|
243
|
+
{#if responseResult.error}
|
|
244
|
+
<div class="text-destructive font-semibold">
|
|
245
|
+
异常报错: {responseResult.error}
|
|
246
|
+
</div>
|
|
247
|
+
{:else if responseResult.data}
|
|
248
|
+
<div>
|
|
249
|
+
<span class="text-muted-foreground block mb-1">响应结果数据 (JSON):</span>
|
|
250
|
+
<pre class="rounded border border-border bg-muted/30 p-2.5 text-foreground max-h-48 overflow-y-auto whitespace-pre-wrap"><code>{JSON.stringify(responseResult.data, null, 2)}</code></pre>
|
|
251
|
+
</div>
|
|
252
|
+
{/if}
|
|
253
|
+
</div>
|
|
254
|
+
{/if}
|
|
255
|
+
</div>
|