提交 | 用户 | 时间
|
fd2207
|
1 |
import Cookies from 'js-cookie' |
懒 |
2 |
|
|
3 |
const state = { |
|
4 |
sidebar: { |
|
5 |
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true, |
|
6 |
withoutAnimation: false, |
|
7 |
hide: false |
|
8 |
}, |
|
9 |
device: 'desktop', |
|
10 |
size: Cookies.get('size') || 'medium' |
|
11 |
} |
|
12 |
|
|
13 |
const mutations = { |
|
14 |
TOGGLE_SIDEBAR: state => { |
|
15 |
if (state.sidebar.hide) { |
|
16 |
return false; |
|
17 |
} |
|
18 |
state.sidebar.opened = !state.sidebar.opened |
|
19 |
state.sidebar.withoutAnimation = false |
|
20 |
if (state.sidebar.opened) { |
|
21 |
Cookies.set('sidebarStatus', 1) |
|
22 |
} else { |
|
23 |
Cookies.set('sidebarStatus', 0) |
|
24 |
} |
|
25 |
}, |
|
26 |
CLOSE_SIDEBAR: (state, withoutAnimation) => { |
|
27 |
Cookies.set('sidebarStatus', 0) |
|
28 |
state.sidebar.opened = false |
|
29 |
state.sidebar.withoutAnimation = withoutAnimation |
|
30 |
}, |
|
31 |
TOGGLE_DEVICE: (state, device) => { |
|
32 |
state.device = device |
|
33 |
}, |
|
34 |
SET_SIZE: (state, size) => { |
|
35 |
state.size = size |
|
36 |
Cookies.set('size', size) |
|
37 |
}, |
|
38 |
SET_SIDEBAR_HIDE: (state, status) => { |
|
39 |
state.sidebar.hide = status |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
const actions = { |
|
44 |
toggleSideBar({ commit }) { |
|
45 |
commit('TOGGLE_SIDEBAR') |
|
46 |
}, |
|
47 |
closeSideBar({ commit }, { withoutAnimation }) { |
|
48 |
commit('CLOSE_SIDEBAR', withoutAnimation) |
|
49 |
}, |
|
50 |
toggleDevice({ commit }, device) { |
|
51 |
commit('TOGGLE_DEVICE', device) |
|
52 |
}, |
|
53 |
setSize({ commit }, size) { |
|
54 |
commit('SET_SIZE', size) |
|
55 |
}, |
|
56 |
toggleSideBarHide({ commit }, status) { |
|
57 |
commit('SET_SIDEBAR_HIDE', status) |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
export default { |
|
62 |
namespaced: true, |
|
63 |
state, |
|
64 |
mutations, |
|
65 |
actions |
|
66 |
} |