fix: 重复提交时间2秒内

This commit is contained in:
TsMask
2023-10-11 14:19:54 +08:00
parent 5b220260b6
commit d0cfe66a7c
2 changed files with 12 additions and 5 deletions

View File

@@ -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!';
export const RESULT_MSG_URL_NOTFOUND = 'Request address not found!';
/**响应-数据正在处理,请勿重复提交 */
export const RESULT_MSG_URL_RESUBMIT = 'Data is being processed, please do not resubmit!';

View File

@@ -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<any> {
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);
}