aops-hermes/0005-fix-token-refresh-issue.patch
wkl505997900 2cf53c0c78 fix three issue
(cherry picked from commit bf501046ae3eccd63e7f3e733095cd176146c4ac)
2023-06-09 18:35:28 +08:00

158 lines
5.3 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From 6d60ace02d2a80c5ecc200e847963780cbc861cc Mon Sep 17 00:00:00 2001
From: wkl505997900 <2313665567@qq.com>
Date: Fri, 9 Jun 2023 17:50:01 +0800
Subject: [PATCH] fix tokenissue
---
src/vendor/ant-design-pro/utils/request.js | 64 +++++++++++++++++-----
src/vendor/ant-design-pro/utils/util.js | 16 ++++++
src/views/leaks/LeakTaskList.vue | 3 +-
src/views/leaks/components/HostTable.vue | 3 +-
4 files changed, 69 insertions(+), 17 deletions(-)
diff --git a/src/vendor/ant-design-pro/utils/request.js b/src/vendor/ant-design-pro/utils/request.js
index 53d4f3b..bccd36c 100644
--- a/src/vendor/ant-design-pro/utils/request.js
+++ b/src/vendor/ant-design-pro/utils/request.js
@@ -7,6 +7,24 @@ import store from '@/store';
import notification from 'ant-design-vue/es/notification';
import { VueAxios } from './axios';
+// 全局声明缓存变量
+var timestamp1;
+var isRefreshing = false;
+
+let subscribers = []
+// 刷新 token 后, 将缓存的接口重新请求一次
+function onAccessTokenFetched(newToken) {
+ subscribers.forEach((callback) => {
+ callback(newToken)
+ })
+ // 清空缓存接口
+ subscribers = []
+}
+// 添加缓存接口
+function addSubscriber(callback) {
+ subscribers.push(callback)
+}
+
const errorMsgs = {
noResponse: 'request failed, no response'
};
@@ -77,25 +95,41 @@ request.interceptors.response.use(response => {
let err = null;
switch (code) {
case '1201':
- notification.error({
- message: '用户校验失败',
- description: response.data.message
- });
- store.dispatch('Logout').then(() => {
+ if (!timestamp1 || timestamp1 + 1632252465 < new Date().getTime()) {
+ timestamp1 = new Date().getTime();
+ notification.error({
+ message: '用户校验失败',
+ description: response.data.message
+ });
setTimeout(() => {
- window.location.reload();
- }, 1500);
- })
+ store.dispatch('Logout').then(() => {
+ window.location.reload();
+ }).catch((err) => {
+ this.$message.error(err.response.message)
+ })
+ }, 1000)
+ }
break;
case '1207':
- // token过期后调接口刷新token
- store.dispatch('RefreshToken').then(() => {
- // 再发请求
- return request(response.config);
- }).catch((err) => {
- this.$message.error(err.response.message)
+ if (!isRefreshing) {
+ isRefreshing = true
+ store.dispatch('RefreshToken').then(() => {
+ // 再发请求
+ isRefreshing = false
+ onAccessTokenFetched(localStorage.getItem('Access-Token'))
+ }).catch(() => {
+ isRefreshing = false;
+ window.location.reload();
+ })
+ }
+ const retryRequest = new Promise((resolve) => {
+ addSubscriber((newToken) => {
+ response.config.headers['Access-Token'] = newToken;
+ response.config.url = response.config.url.replace(response.config.baseURL, '')
+ resolve(request(response.config))
+ })
})
- break;
+ return retryRequest
default:
err = new Error(response.data.message);
err.data = response.data.data;
diff --git a/src/vendor/ant-design-pro/utils/util.js b/src/vendor/ant-design-pro/utils/util.js
index 979e320..dd73f3e 100644
--- a/src/vendor/ant-design-pro/utils/util.js
+++ b/src/vendor/ant-design-pro/utils/util.js
@@ -2,6 +2,22 @@
* @file: antd vue框架的通用工具文件
*/
+// 节流函数
+export function throttle(func, wait) {
+ let timeout;
+ return () => {
+ const context = this
+ const args = arguments
+ if (!timeout) {
+ func.apply(context, args);
+ timeout = setTimeout(function () {
+ timeout = null
+ }, wait)
+ }
+ }
+}
+export default throttle
+
export function timeFix() {
const time = new Date();
const hour = time.getHours();
diff --git a/src/views/leaks/LeakTaskList.vue b/src/views/leaks/LeakTaskList.vue
index d40d8d8..ca4b697 100644
--- a/src/views/leaks/LeakTaskList.vue
+++ b/src/views/leaks/LeakTaskList.vue
@@ -251,7 +251,8 @@ export default {
handleTableChange(pagination, filters, sorter) {
// 存储翻页状态
this.pagination = pagination;
- this.filters = filters;
+ // this.filters = filters;
+ this.filters = Object.assign({}, this.filters, filters);
this.sorter = sorter;
// 出发排序、筛选、分页时,重新请求主机列表
this.getTaskList();
diff --git a/src/views/leaks/components/HostTable.vue b/src/views/leaks/components/HostTable.vue
index 96a7737..4f9e431 100644
--- a/src/views/leaks/components/HostTable.vue
+++ b/src/views/leaks/components/HostTable.vue
@@ -20,8 +20,9 @@
已修复
</a-radio-button>
</a-radio-group>
+ <a-input-search placeholder="按主机名搜索" v-model="hostSearch" @change="searchChange" style="width: 200px;margin-left: 10px;" @search="onSearch" />
</a-col>
- <a-col>
+ <a-col v-else>
<a-input-search placeholder="按主机名搜索" v-model="hostSearch" @change="searchChange" style="width: 200px" @search="onSearch" />
</a-col>
<a-col>
--
Gitee