修改刷新时间

dev_xd
lj7788 2026-01-05 11:01:42 +08:00
parent c276e09c7f
commit 35376801aa
1 changed files with 82 additions and 3 deletions

View File

@ -6,7 +6,13 @@
<el-card class="box-card" shadow="never"> <el-card class="box-card" shadow="never">
<template #header> <template #header>
<div class="card-header"> <div class="card-header">
<span>LED服务器状态</span> <div class="header-left">
<span>LED服务器状态</span>
<div class="update-info">
<span>更新时间: {{ lastUpdateTime }}</span>
<span class="countdown">将于 {{ formatCountdown(countdownSeconds) }} 后刷新</span>
</div>
</div>
<el-button class="button" type="primary" @click="getServerStatus(true)"></el-button> <el-button class="button" type="primary" @click="getServerStatus(true)"></el-button>
</div> </div>
</template> </template>
@ -205,6 +211,7 @@ const dialogTitle = ref("查看LED屏");
// //
let timer = null; let timer = null;
let countdownTimer = null;
// //
const serverStatus = ref({ const serverStatus = ref({
@ -212,6 +219,10 @@ const serverStatus = ref({
connectedCount: 0 connectedCount: 0
}); });
//
const lastUpdateTime = ref('');
const countdownSeconds = ref(30);
// //
const ids = ref([]); const ids = ref([]);
const single = ref(true); const single = ref(true);
@ -294,7 +305,12 @@ function getServerStatus(showMsg) {
serverStatus.value.isRunning = isRunningMatch ? isRunningMatch[1] === "运行中" : false; serverStatus.value.isRunning = isRunningMatch ? isRunningMatch[1] === "运行中" : false;
serverStatus.value.connectedCount = connectedCountMatch ? parseInt(connectedCountMatch[1]) : 0; serverStatus.value.connectedCount = connectedCountMatch ? parseInt(connectedCountMatch[1]) : 0;
if(showMsg){
//
updateLastUpdateTime();
resetCountdown();
if (showMsg) {
proxy.$modal.msgSuccess("服务器状态已刷新"); proxy.$modal.msgSuccess("服务器状态已刷新");
} }
}).catch(error => { }).catch(error => {
@ -302,6 +318,43 @@ function getServerStatus(showMsg) {
}); });
} }
/** 更新最后更新时间 */
function updateLastUpdateTime() {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
lastUpdateTime.value = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
/** 格式化倒计时 */
function formatCountdown(seconds) {
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
return `${String(mins).padStart(2, '0')}:${String(secs).padStart(2, '0')}`;
}
/** 重置倒计时 */
function resetCountdown() {
countdownSeconds.value = 30;
}
/** 启动倒计时定时器 */
function startCountdown() {
if (countdownTimer) {
clearInterval(countdownTimer);
}
countdownTimer = setInterval(() => {
countdownSeconds.value--;
if (countdownSeconds.value <= 0) {
resetCountdown();
}
}, 1000);
}
/** 查询所有屏幕使用LED控制器接口 */ /** 查询所有屏幕使用LED控制器接口 */
function getAllScreensFromController() { function getAllScreensFromController() {
loading.value = true; loading.value = true;
@ -391,9 +444,12 @@ function submitForm() {
onMounted(() => { onMounted(() => {
getServerStatus(); getServerStatus();
getAllScreensFromController(); getAllScreensFromController();
// 30 // 30
startTimer(); startTimer();
//
startCountdown();
}); });
// //
@ -413,6 +469,10 @@ function stopTimer() {
clearInterval(timer); clearInterval(timer);
timer = null; timer = null;
} }
if (countdownTimer) {
clearInterval(countdownTimer);
countdownTimer = null;
}
} }
// //
@ -432,6 +492,25 @@ onBeforeUnmount(() => {
align-items: center; align-items: center;
} }
.header-left {
display: flex;
flex-direction: column;
gap: 8px;
}
.update-info {
display: flex;
align-items: center;
gap: 15px;
font-size: 12px;
color: #909399;
}
.update-info .countdown {
color: #409EFF;
font-weight: 500;
}
.dialog-footer { .dialog-footer {
text-align: right; text-align: right;
} }