mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-07-03 05:21:41 +08:00
新增服务状态检测与轮询功能,优化重启流程,增加超时提示信息
This commit is contained in:
@@ -56,6 +56,49 @@ function logout() {
|
|||||||
router.push('/login')
|
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() {
|
async function restart() {
|
||||||
// 调用API重启
|
// 调用API重启
|
||||||
@@ -73,10 +116,11 @@ async function restart() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
// 等待10秒后注销
|
|
||||||
|
// 重启请求成功,开始轮询检测服务状态
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
logout()
|
pollServiceStatus()
|
||||||
}, 10000)
|
}, 5000)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示重启确认对话框
|
// 显示重启确认对话框
|
||||||
|
|||||||
@@ -124,6 +124,8 @@ export default {
|
|||||||
restarting: 'Restarting...',
|
restarting: 'Restarting...',
|
||||||
confirmRestart: 'Confirm restart system?',
|
confirmRestart: 'Confirm restart system?',
|
||||||
restartTip: 'After restart, you will be logged out and need to log in again.',
|
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: {
|
login: {
|
||||||
wallpapers: 'Wallpapers',
|
wallpapers: 'Wallpapers',
|
||||||
|
|||||||
@@ -124,6 +124,8 @@ export default {
|
|||||||
restarting: '正在重启...',
|
restarting: '正在重启...',
|
||||||
confirmRestart: '确认重启系统吗?',
|
confirmRestart: '确认重启系统吗?',
|
||||||
restartTip: '重启后,您将被注销并需要重新登录。',
|
restartTip: '重启后,您将被注销并需要重新登录。',
|
||||||
|
restartTimeout: '重启超时,系统可能需要更长时间恢复,请稍后手动刷新页面',
|
||||||
|
restartFailed: '重启失败,请检查系统状态',
|
||||||
},
|
},
|
||||||
login: {
|
login: {
|
||||||
wallpapers: '壁纸',
|
wallpapers: '壁纸',
|
||||||
|
|||||||
@@ -125,6 +125,8 @@ export default {
|
|||||||
restarting: '正在重啟...',
|
restarting: '正在重啟...',
|
||||||
confirmRestart: '確認重啟系統嗎?',
|
confirmRestart: '確認重啟系統嗎?',
|
||||||
restartTip: '重啟後,您將被註銷並需要重新登錄。',
|
restartTip: '重啟後,您將被註銷並需要重新登錄。',
|
||||||
|
restartTimeout: '重啟超時,系統可能需要更長時間恢復,請稍後手動刷新頁面',
|
||||||
|
restartFailed: '重啟失敗,請檢查系統狀態',
|
||||||
},
|
},
|
||||||
login: {
|
login: {
|
||||||
wallpapers: '壁紙',
|
wallpapers: '壁紙',
|
||||||
|
|||||||
Reference in New Issue
Block a user