|
1 | 1 | <template> |
2 | | - <div class="app-container"> |
3 | | - <!-- 侧边栏 --> |
4 | | - <SideBarMenu |
5 | | - :isCollapsed="sidebarStore.isCollapsed" |
6 | | - @toggleSidebar="sidebarStore.toggleSidebar" |
7 | | - :selectedTab="selectedTab" |
8 | | - @selectTab="updateSelectedTab" |
9 | | - /> |
10 | | - <!-- 头部工具栏 --> |
11 | | - <HeaderToolbar/> |
12 | | - <!-- 内容区域 --> |
13 | | - <div class="content"> |
14 | | - <!-- 路由视图 --> |
15 | | - <router-view></router-view> |
16 | | - </div> |
17 | | - </div> |
| 2 | + <Layout> |
| 3 | + <!-- 使用 slot 渲染页面内容 --> |
| 4 | + <router-view /> |
| 5 | + </Layout> |
18 | 6 | </template> |
19 | 7 |
|
20 | 8 | <script> |
21 | | -import { useSidebarStore } from './stores/sidebarStore'; |
22 | | -import SideBarMenu from './components/SideBarMenu.vue'; |
23 | | -import HeaderToolbar from './components/HeaderToolbar.vue'; |
| 9 | +import Layout from './components/Layout.vue'; |
24 | 10 |
|
25 | 11 | export default { |
| 12 | + name: 'App', |
26 | 13 | components: { |
27 | | - SideBarMenu, |
28 | | - HeaderToolbar, |
| 14 | + Layout, |
29 | 15 | }, |
30 | | - setup() { |
31 | | - const sidebarStore = useSidebarStore(); // 使用 Pinia store |
32 | | - return { sidebarStore }; |
33 | | - }, |
34 | | - data() { |
35 | | - return { |
36 | | - selectedTab: 1 // 默认选中的 Tab |
37 | | - }; |
38 | | - }, |
39 | | - computed: { |
40 | | - // 根据侧边栏的状态动态调整内容区域的样式 |
41 | | - contentStyle() { |
42 | | - const sidebarWidth = this.sidebarStore.isCollapsed ? 80 : this.sidebarStore.sidebarWidth; // 获取侧边栏宽度,并考虑是否收缩 |
43 | | - return { |
44 | | - marginTop: '60px', // 头部工具栏的高度 |
45 | | - marginLeft: `${sidebarWidth}px`, // 动态设置左边距 |
46 | | - padding: '20px', |
47 | | - flex: 1, |
48 | | - overflowY: 'auto', // 启用纵向滚动 |
49 | | - boxSizing: 'border-box', |
50 | | - }; |
51 | | - }, |
52 | | - }, |
53 | | - methods: { |
54 | | - // 更新 selectedTab 的值 |
55 | | - updateSelectedTab(tabId) { |
56 | | - this.selectedTab = tabId; |
57 | | - } |
58 | | - } |
59 | 16 | }; |
60 | 17 | </script> |
61 | 18 |
|
62 | 19 | <style> |
63 | | -/* 确保html和body的高度为100% */ |
64 | | -html, body { |
65 | | - height: 100%; |
66 | | - margin: 0; |
67 | | -} |
68 | | -
|
69 | | -/* 使 app-container 占满全高,并设置flex布局 */ |
70 | | -.app-container { |
71 | | - display: flex; |
72 | | - height: 100%; /* 占满屏幕高度 */ |
73 | | - flex-direction: column; /* 使 header 在顶部,sidebar 和 content 在下方 */ |
74 | | -} |
75 | | -
|
76 | | -/* 内容区域样式 */ |
77 | | -.content { |
78 | | - flex: 1; |
79 | | - overflow-y: auto; /* 启用纵向滚动 */ |
80 | | - padding: 20px; |
81 | | - box-sizing: border-box; |
82 | | - margin-top: 60px; /* 确保内容区域位于头部工具栏下方 */ |
83 | | - margin-left: 250px; /* 假设侧边栏宽度为250px */ |
84 | | -} |
85 | | -
|
86 | | -@media (max-width: 768px) { |
87 | | - .content { |
88 | | - margin-left: 0; /* 在小屏幕下,移除侧边栏 */ |
89 | | - margin-top: 0; /* 确保在小屏幕下内容不被头部遮挡 */ |
90 | | - } |
91 | | -} |
| 20 | +/* 你可以在这里写一些全局样式 */ |
92 | 21 | </style> |
0 commit comments