From c0c0d75b2ed0191877d8cadfb39dedad6eabb407 Mon Sep 17 00:00:00 2001
From: chenzeping <ChenZeping02609@163.com>
Date: 星期二, 30 三月 2021 21:33:00 +0800
Subject: [PATCH] Merge branch 'develop' of http://xearth.cn:6600/r/wuyushui/SewerAndRainNetwork into develop

---
 src/router/index.js |   29 +++++++++++++++++++++++++----
 1 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/router/index.js b/src/router/index.js
index 32dae04..6bc1550 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -1,10 +1,11 @@
 import Vue from 'vue'
 import Router from 'vue-router'
 import { routes } from './routes'
+import { getToken } from '@/utils/navigation'
 import 'nprogress/nprogress.css'
 const appConfig = require('@/app.config')
-const { routeMode } = appConfig
-
+const { homeRouterName, loginRouteName, routeMode } = appConfig
+const LOGIN_PAGE_ROUTE_NAME = loginRouteName
 Vue.use(Router)
 const baseName = process.env.NODE_ENV === 'production' ? `/${appConfig.projectName}/` : '/'
 const router = new Router({
@@ -17,12 +18,32 @@
     cancel()
   })
   Vue.prototype.$cancels = []
+  const token = getToken()
+  if (!token && to.name !== LOGIN_PAGE_ROUTE_NAME) {
+    // 鏈櫥褰曚笖瑕佽烦杞殑椤甸潰涓嶆槸鐧诲綍椤�
+    next({
+      name: LOGIN_PAGE_ROUTE_NAME // 璺宠浆鍒扮櫥褰曢〉
+    })
+  } else if (!token && to.name === LOGIN_PAGE_ROUTE_NAME) {
+    // 鏈櫥闄嗕笖瑕佽烦杞殑椤甸潰鏄櫥褰曢〉
+    next() // 璺宠浆
+  } else if (token && to.name === LOGIN_PAGE_ROUTE_NAME) {
+    // 宸茬櫥褰曚笖瑕佽烦杞殑椤甸潰鏄櫥褰曢〉
+    next({
+      name: homeRouterName // 璺宠浆鍒癶omeName椤�
+    })
+  } else if (!token) {
+    next({
+      name: LOGIN_PAGE_ROUTE_NAME // 璺宠浆鍒扮櫥褰曢〉
+    })
+  } else {
+    next()
+  }
   // 涓嶉渶瑕佺櫥褰曡璇佺殑璺敱
   if (Object.hasOwnProperty.call(to.meta, 'noLoginIdentify') && to.meta.noLoginIdentify) {
     next()
-    return
   }
-  next()
+  // next()
 })
 router.beforeResolve((to, from, next) => {
   next()

--
Gitblit v1.8.0