feat: 本次提交更新内容如下

定稿了,开始迁移。
This commit is contained in:
笔记本里的永平
2025-07-17 22:48:37 +08:00
parent f232866825
commit e2ad86ca45

View File

@@ -1,7 +1,7 @@
import axios, { AxiosInstance, AxiosRequestConfig, Method, AxiosResponse } from 'axios';
import { Toast } from 'antd-mobile';
const DEBOUNCE_GAP = 1000;
const DEFAULT_DEBOUNCE_GAP = 1000;
const debounceMap = new Map<string, number>();
const instance: AxiosInstance = axios.create({
@@ -32,11 +32,9 @@ instance.interceptors.response.use(
// 分类处理
if (code === 401) {
// 未登录或登录失效
// 可跳转登录页或清除 token
localStorage.removeItem('token');
} else if (code === 403) {
// 无权限
// 可做特殊处理
} else if (code === 500) {
// 服务端异常
}
@@ -49,16 +47,25 @@ instance.interceptors.response.use(
}
);
/**
* @param url 接口地址
* @param data 请求参数
* @param method 请求方法
* @param config axios 配置
* @param debounceGap 防抖时间(毫秒),不传则用默认值
*/
export function request(
url: string,
data?: any,
method: Method = 'GET',
config?: AxiosRequestConfig
config?: AxiosRequestConfig,
debounceGap?: number
): Promise<any> {
const gap = typeof debounceGap === 'number' ? debounceGap : DEFAULT_DEBOUNCE_GAP;
const key = `${method}_${url}_${JSON.stringify(data)}`;
const now = Date.now();
const last = debounceMap.get(key) || 0;
if (now - last < DEBOUNCE_GAP) {
if (gap > 0 && now - last < gap) {
Toast.show({ content: '请求过于频繁,请稍后再试', position: 'top' });
return Promise.reject('请求过于频繁,请稍后再试');
}