|
@@ -57,33 +57,38 @@ const websocketonopen = (res) => {
|
|
|
|
|
|
// Websoket接收消息事件
|
|
|
const websocketonmessage = (res) => {
|
|
|
- console.log('websocket接受消息:',res.data)
|
|
|
- if (res.data.indexOf("{") !== -1) {
|
|
|
-
|
|
|
- } else {
|
|
|
- if (res.data.indexOf("——开始") !== -1) {
|
|
|
- arrobj.value = [] // 清空数据点数组
|
|
|
- }
|
|
|
- if (res.data.indexOf("——成功") !== -1) {
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- if (res.data.indexOf("msg=heartChec") == -1) {
|
|
|
- // 去除空行
|
|
|
- const cleanedLog = res.data
|
|
|
- .split("\n")
|
|
|
- .filter((line) => line.trim() !== "")
|
|
|
- .join("\n")
|
|
|
- logContent.value = logContent.value + "\n" + cleanedLog
|
|
|
- let textarea = document.getElementById("textarea_id")
|
|
|
- textarea.scrollTop = textarea.scrollHeight
|
|
|
+ console.log('websocket接受消息:', res.data)
|
|
|
+
|
|
|
+ const data = res.data.replace(/\r/g, "") // 去掉回车符
|
|
|
+
|
|
|
+ // 判断开始/成功标记
|
|
|
+ if (data.includes("——开始")) {
|
|
|
+ arrobj.value = [] // 清空数据点数组
|
|
|
+ }
|
|
|
+ if (data.includes("——成功")) {
|
|
|
+ // 成功逻辑,如果需要可以在这里处理
|
|
|
+ }
|
|
|
+
|
|
|
+ // 非心跳消息追加日志
|
|
|
+ if (!data.includes("msg=heartChec")) {
|
|
|
+ const cleanedLog = data
|
|
|
+ .split("\n")
|
|
|
+ .filter(line => line.trim() !== "") // 只去掉空行,但保留前后空格
|
|
|
+ .join("\n")
|
|
|
+
|
|
|
+ if (cleanedLog) {
|
|
|
+ // 如果已有日志内容,先加换行
|
|
|
+ logContent.value += (logContent.value ? "\n" : "") + cleanedLog
|
|
|
+
|
|
|
+ // 滚动到底部
|
|
|
+ const textarea = document.getElementById("textarea_id")
|
|
|
+ if (textarea) textarea.scrollTop = textarea.scrollHeight
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+ // 其他通用重置逻辑
|
|
|
reset()
|
|
|
}
|
|
|
-
|
|
|
// Websoket连接错误事件
|
|
|
const websocketonerror = (res) => {
|
|
|
console.log("连接错误", res);
|