|
@@ -3,10 +3,10 @@ import store from './store'
|
|
|
import { Message } from 'element-ui'
|
|
|
import NProgress from 'nprogress' // progress bar
|
|
|
import 'nprogress/nprogress.css' // progress bar style
|
|
|
-import { getToken,setUserUrl } from '@/utils/auth' // get token from cookie
|
|
|
+import { getToken,setUserUrl, setUseType,setWebSiteId,hashParams} from '@/utils/auth' // get token from cookie
|
|
|
import getPageTitle from '@/utils/get-page-title'
|
|
|
import URL from '@/utils/baseUrl';
|
|
|
-
|
|
|
+import {getInfo} from '@/api/user'
|
|
|
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
|
|
|
|
|
const whiteList = ['/login', '/auth-redirect'] // no redirect whitelist
|
|
@@ -25,9 +25,28 @@ router.beforeEach(async(to, from, next) => {
|
|
|
|
|
|
if (hasToken) {
|
|
|
if (to.path === '/login') {
|
|
|
+
|
|
|
+ // Retrieve userurl
|
|
|
+ const userurl = hashParams();
|
|
|
+ if(userurl){
|
|
|
+ setUserUrl(userurl, 86400)
|
|
|
+ }
|
|
|
+
|
|
|
+ const userInfo = await getInfo();
|
|
|
+ console.log("User Info:", userInfo);
|
|
|
+ if (userInfo.code === 200) {
|
|
|
+ console.log("####")
|
|
|
+ setUseType(userInfo.data.userType, 86400)
|
|
|
+ setWebSiteId(userInfo.data.siteId, 86400)
|
|
|
+ next({ path: '/' })
|
|
|
+ NProgress.done() // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
|
|
|
+ }else{
|
|
|
+ next({ path: '/' })
|
|
|
+ NProgress.done() // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
|
|
|
+ }
|
|
|
// if is logged in, redirect to the home page
|
|
|
- next({ path: '/' })
|
|
|
- NProgress.done() // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
|
|
|
+
|
|
|
+
|
|
|
} else {
|
|
|
// determine whether the user has obtained his permission roles through getInfo
|
|
|
const hasRoles = store.getters.roles && store.getters.roles.length > 0
|
|
@@ -48,6 +67,10 @@ router.beforeEach(async(to, from, next) => {
|
|
|
// hack method to ensure that addRoutes is complete
|
|
|
// set the replace: true, so the navigation will not leave a history record
|
|
|
next({ ...to, replace: true })
|
|
|
+
|
|
|
+ // Call getInfo to fetch user information
|
|
|
+ const userInfo = await getInfo();
|
|
|
+ console.log("User Info:", userInfo);
|
|
|
} catch (error) {
|
|
|
// remove token and go to login page to re-login
|
|
|
await store.dispatch('user/resetToken')
|