index.vue 1.58 KB
<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>