rkljw 4 days ago
parent
commit
9e5eb4a26f
2 changed files with 25 additions and 2 deletions
  1. 8 2
      src/permission.js
  2. 17 0
      src/utils/auth.js

+ 8 - 2
src/permission.js

@@ -3,7 +3,7 @@ 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, setUseType,setWebSiteId} 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'
@@ -25,13 +25,19 @@ 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)
-        setUserUrl(URL.webUrl, 86400)  
         next({ path: '/' })
         NProgress.done() // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
       }else{

+ 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
+}
+