feat:获取用户信息
Showing
4 changed files
with
23 additions
and
21 deletions
| 1 | import request from '@/utils/request' | 1 | import request from '@/utils/request' |
| 2 | import SERVER from './config' | 2 | import SERVER from './config' |
| 3 | // export function getMenuInfo () { | 3 | |
| 4 | // return request({ | 4 | // 获取用户信息 |
| 5 | // url: SERVER.SERVERAPI + '/rest/user/getUserMenus', | 5 | export function getUserInfo () { |
| 6 | // method: 'get', | 6 | return request({ |
| 7 | // }) | 7 | url: SERVER.SERVERAPI + '/rest/user/getUserInfo', |
| 8 | // } | 8 | method: 'get', |
| 9 | }) | ||
| 10 | } | ||
| 11 | |||
| 12 | // 获取菜单信息 | ||
| 9 | export function getMenuInfo () { | 13 | export function getMenuInfo () { |
| 10 | return request({ | 14 | return request({ |
| 11 | url: SERVER.SERVERAPI + '/rest/user/getUserAuthorizationMenus', | 15 | url: SERVER.SERVERAPI + '/rest/user/getUserAuthorizationMenus', | ... | ... |
| ... | @@ -103,8 +103,8 @@ export default { | ... | @@ -103,8 +103,8 @@ export default { |
| 103 | display: flex; | 103 | display: flex; |
| 104 | align-items: center; | 104 | align-items: center; |
| 105 | width: 100%; | 105 | width: 100%; |
| 106 | line-height: 32px; | 106 | height: 28px; |
| 107 | height: 32px; | 107 | line-height: 28px; |
| 108 | background: rgba(0, 0, 0, 0.1); | 108 | background: rgba(0, 0, 0, 0.1); |
| 109 | 109 | ||
| 110 | .icon { | 110 | .icon { | ... | ... |
| ... | @@ -5,7 +5,6 @@ import NProgress from 'nprogress' // progress bar | ... | @@ -5,7 +5,6 @@ import NProgress from 'nprogress' // progress bar |
| 5 | import 'nprogress/nprogress.css' // progress bar style | 5 | import 'nprogress/nprogress.css' // progress bar style |
| 6 | import getPageTitle from '@/utils/get-page-title' | 6 | import getPageTitle from '@/utils/get-page-title' |
| 7 | import Cookies from 'js-cookie' | 7 | import Cookies from 'js-cookie' |
| 8 | |||
| 9 | NProgress.configure({ showSpinner: false }) // NProgress Configuration | 8 | NProgress.configure({ showSpinner: false }) // NProgress Configuration |
| 10 | 9 | ||
| 11 | router.beforeEach(async (to, from, next) => { | 10 | router.beforeEach(async (to, from, next) => { |
| ... | @@ -22,6 +21,8 @@ router.beforeEach(async (to, from, next) => { | ... | @@ -22,6 +21,8 @@ router.beforeEach(async (to, from, next) => { |
| 22 | } else { | 21 | } else { |
| 23 | const { result: getMenuData } = await getMenuInfo() | 22 | const { result: getMenuData } = await getMenuInfo() |
| 24 | const accessRoutes = await store.dispatch('permission/generateRoutes', getMenuData) | 23 | const accessRoutes = await store.dispatch('permission/generateRoutes', getMenuData) |
| 24 | // 获取用户信息 | ||
| 25 | await store.dispatch('user/getUserInfo') | ||
| 25 | router.addRoutes([...accessRoutes, { path: '*', redirect: '/404', hidden: true }]) | 26 | router.addRoutes([...accessRoutes, { path: '*', redirect: '/404', hidden: true }]) |
| 26 | const routeTo = Cookies.get('routerTo') | 27 | const routeTo = Cookies.get('routerTo') |
| 27 | console.log(routeTo) | 28 | console.log(routeTo) |
| ... | @@ -32,7 +33,6 @@ router.beforeEach(async (to, from, next) => { | ... | @@ -32,7 +33,6 @@ router.beforeEach(async (to, from, next) => { |
| 32 | } | 33 | } |
| 33 | } | 34 | } |
| 34 | NProgress.done() | 35 | NProgress.done() |
| 35 | |||
| 36 | }) | 36 | }) |
| 37 | router.afterEach(to => { | 37 | router.afterEach(to => { |
| 38 | // 解决刷新页面报404问题 | 38 | // 解决刷新页面报404问题 | ... | ... |
| 1 | import store from '../index' | 1 | import { getUserInfo } from '@/api/user' |
| 2 | import router, { resetRouter } from '@/router' | ||
| 3 | import Cookies from 'js-cookie'; | ||
| 4 | const state = { | 2 | const state = { |
| 5 | name: Cookies.get('username'), | 3 | name: '', |
| 6 | avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png', | 4 | avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png', |
| 7 | userInfo: null | ||
| 8 | } | 5 | } |
| 9 | const mutations = { | 6 | const mutations = { |
| 10 | SET_NAME: (state, name) => { | 7 | SET_NAME: (state, name) => { |
| 11 | state.name = name | 8 | state.name = name |
| 12 | }, | ||
| 13 | SET_AVATAR: (state, avatar) => { | ||
| 14 | state.avatar = avatar | ||
| 15 | }, | ||
| 16 | SET_USERINFO: (state, userInfo) => { | ||
| 17 | state.userInfo = userInfo | ||
| 18 | } | 9 | } |
| 19 | } | 10 | } |
| 20 | 11 | ||
| 21 | const actions = { | 12 | const actions = { |
| 13 | getUserInfo ({ commit }) { | ||
| 14 | return new Promise(async (resolve) => { | ||
| 15 | let { result: res } = await getUserInfo() | ||
| 16 | commit('SET_NAME', res.loginName) | ||
| 17 | resolve(true) | ||
| 18 | }) | ||
| 19 | }, | ||
| 22 | } | 20 | } |
| 23 | export default { | 21 | export default { |
| 24 | namespaced: true, | 22 | namespaced: true, | ... | ... |
-
Please register or sign in to post a comment