mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-08-28 03:27:54 +08:00
fix: ensure clear cache reloads page
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { formatDateDifference } from '@/@core/utils/formatters'
|
import { formatDateDifference } from '@/@core/utils/formatters'
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import { clearCachesAndServiceWorker, reloadWithTimestamp } from '@/composables/useVersionChecker'
|
import { clearCacheAndReload } from '@/composables/useVersionChecker'
|
||||||
import MarkdownIt from 'markdown-it'
|
import MarkdownIt from 'markdown-it'
|
||||||
import mdLinkAttributes from 'markdown-it-link-attributes'
|
import mdLinkAttributes from 'markdown-it-link-attributes'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
@@ -138,9 +138,7 @@ function releaseTime(releaseDate: string) {
|
|||||||
|
|
||||||
// 强制清除缓存
|
// 强制清除缓存
|
||||||
async function clearCache() {
|
async function clearCache() {
|
||||||
await clearCachesAndServiceWorker()
|
await clearCacheAndReload()
|
||||||
// 刷新页面,添加时间戳参数以强制更新
|
|
||||||
reloadWithTimestamp()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
@@ -51,9 +51,25 @@ export const clearCachesAndServiceWorker = async (): Promise<void> => {
|
|||||||
/**
|
/**
|
||||||
* 清除缓存并刷新
|
* 清除缓存并刷新
|
||||||
*/
|
*/
|
||||||
const clearCacheAndReload = async (): Promise<void> => {
|
export const clearCacheAndReload = async (): Promise<void> => {
|
||||||
await clearCachesAndServiceWorker()
|
let isReloading = false
|
||||||
reloadWithTimestamp()
|
const reload = () => {
|
||||||
|
if (isReloading) return
|
||||||
|
isReloading = true
|
||||||
|
reloadWithTimestamp()
|
||||||
|
}
|
||||||
|
|
||||||
|
const reloadTimer = window.setTimeout(reload, 3000)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await Promise.race([
|
||||||
|
clearCachesAndServiceWorker(),
|
||||||
|
new Promise(resolve => window.setTimeout(resolve, 2500)),
|
||||||
|
])
|
||||||
|
} finally {
|
||||||
|
window.clearTimeout(reloadTimer)
|
||||||
|
reload()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user