zb-admin/src/layout/index.vue

115 lines
2.6 KiB
Vue
Raw Normal View History

2022-03-24 04:15:14 +00:00
<template>
<div class="g-container-layout" :class="classObj">
<div v-if="device === 'mobile' && !isCollapse" class="drawer-bg" @click="handleClickOutside" />
2022-08-24 09:53:08 +00:00
<sidebar class="sidebar-container" v-if="mode === 'vertical'" />
<div
class="main-container"
:class="{
hideSliderLayout: mode === 'horizontal',
}"
>
2022-03-24 04:15:14 +00:00
<u-header />
2022-08-24 10:53:05 +00:00
<div class="m-container-content" :class="{ 'app-main-hide-tag': !showTag }">
2022-08-24 09:53:08 +00:00
<u-main />
2022-04-30 13:19:10 +00:00
</div>
2022-03-24 04:15:14 +00:00
</div>
</div>
</template>
<script lang="ts">
import { computed, defineComponent, ref } from 'vue'
2022-08-24 09:53:08 +00:00
import Sidebar from './Sidebar/index.vue'
import UHeader from './Header/index.vue'
import UMain from './Main/index.vue'
import { useResizeHandler } from './hooks/useResizeHandler'
2022-03-31 02:13:27 +00:00
import { useStore } from 'vuex'
2022-03-24 04:15:14 +00:00
export default defineComponent({
name: 'layout',
components: {
2022-08-24 09:53:08 +00:00
Sidebar,
2022-03-24 04:15:14 +00:00
UHeader,
2022-08-24 09:53:08 +00:00
UMain,
2022-03-24 04:15:14 +00:00
},
setup() {
2022-03-24 04:15:14 +00:00
const store = useStore()
// 是否折叠
const isCollapse = computed(() => {
2022-04-06 07:48:24 +00:00
return !store.state.app.isCollapse
2022-03-24 04:15:14 +00:00
})
let { device } = useResizeHandler()
2022-04-06 07:48:24 +00:00
const classObj = computed(() => {
2022-04-06 07:48:24 +00:00
return {
hideSidebar: !store.state.app.isCollapse,
2022-04-06 07:48:24 +00:00
openSidebar: store.state.app.isCollapse,
withoutAnimation: store.state.app.withoutAnimation,
mobile: device.value === 'mobile',
2022-04-06 07:48:24 +00:00
}
})
const handleClickOutside = () => {
2022-04-06 07:48:24 +00:00
store.dispatch('app/closeSideBar', { withoutAnimation: false })
}
2022-08-24 10:53:05 +00:00
const showTag = computed(() => {
return store.state.setting.themeConfig.showTag
2022-04-30 13:19:10 +00:00
})
2022-04-06 07:48:24 +00:00
const mode = computed(() => {
2022-08-24 10:53:05 +00:00
return store.state.setting.themeConfig.mode
2022-04-30 13:19:10 +00:00
})
return {
2022-04-06 07:48:24 +00:00
isCollapse,
device,
classObj,
2022-08-24 10:53:05 +00:00
showTag,
2022-04-30 13:19:10 +00:00
mode,
handleClickOutside,
2022-03-24 04:15:14 +00:00
}
},
})
2022-03-24 04:15:14 +00:00
</script>
<style lang="scss" scoped>
.g-container-layout {
2022-04-25 07:48:25 +00:00
//display: flex;
2022-03-24 04:15:14 +00:00
height: 100%;
width: 100%;
.main-container {
2022-03-31 02:13:27 +00:00
//overflow: auto;
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;
z-index: 999;
2022-03-24 04:15:14 +00:00
}
.m-container-content {
2022-06-10 03:01:39 +00:00
//padding: 20px;
2022-04-30 13:19:10 +00:00
/*background: #f6f8f9;*/
2022-06-10 03:01:39 +00:00
padding-top: 93px;
2022-06-16 06:48:48 +00:00
box-sizing: border-box;
height: 100vh;
2022-05-01 15:06:11 +00:00
position: relative;
2022-04-30 13:19:10 +00:00
}
.app-main-hide-tag {
2022-04-30 13:19:10 +00:00
padding-top: 80px;
}
2022-03-24 04:15:14 +00:00
</style>