2019-07-25 10:30:30 +08:00
|
|
|
import Cookies from 'js-cookie';
|
2019-07-02 16:29:52 +08:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
sidebar: {
|
|
|
|
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
|
|
|
|
withoutAnimation: false
|
|
|
|
},
|
|
|
|
device: 'desktop'
|
2019-07-25 10:30:30 +08:00
|
|
|
};
|
2019-07-02 16:29:52 +08:00
|
|
|
|
|
|
|
const mutations = {
|
|
|
|
TOGGLE_SIDEBAR: state => {
|
2019-07-25 10:30:30 +08:00
|
|
|
state.sidebar.opened = !state.sidebar.opened;
|
|
|
|
state.sidebar.withoutAnimation = false;
|
2019-07-02 16:29:52 +08:00
|
|
|
if (state.sidebar.opened) {
|
2019-07-25 10:30:30 +08:00
|
|
|
Cookies.set('sidebarStatus', 1);
|
2019-07-02 16:29:52 +08:00
|
|
|
} else {
|
2019-07-25 10:30:30 +08:00
|
|
|
Cookies.set('sidebarStatus', 0);
|
2019-07-02 16:29:52 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
CLOSE_SIDEBAR: (state, withoutAnimation) => {
|
2019-07-25 10:30:30 +08:00
|
|
|
Cookies.set('sidebarStatus', 0);
|
|
|
|
state.sidebar.opened = false;
|
|
|
|
state.sidebar.withoutAnimation = withoutAnimation;
|
2019-07-02 16:29:52 +08:00
|
|
|
},
|
|
|
|
TOGGLE_DEVICE: (state, device) => {
|
2019-07-25 10:30:30 +08:00
|
|
|
state.device = device;
|
2019-07-02 16:29:52 +08:00
|
|
|
}
|
2019-07-25 10:30:30 +08:00
|
|
|
};
|
2019-07-02 16:29:52 +08:00
|
|
|
|
|
|
|
const actions = {
|
|
|
|
toggleSideBar({ commit }) {
|
2019-07-25 10:30:30 +08:00
|
|
|
commit('TOGGLE_SIDEBAR');
|
2019-07-02 16:29:52 +08:00
|
|
|
},
|
|
|
|
closeSideBar({ commit }, { withoutAnimation }) {
|
2019-07-25 10:30:30 +08:00
|
|
|
commit('CLOSE_SIDEBAR', withoutAnimation);
|
2019-07-02 16:29:52 +08:00
|
|
|
},
|
|
|
|
toggleDevice({ commit }, device) {
|
2019-07-25 10:30:30 +08:00
|
|
|
commit('TOGGLE_DEVICE', device);
|
2019-07-02 16:29:52 +08:00
|
|
|
}
|
2019-07-25 10:30:30 +08:00
|
|
|
};
|
2019-07-02 16:29:52 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state,
|
|
|
|
mutations,
|
|
|
|
actions
|
2019-07-25 10:30:30 +08:00
|
|
|
};
|