| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- 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<UserState, RootState> = {
- 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<UserState> = {
- 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<UserState, RootState> = {
- state: () => DEFAULT,
- actions,
- mutations,
- };
|