From bd332b9a03aef5d1304267a6be50561d8a6f6943 Mon Sep 17 00:00:00 2001
From: suerprisePlus <15810472099@163.com>
Date: 星期五, 29 十一月 2024 09:40:22 +0800
Subject: [PATCH] 前端跳转地址优化

---
 se-ui/src/utils/request.js             |    2 
 se-ui/src/layout/components/Navbar.vue |    2 
 se-ui/src/permission.js                |   97 +++++++++++++++++++++++++-----------------------
 3 files changed, 52 insertions(+), 49 deletions(-)

diff --git a/se-ui/src/layout/components/Navbar.vue b/se-ui/src/layout/components/Navbar.vue
index acc5355..5cb7bc6 100644
--- a/se-ui/src/layout/components/Navbar.vue
+++ b/se-ui/src/layout/components/Navbar.vue
@@ -105,7 +105,7 @@
           this.$store.dispatch("LogOut").then(() => {
               console.log(process.env.NODE_ENV);
             if (process.env.NODE_ENV == "development") {
-              window.location.href = "http://localhost:8080/login";
+              window.location.href =  window.location.origin + "/login";
             } else if (process.env.NODE_ENV == "production") {
               window.location.href = window.location.origin + "/sso/login";
             }
diff --git a/se-ui/src/permission.js b/se-ui/src/permission.js
index bec8366..f183ebf 100644
--- a/se-ui/src/permission.js
+++ b/se-ui/src/permission.js
@@ -1,73 +1,76 @@
-import router from './router'
-import store from './store'
-import { Message } from 'element-ui'
-import NProgress from 'nprogress'
-import 'nprogress/nprogress.css'
-import { getToken } from '@/utils/auth'
-import { isRelogin } from '@/utils/request'
+import router from "./router";
+import store from "./store";
+import { Message } from "element-ui";
+import NProgress from "nprogress";
+import "nprogress/nprogress.css";
+import { getToken } from "@/utils/auth";
+import { isRelogin } from "@/utils/request";
 
-NProgress.configure({ showSpinner: false })
+NProgress.configure({ showSpinner: false });
 
-const whiteList = ['/login', '/register']
+const whiteList = ["/login", "/register"];
 
 router.beforeEach((to, from, next) => {
-  NProgress.start()
+  NProgress.start();
   if (getToken()) {
-    to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
+    to.meta.title && store.dispatch("settings/setTitle", to.meta.title);
     /* has token*/
-    if (to.path === '/login') {
-      if (process.env.NODE_ENV == 'development') {
-        window.location.href = 'http://localhost:8080/login'
-      } else if (process.env.NODE_ENV == 'production') {
-        window.location.href = window.location.origin + '/sso/login'
+    if (to.path === "/login") {
+      if (process.env.NODE_ENV == "development") {
+        window.location.href = window.location.origin + "/login";
+      } else if (process.env.NODE_ENV == "production") {
+        window.location.href = window.location.origin + "/sso/login";
       }
       // next({ path: '/' })
-      NProgress.done()
+      NProgress.done();
     } else if (whiteList.indexOf(to.path) !== -1) {
-      next()
+      next();
     } else {
       if (store.getters.roles.length === 0) {
-        isRelogin.show = true
+        isRelogin.show = true;
         // 鍒ゆ柇褰撳墠鐢ㄦ埛鏄惁宸叉媺鍙栧畬user_info淇℃伅
-        store.dispatch('GetInfo').then(() => {
-          isRelogin.show = false
-          store.dispatch('GenerateRoutes').then(accessRoutes => {
-            // 鏍规嵁roles鏉冮檺鐢熸垚鍙闂殑璺敱琛�
-            router.addRoutes(accessRoutes) // 鍔ㄦ�佹坊鍔犲彲璁块棶璺敱琛�
-            next({ ...to, replace: true }) // hack鏂规硶 纭繚addRoutes宸插畬鎴�
+        store
+          .dispatch("GetInfo")
+          .then(() => {
+            isRelogin.show = false;
+            store.dispatch("GenerateRoutes").then((accessRoutes) => {
+              // 鏍规嵁roles鏉冮檺鐢熸垚鍙闂殑璺敱琛�
+              router.addRoutes(accessRoutes); // 鍔ㄦ�佹坊鍔犲彲璁块棶璺敱琛�
+              next({ ...to, replace: true }); // hack鏂规硶 纭繚addRoutes宸插畬鎴�
+            });
           })
-        }).catch(err => {
-          store.dispatch('LogOut').then(() => {
-            Message.error(err)
-            console.log(process.env.NODE_ENV);
-            if (process.env.NODE_ENV == 'development') {
-              window.location.href = 'http://localhost:8080/login'
-            } else if (process.env.NODE_ENV == 'production') {
-              window.location.href = window.location.origin + '/sso/login'
-            }
-            // next({ path: '/' })
-          })
-        })
+          .catch((err) => {
+            store.dispatch("LogOut").then(() => {
+              Message.error(err);
+              console.log(process.env.NODE_ENV);
+              if (process.env.NODE_ENV == "development") {
+                window.location.href = window.location.origin + "/login";
+              } else if (process.env.NODE_ENV == "production") {
+                window.location.href = window.location.origin + "/sso/login";
+              }
+              // next({ path: '/' })
+            });
+          });
       } else {
-        next()
+        next();
       }
     }
   } else {
     // 娌℃湁token
     if (whiteList.indexOf(to.path) !== -1) {
       // 鍦ㄥ厤鐧诲綍鐧藉悕鍗曪紝鐩存帴杩涘叆
-      next()
+      next();
     } else {
-      if (process.env.NODE_ENV == 'development') {
-        window.location.href = 'http://localhost:8080/login'
-      } else if (process.env.NODE_ENV == 'production') {
-        window.location.href = window.location.origin + '/sso/login'
+      if (process.env.NODE_ENV == "development") {
+        window.location.href =  window.location.origin + "/login";
+      } else if (process.env.NODE_ENV == "production") {
+        window.location.href = window.location.origin + "/sso/login";
       }
-      NProgress.done()
+      NProgress.done();
     }
   }
-})
+});
 
 router.afterEach(() => {
-  NProgress.done()
-})
+  NProgress.done();
+});
diff --git a/se-ui/src/utils/request.js b/se-ui/src/utils/request.js
index f93db4f..5ee16be 100644
--- a/se-ui/src/utils/request.js
+++ b/se-ui/src/utils/request.js
@@ -90,7 +90,7 @@
         store.dispatch('LogOut').then(() => {
           console.log(process.env.NODE_ENV);
           if (process.env.NODE_ENV == "development") {
-            window.location.href = "http://localhost:8080/login";
+            window.location.href =  window.location.origin + "/login";
           } else if (process.env.NODE_ENV == "production") {
 
             window.location.href = window.location.origin + "/sso/login";

--
Gitblit v1.9.3