Explorar o código

fix: 登录态过期路由跳转中增加redirect参数

lanjianrong %!s(int64=4) %!d(string=hai) anos
pai
achega
6eac976012
Modificáronse 3 ficheiros con 15 adicións e 8 borrados
  1. 1 1
      config/proxy.js
  2. 13 2
      src/app.tsx
  3. 1 5
      src/pages/User/Login/index.jsx

+ 1 - 1
config/proxy.js

@@ -8,7 +8,7 @@
 export default {
   dev: {
     '/api/': {
-      target: 'http://cld2qa.com',
+      target: 'http://cld2.com',
       changeOrigin: true,
       pathRewrite: {
         '^': ''

+ 13 - 2
src/app.tsx

@@ -11,6 +11,7 @@ import { getAuthCache, setAuthCache } from './utils/auth'
 import { LAYOUT_COLLAPSED_KEY } from './utils/cache/cacheEnum'
 import consts from './consts'
 import ModalStore from './components/ModalStore'
+import { stringify } from 'qs'
 
 const loginPath = '/user/login'
 
@@ -83,7 +84,12 @@ export const layout = ({ initialState, setInitialState }) => {
     onPageChange: async location => {
       // 如果没有登录,重定向到 login
       if (!initialState?.currentUser?.staffId && location.pathname !== loginPath) {
-        history.replace('/user/login')
+        history.replace({
+          pathname: loginPath,
+          search: stringify({
+            redirect: history.location.pathname
+          })
+        })
       } else {
         location.pathname !== loginPath &&
           tryChangeWorkStatus(initialState?.currentUser?.staffId, location.pathname)
@@ -101,7 +107,12 @@ const errorHandler = error => {
   if (info) {
     const { errorMessage = '请求失败', showType, errorCode } = info
     if (consts.TOKEN_INVALID_CODE.includes(errorCode)) {
-      history.replace(consts.LOGIN_PATH)
+      history.replace({
+        pathname: loginPath,
+        search: stringify({
+          redirect: window.location.pathname
+        })
+      })
     }
     switch (showType) {
       case ErrorShowType.ERROR_MESSAGE:

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

@@ -38,10 +38,6 @@ const Login = () => {
     const permData = await initialState?.fetchPermData?.()
     if (userInfo) {
       setInitialState({ ...initialState, ...userInfo, permData })
-      // const { username, staffId: id, wsToken: token } = userInfo?.currentUser
-      // ws.init(`ws://cld2qa.com/summon/v1/chat/link?username=${username}&id=${id}&token=${token}`, {
-      //   onMessage
-      // })
     }
     return userInfo
   }
@@ -52,7 +48,7 @@ const Login = () => {
     setTimeout(() => {
       const { query } = history.location
       const { redirect } = query
-      history.push(redirect || '/')
+      history.replace(redirect || '/')
       return notification.success({
         message: intl.formatMessage({ id: 'pages.login.success.title' }),
         description: redirect && `${intl.formatMessage({ id: 'pages.login.success.desc' })}: ${username}`,