Skip to content

Commit 180439c

Browse files
committed
feat: add fixed sidemenu
1 parent c4fec01 commit 180439c

File tree

8 files changed

+85
-14
lines changed

8 files changed

+85
-14
lines changed

src/components/menu/SideMenu.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<a-layout-sider
3-
:class="['sider', device === 'desktop' ? null : 'shadow', theme ]"
3+
:class="['sider', device === 'desktop' ? null : 'shadow', theme, fixedSideMenu ? 'ant-fixed-sidemenu' : null ]"
44
width="256px"
55
:collapsible="collapsible"
66
v-model="collapsed"
@@ -58,6 +58,7 @@
5858
computed: {
5959
...mapState({
6060
device: state => state.app.device,
61+
fixedSideMenu: state => state.app.fixedSideMenu,
6162
})
6263
},
6364
methods: {

src/components/page/GlobalHeader.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
2-
<a-layout-header v-if="!headerBarFixed" :class="[fixedHeader && 'ant-header-fixedHeader']" :style="{ padding: '0', width: fixedHeader ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%' }">
2+
<!-- , width: fixedHeader ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%' -->
3+
<a-layout-header v-if="!headerBarFixed" :class="[fixedHeader && 'ant-header-fixedHeader', sidebarOpened ? 'ant-header-side-opened' : 'ant-header-side-closed', ]" :style="{ padding: '0' }">
34
<div v-if="mode === 'sidemenu'" class="header">
45
<a-icon
56
v-if="device==='mobile'"

src/components/page/GlobalLayout.vue

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
</a-drawer>
4848
</template>
4949

50-
<a-layout :class="[layoutMode]">
50+
<a-layout :class="[layoutMode]" :style="{ paddingLeft: fixedSideMenu ? `${sidebarOpened ? 256 : 80}px` : '0' }">
5151
<!-- layout header -->
5252
<global-header :mode="layoutMode" :theme="theme" :collapsed="collapsed" :device="device" @toggle="toggle"/>
5353

@@ -97,6 +97,7 @@
9797
layoutMode: state => state.app.layout,
9898
sidebarOpened: state => state.app.sidebar.opened,
9999
fixedHeader: state => state.app.fixedHeader,
100+
fixedSideMenu: state => state.app.fixedSideMenu,
100101
theme: state => state.app.theme,
101102
device: state => state.app.device,
102103
})
@@ -167,15 +168,47 @@
167168
background: rgba(0, 0, 0, 0.025);
168169
}
169170
}
170-
.ant-header-fixedHeader {
171-
position: fixed;
172-
top: 0;
173-
right: 0;
174-
z-index: 9;
175-
width: 100%;
176-
transition: width .2s;
171+
172+
.topmenu {
173+
.ant-header-fixedHeader {
174+
position: fixed;
175+
top: 0;
176+
right: 0;
177+
z-index: 9;
178+
width: 100%;
179+
transition: width .2s;
180+
181+
&.ant-header-side-opened {
182+
width: 100%;
183+
}
184+
185+
&.ant-header-side-closed {
186+
width: 100%;
187+
}
188+
}
189+
}
190+
191+
.sidemenu {
192+
.ant-header-fixedHeader {
193+
position: fixed;
194+
top: 0;
195+
right: 0;
196+
z-index: 9;
197+
width: 100%;
198+
transition: width .2s;
199+
200+
&.ant-header-side-opened {
201+
width: calc(100% - 256px)
202+
}
203+
204+
&.ant-header-side-closed {
205+
width: calc(100% - 80px)
206+
}
207+
}
177208
}
178209
210+
211+
179212
.header {
180213
height: 64px;
181214
padding: 0 12px 0 0;
@@ -400,6 +433,11 @@
400433
position: relative;
401434
z-index: 10;
402435
436+
&.ant-fixed-sidemenu {
437+
position: fixed;
438+
height: 100%;
439+
}
440+
403441
.logo {
404442
height: 64px;
405443
position: relative;

src/components/setting/SettingDrawer.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<a-list :split="false">
9090
<a-list-item>
9191
<a-select slot="actions" defaultValue="auto" size="small">
92-
<a-select-option value="fixed">固定</a-select-option>
92+
<a-select-option value="fixed" v-if="layoutMode !== 'sidemenu'" disabled>固定</a-select-option>
9393
<a-select-option value="auto">流式</a-select-option>
9494
</a-select>
9595
<a-list-item-meta>
@@ -108,6 +108,12 @@
108108
<div slot="title">下滑时隐藏 Header</div>
109109
</a-list-item-meta>
110110
</a-list-item>
111+
<a-list-item>
112+
<a-switch slot="actions" size="small" :defaultChecked="fixedSideMenu" @change="handleFixedSideMenu" />
113+
<a-list-item-meta>
114+
<div slot="title">固定侧边菜单</div>
115+
</a-list-item-meta>
116+
</a-list-item>
111117
</a-list>
112118
</div>
113119
</div>
@@ -169,6 +175,7 @@
169175
primaryColor: state => state.app.color,
170176
colorWeak: state => state.app.weak,
171177
fixedHeader: state => state.app.fixedHeader,
178+
fixedSideMenu: state => state.app.fixedSideMenu,
172179
swipeDownHiddenHeader: state => state.app.swipeDownHiddenHeader,
173180
})
174181
},
@@ -219,6 +226,9 @@
219226
},
220227
handleFixedHeaderHidden (autoHidden) {
221228
this.$store.dispatch('ToggleFixedHeaderHidden', autoHidden)
229+
},
230+
handleFixedSideMenu (fixed) {
231+
this.$store.dispatch('ToggleFixedSidemenu', fixed)
222232
}
223233
},
224234
}

