Skip to content

Commit 25ec2f1

Browse files
committed
refactor: 布局相关css变量移入到布局组件中维护
1 parent 2ce2b5f commit 25ec2f1

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

src/App.vue

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,6 @@ import useSettingsStore from '@/store/modules/settings'
66
77
const settingsStore = useSettingsStore()
88
9-
// 侧边栏主导航当前实际宽度
10-
const mainSidebarActualWidth = computed(() => {
11-
let actualWidth = Number.parseInt(getComputedStyle(document.documentElement).getPropertyValue('--g-main-sidebar-width'))
12-
if (['head', 'single'].includes(settingsStore.settings.menu.mode)) {
13-
actualWidth = 0
14-
}
15-
return `${actualWidth}px`
16-
})
17-
18-
// 侧边栏次导航当前实际宽度
19-
const subSidebarActualWidth = computed(() => {
20-
let actualWidth = Number.parseInt(getComputedStyle(document.documentElement).getPropertyValue('--g-sub-sidebar-width'))
21-
if (settingsStore.settings.menu.subMenuCollapse) {
22-
actualWidth = 64
23-
}
24-
return `${actualWidth}px`
25-
})
26-
279
watch(() => settingsStore.title, () => {
2810
document.title = import.meta.env.VITE_APP_TITLE
2911
}, {
@@ -39,12 +21,7 @@ onMounted(() => {
3921

4022
<template>
4123
<Provider>
42-
<RouterView
43-
:style="{
44-
'--g-main-sidebar-actual-width': mainSidebarActualWidth,
45-
'--g-sub-sidebar-actual-width': subSidebarActualWidth,
46-
}"
47-
/>
24+
<RouterView />
4825
<SystemInfo />
4926
</Provider>
5027
</template>

src/views/index.vue

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ import eventBus from '@/utils/eventBus'
1616
const settingsStore = useSettingsStore()
1717
const menuStore = useMenuStore()
1818
19+
// 侧边栏主导航当前实际宽度
20+
const mainSidebarActualWidth = computed(() => {
21+
let actualWidth = Number.parseInt(getComputedStyle(document.documentElement).getPropertyValue('--g-main-sidebar-width'))
22+
if (['head', 'single'].includes(settingsStore.settings.menu.mode)) {
23+
actualWidth = 0
24+
}
25+
return `${actualWidth}px`
26+
})
27+
28+
// 侧边栏次导航当前实际宽度
29+
const subSidebarActualWidth = computed(() => {
30+
let actualWidth = Number.parseInt(getComputedStyle(document.documentElement).getPropertyValue('--g-sub-sidebar-width'))
31+
if (settingsStore.settings.menu.subMenuCollapse) {
32+
actualWidth = 64
33+
}
34+
return `${actualWidth}px`
35+
})
36+
1937
const enableToolbar = computed(() => {
2038
return !(settingsStore.settings.menu.mode === 'head' && !settingsStore.settings.toolbar.previewWindows)
2139
})
@@ -36,7 +54,12 @@ const enableAppSetting = import.meta.env.VITE_APP_SETTING === 'true'
3654
</script>
3755

3856
<template>
39-
<div class="layout">
57+
<div
58+
class="layout" :style="{
59+
'--g-main-sidebar-actual-width': mainSidebarActualWidth,
60+
'--g-sub-sidebar-actual-width': subSidebarActualWidth,
61+
}"
62+
>
4063
<div id="app-main">
4164
<Header />
4265
<div class="wrapper">

0 commit comments

Comments
 (0)