Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-middle-front
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xingmin
yd-middle-front
Commits
1c500b13
Commit
1c500b13
authored
Apr 07, 2026
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
push
parent
e52639b8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
5 deletions
+35
-5
src/api/ai/ai.js
+22
-2
src/views/ai/index.vue
+13
-3
No files found.
src/api/ai/ai.js
View file @
1c500b13
...
@@ -14,6 +14,7 @@ export function randList(data) {
...
@@ -14,6 +14,7 @@ export function randList(data) {
/**
/**
* 查询输出流信息(流式响应)
* 查询输出流信息(流式响应)
* 增强错误处理:当HTTP状态非2xx时,解析错误响应体并抛出包含code属性的错误
*/
*/
export
function
getStream
(
question
,
timeout
=
300000
)
{
export
function
getStream
(
question
,
timeout
=
300000
)
{
const
userStore
=
useUserStore
()
const
userStore
=
useUserStore
()
...
@@ -38,6 +39,27 @@ export function getStream(question, timeout = 300000) {
...
@@ -38,6 +39,27 @@ export function getStream(question, timeout = 300000) {
method
:
'GET'
,
method
:
'GET'
,
headers
,
headers
,
signal
:
controller
.
signal
signal
:
controller
.
signal
}).
then
(
async
(
response
)
=>
{
clearTimeout
(
timeoutId
)
if
(
!
response
.
ok
)
{
// 尝试解析错误响应体
let
errorCode
=
null
let
errorMessage
=
response
.
statusText
try
{
const
errorBody
=
await
response
.
json
()
if
(
errorBody
&&
errorBody
.
code
!==
undefined
)
{
errorCode
=
errorBody
.
code
errorMessage
=
errorBody
.
msg
||
errorBody
.
message
||
errorMessage
}
}
catch
(
e
)
{
// 无法解析JSON,使用默认错误信息
}
const
error
=
new
Error
(
errorMessage
)
error
.
code
=
errorCode
error
.
status
=
response
.
status
throw
error
}
return
response
}).
finally
(()
=>
{
}).
finally
(()
=>
{
clearTimeout
(
timeoutId
)
clearTimeout
(
timeoutId
)
})
})
...
@@ -49,10 +71,8 @@ export function getStream(question, timeout = 300000) {
...
@@ -49,10 +71,8 @@ export function getStream(question, timeout = 300000) {
export
async
function
getServiceCardList
()
{
export
async
function
getServiceCardList
()
{
const
userStore
=
useUserStore
()
const
userStore
=
useUserStore
()
const
token
=
getToken
()
const
token
=
getToken
()
// 根据实际 store 获取 userId,如果不存在则使用默认值(示例中为 '30')
const
userId
=
userStore
.
userInfo
?.
userId
||
userStore
.
userId
||
'30'
const
userId
=
userStore
.
userInfo
?.
userId
||
userStore
.
userId
||
'30'
// 处理 token 格式(去掉 "Bearer " 前缀)
let
cleanToken
=
token
let
cleanToken
=
token
if
(
token
&&
token
.
startsWith
(
'Bearer '
))
{
if
(
token
&&
token
.
startsWith
(
'Bearer '
))
{
cleanToken
=
token
.
slice
(
7
)
cleanToken
=
token
.
slice
(
7
)
...
...
src/views/ai/index.vue
View file @
1c500b13
...
@@ -373,9 +373,19 @@ export default {
...
@@ -373,9 +373,19 @@ export default {
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
'流式请求失败:'
,
error
)
console
.
error
(
'流式请求失败:'
,
error
)
const
errorMsg
=
error
.
name
===
'AbortError'
?
'请求超时,请稍后重试'
:
`错误:
${
error
.
message
}
`
this
.
messages
[
assistantMessageIndex
].
content
=
`❌
${
errorMsg
}
`
// 处理通知类型敏感词错误码 50002
this
.
scrollToBottom
()
if
(
error
.
code
===
50002
)
{
// 移除刚添加的空助手消息
this
.
messages
.
pop
()
// 调用产品列表展示
await
this
.
fetchAndShowProducts
(
userQuestion
)
}
else
{
// 其他错误正常显示错误消息
const
errorMsg
=
error
.
name
===
'AbortError'
?
'请求超时,请稍后重试'
:
`错误:
${
error
.
message
}
`
this
.
messages
[
assistantMessageIndex
].
content
=
`❌
${
errorMsg
}
`
this
.
scrollToBottom
()
}
}
finally
{
}
finally
{
this
.
isLoading
=
false
this
.
isLoading
=
false
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment