mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-07-13 00:11:37 +08:00
feat(aboutDialog): 添加清除缓存按钮
This commit is contained in:
@@ -1,6 +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 } from '@/composables/useVersionChecker'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useDisplay } from 'vuetify'
|
import { useDisplay } from 'vuetify'
|
||||||
|
|
||||||
@@ -120,6 +121,13 @@ function releaseTime(releaseDate: string) {
|
|||||||
return formatDateDifference(releaseDate)
|
return formatDateDifference(releaseDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 强制清除缓存
|
||||||
|
async function cleanCache() {
|
||||||
|
await clearCachesAndServiceWorker()
|
||||||
|
// 刷新页面
|
||||||
|
window.location.reload()
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
querySystemEnv()
|
querySystemEnv()
|
||||||
queryAllRelease()
|
queryAllRelease()
|
||||||
@@ -181,6 +189,17 @@ onMounted(() => {
|
|||||||
<dd class="flex text-sm sm:col-span-2 sm:mt-0">
|
<dd class="flex text-sm sm:col-span-2 sm:mt-0">
|
||||||
<span class="flex-grow flex flex-row items-center truncate">
|
<span class="flex-grow flex flex-row items-center truncate">
|
||||||
<code class="truncate">{{ appVersion }}</code>
|
<code class="truncate">{{ appVersion }}</code>
|
||||||
|
<VBtn
|
||||||
|
size="x-small"
|
||||||
|
variant="tonal"
|
||||||
|
class="ms-2"
|
||||||
|
@click="cleanCache"
|
||||||
|
>
|
||||||
|
<template #prepend>
|
||||||
|
<VIcon icon="mdi-refresh" size="14" />
|
||||||
|
</template>
|
||||||
|
{{ t('setting.about.cleanCache') }}
|
||||||
|
</VBtn>
|
||||||
</span>
|
</span>
|
||||||
</dd>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -14,6 +14,29 @@ const needsUpdate = computed(() => {
|
|||||||
return serverVersion.value !== null && serverVersion.value !== currentVersion.value
|
return serverVersion.value !== null && serverVersion.value !== currentVersion.value
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除所有缓存和 Service Worker
|
||||||
|
*/
|
||||||
|
export const clearCachesAndServiceWorker = async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
// 1. 清除所有缓存
|
||||||
|
if ('caches' in window) {
|
||||||
|
const cacheNames = await caches.keys()
|
||||||
|
await Promise.all(cacheNames.map(name => caches.delete(name)))
|
||||||
|
console.log('[VersionChecker] 已清除所有缓存')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 注销 Service Worker
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
const registrations = await navigator.serviceWorker.getRegistrations()
|
||||||
|
await Promise.all(registrations.map(registration => registration.unregister()))
|
||||||
|
console.log('[VersionChecker] 已注销所有 Service Worker')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[VersionChecker] 清除缓存失败:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 版本检查 Composable
|
* 版本检查 Composable
|
||||||
*
|
*
|
||||||
@@ -25,29 +48,6 @@ const needsUpdate = computed(() => {
|
|||||||
export function useVersionChecker() {
|
export function useVersionChecker() {
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除所有缓存和 Service Worker
|
|
||||||
*/
|
|
||||||
const clearCachesAndServiceWorker = async (): Promise<void> => {
|
|
||||||
try {
|
|
||||||
// 1. 清除所有缓存
|
|
||||||
if ('caches' in window) {
|
|
||||||
const cacheNames = await caches.keys()
|
|
||||||
await Promise.all(cacheNames.map(name => caches.delete(name)))
|
|
||||||
console.log('[VersionChecker] 已清除所有缓存')
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 注销 Service Worker
|
|
||||||
if ('serviceWorker' in navigator) {
|
|
||||||
const registrations = await navigator.serviceWorker.getRegistrations()
|
|
||||||
await Promise.all(registrations.map(registration => registration.unregister()))
|
|
||||||
console.log('[VersionChecker] 已注销所有 Service Worker')
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('[VersionChecker] 清除缓存失败:', error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 显示版本更新通知(带刷新按钮)
|
* 显示版本更新通知(带刷新按钮)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1249,6 +1249,7 @@ export default {
|
|||||||
dataDirectory: '/moviepilot',
|
dataDirectory: '/moviepilot',
|
||||||
expand: 'Expand',
|
expand: 'Expand',
|
||||||
collapse: 'Collapse',
|
collapse: 'Collapse',
|
||||||
|
cleanCache: 'Clear Cache',
|
||||||
},
|
},
|
||||||
system: {
|
system: {
|
||||||
custom: 'Custom',
|
custom: 'Custom',
|
||||||
|
|||||||
@@ -1246,6 +1246,7 @@ export default {
|
|||||||
dataDirectory: '/moviepilot',
|
dataDirectory: '/moviepilot',
|
||||||
expand: '展开',
|
expand: '展开',
|
||||||
collapse: '收起',
|
collapse: '收起',
|
||||||
|
cleanCache: '清除缓存',
|
||||||
},
|
},
|
||||||
system: {
|
system: {
|
||||||
custom: '自定义',
|
custom: '自定义',
|
||||||
|
|||||||
@@ -1234,6 +1234,7 @@ export default {
|
|||||||
dataDirectory: '/moviepilot',
|
dataDirectory: '/moviepilot',
|
||||||
expand: '展開',
|
expand: '展開',
|
||||||
collapse: '收起',
|
collapse: '收起',
|
||||||
|
cleanCache: '清除緩存',
|
||||||
},
|
},
|
||||||
system: {
|
system: {
|
||||||
custom: '自定義',
|
custom: '自定義',
|
||||||
|
|||||||
Reference in New Issue
Block a user