zb-admin/src/layout/index.vue

86 lines
2.1 KiB
Vue
Raw Normal View History

2022-03-24 04:15:14 +00:00
<template>
<div class="g-container-layout" :class="classObj">
2023-10-22 05:31:07 +00:00
<Mobile />
<LayoutVertical v-if="device === 'mobile'" />
<component :is="LayoutComponents[themeConfig.mode]" v-else />
2023-02-27 09:44:14 +00:00
<Theme />
2022-03-24 04:15:14 +00:00
</div>
</template>
<script lang="ts" setup>
2023-10-22 05:31:07 +00:00
import { computed, watch } from 'vue'
import Theme from '@/components/Theme/index.vue'
import Mobile from './components/Mobile/index.vue'
2023-10-22 05:31:07 +00:00
import { useSettingStore } from '@/store/modules/setting'
import { useResizeHandler } from '@/hooks/useResizeHandler'
import LayoutVertical from './LayoutVertical/index.vue'
import LayoutHorizontal from './LayoutHorizontal/index.vue'
2023-02-22 13:00:10 +00:00
import LayoutColumns from './LayoutColumns/index.vue'
2022-03-31 02:13:27 +00:00
2022-09-12 12:31:21 +00:00
const SettingStore = useSettingStore()
const themeConfig = computed(() => SettingStore.themeConfig)
const LayoutComponents = {
horizontal: LayoutHorizontal,
vertical: LayoutVertical,
2023-02-22 13:00:10 +00:00
columns: LayoutColumns,
2023-10-22 05:31:07 +00:00
}
2022-03-24 04:15:14 +00:00
2022-09-12 12:31:21 +00:00
// 是否折叠
const isCollapse = computed(() => {
return !SettingStore.isCollapse
})
let { device } = useResizeHandler()
2023-10-22 05:31:07 +00:00
watch(
() => device.value,
(val) => {
let vertical = val === 'mobile' ? 'vertical' : themeConfig.value.mode
const body = document.body as HTMLElement
body.setAttribute('class', `layout-${vertical}`)
},
{
immediate: true,
},
)
2022-09-12 12:31:21 +00:00
// 当屏幕切换的时候进行变换
const classObj = computed(() => {
return {
hideSidebar: !SettingStore.isCollapse,
openSidebar: SettingStore.isCollapse,
withoutAnimation: SettingStore.withoutAnimation,
mobile: device.value === 'mobile',
}
})
2022-03-24 04:15:14 +00:00
</script>
<style lang="scss" scoped>
.g-container-layout {
2022-03-24 04:15:14 +00:00
height: 100%;
width: 100%;
.main-container {
2022-03-24 04:15:14 +00:00
display: flex;
flex: 1;
2022-03-28 10:32:20 +00:00
box-sizing: border-box;
flex-direction: column;
2022-03-24 04:15:14 +00:00
}
2022-04-06 07:48:24 +00:00
&.mobile.openSidebar {
position: fixed;
top: 0;
}
}
.sidebar-container {
2022-04-19 01:47:14 +00:00
display: flex;
flex-direction: column;
}
2022-04-06 07:48:24 +00:00
.drawer-bg {
background: #000;
opacity: 0.3;
width: 100%;
top: 0;
height: 100%;
position: absolute;
2022-09-02 13:28:40 +00:00
z-index: 90;
2022-03-24 04:15:14 +00:00
}
</style>