4b4f5d50 by 任超

feat:获取用户信息

1 parent 5e04abed
import request from '@/utils/request'
import SERVER from './config'
// export function getMenuInfo () {
// return request({
// url: SERVER.SERVERAPI + '/rest/user/getUserMenus',
// method: 'get',
// })
// }
// 获取用户信息
export function getUserInfo () {
return request({
url: SERVER.SERVERAPI + '/rest/user/getUserInfo',
method: 'get',
})
}
// 获取菜单信息
export function getMenuInfo () {
return request({
url: SERVER.SERVERAPI + '/rest/user/getUserAuthorizationMenus',
......
......@@ -103,8 +103,8 @@ export default {
display: flex;
align-items: center;
width: 100%;
line-height: 32px;
height: 32px;
height: 28px;
line-height: 28px;
background: rgba(0, 0, 0, 0.1);
.icon {
......
......@@ -5,7 +5,6 @@ import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import getPageTitle from '@/utils/get-page-title'
import Cookies from 'js-cookie'
NProgress.configure({ showSpinner: false }) // NProgress Configuration
router.beforeEach(async (to, from, next) => {
......@@ -22,6 +21,8 @@ router.beforeEach(async (to, from, next) => {
} else {
const { result: getMenuData } = await getMenuInfo()
const accessRoutes = await store.dispatch('permission/generateRoutes', getMenuData)
// 获取用户信息
await store.dispatch('user/getUserInfo')
router.addRoutes([...accessRoutes, { path: '*', redirect: '/404', hidden: true }])
const routeTo = Cookies.get('routerTo')
console.log(routeTo)
......@@ -32,7 +33,6 @@ router.beforeEach(async (to, from, next) => {
}
}
NProgress.done()
})
router.afterEach(to => {
// 解决刷新页面报404问题
......
import store from '../index'
import router, { resetRouter } from '@/router'
import Cookies from 'js-cookie';
import { getUserInfo } from '@/api/user'
const state = {
name: Cookies.get('username'),
name: '',
avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
userInfo: null
}
const mutations = {
SET_NAME: (state, name) => {
state.name = name
},
SET_AVATAR: (state, avatar) => {
state.avatar = avatar
},
SET_USERINFO: (state, userInfo) => {
state.userInfo = userInfo
}
}
const actions = {
getUserInfo ({ commit }) {
return new Promise(async (resolve) => {
let { result: res } = await getUserInfo()
commit('SET_NAME', res.loginName)
resolve(true)
})
},
}
export default {
namespaced: true,
......