136 lines
3.5 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 }">
2023-05-05 11:06:32 +08:00
<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">
2023-05-05 11:06:32 +08:00
<!-- <el-scrollbar>
<div :class="{ 'fixed-header': fixedHeader }">
2023-05-05 11:06:32 +08:00
<navbar ref="navbarRef" @setLayout="setLayout" />
<tags-view v-if="needTagsView" />
</div>
<app-main />
<settings ref="settingRef" />
2023-05-05 11:06:32 +08:00
</el-scrollbar> -->
<div :class="{ 'fixed-header': fixedHeader }">
<navbar ref="navbarRef" @set-layout="setLayout" />
2023-05-05 11:06:32 +08:00
<tags-view v-if="needTagsView" />
</div>
<app-main />
<settings ref="settingRef" />
</div>
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';
import { AppMain, Navbar, Settings, TagsView } from './components';
import useAppStore from '@/store/modules/app';
import useSettingsStore from '@/store/modules/settings';
import { initWebSocket } from '@/utils/websocket';
2024-07-26 16:06:17 +08:00
import { initSSE } from "@/utils/sse";
const settingsStore = useSettingsStore();
2023-03-15 15:59:21 +08:00
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(() => ({
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(() => {
if (device.value === 'mobile') {
useAppStore().closeSideBar({ withoutAnimation: false });
}
if (width.value - 1 < WIDTH) {
useAppStore().toggleDevice('mobile');
useAppStore().closeSideBar({ withoutAnimation: true });
} else {
useAppStore().toggleDevice('desktop');
}
});
const navbarRef = ref<InstanceType<typeof Navbar>>();
const settingRef = ref<InstanceType<typeof Settings>>();
2023-03-15 15:59:21 +08:00
onMounted(() => {
2023-05-05 11:06:32 +08:00
nextTick(() => {
navbarRef.value?.initTenantList();
});
});
2023-03-15 15:59:21 +08:00
2023-12-23 19:49:17 +08:00
onMounted(() => {
let protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
initWebSocket(protocol + window.location.host + import.meta.env.VITE_APP_BASE_API + '/resource/websocket');
});
onMounted(() => {
2024-10-07 10:45:25 +08:00
initSSE(import.meta.env.VITE_APP_BASE_API + '/resource/sse');
2023-12-23 19:49:17 +08:00
});
2023-04-02 01:01:56 +08:00
const handleClickOutside = () => {
useAppStore().closeSideBar({ withoutAnimation: false });
};
2023-03-15 15:59:21 +08:00
2023-04-02 01:01:56 +08:00
const setLayout = () => {
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';
2023-03-15 15:59:21 +08:00
.app-wrapper {
@include clearfix;
position: relative;
height: 100%;
width: 100%;
&.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;
background: $fixed-header-bg;
2023-03-15 15:59:21 +08:00
}
.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>