index.vue
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<script setup lang="ts">
import { useWindowSize } from '@vueuse/core'
import Sidebar from './components/Sidebar/index.vue'
import Navbar from './components/Navbar.vue'
import TagsView from './components/TagsView.vue'
import AppMain from './components/AppMain.vue'
import { useAppStore } from '@/store'
/**
* 主布局:左侧菜单 + 顶部导航 + 标签页 + 内容区
* 侧边栏折叠宽度用 SCSS 变量,保证与 Sidebar 内部样式一致
*/
const appStore = useAppStore()
const { width } = useWindowSize()
const sidebarWidth = computed(() => (appStore.sidebarCollapsed ? '64px' : '210px'))
// 小屏自动折叠侧边栏
watch(
() => width.value,
(w) => {
if (w < 992 && !appStore.sidebarCollapsed) appStore.sidebarCollapsed = true
},
{ immediate: true }
)
</script>
<template>
<div class="layout-root">
<aside class="layout-sidebar" :style="{ width: sidebarWidth }">
<Sidebar />
</aside>
<div class="layout-main">
<header class="layout-navbar">
<Navbar />
</header>
<TagsView />
<AppMain />
</div>
</div>
</template>
<style scoped lang="scss">
.layout-root {
display: flex;
height: 100%;
width: 100%;
overflow: hidden;
}
.layout-sidebar {
height: 100%;
transition: width 0.28s;
background-color: #304156;
overflow: hidden;
flex-shrink: 0;
}
.layout-main {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
}
.layout-navbar {
height: $navbar-height;
flex-shrink: 0;
background: $bg-white;
border-bottom: 1px solid $border-color-light;
}
</style>