mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-07 00:36:41 +08:00
feat(App): 添加心跳机制通过后端刷新资源访问令牌
This commit is contained in:
+34
@@ -38,6 +38,9 @@ const backgroundImages = ref<string[]>([])
|
|||||||
const activeImageIndex = ref(0)
|
const activeImageIndex = ref(0)
|
||||||
const isTransparentTheme = computed(() => globalTheme.name.value === 'transparent')
|
const isTransparentTheme = computed(() => globalTheme.name.value === 'transparent')
|
||||||
|
|
||||||
|
// 心跳检测
|
||||||
|
let heartbeatInterval: number | null = null
|
||||||
|
|
||||||
// ApexCharts 全局配置
|
// ApexCharts 全局配置
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
@@ -45,6 +48,33 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 启动心跳
|
||||||
|
const startHeartbeat = () => {
|
||||||
|
// 如果已经有心跳,则先停止
|
||||||
|
if (heartbeatInterval) {
|
||||||
|
stopHeartbeat()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始心跳任务
|
||||||
|
heartbeatInterval = window.setInterval(async () => {
|
||||||
|
try {
|
||||||
|
if (isLogin.value) {
|
||||||
|
await api.get('dashboard/cpu')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Heartbeat request failed:', error)
|
||||||
|
}
|
||||||
|
}, 5 * 60 * 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 停止心跳
|
||||||
|
const stopHeartbeat = () => {
|
||||||
|
if (heartbeatInterval) {
|
||||||
|
window.clearInterval(heartbeatInterval)
|
||||||
|
heartbeatInterval = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 配置 ApexCharts 全局选项
|
// 配置 ApexCharts 全局选项
|
||||||
function configureApexCharts() {
|
function configureApexCharts() {
|
||||||
if (typeof window !== 'undefined' && window.Apex) {
|
if (typeof window !== 'undefined' && window.Apex) {
|
||||||
@@ -234,11 +264,15 @@ onMounted(async () => {
|
|||||||
ensureRenderComplete(() => {
|
ensureRenderComplete(() => {
|
||||||
nextTick(removeLoadingWithStateCheck)
|
nextTick(removeLoadingWithStateCheck)
|
||||||
})
|
})
|
||||||
|
// 启动心跳
|
||||||
|
startHeartbeat()
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
// 清除背景轮换定时器
|
// 清除背景轮换定时器
|
||||||
removeBackgroundTimer('background-rotation')
|
removeBackgroundTimer('background-rotation')
|
||||||
|
// 停止心跳
|
||||||
|
stopHeartbeat()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user