fix(service_worker): 根据标志位在app.vue开启缓存检测工具

This commit is contained in:
huangjunsen0406
2025-04-15 09:53:06 +08:00
parent afa0527b4c
commit 20d66ff401
+10 -3
View File
@@ -1,7 +1,7 @@
<template> <template>
<div id="app"> <div id="app">
<router-view /> <router-view />
<cache-viewer :visible.sync="showCacheViewer" /> <cache-viewer v-if="isCDNEnabled" :visible.sync="showCacheViewer" />
</div> </div>
</template> </template>
@@ -61,8 +61,9 @@ export default {
}, },
mounted() { mounted() {
// 只有在启用CDN时才添加相关事件和功能 // 只有在启用CDN时才添加相关事件和功能
// 添加全局快捷键Alt+C用于显示缓存查看器 if (this.isCDNEnabled) {
document.addEventListener('keydown', this.handleKeyDown); // 添加全局快捷键Alt+C用于显示缓存查看器
document.addEventListener('keydown', this.handleKeyDown);
// 在全局对象上添加缓存检查方法,便于调试 // 在全局对象上添加缓存检查方法,便于调试
window.checkCDNCacheStatus = () => { window.checkCDNCacheStatus = () => {
@@ -80,6 +81,12 @@ export default {
// 检查Service Worker状态 // 检查Service Worker状态
this.checkServiceWorkerStatus(); this.checkServiceWorkerStatus();
} else {
console.info(
'%c[小智服务] CDN模式已禁用,使用本地打包资源',
'color: #67C23A; font-weight: bold;'
);
}
}, },
beforeDestroy() { beforeDestroy() {
// 只有在启用CDN时才需要移除事件监听 // 只有在启用CDN时才需要移除事件监听