130 lines
3.1 KiB
Vue
Raw Normal View History

2023-04-03 00:26:04 +08:00
<template>
<div :class="classObj" class="app-wrapper" :style="{ '--current-color': theme }">
<el-scrollbar>
<div v-if="device === 'mobile' && sidebar.opened" class="drawer-bg" @click="handleClickOutside"/>
<side-bar v-if="!sidebar.hide" class="sidebar-container" />
<div :class="{ hasTagsView: needTagsView, sidebarHide: sidebar.hide }" class="main-container">
<div :class="{ 'fixed-header': fixedHeader }">
<navbar ref="navbarRef" @setLayout="setLayout" />
<tags-view v-if="needTagsView" />
</div>
<app-main />
<settings ref="settingRef" />
2023-04-03 00:26:04 +08:00
</div>
</el-scrollbar>
2023-04-03 00:26:04 +08:00
</div>
</template>
2023-04-02 01:01:56 +08:00
<script setup lang="ts">
import SideBar from './components/Sidebar/index.vue'
2023-03-15 15:59:21 +08:00
import { AppMain, Navbar, Settings, TagsView } from './components'
import useAppStore from '@/store/modules/app'
import useSettingsStore from '@/store/modules/settings'
const settingsStore = useSettingsStore()
const theme = computed(() => settingsStore.theme);
const sidebar = computed(() => useAppStore().sidebar);
const device = computed(() => useAppStore().device);
const needTagsView = computed(() => settingsStore.tagsView);
const fixedHeader = computed(() => settingsStore.fixedHeader);
const classObj = computed(() => ({
2023-04-03 00:26:04 +08:00
hideSidebar: !sidebar.value.opened,
openSidebar: sidebar.value.opened,
withoutAnimation: sidebar.value.withoutAnimation,
mobile: device.value === 'mobile'
2023-03-15 15:59:21 +08:00
}))
2023-04-02 01:01:56 +08:00
const { width } = useWindowSize();
2023-03-15 15:59:21 +08:00
const WIDTH = 992; // refer to Bootstrap's responsive design
watchEffect(() => {
2023-04-03 00:26:04 +08:00
if (device.value === 'mobile' && sidebar.value.opened) {
useAppStore().closeSideBar({ withoutAnimation: false })
}
if (width.value - 1 < WIDTH) {
useAppStore().toggleDevice('mobile')
useAppStore().closeSideBar({ withoutAnimation: true })
} else {
useAppStore().toggleDevice('desktop')
}
2023-03-15 15:59:21 +08:00
})
2023-04-02 01:01:56 +08:00
const navbarRef = ref(Navbar);
const settingRef = ref(Settings);
2023-03-15 15:59:21 +08:00
onMounted(() => {
2023-04-03 00:26:04 +08:00
nextTick(() => {
navbarRef.value.initTenantList();
})
2023-03-15 15:59:21 +08:00
})
2023-04-02 01:01:56 +08:00
const handleClickOutside = () => {
2023-04-03 00:26:04 +08:00
useAppStore().closeSideBar({ withoutAnimation: false })
2023-03-15 15:59:21 +08:00
}
2023-04-02 01:01:56 +08:00
const setLayout = () => {
2023-04-03 00:26:04 +08:00
settingRef.value.openSetting();
2023-03-15 15:59:21 +08:00
}
</script>
<style lang="scss" scoped>
@import "@/assets/styles/mixin.scss";
@import "@/assets/styles/variables.module.scss";
.app-wrapper {
@include clearfix;
position: relative;
height: 100%;
width: 100%;
.el-scrollbar {
height: 100%;
}
:deep(.el-scrollbar__bar).is-vertical {
z-index: 10;
}
:deep(.el-scrollbar__wrap) {
overflow-x: hidden;
}
2023-03-15 15:59:21 +08:00
&.mobile.openSidebar {
position: fixed;
top: 0;
}
}
.drawer-bg {
background: #000;
opacity: 0.3;
width: 100%;
top: 0;
height: 100%;
position: absolute;
z-index: 999;
}
.fixed-header {
position: fixed;
top: 0;
right: 0;
z-index: 9;
width: calc(100% - #{$base-sidebar-width});
transition: width 0.28s;
}
.hideSidebar .fixed-header {
width: calc(100% - 54px);
}
.sidebarHide .fixed-header {
width: 100%;
}
.mobile .fixed-header {
width: 100%;
}
2023-04-02 01:01:56 +08:00
</style>