mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-22 17:38:57 +08:00
many update
This commit is contained in:
@@ -13,15 +13,14 @@ export default {
|
||||
token: null,
|
||||
firstConnect: true,
|
||||
connected: false,
|
||||
connectCount: 0,
|
||||
},
|
||||
allowLoginDialog: false, // Allowed to show login dialog, but "loggedIn" have to be true too. This exists because prevent the login dialog show 0.1s in first before the socket server auth-ed.
|
||||
loggedIn: false,
|
||||
monitorList: [
|
||||
|
||||
],
|
||||
importantHeartbeatList: [
|
||||
|
||||
],
|
||||
heartbeatList: {
|
||||
|
||||
},
|
||||
@@ -38,7 +37,6 @@ export default {
|
||||
});
|
||||
|
||||
socket.on('heartbeat', (data) => {
|
||||
|
||||
if (! (data.monitorID in this.heartbeatList)) {
|
||||
this.heartbeatList[data.monitorID] = [];
|
||||
}
|
||||
@@ -46,14 +44,30 @@ export default {
|
||||
this.heartbeatList[data.monitorID].push(data)
|
||||
});
|
||||
|
||||
socket.on('heartbeatList', (monitorID, data) => {
|
||||
if (! (monitorID in this.heartbeatList)) {
|
||||
this.heartbeatList[monitorID] = data;
|
||||
} else {
|
||||
this.heartbeatList[monitorID] = data.concat(this.heartbeatList[monitorID])
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
console.log("disconnect")
|
||||
this.socket.connected = false;
|
||||
});
|
||||
|
||||
socket.on('connect', () => {
|
||||
console.log("connect")
|
||||
this.socket.connectCount++;
|
||||
this.socket.connected = true;
|
||||
this.socket.firstConnect = false;
|
||||
|
||||
// Reset Heartbeat list if it is re-connect
|
||||
if (this.socket.connectCount >= 2) {
|
||||
console.log("reset heartbeat list")
|
||||
this.heartbeatList = {}
|
||||
}
|
||||
|
||||
if (storage.token) {
|
||||
this.loginByToken(storage.token)
|
||||
@@ -61,6 +75,7 @@ export default {
|
||||
this.allowLoginDialog = true;
|
||||
}
|
||||
|
||||
this.socket.firstConnect = false;
|
||||
});
|
||||
|
||||
},
|
||||
@@ -113,10 +128,9 @@ export default {
|
||||
logout() {
|
||||
storage.removeItem("token");
|
||||
this.socket.token = null;
|
||||
this.loggedIn = false;
|
||||
|
||||
socket.emit("logout", () => {
|
||||
toast.success("Logout Successfully")
|
||||
window.location.reload()
|
||||
})
|
||||
},
|
||||
|
||||
@@ -142,6 +156,26 @@ export default {
|
||||
return result;
|
||||
},
|
||||
|
||||
// TODO: handle history + real time
|
||||
importantHeartbeatList() {
|
||||
let result = {}
|
||||
|
||||
for (let monitorID in this.heartbeatList) {
|
||||
result[monitorID] = [];
|
||||
|
||||
let index = this.heartbeatList[monitorID].length - 1;
|
||||
let list = this.heartbeatList[monitorID];
|
||||
|
||||
for (let heartbeat of list) {
|
||||
if (heartbeat.important) {
|
||||
result[monitorID].push(heartbeat)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
statusList() {
|
||||
let result = {}
|
||||
|
||||
|
Reference in New Issue
Block a user