From b6c0dbb3efe61053e63a0b4ad227c9b4da2abc8f Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期二, 06 十二月 2022 14:00:31 +0800
Subject: [PATCH] 1.增加页签关闭时重新登录功能

---
 src/utils/request.js      |    1 +
 src/permission.js         |    2 +-
 src/store/modules/user.js |    4 +++-
 src/store/modules/app.js  |    4 +++-
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/permission.js b/src/permission.js
index fd74217..41717e7 100644
--- a/src/permission.js
+++ b/src/permission.js
@@ -19,7 +19,7 @@
 
   // determine whether the user has logged in
   // const hasToken = getToken()
-  const hasToken = getCookie('admin')
+  const hasToken = store.state.app.isGoToIndex
   if (hasToken) {
     if (to.path === '/login') {
       // if is logged in, redirect to the home page
diff --git a/src/store/modules/app.js b/src/store/modules/app.js
index a868bf9..19b8157 100644
--- a/src/store/modules/app.js
+++ b/src/store/modules/app.js
@@ -6,7 +6,8 @@
     withoutAnimation: false
   },
   device: 'desktop',
-  buttonIsDisabled: false // 鑷畾涔夊叏灞�鍙橀噺鍙傛暟  鎺у埗鎸夐挳鎻愪氦鏃禿isabled
+  buttonIsDisabled: false, // 鑷畾涔夊叏灞�鍙橀噺鍙傛暟  鎺у埗鎸夐挳鎻愪氦鏃禿isabled
+  isGoToIndex: false // 鑷畾涔夊叏灞�鍙橀噺鍙傛暟  鏄惁杩涘叆鍒扮郴缁熼椤�
 }
 
 const mutations = {
@@ -44,6 +45,7 @@
 export default {
   namespaced: true,
   buttonIsDisabled: false,
+  isGoToIndex: false,
   state,
   mutations,
   actions
diff --git a/src/store/modules/user.js b/src/store/modules/user.js
index e7e2267..462466b 100644
--- a/src/store/modules/user.js
+++ b/src/store/modules/user.js
@@ -1,6 +1,7 @@
 import { login, logout, getInfo, LoginMenu } from '@/api/user'
 import { getToken, setToken, removeToken, setCookie, removeCookie, getCookie } from '@/utils/auth'
 import { resetRouter } from '@/router'
+import store from '@/store'
 
 const getDefaultState = () => {
   return {
@@ -53,7 +54,7 @@
         // if (res.code === '302') {
         setCookie('code', res.code)
         // }
-
+        store.state.app.isGoToIndex = true
         // commit('SET_TOKEN', data.token)
         // setToken(res)
         // commit('SET_TOKEN', res)
@@ -116,6 +117,7 @@
 
       logout(data).then(res => {
         if (res.code === '200') {
+          store.state.app.isGoToIndex = false
           removeToken() // must remove  token  first
           resetRouter()
 
diff --git a/src/utils/request.js b/src/utils/request.js
index e95e5b7..5f7ded7 100644
--- a/src/utils/request.js
+++ b/src/utils/request.js
@@ -68,6 +68,7 @@
         removeCookie('rediskey')
         removeCookie('guid')
         removeCookie('code')
+        store.state.app.isGoToIndex = false
         setTimeout(() => {
           sessionStorage.removeItem('tabViews')
           window.location.reload()

--
Gitblit v1.9.3