src/defaultConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default {
1515
navTheme: 'dark', // theme for nav menu
1616
layout: 'sidemenu',
1717
fixedHeader: false, // fixed header
18+
fixedSideMenu: false,
1819
swipeDownHiddenHeader: false,
1920
colorWeak: false,
2021
// vue-ls options

src/main.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ import 'ant-design-vue/dist/antd.less'; // or 'ant-design-vue/dist/antd.less'
1313
import '@/permission' // permission control
1414
import '@/utils/filter' // base filter
1515

16-
import { ACCESS_TOKEN, DEFAULT_COLOR, DEFAULT_THEME, DEFAULT_LAYOUT_MODE, DEFAULT_COLOR_WEAK, SIDEBAR_TYPE, DEFAULT_FIXED_HEADER, DEFAULT_FIXED_HEADER_HIDDEN } from "@/store/mutation-types"
16+
import {
17+
ACCESS_TOKEN,
18+
DEFAULT_COLOR,
19+
DEFAULT_THEME,
20+
DEFAULT_LAYOUT_MODE,
21+
DEFAULT_COLOR_WEAK,
22+
SIDEBAR_TYPE,
23+
DEFAULT_FIXED_HEADER,
24+
DEFAULT_FIXED_HEADER_HIDDEN,
25+
DEFAULT_FIXED_SIDEMENU
26+
} from "@/store/mutation-types"
1727
import config from '@/defaultConfig'
1828

1929
Vue.config.productionTip = false
@@ -27,10 +37,11 @@ new Vue({
2737
router,
2838
store,
2939
mounted () {
30-
store.commit('SET_SIDEBAR_TYPE', Vue.ls.get(SIDEBAR_TYPE, false))
40+
store.commit('SET_SIDEBAR_TYPE', Vue.ls.get(SIDEBAR_TYPE, true))
3141
store.commit('TOGGLE_THEME', Vue.ls.get(DEFAULT_THEME, config.navTheme))
3242
store.commit('TOGGLE_LAYOUT_MODE', Vue.ls.get(DEFAULT_LAYOUT_MODE, config.layout))
3343
store.commit('TOGGLE_FIXED_HEADER', Vue.ls.get(DEFAULT_FIXED_HEADER, config.fixedHeader))
44+
store.commit('TOGGLE_FIXED_SIDEMENU', Vue.ls.get(DEFAULT_FIXED_SIDEMENU, config.fixedSideMenu))
3445
store.commit('TOGGLE_FIXED_HEADER_HIDDEN', Vue.ls.get(DEFAULT_FIXED_HEADER_HIDDEN, config.swipeDownHiddenHeader))
3546
store.commit('TOGGLE_WEAK', Vue.ls.get(DEFAULT_COLOR_WEAK, config.colorWeak))
3647
store.commit('TOGGLE_COLOR', Vue.ls.get(DEFAULT_COLOR, config.primaryColor))

src/store/modules/app.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Vue from 'vue'
2-
import { SIDEBAR_TYPE, DEFAULT_THEME, DEFAULT_LAYOUT_MODE, DEFAULT_COLOR, DEFAULT_COLOR_WEAK, DEFAULT_FIXED_HEADER, DEFAULT_FIXED_HEADER_HIDDEN } from "@/store/mutation-types"
2+
import { SIDEBAR_TYPE, DEFAULT_THEME, DEFAULT_LAYOUT_MODE, DEFAULT_COLOR, DEFAULT_COLOR_WEAK, DEFAULT_FIXED_HEADER, DEFAULT_FIXED_SIDEMENU, DEFAULT_FIXED_HEADER_HIDDEN } from "@/store/mutation-types"
33

44
const app = {
55
state: {
@@ -11,6 +11,7 @@ const app = {
1111
theme: '',
1212
layout: '',
1313
fixedHeader: false,
14+
fixedSideMenu: false,
1415
swipeDownHiddenHeader: false,
1516
color: null,
1617
weak: false
@@ -41,6 +42,10 @@ const app = {
4142
Vue.ls.set(DEFAULT_FIXED_HEADER, fixed)
4243
state.fixedHeader = fixed
4344
},
45+
TOGGLE_FIXED_SIDEMENU: (state, fixed) => {
46+
Vue.ls.set(DEFAULT_FIXED_SIDEMENU, fixed)
47+
state.fixedSideMenu = fixed
48+
},
4449
TOGGLE_FIXED_HEADER_HIDDEN: (state, show) => {
4550
Vue.ls.set(DEFAULT_FIXED_HEADER_HIDDEN, show)
4651
state.swipeDownHiddenHeader = show
@@ -74,6 +79,9 @@ const app = {
7479
ToggleFixedHeader({ commit }, fixedHeader) {
7580
commit('TOGGLE_FIXED_HEADER', fixedHeader)
7681
},
82+
ToggleFixedSidemenu({ commit }, fixedSideMenu) {
83+
commit( 'TOGGLE_FIXED_SIDEMENU', fixedSideMenu)
84+
},
7785
ToggleFixedHeaderHidden({ commit }, show) {
7886
commit('TOGGLE_FIXED_HEADER_HIDDEN', show)
7987
},

src/store/mutation-types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export const DEFAULT_LAYOUT_MODE = 'DEFAULT_LAYOUT_MODE'
55
export const DEFAULT_COLOR = 'DEFAULT_COLOR'
66
export const DEFAULT_COLOR_WEAK = 'DEFAULT_COLOR_WEAK'
77
export const DEFAULT_FIXED_HEADER = 'DEFAULT_FIXED_HEADER'
8+
export const DEFAULT_FIXED_SIDEMENU= 'DEFAULT_FIXED_SIDEMENU'
89
export const DEFAULT_FIXED_HEADER_HIDDEN = 'DEFAULT_FIXED_HEADER_HIDDEN'

0 commit comments

Comments
 (0)