File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
import { createStore } from 'vuex';
export default createStore({
state: {
token: null,
userId: null,
authcd: null,
stdId: null,
schdlId: null,
bookId: null,
unitId: null,
},
getters: {
isLoggedIn(state) {
return !!state.token;
},
getUserInfo(state) {
return {
userId: state.userId,
authcd: state.authcd,
};
},
getStdId(state) {
return state.stdId;
},
getSchdlId(state) {
return state.schdlId;
},
getBookId(state) {
return state.bookId;
},
getUnitId(state) {
return state.unitId;
},
},
mutations: {
setToken(state, token) {
state.token = token;
},
clearToken(state) {
state.token = null;
state.userId = null;
state.authcd = null;
state.stdId = null;
state.schdlId = null;
state.bookId = null;
state.unitId = null;
},
setUser(state, userId) {
state.userId = userId;
},
setAuthcd(state, authcd) {
state.authcd = authcd;
},
setStdId(state, stdId) {
state.stdId = stdId;
},
setSchdlId(state, schdlId) {
state.schdlId = schdlId;
},
setBookId(state, bookId) {
state.bookId = bookId;
},
setUnitId(state, unitId) {
state.unitId = unitId;
}
},
actions: {
login({ commit }, token) {
commit('setToken', token);
localStorage.setItem('token', token);
},
logout({ commit }) {
commit('clearToken');
localStorage.removeItem('token');
},
updateStdId({ commit }, payload) {
return new Promise((resolve) => {
commit('setStdId', payload);
resolve();
});
},
updateSchdlId({ commit }, payload) {
return new Promise((resolve) => {
commit('setSchdlId', payload);
resolve();
});
},
updateBookId({ commit }, payload) {
return new Promise((resolve) => {
commit('setBookId', payload);
resolve();
});
},
updateUnitId({ commit }, payload) {
return new Promise((resolve) => {
commit('setUnitId', payload);
resolve();
});
}
}
});