mirror of
https://github.com/MeowLynxSea/Uptimeow.git
synced 2025-07-09 10:54:38 +00:00
修复了由于前端传入的时间格式错误而导致部分时间内无法正常获取数据的错误
This commit is contained in:
parent
a442f8850f
commit
20a671c8b7
@ -189,6 +189,36 @@
|
|||||||
|
|
||||||
<script src="/js/meowdream-utils.js"></script>
|
<script src="/js/meowdream-utils.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
function formatDateTime(date, format) {
|
||||||
|
const o = {
|
||||||
|
"M+": date.getMonth() + 1, // 月份
|
||||||
|
"d+": date.getDate(), // 日
|
||||||
|
"h+": date.getHours() % 12 === 0 ? 12 : date.getHours() % 12, // 小时
|
||||||
|
"H+": date.getHours(), // 小时
|
||||||
|
"m+": date.getMinutes(), // 分
|
||||||
|
"s+": date.getSeconds(), // 秒
|
||||||
|
"q+": Math.floor((date.getMonth() + 3) / 3), // 季度
|
||||||
|
S: date.getMilliseconds(), // 毫秒
|
||||||
|
a: date.getHours() < 12 ? "上午" : "下午", // 上午/下午
|
||||||
|
A: date.getHours() < 12 ? "AM" : "PM", // AM/PM
|
||||||
|
};
|
||||||
|
if (/(y+)/.test(format)) {
|
||||||
|
format = format.replace(
|
||||||
|
RegExp.$1,
|
||||||
|
(date.getFullYear() + "").substr(4 - RegExp.$1.length)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (let k in o) {
|
||||||
|
if (new RegExp("(" + k + ")").test(format)) {
|
||||||
|
format = format.replace(
|
||||||
|
RegExp.$1,
|
||||||
|
RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
// 发起请求
|
// 发起请求
|
||||||
fetch('/api?type=server_info')
|
fetch('/api?type=server_info')
|
||||||
@ -224,7 +254,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 记录网页加载完成的时间
|
// 记录网页加载完成的时间
|
||||||
let recordedTime = new Date().toLocaleString();
|
let recordedTime = formatDateTime(new Date(), "yyyy/MM/dd HH:mm:ss");
|
||||||
let tempTime;
|
let tempTime;
|
||||||
var intervalId = null;
|
var intervalId = null;
|
||||||
console.log("网页加载完成,当前时间:" + recordedTime);
|
console.log("网页加载完成,当前时间:" + recordedTime);
|
||||||
@ -233,7 +263,7 @@
|
|||||||
intervalId = setInterval(function() {
|
intervalId = setInterval(function() {
|
||||||
try {
|
try {
|
||||||
console.log("发送定期消息。");
|
console.log("发送定期消息。");
|
||||||
let recordedTime = new Date(new Date().getTime() - 5000).toLocaleString();
|
let recordedTime = formatDateTime(new Date(new Date().getTime() - 5000), "yyyy/MM/dd HH:mm:ss");
|
||||||
// 假设 ws.send 可能会失败,并且会抛出一个错误
|
// 假设 ws.send 可能会失败,并且会抛出一个错误
|
||||||
ws.send("later than " + recordedTime);
|
ws.send("later than " + recordedTime);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -260,7 +290,7 @@
|
|||||||
statusBar.appendChild(newDiv);
|
statusBar.appendChild(newDiv);
|
||||||
}
|
}
|
||||||
ws = new WebSocket("/ws");
|
ws = new WebSocket("/ws");
|
||||||
let recordedTime = new Date(new Date().getTime() - 5000).toLocaleString();
|
let recordedTime = formatDateTime(new Date(new Date().getTime() - 5000), "yyyy/MM/dd HH:mm:ss");
|
||||||
|
|
||||||
ws.onopen = function() {
|
ws.onopen = function() {
|
||||||
// 连接成功时发送消息并更新时间
|
// 连接成功时发送消息并更新时间
|
||||||
@ -272,7 +302,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("WebSocket初始消息发送成功。");
|
console.log("WebSocket初始消息发送成功。");
|
||||||
recordedTime = new Date().toLocaleString();
|
recordedTime = formatDateTime(new Date(), "yyyy/MM/dd HH:mm:ss");
|
||||||
|
|
||||||
updateStatus();
|
updateStatus();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user