| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 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<UserState, RootState> = {
- async updateUserInfo({ commit }) {
- const userinfo = await UserAPI.getUserInfo();
- if (!userinfo) {
- return;
- }
- commit('updateUserInfo', userinfo);
- },
- userLogOut({ commit }) {
- commit('updateUserInfo', DEFAULT);
- },
- };
- const mutations: MutationTree<UserState> = {
- 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<UserState, RootState> = {
- state: () => DEFAULT,
- actions,
- mutations,
- };
|