This commit is contained in:
aaron 2025-05-18 10:43:16 +08:00
parent f9198ee01b
commit 3c9f647e8c

View File

@ -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<HTMLElement | null>(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' },
]
// APIURL
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 = `<div class="error-message">分析过程中出现错误:${errorMessage}</div>`
currentThought.value = '分析过程出现错误'
setErrorMessage(errorMessage)
await scrollToBottom()
break
}
} catch (error) {
console.error('解析响应数据出错:', error)
analysisContent.value = '<div class="error-message">解析响应数据时出错,请稍后重试</div>'
currentThought.value = '数据解析出错'
setErrorMessage('解析响应数据时出错,请稍后重试')
}
}
}
} catch {
analysisContent.value = '<div class="error-message">抱歉,分析请求失败,请稍后重试</div>'
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()
}
</script>
@ -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 }) => {
</svg>
</button>
</div>
<!-- 时间周期选择 -->
<div class="timeframe-selector">
<div
v-for="timeframe in timeframes"
:key="timeframe.value"
class="timeframe-option"
:class="{ active: selectedTimeframe === timeframe.value }"
@click="selectedTimeframe = timeframe.value"
>
<span class="timeframe-label">{{ timeframe.label }}</span>
</div>
</div>
<button
class="analyze-button"
@click="handleAnalysis"
@ -267,7 +261,7 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => {
<div class="common-analysis-section">
<div class="common-analysis-container">
<div class="section-header">
<span class="section-title">快速分析</span>
<span class="section-title">点击直接快速分析币种</span>
</div>
<div class="common-analysis-list">
<button
@ -290,9 +284,6 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => {
<div class="target-info">
<span class="label">正在分析</span>
<span class="value">{{ cryptoCode.toUpperCase() }}</span>
<span class="timeframe">{{
timeframes.find((t) => t.value === selectedTimeframe)?.label
}}</span>
</div>
<div class="action-buttons" v-if="!isAnalyzing">
<button class="action-button" @click="resetView">
@ -340,7 +331,12 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => {
ref="analysisContainer"
:class="{ 'fade-in': analysisContent }"
>
<div class="analysis-content" v-html="analysisContent"></div>
<div v-if="analysisContent.startsWith('错误:')" class="error-message">
{{ analysisContent.substring(4) }}
</div>
<div v-else class="analysis-content">
{{ analysisContent }}
</div>
</div>
</div>
</div>
@ -348,8 +344,15 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => {
</template>
<style scoped>
/* 移除不需要的时间周期选择样式 */
.timeframe-section {
/* 移除所有时间周期相关样式 */
.timeframe-selector,
.timeframe-selector::-webkit-scrollbar,
.timeframe-selector .timeframe-option,
.timeframe-selector .timeframe-label,
.timeframe-selector .timeframe-option:not(.active):hover .timeframe-label,
.timeframe-selector .timeframe-option.active .timeframe-label,
.target-info .timeframe,
.history-code .timeframe {
display: none;
}
@ -700,11 +703,13 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => {
}
.analysis-content {
line-height: 2;
font-size: 1rem;
line-height: 1.6;
white-space: pre-wrap;
word-break: break-word;
color: var(--color-text-primary);
padding: 1.5rem 2rem;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}
.analysis-content :deep(h1),
@ -804,14 +809,21 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => {
line-height: 1.5;
}
:deep(.error-message) {
margin: 1rem 0;
padding: 0.75rem 1rem;
background-color: rgba(255, 0, 0, 0.05);
border: 1px solid rgba(255, 0, 0, 0.1);
.error-message {
color: #ff3333;
font-weight: 500;
padding: 1rem;
background-color: rgba(255, 51, 51, 0.08);
border: 1px solid rgba(255, 51, 51, 0.2);
border-radius: 0.5rem;
color: #ff4444;
font-size: 0.95rem;
margin: 1rem;
text-align: center;
font-size: 1rem;
line-height: 1.5;
}
.error-message::before {
content: '⚠️ ';
}
.analysis-content::-webkit-scrollbar {