diff --git a/src/App.vue b/src/App.vue index dd26c6b..eaee8ce 100644 --- a/src/App.vue +++ b/src/App.vue @@ -8,12 +8,16 @@ const settingsStore = useSettingsStore() const $router = useRouter() const buttonConfig = ref({ - autoInsertSpace: true, + autoInsertSpace: true }) // 侧边栏主导航当前实际宽度 const mainSidebarActualWidth = computed(() => { - let actualWidth = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--g-main-sidebar-width')) + let actualWidth = parseInt( + getComputedStyle(document.documentElement).getPropertyValue( + '--g-main-sidebar-width' + ) + ) if (['head', 'single', 'top'].includes(settingsStore.menu.menuMode)) { actualWidth = 0 } @@ -22,63 +26,81 @@ // 侧边栏次导航当前实际宽度 const subSidebarActualWidth = computed(() => { - let actualWidth = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--g-sub-sidebar-width')) + let actualWidth = parseInt( + getComputedStyle(document.documentElement).getPropertyValue( + '--g-sub-sidebar-width' + ) + ) if (settingsStore.menu.menuMode === 'top') { actualWidth = 0 - } - else if (settingsStore.menu.subMenuCollapse) { + } else if (settingsStore.menu.subMenuCollapse) { actualWidth = 55 } return `${actualWidth}px` }) -watch(() => settingsStore.app.colorScheme, () => { - if (settingsStore.app.colorScheme === 'dark') { - document.documentElement.classList.add('dark') +watch( + () => settingsStore.app.colorScheme, + () => { + if (settingsStore.app.colorScheme === 'dark') { + document.documentElement.classList.add('dark') + } else { + document.documentElement.classList.remove('dark') + } + }, + { + immediate: true } - else { - document.documentElement.classList.remove('dark') - } -}, { - immediate: true, -}) +) -watch(() => settingsStore.mode, () => { - if (settingsStore.mode === 'pc') { - settingsStore.$patch((state) => { - state.menu.subMenuCollapse = settingsStore.subMenuCollapseLastStatus - }) +watch( + () => settingsStore.mode, + () => { + if (settingsStore.mode === 'pc') { + settingsStore.$patch(state => { + state.menu.subMenuCollapse = settingsStore.subMenuCollapseLastStatus + }) + } else if (settingsStore.mode === 'mobile') { + settingsStore.$patch(state => { + state.menu.subMenuCollapse = true + }) + } + document.body.setAttribute('data-mode', settingsStore.mode) + }, + { + immediate: true } - else if (settingsStore.mode === 'mobile') { - settingsStore.$patch((state) => { - state.menu.subMenuCollapse = true - }) - } - document.body.setAttribute('data-mode', settingsStore.mode) -}, { - immediate: true, -}) +) -watch(() => settingsStore.menu.menuMode, () => { - document.body.setAttribute('data-menu-mode', settingsStore.menu.menuMode) -}, { - immediate: true, -}) +watch( + () => settingsStore.menu.menuMode, + () => { + document.body.setAttribute('data-menu-mode', settingsStore.menu.menuMode) + }, + { + immediate: true + } +) -watch([ - () => settingsStore.app.enableDynamicTitle, - () => settingsStore.title, -], () => { - if (settingsStore.app.enableDynamicTitle && settingsStore.title) { - const title = settingsStore.title - document.title = `${title} - ${window.localStorage.getItem('project-name') || import.meta.env.VITE_APP_TITLE}` +watch( + [() => settingsStore.app.enableDynamicTitle, () => settingsStore.title], + () => { + if (settingsStore.app.enableDynamicTitle && settingsStore.title) { + const title = settingsStore.title + document.title = `${title} - ${ + window.localStorage.getItem('project-name') || + import.meta.env.VITE_APP_TITLE + }` + } else { + document.title = + window.localStorage.getItem('project-name') || + import.meta.env.VITE_APP_TITLE + } + }, + { + immediate: true } - else { - document.title = window.localStorage.getItem('project-name') || import.meta.env.VITE_APP_TITLE - } -}, { - immediate: true, -}) +) onMounted(() => { // // 浏览器访问当前位置 @@ -99,11 +121,24 @@ settingsStore.setMode(document.documentElement.clientWidth) // 监听浏览器类型变化 刷新浏览器 const userAgent = navigator.userAgent || navigator.vendor || window.opera - const isMobile = /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(userAgent) - if (`${isMobile ? 'mobile' : 'pc'}` !== window.localStorage.getItem('browser-type-bj-well')) { + const isMobile = + /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test( + userAgent + ) + if ( + `${isMobile ? 'mobile' : 'pc'}` !== + window.localStorage.getItem('browser-type-bj-well') + ) { // if (!window.localStorage.getItem('browser-type-bj-well')) { return } - console.log(`浏览器类型发生变化,由${window.localStorage.getItem('browser-type-bj-well')}变为${isMobile ? 'mobile' : 'pc'}`) - window.localStorage.setItem('browser-type-bj-well', `${isMobile ? 'mobile' : 'pc'}`) + console.log( + `浏览器类型发生变化,由${window.localStorage.getItem( + 'browser-type-bj-well' + )}变为${isMobile ? 'mobile' : 'pc'}` + ) + window.localStorage.setItem( + 'browser-type-bj-well', + `${isMobile ? 'mobile' : 'pc'}` + ) $router.push('/') setTimeout(() => { window.location.reload() @@ -116,29 +151,33 @@ }) const browserType = window.localStorage.getItem('browser-type-bj-well') // mobile || pc - window.addEventListener('beforeunload', function (e) { console.log(1111) // var confirmationMessage = '确定要离开此页面吗?'; // e.returnValue = confirmationMessage; console.log(e.type, 'type') if (e.type === 'unload') { - console.log('页面被关闭'); + console.log('页面被关闭') // 删除所有缓存数据 indexDB.deleteAll() } else if (e.type === 'beforeunload') { - console.log('页面被刷新'); + console.log('页面被刷新') } // return confirmationMessage; })