update
This commit is contained in:
parent
f9198ee01b
commit
3c9f647e8c
@ -4,7 +4,6 @@ import { useUserStore } from '../stores/user'
|
|||||||
|
|
||||||
interface AnalysisRequest {
|
interface AnalysisRequest {
|
||||||
symbol: string
|
symbol: string
|
||||||
timeframe?: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
@ -13,17 +12,9 @@ const isAnalyzing = ref(false)
|
|||||||
const analysisContent = ref('')
|
const analysisContent = ref('')
|
||||||
const analysisContainer = ref<HTMLElement | null>(null)
|
const analysisContainer = ref<HTMLElement | null>(null)
|
||||||
const currentThought = ref('')
|
const currentThought = ref('')
|
||||||
const selectedTimeframe = ref('15m')
|
|
||||||
const showInitialView = ref(true)
|
const showInitialView = ref(true)
|
||||||
const copySuccess = ref(false)
|
const copySuccess = ref(false)
|
||||||
|
|
||||||
const timeframes = [
|
|
||||||
{ label: '15分钟', value: '15m' },
|
|
||||||
{ label: '1小时', value: '1h' },
|
|
||||||
{ label: '4小时', value: '4h' },
|
|
||||||
{ label: '1天', value: '1d' },
|
|
||||||
]
|
|
||||||
|
|
||||||
// 根据环境选择API基础URL
|
// 根据环境选择API基础URL
|
||||||
const apiBaseUrl =
|
const apiBaseUrl =
|
||||||
import.meta.env.MODE === 'development' ? 'http://127.0.0.1:8000' : 'https://api.ibtc.work'
|
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 () => {
|
const handleAnalysis = async () => {
|
||||||
if (!cryptoCode.value.trim() || isAnalyzing.value) return
|
if (!cryptoCode.value.trim() || isAnalyzing.value) return
|
||||||
|
|
||||||
@ -61,7 +59,6 @@ const handleAnalysis = async () => {
|
|||||||
|
|
||||||
const requestData: AnalysisRequest = {
|
const requestData: AnalysisRequest = {
|
||||||
symbol: cryptoCode.value.trim().toUpperCase(),
|
symbol: cryptoCode.value.trim().toUpperCase(),
|
||||||
timeframe: selectedTimeframe.value,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(`${apiBaseUrl}/crypto/analysis_v2`, {
|
const response = await fetch(`${apiBaseUrl}/crypto/analysis_v2`, {
|
||||||
@ -71,7 +68,18 @@ const handleAnalysis = async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
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()
|
const reader = response.body?.getReader()
|
||||||
@ -123,21 +131,18 @@ const handleAnalysis = async () => {
|
|||||||
|
|
||||||
case 'error':
|
case 'error':
|
||||||
const errorMessage = data.error || '未知错误'
|
const errorMessage = data.error || '未知错误'
|
||||||
analysisContent.value = `<div class="error-message">分析过程中出现错误:${errorMessage}</div>`
|
setErrorMessage(errorMessage)
|
||||||
currentThought.value = '分析过程出现错误'
|
|
||||||
await scrollToBottom()
|
await scrollToBottom()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('解析响应数据出错:', error)
|
console.error('解析响应数据出错:', error)
|
||||||
analysisContent.value = '<div class="error-message">解析响应数据时出错,请稍后重试</div>'
|
setErrorMessage('解析响应数据时出错,请稍后重试')
|
||||||
currentThought.value = '数据解析出错'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
analysisContent.value = '<div class="error-message">抱歉,分析请求失败,请稍后重试</div>'
|
setErrorMessage('抱歉,分析请求失败,请稍后重试')
|
||||||
currentThought.value = '请求失败'
|
|
||||||
} finally {
|
} finally {
|
||||||
isAnalyzing.value = false
|
isAnalyzing.value = false
|
||||||
await scrollToBottom()
|
await scrollToBottom()
|
||||||
@ -177,22 +182,23 @@ const copyAnalysis = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加快速分析列表数据
|
// 修改快速分析列表数据
|
||||||
const commonAnalysisList = [
|
const commonAnalysisList = [
|
||||||
{ code: 'BTC', timeframe: '15m', label: 'BTC 15分钟' },
|
{ code: 'BTC', label: 'BTC' },
|
||||||
{ code: 'BTC', timeframe: '1h', label: 'BTC 1小时' },
|
{ code: 'ETH', label: 'ETH' },
|
||||||
{ code: 'BTC', timeframe: '4h', label: 'BTC 4小时' },
|
{ code: 'SOL', label: 'SOL' },
|
||||||
{ code: 'BTC', timeframe: '1d', label: 'BTC 日线' },
|
{ code: 'SUI', label: 'SUI' },
|
||||||
{ code: 'ETH', timeframe: '15m', label: 'ETH 15分钟' },
|
{ code: 'TRX', label: 'TRX' },
|
||||||
{ code: 'ETH', timeframe: '1h', label: 'ETH 1小时' },
|
{ code: 'XRP', label: 'XRP' },
|
||||||
{ code: 'ETH', timeframe: '4h', label: 'ETH 4小时' },
|
{ code: 'BNB', label: 'BNB' },
|
||||||
{ code: 'ETH', timeframe: '1d', label: 'ETH 日线' },
|
{ 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
|
cryptoCode.value = item.code
|
||||||
selectedTimeframe.value = item.timeframe
|
|
||||||
handleAnalysis()
|
handleAnalysis()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@ -216,7 +222,7 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => {
|
|||||||
v-model="cryptoCode"
|
v-model="cryptoCode"
|
||||||
type="text"
|
type="text"
|
||||||
class="search-input"
|
class="search-input"
|
||||||
placeholder="请输入BTC、ETH,仅支持输入一个分析。"
|
placeholder="请输入BTC、ETH,仅支持输入一个分析币种"
|
||||||
@keydown="handleKeydown"
|
@keydown="handleKeydown"
|
||||||
:disabled="isAnalyzing"
|
:disabled="isAnalyzing"
|
||||||
/>
|
/>
|
||||||
@ -239,18 +245,6 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => {
|
|||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</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
|
<button
|
||||||
class="analyze-button"
|
class="analyze-button"
|
||||||
@click="handleAnalysis"
|
@click="handleAnalysis"
|
||||||
@ -267,7 +261,7 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => {
|
|||||||
<div class="common-analysis-section">
|
<div class="common-analysis-section">
|
||||||
<div class="common-analysis-container">
|
<div class="common-analysis-container">
|
||||||
<div class="section-header">
|
<div class="section-header">
|
||||||
<span class="section-title">快速分析</span>
|
<span class="section-title">点击直接快速分析币种</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="common-analysis-list">
|
<div class="common-analysis-list">
|
||||||
<button
|
<button
|
||||||
@ -290,9 +284,6 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => {
|
|||||||
<div class="target-info">
|
<div class="target-info">
|
||||||
<span class="label">正在分析:</span>
|
<span class="label">正在分析:</span>
|
||||||
<span class="value">{{ cryptoCode.toUpperCase() }}</span>
|
<span class="value">{{ cryptoCode.toUpperCase() }}</span>
|
||||||
<span class="timeframe">{{
|
|
||||||
timeframes.find((t) => t.value === selectedTimeframe)?.label
|
|
||||||
}}</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="action-buttons" v-if="!isAnalyzing">
|
<div class="action-buttons" v-if="!isAnalyzing">
|
||||||
<button class="action-button" @click="resetView">
|
<button class="action-button" @click="resetView">
|
||||||
@ -340,7 +331,12 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => {
|
|||||||
ref="analysisContainer"
|
ref="analysisContainer"
|
||||||
:class="{ 'fade-in': analysisContent }"
|
: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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -348,8 +344,15 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<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;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -700,11 +703,13 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.analysis-content {
|
.analysis-content {
|
||||||
line-height: 2;
|
font-size: 1rem;
|
||||||
|
line-height: 1.6;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
color: var(--color-text-primary);
|
color: var(--color-text-primary);
|
||||||
padding: 1.5rem 2rem;
|
padding: 1.5rem 2rem;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
.analysis-content :deep(h1),
|
.analysis-content :deep(h1),
|
||||||
@ -804,14 +809,21 @@ const handleCommonAnalysis = (item: { code: string; timeframe: string }) => {
|
|||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.error-message) {
|
.error-message {
|
||||||
margin: 1rem 0;
|
color: #ff3333;
|
||||||
padding: 0.75rem 1rem;
|
font-weight: 500;
|
||||||
background-color: rgba(255, 0, 0, 0.05);
|
padding: 1rem;
|
||||||
border: 1px solid rgba(255, 0, 0, 0.1);
|
background-color: rgba(255, 51, 51, 0.08);
|
||||||
|
border: 1px solid rgba(255, 51, 51, 0.2);
|
||||||
border-radius: 0.5rem;
|
border-radius: 0.5rem;
|
||||||
color: #ff4444;
|
margin: 1rem;
|
||||||
font-size: 0.95rem;
|
text-align: center;
|
||||||
|
font-size: 1rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message::before {
|
||||||
|
content: '⚠️ ';
|
||||||
}
|
}
|
||||||
|
|
||||||
.analysis-content::-webkit-scrollbar {
|
.analysis-content::-webkit-scrollbar {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user