码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-07-05 13:14:28      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:mic   port   closed   reject   UNC   isp   比较   简单   测试   

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

首先将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 = data.currentUser.roles

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

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

技术图片

代码备份

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

标签:mic   port   closed   reject   UNC   isp   比较   简单   测试   

原文地址:https://www.cnblogs.com/liessay/p/13245718.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!