rkljw 5 days ago
parent
commit
5baea63b86
2 changed files with 14 additions and 2 deletions
  1. BIN
      dist.zip
  2. 14 2
      src/permission.js

BIN
dist.zip


+ 14 - 2
src/permission.js

@@ -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} 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,7 +25,15 @@ router.beforeEach(async(to, from, next) => {
 
   if (hasToken) {
     if (to.path === '/login') {
+      const userInfo = await getInfo();
+      // console.log("User Info:", userInfo);
+      if (userInfo.status === 200) {
+        setUseType(userInfo.data.userType, 86400)
+        setWebSiteId(userInfo.data.siteId, 86400)
+        setUserUrl(URL.webUrl, 86400)  
+      }
       // if is logged in, redirect to the home page
+
       next({ path: '/' })
       NProgress.done() // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
     } else {
@@ -48,6 +56,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')