|
1 | 1 | <template> |
2 | | - <div class="layout" :class="layoutClass"> |
3 | | - <!-- 移动端遮罩层 --> |
4 | | - <div v-if="isMobile && isSidebarOpen" class="layout__overlay" @click="closeSidebar" /> |
| 2 | + <div class="layout-wrapper"> |
| 3 | + <component :is="currentLayoutComponent" /> |
5 | 4 |
|
6 | | - <!-- 布局内容插槽 --> |
7 | | - <slot></slot> |
| 5 | + <!-- 设置面板 - 独立于布局组件 --> |
| 6 | + <Settings v-if="isShowSettings" /> |
8 | 7 | </div> |
9 | 8 | </template> |
10 | 9 |
|
11 | 10 | <script setup lang="ts"> |
12 | | -import { useLayout, useLayoutResponsive } from "@/composables"; |
| 11 | +import { useRoute } from "vue-router"; |
| 12 | +import { useLayout } from "@/composables/layout/useLayout"; |
| 13 | +import LeftLayout from "@/layouts/modes/left/index.vue"; |
| 14 | +import TopLayout from "@/layouts/modes/top/index.vue"; |
| 15 | +import MixLayout from "@/layouts/modes/mix/index.vue"; |
| 16 | +import Settings from "./components/Settings/index.vue"; |
| 17 | +import { LayoutMode } from "@/enums/settings/layout.enum"; |
| 18 | +import { defaultSettings } from "@/settings"; |
13 | 19 |
|
14 | | -// 布局相关 |
15 | | -const { layoutClass, isSidebarOpen, closeSidebar } = useLayout(); |
| 20 | +const { currentLayout } = useLayout(); |
| 21 | +const route = useRoute(); |
16 | 22 |
|
17 | | -// 响应式布局 |
18 | | -const { isMobile } = useLayoutResponsive(); |
| 23 | +/// Select the corresponding component based on the current layout mode |
| 24 | +const currentLayoutComponent = computed(() => { |
| 25 | + const override = route.meta?.layout as LayoutMode | undefined; |
| 26 | + const layoutToUse = override ?? currentLayout.value; |
| 27 | + switch (layoutToUse) { |
| 28 | + case LayoutMode.TOP: |
| 29 | + return TopLayout; |
| 30 | + case LayoutMode.MIX: |
| 31 | + return MixLayout; |
| 32 | + case LayoutMode.LEFT: |
| 33 | + default: |
| 34 | + return LeftLayout; |
| 35 | + } |
| 36 | +}); |
| 37 | +
|
| 38 | +/// Whether to show the settings panel |
| 39 | +const isShowSettings = computed(() => defaultSettings.showSettings); |
19 | 40 | </script> |
20 | 41 |
|
21 | 42 | <style lang="scss" scoped> |
22 | | -.layout { |
| 43 | +.layout-wrapper { |
23 | 44 | width: 100%; |
24 | 45 | height: 100%; |
25 | | -
|
26 | | - &__overlay { |
27 | | - position: fixed; |
28 | | - top: 0; |
29 | | - left: 0; |
30 | | - z-index: 999; |
31 | | - width: 100%; |
32 | | - height: 100%; |
33 | | - background-color: rgba(0, 0, 0, 0.3); |
34 | | - } |
35 | 46 | } |
36 | 47 | </style> |
0 commit comments