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

70 lines
1.5 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',
course: [],
courseDetail: {},
ruleList: []
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
},
HANDLECOURSE: (state, course) => {
state.course = course;
},
HANDLECOURSEDETAIL: (state, courseDetail) => {
state.courseDetail = courseDetail;
},
HANDLERULELIST: (state, ruleList) => {
state.ruleList = ruleList;
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
},
handleCourse({ commit }, course) {
commit('HANDLECOURSE', course);
},
handleCourseDetail({ commit }, courseDetail) {
commit('HANDLECOURSEDETAIL', courseDetail);
},
handleRuleList({ commit }, ruleList) {
commit('HANDLERULELIST', ruleList);
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
};