Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
水玉婷
ai-wechat
Commits
4fbf0b04
Commit
4fbf0b04
authored
Mar 24, 2026
by
水玉婷
Browse files
feat:sse消息分片
parent
a119005a
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/views/components/AiChat.vue
View file @
4fbf0b04
...
@@ -583,22 +583,45 @@ const processSSEStreamResponse = async (stream: ReadableStream | null) => {
...
@@ -583,22 +583,45 @@ const processSSEStreamResponse = async (stream: ReadableStream | null) => {
const
decoder
=
new
TextDecoder
();
const
decoder
=
new
TextDecoder
();
try
{
try
{
let
fullData
=
''
;
let
isCollecting
=
false
;
while
(
true
)
{
while
(
true
)
{
const
{
done
,
value
}
=
await
reader
.
read
();
const
{
done
,
value
}
=
await
reader
.
read
();
if
(
done
)
break
;
if
(
done
)
break
;
const
chunk
=
decoder
.
decode
(
value
,
{
stream
:
true
});
const
chunk
=
decoder
.
decode
(
value
,
{
stream
:
true
});
const
lines
=
chunk
.
split
(
'
\n
'
);
const
lines
=
chunk
.
split
(
'
\n
'
);
for
(
const
line
of
lines
)
{
for
(
const
line
of
lines
)
{
if
(
line
.
startsWith
(
'
data:
'
))
{
if
(
line
.
startsWith
(
'
data:
'
))
{
try
{
try
{
const
data
=
JSON
.
parse
(
line
.
slice
(
6
));
// 移除'data: '前缀
if
(
line
.
startsWith
(
'
data: 0
'
))
{
// 使用现有的SSE消息处理函数
isCollecting
=
true
;
handleSSEMessage
(
data
);
fullData
+=
line
.
slice
(
7
);
// 移除 'data:��缀
}
else
if
(
line
.
startsWith
(
'
data: 1
'
))
{
if
(
isCollecting
)
{
// 遇到1的停止,整合成完整JSON
fullData
+=
line
.
slice
(
7
);
// 移除 'data: 1 ' 前缀
// 确保有数据才处理
if
(
fullData
.
trim
())
{
const
data
=
JSON
.
parse
(
fullData
);
handleSSEMessage
(
data
);
}
isCollecting
=
false
;
fullData
=
''
;
}
else
{
fullData
=
line
.
slice
(
7
)
const
data
=
JSON
.
parse
(
fullData
);
handleSSEMessage
(
data
);
isCollecting
=
false
;
fullData
=
''
;
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
loading
.
value
=
false
;
loading
.
value
=
false
;
console
.
warn
(
'
解析SSE数据失败:
'
);
isCollecting
=
false
;
fullData
=
''
;
console
.
warn
(
'
解析SSE数据失败:
'
,
e
);
}
}
}
}
}
}
...
...
src/views/components/TableComponent.vue
View file @
4fbf0b04
...
@@ -287,6 +287,18 @@ const renderCellContent = (header: string, value: any, record: any) => {
...
@@ -287,6 +287,18 @@ const renderCellContent = (header: string, value: any, record: any) => {
return
'
↓
'
;
return
'
↓
'
;
}
}
}
}
// 如果是数字列,进行格式化
if
(
isNumericColumn
(
header
))
{
// 判断value是否为数字(字符串)
if
(
!
isNaN
(
Number
(
value
)))
{
// 格式化数字(字符串)
return
formatNumber
(
Number
(
value
));
}
else
{
// 非数字,直接返回原始值
return
value
;
}
}
return
value
;
return
value
;
};
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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