From d0cfe66a7c5703694b4d8c080b1edaad070e09cf Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Wed, 11 Oct 2023 14:19:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=87=8D=E5=A4=8D=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=97=B6=E9=97=B42=E7=A7=92=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/result-constants.ts | 5 ++++- src/plugins/http-fetch.ts | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/constants/result-constants.ts b/src/constants/result-constants.ts index 9db18e1f..f0458353 100644 --- a/src/constants/result-constants.ts +++ b/src/constants/result-constants.ts @@ -20,4 +20,7 @@ export const RESULT_MSG_NOT_TYPE = 'Unknown response data type!'; export const RESULT_MSG_SERVER_ERROR = 'Server connection error!'; /**响应-请求地址未找到 */ -export const RESULT_MSG_URL_NOTFOUND = 'Request address not found!'; \ No newline at end of file +export const RESULT_MSG_URL_NOTFOUND = 'Request address not found!'; + +/**响应-数据正在处理,请勿重复提交 */ +export const RESULT_MSG_URL_RESUBMIT = 'Data is being processed, please do not resubmit!'; diff --git a/src/plugins/http-fetch.ts b/src/plugins/http-fetch.ts index 7b6df6fd..9704d23e 100644 --- a/src/plugins/http-fetch.ts +++ b/src/plugins/http-fetch.ts @@ -15,6 +15,7 @@ import { RESULT_MSG_SUCCESS, RESULT_MSG_TIMEOUT, RESULT_MSG_URL_NOTFOUND, + RESULT_MSG_URL_RESUBMIT, } from '@/constants/result-constants'; /**响应结果类型 */ @@ -76,7 +77,7 @@ type OptionsType = { /**默认请求参数 */ const FATCH_OPTIONS: OptionsType = { baseUrl: import.meta.env.VITE_API_BASE_URL, - timeout: 30 * 1000, + timeout: 10 * 1000, url: '', method: 'get', headers: { @@ -125,15 +126,18 @@ function beforeRequest(options: OptionsType): OptionsType | Promise { const sessionObj: RepeatSubmitType = sessionGetJSON(CACHE_SESSION_FATCH); if (sessionObj) { const { url, data, time } = sessionObj; - const interval = 1000; // 间隔时间(ms),小于此时间视为重复提交 + const interval = 2000; // 间隔时间(ms),小于此时间视为重复提交 if ( requestObj.url === url && requestObj.data === data && requestObj.time - time < interval ) { - const message = '数据正在处理,请勿重复提交'; + const message = RESULT_MSG_URL_RESUBMIT; console.warn(`[${url}]: ${message}`); - return Promise.reject(message); + return Promise.resolve({ + code: RESULT_CODE_ERROR, + msg: message, + }); } else { sessionSetJSON(CACHE_SESSION_FATCH, requestObj); }