修复AI分析SSE流断开:中间件透传Flusher、DB Key生效、错误提示不覆盖

This commit is contained in:
fish
2026-05-10 17:11:51 +08:00
parent 1094e82e88
commit 4cdc542291
4 changed files with 35 additions and 6 deletions

View File

@@ -31,7 +31,7 @@ async function askAI() {
aiContent.value = ''
aiError.value = ''
const url = `/api/v1/ai/analyze?ts_code=${encodeURIComponent(score.value.ts_code)}&trade_date=${encodeURIComponent(score.value.trade_date)}`
const url = `/api/ai/analyze?ts_code=${encodeURIComponent(score.value.ts_code)}&trade_date=${encodeURIComponent(score.value.trade_date)}`
es = new EventSource(url)
es.addEventListener('token', (e) => {
aiContent.value += e.data
@@ -44,7 +44,7 @@ async function askAI() {
closeAI()
})
es.onerror = () => {
if (!aiContent.value) aiError.value = '连接中断'
if (!aiContent.value && !aiError.value) aiError.value = '连接中断'
closeAI()
}
}
@@ -267,7 +267,7 @@ const quadrantLabel = (q: string) => {
🤖 AI 分析当前打分
</el-button>
</div>
<div v-if="aiLoading || aiContent" class="ai-card">
<div v-if="aiLoading || aiContent || aiError" class="ai-card">
<div class="ai-header">
<span>🤖 AI 分析</span>
<el-button text size="small" @click="closeAI" v-if="aiLoading">取消</el-button>