Commit 751a1ced authored by 水玉婷's avatar 水玉婷
Browse files

feat:解决TCP拆包/粘包导致数据不全bug

parent f7e471f6
...@@ -351,21 +351,21 @@ const validateMessageParams = (type: MessageType, params: MessageParams): boolea ...@@ -351,21 +351,21 @@ const validateMessageParams = (type: MessageType, params: MessageParams): boolea
// 统一发送消息函数 // 统一发送消息函数
const sendMessage = async (type: MessageType = 'text', params: MessageParams = {}) => { const sendMessage = async (type: MessageType = 'text', params: MessageParams = {}) => {
//如果消息文本为空且是文本类型,则延迟1秒后模拟折线图消息进行测试 //如果消息文本为空且是文本类型,则延迟1秒后模拟折线图消息进行测试
if (type === 'text' && !messageText.value.trim() && !params.message) { // if (type === 'text' && !messageText.value.trim() && !params.message) {
loading.value = true; // loading.value = true;
console.log('📊 检测到空消息,1秒后发送折线图测试...'); // console.log('📊 检测到空消息,1秒后发送折线图测试...');
// setTimeout(() => { // // setTimeout(() => {
// simulateLineChartMessage(); // // simulateLineChartMessage();
// loading.value = false; // // loading.value = false;
// }, 1000); // // }, 1000);
setTimeout(() => { // setTimeout(() => {
simulateTips(); // simulateTips();
loading.value = false; // loading.value = false;
}, 2000); // }, 2000);
return; // return;
} // }
loading.value = true; loading.value = true;
...@@ -585,11 +585,21 @@ const processSSEStreamResponse = async (stream: ReadableStream | null) => { ...@@ -585,11 +585,21 @@ const processSSEStreamResponse = async (stream: ReadableStream | null) => {
try { try {
let fullData = ''; let fullData = '';
let isCollecting = false; let isCollecting = false;
let raw_data = '';
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'); raw_data += chunk;
//查找最后一个/n/n 拿到最大的完整行数据然后拼接起来
const index = raw_data.lastIndexOf('\n\n');
if(index === -1){
continue;
}
let dataLine = raw_data.slice(0,index);
//截取/n/n后的数据
raw_data = raw_data.slice(index+2, raw_data.length);
const lines = dataLine.split('\n');
for (const line of lines) { for (const line of lines) {
if (line.startsWith('data: ')) { if (line.startsWith('data: ')) {
......
...@@ -291,7 +291,7 @@ const renderCellContent = (header: string, value: any, record: any) => { ...@@ -291,7 +291,7 @@ const renderCellContent = (header: string, value: any, record: any) => {
// 如果是数字列,进行格式化 // 如果是数字列,进行格式化
if (isNumericColumn(header)) { if (isNumericColumn(header)) {
// 判断value是否为数字(字符串) // 判断value是否为数字(字符串)
if (!isNaN(Number(value))) { if (value &&!isNaN(Number(value))) {
// 格式化数字(字符串) // 格式化数字(字符串)
return formatNumber(Number(value)); return formatNumber(Number(value));
} else { } else {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment