fix:移动端点击菜单之后面板不会隐藏

This commit is contained in:
不做码农
2023-05-07 09:33:06 +08:00
parent 3db1fecbb8
commit 1217f1abdc
3 changed files with 32 additions and 17 deletions
+6 -1
View File
@@ -34,7 +34,7 @@ const showLogo = computed(() => settingsStore.sidebarLogo)
const sideTheme = computed(() => settingsStore.sideTheme)
const theme = computed(() => settingsStore.theme)
const isCollapse = computed(() => !appStore.sidebar.opened)
const device = computed(() => appStore.device)
const activeMenu = computed(() => {
const { meta, path } = route
// if set path, the sidebar will highlight the path you set
@@ -43,4 +43,9 @@ const activeMenu = computed(() => {
}
return path
})
watch(route, (val) => {
if (device.value === 'mobile') {
appStore.closeSideBar()
}
})
</script>
+21 -9
View File
@@ -1,7 +1,14 @@
<template>
<el-container :class="classObj" class="app-layout" :style="{ '--current-color': theme }">
<!-- 移动端打开菜单遮罩 -->
<el-drawer v-if="device === 'mobile'" :size="220" v-model="menuDrawer" :with-header="false" modal-class="sidebar-mobile" direction="ltr">
<el-drawer
v-if="device === 'mobile'"
:size="220"
v-model="menuDrawer"
:with-header="false"
modal-class="sidebar-mobile"
direction="ltr"
@close="close">
<sidebar />
</el-drawer>
<sidebar v-else-if="!sidebar.hide" />
@@ -38,12 +45,7 @@ import iframeToggle from './components/IframeToggle/index'
import useAppStore from '@/store/modules/app'
import useSettingsStore from '@/store/modules/settings'
import useTagsViewStore from '@/store/modules/tagsView'
const menuDrawer = computed({
get: () => useAppStore().sidebar.opened,
set: (val) => {
useAppStore().toggleSideBar(val)
}
})
const settingsStore = useSettingsStore()
const theme = computed(() => settingsStore.theme)
const sidebar = computed(() => useAppStore().sidebar)
@@ -51,7 +53,14 @@ const device = computed(() => useAppStore().device)
const needTagsView = computed(() => settingsStore.tagsView)
const fixedHeader = computed(() => settingsStore.fixedHeader)
const showFooter = computed(() => settingsStore.showFooter)
const menuDrawer = computed({
get: () => useAppStore().sidebar.opened,
set: (val) => {
if (device.value !== 'mobile') {
useAppStore().toggleSideBar(val)
}
}
})
// appMain 模块 start
const route = useRoute()
useTagsViewStore().addCachedView(route)
@@ -71,7 +80,7 @@ const WIDTH = 792 // refer to Bootstrap's responsive design
watchEffect(() => {
if (device.value === 'mobile' && sidebar.value.opened) {
// useAppStore().closeSideBar()
useAppStore().closeSideBar()
}
if (width.value - 1 < WIDTH) {
useAppStore().toggleDevice('mobile')
@@ -85,6 +94,9 @@ const settingRef = ref(null)
function setLayout() {
settingRef.value.openSetting()
}
function close() {
useAppStore().closeSideBar()
}
</script>
<style lang="scss">