

export const state = () => ({
  nickName: '',
  userAvatar: '',
  userId: ''
})

export const mutations = {
  /** 保存用户信息 **/
  SET_USER (state, user) {
    state.nickName = user.nickName
    state.userAvatar = user.userAvatar
    state.userId = user.userId
  }
}

export const actions = {
  setUser ({ commit }) {
    return new Promise((resolve, reject) => {
      this.$axios.get('/p/user/userInfo', {
      }).then(({ data }) => {
        const user = {
          nickName: data.nickName,
          userAvatar: data.pic,
          userId: data.userId
        }
        commit('SET_USER', user)
        resolve(user)
      }).catch(error => {
        reject(error)
      })
    })
  }
}