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: '游客', withGitlab: false, }; const actions: ActionTree = { async updateUserInfo({ commit }) { const userinfo = await UserAPI.getUserInfo(); if (!userinfo) { return; } commit('updateUserInfo', userinfo); }, userLogOut({ commit }) { commit('updateUserInfo', DEFAULT); }, }; const mutations: MutationTree = { updateUserInfo(state, { username, email, id, phone, role, }) { state.username = username; state.email = email; state.id = id; state.phone = phone; state.role = role; }, }; export const user: Module = { state: () => DEFAULT, actions, mutations, };