From 190053520a9fd462595fcd9b1c63770500254237 Mon Sep 17 00:00:00 2001 From: non_hana <1209220829@qq.com> Date: Sun, 25 Aug 2024 23:07:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=84=9Ftok?= =?UTF-8?q?en=E5=88=B7=E6=96=B0=E9=89=B4=E6=9D=83=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/user-item/user-work-item.tsx | 2 +- .../common/work-favorite-item/index.tsx | 2 +- .../common/work-history-item/index.tsx | 2 +- src/components/common/work-rank-item/index.tsx | 2 +- src/service/request/index.ts | 17 ++++++++++++++--- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/components/common/user-item/user-work-item.tsx b/src/components/common/user-item/user-work-item.tsx index 32c4c16..dfbcbad 100644 --- a/src/components/common/user-item/user-work-item.tsx +++ b/src/components/common/user-item/user-work-item.tsx @@ -49,7 +49,7 @@ const UserWorkItem: FC = ({ itemInfo, like }) => { - {itemInfo.name} + {itemInfo.name ? itemInfo.name : '无题'} ) diff --git a/src/components/common/work-favorite-item/index.tsx b/src/components/common/work-favorite-item/index.tsx index fee2370..d63879e 100644 --- a/src/components/common/work-favorite-item/index.tsx +++ b/src/components/common/work-favorite-item/index.tsx @@ -120,7 +120,7 @@ const WorkFavoriteItem: FC = ({ - {itemInfo.name} + {itemInfo.name ? itemInfo.name : '无题'}
diff --git a/src/components/common/work-history-item/index.tsx b/src/components/common/work-history-item/index.tsx index 68d2176..ecccebf 100644 --- a/src/components/common/work-history-item/index.tsx +++ b/src/components/common/work-history-item/index.tsx @@ -37,7 +37,7 @@ const WorkHistoryItem: FC = ({ itemInfo, ...props }) => { - {itemInfo.name} + {itemInfo.name ? itemInfo.name : '无题'}
diff --git a/src/components/common/work-rank-item/index.tsx b/src/components/common/work-rank-item/index.tsx index 5a72395..b30fbac 100644 --- a/src/components/common/work-rank-item/index.tsx +++ b/src/components/common/work-rank-item/index.tsx @@ -53,7 +53,7 @@ const WorkRankItem: FC = ({ itemInfo, like }) => { - {itemInfo.name} + {itemInfo.name ? itemInfo.name : '无题'}
diff --git a/src/service/request/index.ts b/src/service/request/index.ts index 60e1026..c4c6798 100644 --- a/src/service/request/index.ts +++ b/src/service/request/index.ts @@ -1,4 +1,3 @@ -import { refreshTokenAPI } from '@/apis/user' import { notification } from 'antd' import axios from 'axios' import type { AxiosInstance, AxiosRequestConfig } from 'axios' @@ -53,7 +52,15 @@ class Request { try { refreshing = true const refreshToken = localStorage.getItem('refreshToken') - const { data } = await refreshTokenAPI({ refreshToken: refreshToken! }) + + const response = await axios({ + url: '/api/user/refresh-token', + method: 'GET', + params: { refreshToken: refreshToken }, + }) + + const data = response.data.data + localStorage.setItem('accessToken', data.access_token) localStorage.setItem('refreshToken', data.refresh_token) @@ -66,12 +73,16 @@ class Request { return this.instance.request(config) } catch (error) { notification.error({ - message: 'token已失效,请重新进行登录~', + message: 'token已失效', + description: '请重新进行登录~即将跳转到首页哦', }) pendingTasks.forEach((task) => { task.reject(error) }) pendingTasks.length = 0 // 清空队列 + setTimeout(() => { + window.location.href = '/login' + }, 2000) } finally { refreshing = false }