|
128 | 128 | <button
|
129 | 129 | class="init-button"
|
130 | 130 | :disabled="isInitializing || isDebugging"
|
131 |
| - :class="{ loading: isInitializing }" |
| 131 | + :class="{ |
| 132 | + loading: isInitializing, |
| 133 | + 'init-success': isInitialized && !isInitializing, |
| 134 | + 'init-pending': !isInitialized && !isInitializing |
| 135 | + }" |
132 | 136 | @click="initializeDataSource"
|
133 |
| - style="padding: 0.75rem 1rem; background: linear-gradient(135deg, #10b981 0%, #059669 100%); color: white; border: none; border-radius: 8px; font-size: 0.8rem; cursor: pointer; transition: all 0.3s ease; display: flex; align-items: center; gap: 0.4rem; font-weight: 500; box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);" |
| 137 | + :style="getInitButtonStyle()" |
134 | 138 | >
|
135 |
| - <i class="bi bi-database-add" v-if="!isInitializing && !isInitialized" style="font-size: 0.8rem;"></i> |
136 |
| - <i class="bi bi-check-circle" v-if="!isInitializing && isInitialized" style="font-size: 0.8rem;"></i> |
| 139 | + <i class="bi bi-database-gear" v-if="!isInitializing && !isInitialized" style="font-size: 0.8rem;"></i> |
| 140 | + <i class="bi bi-check-circle-fill" v-if="!isInitializing && isInitialized" style="font-size: 0.8rem;"></i> |
137 | 141 | <div class="spinner" v-if="isInitializing"></div>
|
138 | 142 | {{ getInitButtonText() }}
|
139 | 143 | </button>
|
@@ -309,10 +313,52 @@ export default {
|
309 | 313 | // 获取初始化按钮文本
|
310 | 314 | const getInitButtonText = () => {
|
311 | 315 | if (isInitializing.value) return '检查中...'
|
312 |
| - if (isInitialized.value) return '已初始化' |
| 316 | + if (isInitialized.value) return '重新检查状态' |
313 | 317 | return '检查初始化状态'
|
314 | 318 | }
|
315 | 319 |
|
| 320 | + // 获取初始化按钮样式 |
| 321 | + const getInitButtonStyle = () => { |
| 322 | + const baseStyle = { |
| 323 | + padding: '0.75rem 1rem', |
| 324 | + border: 'none', |
| 325 | + borderRadius: '8px', |
| 326 | + fontSize: '0.8rem', |
| 327 | + cursor: 'pointer', |
| 328 | + transition: 'all 0.3s ease', |
| 329 | + display: 'flex', |
| 330 | + alignItems: 'center', |
| 331 | + gap: '0.4rem', |
| 332 | + fontWeight: '500', |
| 333 | + minWidth: '140px', |
| 334 | + justifyContent: 'center' |
| 335 | + } |
| 336 | +
|
| 337 | + if (isInitializing.value) { |
| 338 | + return { |
| 339 | + ...baseStyle, |
| 340 | + background: 'linear-gradient(135deg, #6b7280 0%, #4b5563 100%)', |
| 341 | + color: 'white', |
| 342 | + cursor: 'not-allowed', |
| 343 | + boxShadow: '0 2px 8px rgba(107, 114, 128, 0.25)' |
| 344 | + } |
| 345 | + } else if (isInitialized.value) { |
| 346 | + return { |
| 347 | + ...baseStyle, |
| 348 | + background: 'linear-gradient(135deg, #10b981 0%, #059669 100%)', |
| 349 | + color: 'white', |
| 350 | + boxShadow: '0 2px 8px rgba(16, 185, 129, 0.25)' |
| 351 | + } |
| 352 | + } else { |
| 353 | + return { |
| 354 | + ...baseStyle, |
| 355 | + background: 'linear-gradient(135deg, #f59e0b 0%, #d97706 100%)', |
| 356 | + color: 'white', |
| 357 | + boxShadow: '0 2px 8px rgba(245, 158, 11, 0.25)' |
| 358 | + } |
| 359 | + } |
| 360 | + } |
| 361 | +
|
316 | 362 | // 处理调试按钮点击
|
317 | 363 | const handleDebugClick = () => {
|
318 | 364 | console.log('=== 调试按钮被点击 ===')
|
@@ -716,29 +762,63 @@ export default {
|
716 | 762 | }
|
717 | 763 | };
|
718 | 764 |
|
719 |
| - // 初始化数据源 |
| 765 | + // 初始化数据源状态检查 |
720 | 766 | const initializeDataSource = async () => {
|
721 | 767 | if (isInitializing.value || isDebugging.value) return
|
722 | 768 |
|
723 | 769 | try {
|
724 | 770 | isInitializing.value = true
|
725 | 771 | debugStatus.value = '正在检查初始化状态...'
|
726 | 772 |
|
727 |
| - setTimeout(() => { |
728 |
| - isInitialized.value = true |
729 |
| - debugStatus.value = '数据源已初始化,可以开始调试' |
730 |
| - isInitializing.value = false |
731 |
| -
|
732 |
| - setTimeout(() => { |
733 |
| - debugStatus.value = '' |
734 |
| - }, 3000) |
735 |
| - }, 1000) |
736 |
| -
|
| 773 | + // 真正调用接口检查初始化状态 |
| 774 | + const response = await fetch(`/api/agent/${debugAgentId}/schema/statistics`) |
| 775 | + |
| 776 | + if (!response.ok) { |
| 777 | + throw new Error(`HTTP error! status: ${response.status}`) |
| 778 | + } |
| 779 | + |
| 780 | + const result = await response.json() |
| 781 | + |
| 782 | + if (result.success) { |
| 783 | + const hasData = result.data && result.data.documentCount > 0 |
| 784 | + isInitialized.value = hasData |
| 785 | + schemaStatistics.value = result.data |
| 786 | + |
| 787 | + if (hasData) { |
| 788 | + debugStatus.value = `✅ 数据源已初始化,共有 ${result.data.documentCount} 个向量文档,可以开始调试` |
| 789 | + console.log('初始化状态检查成功:', result.data) |
| 790 | + } else { |
| 791 | + debugStatus.value = '⚠️ 数据源未初始化,请点击"初始化信息源"进行配置' |
| 792 | + console.log('检测到未初始化状态:', result.data) |
| 793 | + } |
| 794 | + } else { |
| 795 | + isInitialized.value = false |
| 796 | + schemaStatistics.value = null |
| 797 | + debugStatus.value = `❌ 检查失败: ${result.message || '未知错误'}` |
| 798 | + console.error('获取统计信息失败:', result.message) |
| 799 | + } |
| 800 | + |
737 | 801 | } catch (error) {
|
738 | 802 | console.error('检查初始化状态错误:', error)
|
739 |
| - debugStatus.value = '检查失败,请确保智能体配置正确' |
740 | 803 | isInitialized.value = false
|
| 804 | + schemaStatistics.value = null |
| 805 | + |
| 806 | + // 根据错误类型提供不同的提示 |
| 807 | + if (error.message.includes('Failed to fetch') || error.message.includes('NetworkError')) { |
| 808 | + debugStatus.value = '❌ 网络连接失败,请检查网络状态或后端服务是否正常' |
| 809 | + } else if (error.message.includes('HTTP error')) { |
| 810 | + debugStatus.value = `❌ 服务异常 (${error.message}),请联系管理员` |
| 811 | + } else { |
| 812 | + debugStatus.value = '❌ 检查失败,请确保智能体配置正确' |
| 813 | + } |
| 814 | + } finally { |
741 | 815 | isInitializing.value = false
|
| 816 | + |
| 817 | + // 5秒后清空状态消息(成功状态保留更长时间) |
| 818 | + const clearDelay = isInitialized.value ? 5000 : 8000 |
| 819 | + setTimeout(() => { |
| 820 | + debugStatus.value = '' |
| 821 | + }, clearDelay) |
742 | 822 | }
|
743 | 823 | }
|
744 | 824 |
|
@@ -1001,6 +1081,7 @@ export default {
|
1001 | 1081 | getStatusClass,
|
1002 | 1082 | useExampleQuery,
|
1003 | 1083 | getInitButtonText,
|
| 1084 | + getInitButtonStyle, |
1004 | 1085 | handleDebugClick,
|
1005 | 1086 | startDebug,
|
1006 | 1087 | initializeDataSource,
|
|
0 commit comments