修复导航模式为侧边栏模式(不含主导航)时,在移动端展示报错的问题

This commit is contained in:
hooray 2021-10-13 16:57:08 +08:00
parent 78751d835f
commit b013408bd1
3 changed files with 26 additions and 25 deletions

View File

@ -27,28 +27,6 @@ watch([
immediate: true
})
watch([
() => store.state.settings.enableDynamicTitle,
() => store.state.settings.title
], () => setDocumentTitle(), {
immediate: true
})
onMounted(() => {
window.onresize = () => {
store.commit('settings/setMode', document.documentElement.clientWidth)
}
window.onresize()
})
function setDocumentTitle() {
if (store.state.settings.enableDynamicTitle && store.state.settings.title) {
let title = store.state.settings.title
document.title = `${title} - ${import.meta.env.VITE_APP_TITLE}`
} else {
document.title = import.meta.env.VITE_APP_TITLE
}
}
function setMenuMode() {
document.body.removeAttribute('data-sidebar-no-collapse')
document.body.removeAttribute('data-sidebar-collapse')
@ -59,4 +37,27 @@ function setMenuMode() {
}
document.body.setAttribute('data-menu-mode', store.state.settings.menuMode)
}
watch([
() => store.state.settings.enableDynamicTitle,
() => store.state.settings.title
], () => setDocumentTitle(), {
immediate: true
})
function setDocumentTitle() {
if (store.state.settings.enableDynamicTitle && store.state.settings.title) {
let title = store.state.settings.title
document.title = `${title} - ${import.meta.env.VITE_APP_TITLE}`
} else {
document.title = import.meta.env.VITE_APP_TITLE
}
}
onMounted(() => {
window.onresize = () => {
store.commit('settings/setMode', document.documentElement.clientWidth)
}
window.onresize()
})
</script>

View File

@ -1,8 +1,8 @@
<template>
<div v-if="['side', 'head', 'single'].includes($store.state.settings.menuMode) || $store.state.settings.mode === 'mobile'" class="sub-sidebar-container" :class="{'is-collapse': $store.state.settings.mode === 'pc' && $store.state.settings.sidebarCollapse}" @scroll="onSidebarScroll">
<Logo :show-logo="$store.state.settings.menuMode === 'single'" :class="{
<Logo :show-logo="$store.state.settings.menuMode === 'single' && $store.state.settings.mode === 'pc'" :class="{
'sidebar-logo': true,
'sidebar-logo-bg': $store.state.settings.menuMode === 'single',
'sidebar-logo-bg': $store.state.settings.menuMode === 'single' && $store.state.settings.mode === 'pc',
'shadow': sidebarScrollTop
}"
/>

View File

@ -126,7 +126,7 @@ const getters = {
// 由于 getter 的结果不会被缓存,导致导航栏切换时有明显的延迟,该问题会在 Vue 3.2 版本中修复,详看 https://github.com/vuejs/vuex/pull/1883
routes: (state, getters, rootState) => {
let routes
if (rootState.settings.menuMode === 'single') {
if (rootState.settings.menuMode === 'single' && rootState.settings.mode === 'pc') {
routes = [{ children: [] }]
state.routes.map(item => {
routes[0].children.push(...item.children)