refactor: 抽离独立Layout,实现路由分层

优化内容:
1. 新增 MainLayout.vue 独立布局组件
   - 封装 TopNav、SidebarNav、主内容区域
   - 独立的页面脚注

2. 简化 App.vue
   - 只负责主题配置和SvgSprite
   - 只渲染 RouterView
   - 移除所有布局相关代码

3. 重构路由配置
   - 登录页 /login:独立渲染,不使用Layout
   - 根路由 /:使用 MainLayout,渲染所有需要布局的页面
   - 所有业务页面都作为根路由的子路由嵌套渲染

架构优势:
- 登录页独立,不受主布局影响
- 主布局统一管理,减少重复代码
- 路由结构清晰,易于维护
- 符合Vue最佳实践

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-25 01:24:12 +08:00
parent 36fb09feb6
commit 31f01085a9
3 changed files with 114 additions and 98 deletions

View File

@@ -1,8 +1,6 @@
<script setup>
import { RouterView } from 'vue-router'
import { ref, onMounted } from 'vue'
import SidebarNav from './components/SidebarNav.vue'
import TopNav from './components/TopNav.vue'
import { theme } from 'ant-design-vue'
import SvgSprite from '@/components/icons/SvgSprite.vue'
import { useUserStore } from '@/stores/user'
@@ -73,49 +71,11 @@ onMounted(async () => {
<template>
<a-config-provider :theme="themeToken">
<div class="app-shell">
<SvgSprite />
<TopNav />
<div class="app-body">
<SidebarNav />
<div class="app-content">
<main class="content-scroll">
<keep-alive>
<RouterView />
</keep-alive>
</main>
<footer class="py-6 text-xs text-center text-gray-500">
v0.1 · API 正常 · © 2025 金牌内容大师
</footer>
</div>
</div>
</div>
<SvgSprite />
<RouterView />
</a-config-provider>
</template>
<style scoped>
.app-shell {
min-height: 100vh;
background: var(--color-bg);
}
/* 顶部固定,下面主体需要留出空间 */
.app-body {
padding-top: 70px; /* 与 TopNav 高度对齐 */
display: grid;
grid-template-columns: 220px 1fr; /* 左侧固定宽度侧边栏 */
}
.app-content {
min-height: calc(100vh - 70px);
display: flex;
flex-direction: column;
}
.content-scroll {
flex: 1 1 auto;
overflow: auto; /* 右侧内容区域滚动 */
padding: 0 16px 0 16px;
}
<style>
/* 全局样式保持不变 */
</style>