新增服务状态检测与轮询功能,优化重启流程,增加超时提示信息

This commit is contained in:
jxxghp
2025-06-09 16:21:31 +08:00
parent bff8c0f86b
commit a2c176bdee
4 changed files with 53 additions and 3 deletions

View File

@@ -56,6 +56,49 @@ function logout() {
router.push('/login')
}
// 检测服务状态
async function checkServiceStatus(): Promise<boolean> {
try {
const result: { [key: string]: any } = await api.get('system/env', { timeout: 3000 })
return result?.success === true
} catch (error) {
return false
}
}
// 轮询检测服务恢复状态
async function pollServiceStatus() {
// 最大重试次数约3分钟
const maxRetries = 60
let retryCount = 0
const poll = async () => {
retryCount++
const isServiceUp = await checkServiceStatus()
if (isServiceUp) {
// 服务已恢复,执行注销
setTimeout(() => {
logout()
}, 1000)
return
}
if (retryCount >= maxRetries) {
// 超时未恢复,隐藏进度框并提示用户
progressDialog.value = false
$toast.error(t('app.restartTimeout'))
return
}
// 继续轮询每3秒检测一次
setTimeout(poll, 3000)
}
// 开始轮询
poll()
}
// 执行重启操作
async function restart() {
// 调用API重启
@@ -73,10 +116,11 @@ async function restart() {
} catch (error) {
console.error(error)
}
// 等待10秒后注销
// 重启请求成功,开始轮询检测服务状态
setTimeout(() => {
logout()
}, 10000)
pollServiceStatus()
}, 5000)
}
// 显示重启确认对话框

View File

@@ -124,6 +124,8 @@ export default {
restarting: 'Restarting...',
confirmRestart: 'Confirm restart system?',
restartTip: 'After restart, you will be logged out and need to log in again.',
restartTimeout: 'Restart timeout, the system may need more time to recover, please refresh the page manually later',
restartFailed: 'Restart failed, please check system status',
},
login: {
wallpapers: 'Wallpapers',

View File

@@ -124,6 +124,8 @@ export default {
restarting: '正在重启...',
confirmRestart: '确认重启系统吗?',
restartTip: '重启后,您将被注销并需要重新登录。',
restartTimeout: '重启超时,系统可能需要更长时间恢复,请稍后手动刷新页面',
restartFailed: '重启失败,请检查系统状态',
},
login: {
wallpapers: '壁纸',

View File

@@ -125,6 +125,8 @@ export default {
restarting: '正在重啟...',
confirmRestart: '確認重啟系統嗎?',
restartTip: '重啟後,您將被註銷並需要重新登錄。',
restartTimeout: '重啟超時,系統可能需要更長時間恢復,請稍後手動刷新頁面',
restartFailed: '重啟失敗,請檢查系統狀態',
},
login: {
wallpapers: '壁紙',