wangguoyu 1 giorno fa
parent
commit
cada78943b
1 ha cambiato i file con 24 aggiunte e 33 eliminazioni
  1. 24 33
      utils/request.js

+ 24 - 33
utils/request.js

@@ -12,6 +12,7 @@ import {
 } from '@/utils/common'
 
 let timeout = 20000
+let isShowingLoginExpired = false
 const baseUrl = config.baseUrl
 const request = config => {
 
@@ -50,40 +51,30 @@ const request = config => {
 				const code = res.code
 				const msg = res.msg
 				// const msg = errorCode[code] || res.data.msg || errorCode['default']
-				if (code === 401) {
-					showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
-						if (res.confirm) {
-							const auth = cacheManager.get('auth')
-							if (auth.type == 2 || auth.type == 5) {
-								uni.reLaunch({
-									url: '/pages/Login/index'
-								})
-							} else {
-								uni.reLaunch({
-									url: '/pages/Login/clientIndex'
-								})
-							}
-						
-						}
-					})
-					reject('无效的会话,或者会话已过期,请重新登录。')
-				} else if (code === 405) {
-					showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
-						if (res.confirm) {
-							const auth = cacheManager.get('auth')
-							if (auth.type == 2 || auth.type == 5) {
-								uni.reLaunch({
-									url: '/pages/Login/index'
-								})
-							} else {
-								uni.reLaunch({
-									url: '/pages/Login/clientIndex'
-								})
-							}
-							
-						}
 
-					})
+				if (code == 401 || code == 405) {
+					// 如果已经在显示弹窗,就不再显示新的
+					if (!isShowingLoginExpired) {
+						isShowingLoginExpired = true
+						showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
+							// 弹窗关闭后重置状态
+							isShowingLoginExpired = false
+							if (res.confirm) {
+								const auth = cacheManager.get('auth')
+								if (auth.type == 2 || auth.type == 5) {
+									uni.reLaunch({
+										url: '/pages/Login/index'
+									})
+								} else {
+									uni.reLaunch({
+										url: '/pages/Login/clientIndex'
+									})
+								}
+							}
+						}).finally(() => {
+							isShowingLoginExpired = false
+						})
+					}
 					reject('无效的会话,或者会话已过期,请重新登录。')
 				} else if (code === 500) {
 					toast("数据异常-500")