rkljw 4 өдөр өмнө
parent
commit
35c7e44edf
2 өөрчлөгдсөн 44 нэмэгдсэн , 4 устгасан
  1. 27 4
      src/permission.js
  2. 17 0
      src/utils/auth.js

+ 27 - 4
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,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')

+ 17 - 0
src/utils/auth.js

@@ -86,4 +86,21 @@ function convertSecondsToDays(seconds) {
   return seconds/(60*60*24); //1天=60秒*60分钟*24小时
 }
 
+// Function to parse hash parameters from the URL
+export function hashParams() {
+  const urlString = window.location.href;
+  const url = new URL(urlString);
+  const hash = url.hash;
+  const hashParams = new URLSearchParams(hash.split('?')[1]);
+  const userurl = hashParams.get('userurl');
+
+  if (userurl) {
+    // Create a URL object to extract the domain
+    const userUrlObject = new URL(userurl);
+    return userUrlObject.hostname; // Return only the domain
+  }
+
+  return null; // Return null if userurl is not present
+}
+