import { createStore } from "vuex"; import createPersistedState from "vuex-persistedstate"; import { logOutProc } from "../../resources/api/logOut" export default createStore({ plugins: [createPersistedState()], state: { authorization: null, // refresh: null, userType: "company", menu: null, path: null, roles: [{authority: "ROLE_NONE"}], pageAuth: null }, getters: { getAuthorization: function () {}, // getRefresh: function () {}, getMbrNm: function () {}, getRoles: function () {}, }, mutations: { setAuthorization(state, newValue) { state.authorization = newValue; }, // setRefresh(state, newValue) { // state.refresh = newValue; // }, setMbrNm(state, newValue) { state.mbrNm = newValue; }, setMbrId(state, newValue) { state.mbrId = newValue; }, setRoles(state, newValue) { state.roles = newValue; }, setUserType(state, newValue) { state.userType = newValue; }, setMenu(state, newValue) { state.menu = newValue; }, setPath(state, newValue) { state.path = newValue; }, setStoreReset(state) { state.authorization = null; // state.refresh = null; state.mbrNm = null; state.mbrId = null; state.roles = [{authority: "ROLE_NONE"}]; state.menu = null; state.pageAuth = null; }, setPageAuth(state, newValue) { state.pageAuth = newValue; } }, actions: { async logout({ commit }) { try { const res = await logOutProc(); alert(res.data.message); if (res.status == 200) { commit("setStoreReset"); } } catch(error) { const errorData = error.response.data; if (errorData.message != null && errorData.message != "") { alert(error.response.data.message); } else { alert("에러가 발생했습니다.\n관리자에게 문의해주세요."); } } }, setUserType({ commit }, userType) { commit("setUserType", userType); }, setMenu({ commit }, menu) { commit("setMenu", menu); }, setPath({ commit }, path) { commit("setPath", path); }, setPageAuth({ commit }, pageAuth) { commit("setPageAuth", pageAuth); }, setStoreReset({commit}) { commit("setStoreReset"); } }, });