diff --git a/src/layouts/components/UserProfile.vue b/src/layouts/components/UserProfile.vue index 44742065..417eefbe 100644 --- a/src/layouts/components/UserProfile.vue +++ b/src/layouts/components/UserProfile.vue @@ -56,6 +56,49 @@ function logout() { router.push('/login') } +// 检测服务状态 +async function checkServiceStatus(): Promise { + 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) } // 显示重启确认对话框 diff --git a/src/locales/en-US.ts b/src/locales/en-US.ts index 8b5f5fd8..7bf69a44 100644 --- a/src/locales/en-US.ts +++ b/src/locales/en-US.ts @@ -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', diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 68d501b1..b6e5db11 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -124,6 +124,8 @@ export default { restarting: '正在重启...', confirmRestart: '确认重启系统吗?', restartTip: '重启后,您将被注销并需要重新登录。', + restartTimeout: '重启超时,系统可能需要更长时间恢复,请稍后手动刷新页面', + restartFailed: '重启失败,请检查系统状态', }, login: { wallpapers: '壁纸', diff --git a/src/locales/zh-TW.ts b/src/locales/zh-TW.ts index e61023dc..6a0373f4 100644 --- a/src/locales/zh-TW.ts +++ b/src/locales/zh-TW.ts @@ -125,6 +125,8 @@ export default { restarting: '正在重啟...', confirmRestart: '確認重啟系統嗎?', restartTip: '重啟後,您將被註銷並需要重新登錄。', + restartTimeout: '重啟超時,系統可能需要更長時間恢復,請稍後手動刷新頁面', + restartFailed: '重啟失敗,請檢查系統狀態', }, login: { wallpapers: '壁紙',