Abp Vnext3 vue-admin-template(三获取用户信息)

因为获取用户比较简单,只需要把用户名及头像地址赋值即可(也许理解错误,如果发现请告知谢谢),

首先将src\api\usr.js中的url请求地址改为以下代码

export function getInfo(token) {
  return request({
    url: '/api/abp/application-configuration',
    method: 'get',
    params: { token }
  })
}

再将store\modules\user.js中getinfo方法改为以下代码

  // get user info
  getInfo({ commit, state }) {
    return new Promise((resolve, reject) => {
      getInfo(state.token).then(response => {
        const { data } = response

        if (!data) {
          reject('Verification failed, please Login again.')
        }

        const { roles, name, avatar, introduction } = data

        // roles must be a non-empty array
        if (!roles || roles.length <= 0) {
          reject('getInfo: roles must be a non-null array!')
        }

        commit('SET_ROLES', roles)
        commit('SET_NAME', name)
        commit('SET_AVATAR', avatar)
        commit('SET_INTRODUCTION', introduction)
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
修改前代码
  getInfo({ commit, state }) {
    return new Promise((resolve, reject) => {
      getInfo(state.token).then(response => {
        const { data } = response

        if (!data) {
          return reject('Verification failed, please Login again.')
        }

        this.name = data.currentUser.userName
        this.avatar = null

        commit('SET_NAME', this.name)
        commit('SET_AVATAR', this.avatar)
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

登录测试能正常显示用户名,为了能知道当前登录用户,我将用户名显示到了导航栏

代码备份

根据https://www.cnblogs.com/flypig666/p/11854538.html增加了一份带tagsview版本的下载地址

posted @ 2020-07-05 12:44  liessay  阅读(1200)  评论(0编辑  收藏  举报