All Downloads are FREE. Search and download functionalities are using the official Maven repository.

web.src.store.user.index.ts Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
// 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





© 2015 - 2024 Weber Informatics LLC | Privacy Policy