rt-sim-training-client/src/store/modules/app.js

67 lines
1.4 KiB
JavaScript
Raw Normal View History

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
},
2019-07-26 13:32:43 +08:00
device: 'desktop',
2019-09-02 10:38:10 +08:00
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
windowSizeCount: 0
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-26 13:32:43 +08:00
},
2019-09-02 10:38:10 +08:00
SET_WIDTH: (state, width) => {
state.width = width;
2019-07-26 13:32:43 +08:00
},
2019-09-02 10:38:10 +08:00
SET_HEIGHT: (state, height) => {
state.height = height;
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-26 13:32:43 +08:00
},
2019-09-02 10:38:10 +08:00
resize({ state, commit }, opt) {
if (opt.width) {
commit('SET_WIDTH', opt.width);
}
if (opt.height) {
commit('SET_HEIGHT', opt.height);
}
state.windowSizeCount += 1;
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
};