mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 23:56:42 +08:00
优化重启流程,增加重启状态管理和轮询清理逻辑
This commit is contained in:
@@ -45,11 +45,22 @@ const showLanguageMenu = ref(false)
|
|||||||
// 自定义CSS
|
// 自定义CSS
|
||||||
const customCSS = ref('')
|
const customCSS = ref('')
|
||||||
|
|
||||||
|
// 重启轮询控制标识
|
||||||
|
const restartPollingId = ref<number | null>(null)
|
||||||
|
const isRestarting = ref(false)
|
||||||
|
|
||||||
// 确认框
|
// 确认框
|
||||||
const { createConfirm } = useConfirm()
|
const { createConfirm } = useConfirm()
|
||||||
|
|
||||||
// 执行注销操作
|
// 执行注销操作
|
||||||
function logout() {
|
function logout() {
|
||||||
|
// 清理重启相关状态
|
||||||
|
isRestarting.value = false
|
||||||
|
if (restartPollingId.value) {
|
||||||
|
clearTimeout(restartPollingId.value)
|
||||||
|
restartPollingId.value = null
|
||||||
|
}
|
||||||
|
|
||||||
// 清除登录状态信息
|
// 清除登录状态信息
|
||||||
authStore.logout()
|
authStore.logout()
|
||||||
// 重定向到登录页面或其他适当的页面
|
// 重定向到登录页面或其他适当的页面
|
||||||
@@ -68,16 +79,31 @@ async function checkServiceStatus(): Promise<boolean> {
|
|||||||
|
|
||||||
// 轮询检测服务恢复状态
|
// 轮询检测服务恢复状态
|
||||||
async function pollServiceStatus() {
|
async function pollServiceStatus() {
|
||||||
|
// 如果已经有轮询在运行,先清除
|
||||||
|
if (restartPollingId.value) {
|
||||||
|
clearTimeout(restartPollingId.value)
|
||||||
|
restartPollingId.value = null
|
||||||
|
}
|
||||||
|
|
||||||
// 最大重试次数(约3分钟)
|
// 最大重试次数(约3分钟)
|
||||||
const maxRetries = 60
|
const maxRetries = 60
|
||||||
let retryCount = 0
|
let retryCount = 0
|
||||||
|
|
||||||
const poll = async () => {
|
const poll = async () => {
|
||||||
|
// 如果不在重启状态,停止轮询
|
||||||
|
if (!isRestarting.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
retryCount++
|
retryCount++
|
||||||
const isServiceUp = await checkServiceStatus()
|
const isServiceUp = await checkServiceStatus()
|
||||||
|
|
||||||
if (isServiceUp) {
|
if (isServiceUp) {
|
||||||
// 服务已恢复,执行注销
|
// 服务已恢复,清理状态并执行注销
|
||||||
|
isRestarting.value = false
|
||||||
|
progressDialog.value = false
|
||||||
|
restartPollingId.value = null
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
logout()
|
logout()
|
||||||
}, 1000)
|
}, 1000)
|
||||||
@@ -85,14 +111,16 @@ async function pollServiceStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (retryCount >= maxRetries) {
|
if (retryCount >= maxRetries) {
|
||||||
// 超时未恢复,隐藏进度框并提示用户
|
// 超时未恢复,清理状态并提示用户
|
||||||
|
isRestarting.value = false
|
||||||
progressDialog.value = false
|
progressDialog.value = false
|
||||||
|
restartPollingId.value = null
|
||||||
$toast.error(t('app.restartTimeout'))
|
$toast.error(t('app.restartTimeout'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 继续轮询,每3秒检测一次
|
// 继续轮询,每3秒检测一次
|
||||||
setTimeout(poll, 3000)
|
restartPollingId.value = setTimeout(poll, 3000) as unknown as number
|
||||||
}
|
}
|
||||||
|
|
||||||
// 开始轮询
|
// 开始轮询
|
||||||
@@ -101,20 +129,27 @@ async function pollServiceStatus() {
|
|||||||
|
|
||||||
// 执行重启操作
|
// 执行重启操作
|
||||||
async function restart() {
|
async function restart() {
|
||||||
|
// 设置重启状态
|
||||||
|
isRestarting.value = true
|
||||||
|
|
||||||
// 调用API重启
|
// 调用API重启
|
||||||
try {
|
try {
|
||||||
// 显示等待框
|
// 显示等待框
|
||||||
progressDialog.value = true
|
progressDialog.value = true
|
||||||
const result: { [key: string]: any } = await api.get('system/restart')
|
const result: { [key: string]: any } = await api.get('system/restart')
|
||||||
if (!result?.success) {
|
if (!result?.success) {
|
||||||
// 隐藏等待框
|
// 重启失败,清理状态
|
||||||
|
isRestarting.value = false
|
||||||
progressDialog.value = false
|
progressDialog.value = false
|
||||||
// 重启不成功
|
|
||||||
$toast.error(result.message)
|
$toast.error(result.message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
// 重启失败,清理状态
|
||||||
|
isRestarting.value = false
|
||||||
|
progressDialog.value = false
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重启请求成功,开始轮询检测服务状态
|
// 重启请求成功,开始轮询检测服务状态
|
||||||
@@ -303,6 +338,16 @@ const getThemeIcon = computed(() => {
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getCustomCSS()
|
getCustomCSS()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 组件卸载时清理轮询
|
||||||
|
onUnmounted(() => {
|
||||||
|
// 清理重启轮询
|
||||||
|
if (restartPollingId.value) {
|
||||||
|
clearTimeout(restartPollingId.value)
|
||||||
|
restartPollingId.value = null
|
||||||
|
}
|
||||||
|
isRestarting.value = false
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
Reference in New Issue
Block a user