refactor: ♻️ 移动端点击左侧菜单后关闭左侧菜单
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
<div class="wh-full" :class="classObj">
|
<div class="wh-full" :class="classObj">
|
||||||
<!-- 遮罩层 -->
|
<!-- 遮罩层 -->
|
||||||
<div
|
<div
|
||||||
v-if="classObj.mobile && classObj.openSidebar"
|
v-if="isMobile && isOpenSidebar"
|
||||||
class="wh-full fixed-lt z-999 bg-black bg-opacity-30"
|
class="wh-full fixed-lt z-999 bg-black bg-opacity-30"
|
||||||
@click="handleOutsideClick"
|
@click="handleOutsideClick"
|
||||||
></div>
|
></div>
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
<Sidebar class="sidebar-container" />
|
<Sidebar class="sidebar-container" />
|
||||||
|
|
||||||
<!-- 混合布局 -->
|
<!-- 混合布局 -->
|
||||||
<div v-if="layout === 'mix'" class="mix-container">
|
<div v-if="layout === LayoutEnum.MIX" class="mix-container">
|
||||||
<div class="mix-container__left">
|
<div class="mix-container__left">
|
||||||
<SidebarMenu :menu-list="mixLeftMenus" :base-path="activeTopMenuPath" />
|
<SidebarMenu :menu-list="mixLeftMenus" :base-path="activeTopMenuPath" />
|
||||||
<div class="sidebar-toggle">
|
<div class="sidebar-toggle">
|
||||||
@@ -47,11 +47,16 @@
|
|||||||
import { useAppStore, useSettingsStore, usePermissionStore } from "@/store";
|
import { useAppStore, useSettingsStore, usePermissionStore } from "@/store";
|
||||||
import defaultSettings from "@/settings";
|
import defaultSettings from "@/settings";
|
||||||
import { DeviceEnum } from "@/enums/DeviceEnum";
|
import { DeviceEnum } from "@/enums/DeviceEnum";
|
||||||
|
import { LayoutEnum } from "@/enums/LayoutEnum";
|
||||||
|
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
const settingsStore = useSettingsStore();
|
const settingsStore = useSettingsStore();
|
||||||
const permissionStore = usePermissionStore();
|
const permissionStore = usePermissionStore();
|
||||||
|
const width = useWindowSize().width;
|
||||||
|
|
||||||
|
const WIDTH_DESKTOP = 992; // 响应式布局容器固定宽度 大屏(>=1200px) 中屏(>=992px) 小屏(>=768px)
|
||||||
|
const isMobile = computed(() => appStore.device === DeviceEnum.MOBILE);
|
||||||
|
const isOpenSidebar = computed(() => appStore.sidebar.opened);
|
||||||
const fixedHeader = computed(() => settingsStore.fixedHeader); // 是否固定header
|
const fixedHeader = computed(() => settingsStore.fixedHeader); // 是否固定header
|
||||||
const showTagsView = computed(() => settingsStore.tagsView); // 是否显示tagsView
|
const showTagsView = computed(() => settingsStore.tagsView); // 是否显示tagsView
|
||||||
const layout = computed(() => settingsStore.layout); // 布局模式 left top mix
|
const layout = computed(() => settingsStore.layout); // 布局模式 left top mix
|
||||||
@@ -73,26 +78,17 @@ const classObj = computed(() => ({
|
|||||||
hideSidebar: !appStore.sidebar.opened,
|
hideSidebar: !appStore.sidebar.opened,
|
||||||
openSidebar: appStore.sidebar.opened,
|
openSidebar: appStore.sidebar.opened,
|
||||||
mobile: appStore.device === DeviceEnum.MOBILE,
|
mobile: appStore.device === DeviceEnum.MOBILE,
|
||||||
"layout-left": layout.value === "left",
|
[`layout-${settingsStore.layout}`]: true,
|
||||||
"layout-top": layout.value === "top",
|
|
||||||
"layout-mix": layout.value === "mix",
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const width = useWindowSize().width;
|
|
||||||
const WIDTH = 992; // 响应式布局容器固定宽度 大屏(>=1200px) 中屏(>=992px) 小屏(>=768px)
|
|
||||||
|
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
if (width.value < WIDTH) {
|
appStore.toggleDevice(
|
||||||
appStore.toggleDevice(DeviceEnum.MOBILE);
|
width.value < WIDTH_DESKTOP ? DeviceEnum.MOBILE : DeviceEnum.DESKTOP
|
||||||
appStore.closeSideBar();
|
);
|
||||||
|
if (width.value >= WIDTH_DESKTOP) {
|
||||||
|
appStore.openSideBar();
|
||||||
} else {
|
} else {
|
||||||
appStore.toggleDevice(DeviceEnum.DESKTOP);
|
appStore.closeSideBar();
|
||||||
|
|
||||||
if (width.value >= 1200) {
|
|
||||||
appStore.openSideBar();
|
|
||||||
} else {
|
|
||||||
appStore.closeSideBar();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -103,6 +99,13 @@ function handleOutsideClick() {
|
|||||||
function toggleSidebar() {
|
function toggleSidebar() {
|
||||||
appStore.toggleSidebar();
|
appStore.toggleSidebar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
watch(route, () => {
|
||||||
|
if (isMobile.value && isOpenSidebar.value) {
|
||||||
|
appStore.closeSideBar();
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
Reference in New Issue
Block a user