Explorar el Código

feat: 登录页跳转bug

lanjianrong hace 4 años
padre
commit
01815460eb
Se han modificado 2 ficheros con 18 adiciones y 9 borrados
  1. 13 6
      src/app.tsx
  2. 5 3
      src/pages/User/Login/index.jsx

+ 13 - 6
src/app.tsx

@@ -98,11 +98,12 @@ export const layout = ({ initialState, setInitialState }) => {
   }
 }
 
+let notificationLimit = 0 // 最大1
 const errorHandler = error => {
   const { data, info } = error
   if (info) {
     const { errorMessage = '请求失败', showType, errorCode } = info
-    if (consts.TOKEN_INVALID_CODE.includes(errorCode)) {
+    if (consts.TOKEN_INVALID_CODE.includes(errorCode) && window.location.pathname !== loginPath) {
       history.replace({
         pathname: loginPath,
         search: stringify({
@@ -118,11 +119,14 @@ const errorHandler = error => {
         message.warn(errorMessage)
         break
       case ErrorShowType.NOTIFICATION:
-        const title = consts.TOKEN_INVALID_CODE.includes(errorCode) ? '用户信息过期' : '请求失败'
-        notification.error({
-          message: title,
-          description: errorMessage
-        })
+        if (!notificationLimit) {
+          const title = consts.TOKEN_INVALID_CODE.includes(errorCode) ? '用户信息过期' : '请求失败'
+          notification.error({
+            message: title,
+            description: errorMessage
+          })
+          notificationLimit++
+        }
         break
       default:
         break
@@ -159,6 +163,9 @@ export const request: RequestConfig = {
   cache: 'no-cache',
   errorConfig: {
     adaptor: resData => {
+      if (resData.code === consts.RET_CODE.SUCCESS) {
+        notificationLimit = 0
+      }
       return {
         success: resData.code === consts.RET_CODE.SUCCESS,
         errorMessage: resData.msg,

+ 5 - 3
src/pages/User/Login/index.jsx

@@ -2,7 +2,7 @@ import { LockOutlined, UserOutlined } from '@ant-design/icons'
 import { Alert, message, notification, Tabs } from 'antd'
 import React, { useState } from 'react'
 import ProForm, { ProFormCheckbox, ProFormText } from '@ant-design/pro-form'
-import { useIntl, Link, history, FormattedMessage, SelectLang, useModel } from 'umi'
+import { useIntl, history, FormattedMessage, useModel } from 'umi'
 
 import styles from './index.less'
 import { apiLogin } from '@/services/login'
@@ -47,12 +47,14 @@ const Login = () => {
     if (!history) return
     const { query } = history.location
     const { redirect } = query
-    history.replace(redirect || '/')
-    return notification.success({
+    // 清除所有notification
+    notification.destroy()
+    notification.success({
       message: intl.formatMessage({ id: 'pages.login.success.title' }),
       description: redirect && `${intl.formatMessage({ id: 'pages.login.success.desc' })}: ${username}`,
       duration: 3
     })
+    return history.replace(redirect || '/')
   }
 
   const handleSubmit = async values => {