fix log read

This commit is contained in:
bwcx_jzy 2023-01-29 13:21:46 +08:00
parent 9a7be887d6
commit cd9295da3e
No known key found for this signature in database
GPG Key ID: 5E48E9372088B9E5
2 changed files with 33 additions and 26 deletions

View File

@ -30,15 +30,15 @@ export function editLogRead(params) {
} }
export function updateCache(params) { export function updateCache(params) {
return axios({ return axios({
url: "/log-read/update-cache.json", url: "/log-read/update-cache.json",
method: "post", method: "post",
data: params, data: params,
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
} }
/** /**
* 删除日志阅读 * 删除日志阅读

View File

@ -215,6 +215,16 @@ export default {
this.activeTagKey = this.temp.cacheData.useNodeId + "," + this.temp.cacheData.useProjectId; this.activeTagKey = this.temp.cacheData.useNodeId + "," + this.temp.cacheData.useProjectId;
// console.log(cacheData); // console.log(cacheData);
}, },
beforeDestroy() {
Object.keys(this.socketCache).forEach((item) => {
clearInterval(this.socketCache[item].heart);
});
},
destroyed() {
Object.keys(this.socketCache).forEach((item) => {
clearInterval(this.socketCache[item].heart);
});
},
methods: { methods: {
initWebSocket(id, url) { initWebSocket(id, url) {
let socket; let socket;
@ -228,7 +238,7 @@ export default {
key: "log-read-error", key: "log-read-error",
message: "web socket 错误,请检查是否开启 ws 代理", message: "web socket 错误,请检查是否开启 ws 代理",
}); });
clearInterval(this.socketCache[id]); clearInterval(this.socketCache[id].heart);
}; };
socket.onclose = (err) => { socket.onclose = (err) => {
//onclose //onclose
@ -237,10 +247,10 @@ export default {
key: "log-read-close", key: "log-read-close",
message: "会话已经关闭", message: "会话已经关闭",
}); });
clearInterval(this.socketCache[id]); clearInterval(this.socketCache[id].heart);
}; };
socket.onmessage = (msg) => { socket.onmessage = (msg) => {
// console.log(msg); //console.log(msg);
this.$refs[id][0].appendLine(msg.data); this.$refs[id][0].appendLine(msg.data);
clearInterval(this.socketCache[id].heart); clearInterval(this.socketCache[id].heart);
@ -325,7 +335,7 @@ export default {
this.sendSearchLog(); this.sendSearchLog();
} else { } else {
// //
this.$message.error("当前文件不可读"); this.$message.error("当前文件不可读,需要配置可读文件白名单");
} }
} }
}, },
@ -355,9 +365,8 @@ export default {
// //
setTimeout(() => { setTimeout(() => {
const node = this.treeList[0]; this.tempNode = this.treeList[0];
this.tempNode = node; //this.expandKeys = [key];
this.expandKeys = [key];
//this.loadFileList(); //this.loadFileList();
}, 1000); }, 1000);
}, },
@ -379,14 +388,13 @@ export default {
// //
getFileList(params).then((res) => { getFileList(params).then((res) => {
if (res.code === 200) { if (res.code === 200) {
const treeData = res.data.map((ele) => { data.children = res.data.map((ele) => {
ele.isLeaf = !ele.isDirectory; ele.isLeaf = !ele.isDirectory;
ele.key = ele.filename + "-" + new Date().getTime(); ele.key = ele.filename + "-" + new Date().getTime();
//ele.disabled = ele.textFileEdit; //ele.disabled = ele.textFileEdit;
return ele; return ele;
}); });
data.children = treeData;
this.treeList = [...this.treeList]; this.treeList = [...this.treeList];
resolve(); resolve();
@ -401,12 +409,13 @@ export default {
}, },
sendSearchLog() { sendSearchLog() {
if (this.temp?.cacheData?.logFile) { if (this.temp?.cacheData?.logFile) {
Object.keys(this.socketCache).forEach((item) => { // loading
this.$refs[item][0].clearLogCache(); updateCache(Object.assign({}, this.temp.cacheData, { id: this.temp.id })).then(() => {
this.sendMsg(item, "showlog", this.temp.cacheData); Object.keys(this.socketCache).forEach((item) => {
this.$refs[item][0].clearLogCache();
this.sendMsg(item, "showlog", this.temp.cacheData);
});
}); });
//
updateCache(Object.assign({}, this.temp.cacheData, { id: this.temp.id })).then();
} }
// //
}, },
@ -434,9 +443,7 @@ export default {
.log-filter { .log-filter {
/* margin-top: -22px; */ /* margin-top: -22px; */
/* margin-bottom: 10px; */ /* margin-bottom: 10px; */
padding: 0 10px; padding: 0 10px 10px;
padding-top: 0;
padding-bottom: 10px;
line-height: 0; line-height: 0;
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;
} }