web.src.store.user.index.ts Maven / Gradle / Ivy
// import {adminGetAccountInfoApi, adminLoginApi} from "@/apis/core";
import { setToken } from "@/utils/token";
import {getAccountInfoApi, userLoginApi} from "@/apis/core";
const useUserStore = {
namespaced: true,
state: {
userInfo: {},
token: ''
},
mutations: {
setUserInfo(state: any, userInfo: any) {
state.userInfo = userInfo;
console.log( state.userInfo,' state.userInfo')
},
// 设置token
SET_TOKEN(state: any, token: string) {
state.token = token
}
},
actions: {
async logOut({commit}: any, data: any){
return new Promise(resolve => {
commit('SET_TOKEN','')
setToken('')
resolve('')
})
},
async login({commit}: any, data: any) {
return new Promise(resolve => {
userLoginApi(data).then(e => {
commit('SET_TOKEN', e)
setToken(e)
resolve(e)
})
})
},
getCode() {
},
/**
* 获取用户信息
* @param ctx
*/
getUserInfos({commit}: any) {
getAccountInfoApi().then(e => {
commit("setUserInfo", e)
})
}
},
}
export default useUserStore