import { useInfo } from '@/api/allApi'

const user = {
  state: {
    userInfo:{},
    avatar: '',
  },

  mutations: {
    SET_USERINFO: (state, userInfo) => {
      state.userInfo = userInfo
    },
    SET_AVATAR: (state, avatar) => {
      state.avatar = avatar
    },
  },

  actions: {
    // 获取用户信息
    GetUserInfo({ commit }) {
      return new Promise((resolve, reject) => {
        useInfo().then(response => {
          const data = response.data.data
          commit('SET_USERINFO', data)
          commit('SET_AVATAR', data.httpFile + data.headImage)
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
  }
}

export default user
