import { UserAPI } from '@/api'; import { ActionTree, Module, MutationTree } from 'vuex'; import { RootState, UserState } from '../typings'; const DEFAULT: UserState = { username: 'GUEST', email: '', id: -1, phone: '', role: 'GUEST', }; const actions: ActionTree = { async updateUserInfo({ commit }) { const res = (await UserAPI.getUserInfo()) as unknown as { user_info: UserState; }; commit('updateUserInfo', res.user_info); }, userLogOut({ commit }) { commit('updateUserInfo', DEFAULT); }, }; const mutations: MutationTree = { updateUserInfo(state, { name, email, id, phone, role, }) { state.username = name; state.email = email; state.id = id; state.phone = phone; state.role = role; }, }; export const user: Module = { state: () => DEFAULT, actions, mutations, };