From 424e59b2ca0884244add4f566a82c5b11fa26ea1 Mon Sep 17 00:00:00 2001 From: shaojie <741047428@qq.com> Date: Thu, 18 Sep 2025 14:48:35 +0800 Subject: [PATCH] =?UTF-8?q?-=20initializeDataSource=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E4=BD=BF=E7=94=A8setTimeout=E6=A8=A1=E6=8B=9F=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=EF=BC=8C=E6=9C=AA=E7=9C=9F=E6=AD=A3=E8=B0=83=E7=94=A8?= =?UTF-8?q?API=20-=20=E7=9B=B4=E6=8E=A5=E8=AE=BE=E7=BD=AEisInitialized?= =?UTF-8?q?=E4=B8=BAtrue=EF=BC=8C=E5=AF=BC=E8=87=B4=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=B8=8D=E5=87=86=E7=A1=AE=20-=20=E7=94=A8=E6=88=B7=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E5=9C=A8=E6=9C=AA=E5=88=9D=E5=A7=8B=E5=8C=96=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E4=B8=8B=E8=AF=AF=E4=BB=A5=E4=B8=BA=E5=B7=B2=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E5=88=9D=E5=A7=8B=E5=8C=96=E8=BF=9B=E8=A1=8C=E8=B0=83?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/AgentDebugPanel.vue | 115 +++++++++++++++--- 1 file changed, 98 insertions(+), 17 deletions(-) diff --git a/spring-ai-alibaba-nl2sql/spring-ai-alibaba-nl2sql-web-ui/src/components/AgentDebugPanel.vue b/spring-ai-alibaba-nl2sql/spring-ai-alibaba-nl2sql-web-ui/src/components/AgentDebugPanel.vue index f7736cf218..d14d2ea608 100644 --- a/spring-ai-alibaba-nl2sql/spring-ai-alibaba-nl2sql-web-ui/src/components/AgentDebugPanel.vue +++ b/spring-ai-alibaba-nl2sql/spring-ai-alibaba-nl2sql-web-ui/src/components/AgentDebugPanel.vue @@ -128,12 +128,16 @@ @@ -309,10 +313,52 @@ export default { // 获取初始化按钮文本 const getInitButtonText = () => { if (isInitializing.value) return '检查中...' - if (isInitialized.value) return '已初始化' + if (isInitialized.value) return '重新检查状态' return '检查初始化状态' } + // 获取初始化按钮样式 + const getInitButtonStyle = () => { + const baseStyle = { + padding: '0.75rem 1rem', + border: 'none', + borderRadius: '8px', + fontSize: '0.8rem', + cursor: 'pointer', + transition: 'all 0.3s ease', + display: 'flex', + alignItems: 'center', + gap: '0.4rem', + fontWeight: '500', + minWidth: '140px', + justifyContent: 'center' + } + + if (isInitializing.value) { + return { + ...baseStyle, + background: 'linear-gradient(135deg, #6b7280 0%, #4b5563 100%)', + color: 'white', + cursor: 'not-allowed', + boxShadow: '0 2px 8px rgba(107, 114, 128, 0.25)' + } + } else if (isInitialized.value) { + return { + ...baseStyle, + background: 'linear-gradient(135deg, #10b981 0%, #059669 100%)', + color: 'white', + boxShadow: '0 2px 8px rgba(16, 185, 129, 0.25)' + } + } else { + return { + ...baseStyle, + background: 'linear-gradient(135deg, #f59e0b 0%, #d97706 100%)', + color: 'white', + boxShadow: '0 2px 8px rgba(245, 158, 11, 0.25)' + } + } + } + // 处理调试按钮点击 const handleDebugClick = () => { console.log('=== 调试按钮被点击 ===') @@ -716,7 +762,7 @@ export default { } }; - // 初始化数据源 + // 初始化数据源状态检查 const initializeDataSource = async () => { if (isInitializing.value || isDebugging.value) return @@ -724,21 +770,55 @@ export default { isInitializing.value = true debugStatus.value = '正在检查初始化状态...' - setTimeout(() => { - isInitialized.value = true - debugStatus.value = '数据源已初始化,可以开始调试' - isInitializing.value = false - - setTimeout(() => { - debugStatus.value = '' - }, 3000) - }, 1000) - + // 真正调用接口检查初始化状态 + const response = await fetch(`/api/agent/${debugAgentId}/schema/statistics`) + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + + const result = await response.json() + + if (result.success) { + const hasData = result.data && result.data.documentCount > 0 + isInitialized.value = hasData + schemaStatistics.value = result.data + + if (hasData) { + debugStatus.value = `✅ 数据源已初始化,共有 ${result.data.documentCount} 个向量文档,可以开始调试` + console.log('初始化状态检查成功:', result.data) + } else { + debugStatus.value = '⚠️ 数据源未初始化,请点击"初始化信息源"进行配置' + console.log('检测到未初始化状态:', result.data) + } + } else { + isInitialized.value = false + schemaStatistics.value = null + debugStatus.value = `❌ 检查失败: ${result.message || '未知错误'}` + console.error('获取统计信息失败:', result.message) + } + } catch (error) { console.error('检查初始化状态错误:', error) - debugStatus.value = '检查失败,请确保智能体配置正确' isInitialized.value = false + schemaStatistics.value = null + + // 根据错误类型提供不同的提示 + if (error.message.includes('Failed to fetch') || error.message.includes('NetworkError')) { + debugStatus.value = '❌ 网络连接失败,请检查网络状态或后端服务是否正常' + } else if (error.message.includes('HTTP error')) { + debugStatus.value = `❌ 服务异常 (${error.message}),请联系管理员` + } else { + debugStatus.value = '❌ 检查失败,请确保智能体配置正确' + } + } finally { isInitializing.value = false + + // 5秒后清空状态消息(成功状态保留更长时间) + const clearDelay = isInitialized.value ? 5000 : 8000 + setTimeout(() => { + debugStatus.value = '' + }, clearDelay) } } @@ -1001,6 +1081,7 @@ export default { getStatusClass, useExampleQuery, getInitButtonText, + getInitButtonStyle, handleDebugClick, startDebug, initializeDataSource,