From 3c9f647e8c80d2a321c27a2b87ba0d212411daae Mon Sep 17 00:00:00 2001 From: aaron <> Date: Sun, 18 May 2025 10:43:16 +0800 Subject: [PATCH] update --- src/views/CryptoAnalysisView.vue | 124 +++++++++++++++++-------------- 1 file changed, 68 insertions(+), 56 deletions(-) diff --git a/src/views/CryptoAnalysisView.vue b/src/views/CryptoAnalysisView.vue index e1f8e01..a5b584f 100644 --- a/src/views/CryptoAnalysisView.vue +++ b/src/views/CryptoAnalysisView.vue @@ -4,7 +4,6 @@ import { useUserStore } from '../stores/user' interface AnalysisRequest { symbol: string - timeframe?: string } const userStore = useUserStore() @@ -13,17 +12,9 @@ const isAnalyzing = ref(false) const analysisContent = ref('') const analysisContainer = ref(null) const currentThought = ref('') -const selectedTimeframe = ref('15m') const showInitialView = ref(true) const copySuccess = ref(false) -const timeframes = [ - { label: '15分钟', value: '15m' }, - { label: '1小时', value: '1h' }, - { label: '4小时', value: '4h' }, - { label: '1天', value: '1d' }, -] - // 根据环境选择API基础URL const apiBaseUrl = import.meta.env.MODE === 'development' ? 'http://127.0.0.1:8000' : 'https://api.ibtc.work' @@ -43,6 +34,13 @@ const handleKeydown = (event: KeyboardEvent) => { } } +// 处理错误消息的显示 +const setErrorMessage = (message: string) => { + // 直接使用错误消息内容 + analysisContent.value = `错误: ${message}` + currentThought.value = '分析失败' +} + const handleAnalysis = async () => { if (!cryptoCode.value.trim() || isAnalyzing.value) return @@ -61,7 +59,6 @@ const handleAnalysis = async () => { const requestData: AnalysisRequest = { symbol: cryptoCode.value.trim().toUpperCase(), - timeframe: selectedTimeframe.value, } const response = await fetch(`${apiBaseUrl}/crypto/analysis_v2`, { @@ -71,7 +68,18 @@ const handleAnalysis = async () => { }) if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`) + // 解析错误响应 + try { + const errorData = await response.json() + if (errorData && errorData.detail) { + setErrorMessage(errorData.detail) + } else { + setErrorMessage(`请求失败,状态码: ${response.status}`) + } + } catch { + setErrorMessage(`请求失败,状态码: ${response.status}`) + } + return } const reader = response.body?.getReader() @@ -123,21 +131,18 @@ const handleAnalysis = async () => { case 'error': const errorMessage = data.error || '未知错误' - analysisContent.value = `
分析过程中出现错误:${errorMessage}
` - currentThought.value = '分析过程出现错误' + setErrorMessage(errorMessage) await scrollToBottom() break } } catch (error) { console.error('解析响应数据出错:', error) - analysisContent.value = '
解析响应数据时出错,请稍后重试
' - currentThought.value = '数据解析出错' + setErrorMessage('解析响应数据时出错,请稍后重试') } } } } catch { - analysisContent.value = '
抱歉,分析请求失败,请稍后重试
' - currentThought.value = '请求失败' + setErrorMessage('抱歉,分析请求失败,请稍后重试') } finally { isAnalyzing.value = false await scrollToBottom() @@ -177,22 +182,23 @@ const copyAnalysis = async () => { } } -// 添加快速分析列表数据 +// 修改快速分析列表数据 const commonAnalysisList = [ - { code: 'BTC', timeframe: '15m', label: 'BTC 15分钟' }, - { code: 'BTC', timeframe: '1h', label: 'BTC 1小时' }, - { code: 'BTC', timeframe: '4h', label: 'BTC 4小时' }, - { code: 'BTC', timeframe: '1d', label: 'BTC 日线' }, - { code: 'ETH', timeframe: '15m', label: 'ETH 15分钟' }, - { code: 'ETH', timeframe: '1h', label: 'ETH 1小时' }, - { code: 'ETH', timeframe: '4h', label: 'ETH 4小时' }, - { code: 'ETH', timeframe: '1d', label: 'ETH 日线' }, + { code: 'BTC', label: 'BTC' }, + { code: 'ETH', label: 'ETH' }, + { code: 'SOL', label: 'SOL' }, + { code: 'SUI', label: 'SUI' }, + { code: 'TRX', label: 'TRX' }, + { code: 'XRP', label: 'XRP' }, + { code: 'BNB', label: 'BNB' }, + { code: 'ADA', label: 'ADA' }, + { code: 'DOGE', label: 'DOGE' }, + { code: 'SHIB', label: 'SHIB' }, ] // 处理快速分析项的点击 -const handleCommonAnalysis = (item: { code: string; timeframe: string }) => { +const handleCommonAnalysis = (item: { code: string }) => { cryptoCode.value = item.code - selectedTimeframe.value = item.timeframe handleAnalysis() } @@ -216,7 +222,7 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => { v-model="cryptoCode" type="text" class="search-input" - placeholder="请输入BTC、ETH,仅支持输入一个分析。" + placeholder="请输入BTC、ETH,仅支持输入一个分析币种" @keydown="handleKeydown" :disabled="isAnalyzing" /> @@ -239,18 +245,6 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => { - -
-
- {{ timeframe.label }} -
-