接触所有限制
This commit is contained in:
@@ -7,14 +7,18 @@ import axios, {
|
||||
import { Toast } from "antd-mobile";
|
||||
import { useUserStore } from "@/store/module/user";
|
||||
const { token } = useUserStore.getState();
|
||||
const DEFAULT_DEBOUNCE_GAP = 1000;
|
||||
const DEFAULT_DEBOUNCE_GAP = 0; // 设置为 0 禁用防抖
|
||||
const debounceMap = new Map<string, number>();
|
||||
|
||||
// 需要高频轮询、不走截流的接口白名单(按实际接口路径调整)
|
||||
// 已禁用防抖,此白名单不再需要
|
||||
const NO_DEBOUNCE_URLS = [
|
||||
"/wechat/friend/list", // 好友列表
|
||||
"/wechat/group/list", // 群组列表
|
||||
"/wechat/message/list", // 消息列表
|
||||
"/v1/kefu/message/details", // 聊天消息详情(点击聊天记录时需要频繁请求)
|
||||
"v1/kefu/message/details", // 兼容不带斜杠的情况
|
||||
"kefu/message/details", // 兼容部分路径匹配
|
||||
];
|
||||
|
||||
// 接口错误白名单:这些接口失败时不显示错误提示
|
||||
@@ -116,22 +120,9 @@ export function request(
|
||||
const gap =
|
||||
typeof debounceGap === "number" ? debounceGap : DEFAULT_DEBOUNCE_GAP;
|
||||
|
||||
const enableDebounce = config?.debounce !== false;
|
||||
const isInNoDebounceList = NO_DEBOUNCE_URLS.some(pattern =>
|
||||
url.includes(pattern),
|
||||
);
|
||||
const shouldDebounce = enableDebounce && !isInNoDebounceList;
|
||||
|
||||
if (shouldDebounce) {
|
||||
const key = `${method}_${url}_${JSON.stringify(data)}`;
|
||||
const now = Date.now();
|
||||
const last = debounceMap.get(key) || 0;
|
||||
if (gap > 0 && now - last < gap) {
|
||||
// Toast.show({ content: '请求过于频繁,请稍后再试', position: 'top' });
|
||||
return Promise.reject("请求过于频繁,请稍后再试");
|
||||
}
|
||||
debounceMap.set(key, now);
|
||||
}
|
||||
// 防抖功能已完全禁用(DEFAULT_DEBOUNCE_GAP = 0)
|
||||
// 不再进行防抖检查,所有请求直接通过
|
||||
const shouldDebounce = false;
|
||||
|
||||
const axiosConfig: AxiosRequestConfig & { debounce?: boolean } = {
|
||||
url,
|
||||
|
||||
@@ -6,14 +6,16 @@ import axios, {
|
||||
} from "axios";
|
||||
import { Toast } from "antd-mobile";
|
||||
import { useUserStore } from "@/store/module/user";
|
||||
const DEFAULT_DEBOUNCE_GAP = 1000;
|
||||
const DEFAULT_DEBOUNCE_GAP = 0; // 设置为 0 禁用防抖
|
||||
const debounceMap = new Map<string, number>();
|
||||
|
||||
// 需要高频轮询、不走截流的接口白名单(按实际接口路径调整)
|
||||
// 已禁用防抖,此白名单不再需要
|
||||
const NO_DEBOUNCE_URLS = [
|
||||
"/wechat/friend/list",
|
||||
"/wechat/group/list",
|
||||
"/wechat/message/list",
|
||||
"/v1/kefu/message/details", // 聊天消息详情(点击聊天记录时需要频繁请求)
|
||||
];
|
||||
|
||||
// 接口错误白名单:这些接口失败时不显示错误提示
|
||||
@@ -87,22 +89,9 @@ export function request(
|
||||
const gap =
|
||||
typeof debounceGap === "number" ? debounceGap : DEFAULT_DEBOUNCE_GAP;
|
||||
|
||||
const enableDebounce = config?.debounce !== false;
|
||||
const isInNoDebounceList = NO_DEBOUNCE_URLS.some(pattern =>
|
||||
url.includes(pattern),
|
||||
);
|
||||
const shouldDebounce = enableDebounce && !isInNoDebounceList;
|
||||
|
||||
if (shouldDebounce) {
|
||||
const key = `${method}_${url}_${JSON.stringify(data)}`;
|
||||
const now = Date.now();
|
||||
const last = debounceMap.get(key) || 0;
|
||||
if (gap > 0 && now - last < gap) {
|
||||
// Toast.show({ content: '请求过于频繁,请稍后再试', position: 'top' });
|
||||
return Promise.reject("请求过于频繁,请稍后再试");
|
||||
}
|
||||
debounceMap.set(key, now);
|
||||
}
|
||||
// 防抖功能已完全禁用(DEFAULT_DEBOUNCE_GAP = 0)
|
||||
// 不再进行防抖检查,所有请求直接通过
|
||||
const shouldDebounce = false;
|
||||
|
||||
const axiosConfig: RequestConfig = {
|
||||
url,
|
||||
|
||||
@@ -64,10 +64,16 @@ export interface messreocrParams {
|
||||
[property: string]: any;
|
||||
}
|
||||
export function getChatMessages(params: messreocrParams) {
|
||||
return request("/v1/kefu/message/details", params, "GET");
|
||||
// 禁用防抖,因为聊天消息详情接口需要频繁请求
|
||||
return request("/v1/kefu/message/details", params, "GET", {
|
||||
debounce: false,
|
||||
});
|
||||
}
|
||||
export function getChatroomMessages(params: messreocrParams) {
|
||||
return request("/v1/kefu/message/details", params, "GET");
|
||||
// 禁用防抖,因为聊天消息详情接口需要频繁请求
|
||||
return request("/v1/kefu/message/details", params, "GET", {
|
||||
debounce: false,
|
||||
});
|
||||
}
|
||||
//=====================旧==============================
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ const ChatRecordSearch: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// 移除重复请求拦截,允许并发请求
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
const [From, To] = dateRange;
|
||||
@@ -45,7 +47,7 @@ const ChatRecordSearch: React.FC = () => {
|
||||
setSearchContent("");
|
||||
setDateRange(null);
|
||||
setLoading(false);
|
||||
handleSearch();
|
||||
// 关闭搜索窗口,不触发搜索
|
||||
updateShowChatRecordModel(false);
|
||||
};
|
||||
|
||||
|
||||
@@ -672,10 +672,12 @@ export const useWeChatStore = create<WeChatState>()(
|
||||
const requestedContactId = contact?.id;
|
||||
|
||||
if (!contact || !requestedContactId) {
|
||||
console.warn("loadChatMessages: 没有当前联系人,跳过请求");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Init && !state.currentMessagesHasMore) {
|
||||
console.warn("loadChatMessages: 没有更多消息,跳过请求");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -685,10 +687,8 @@ export const useWeChatStore = create<WeChatState>()(
|
||||
const limit =
|
||||
state.currentMessagesPageSize || DEFAULT_MESSAGE_PAGE_SIZE;
|
||||
|
||||
if (state.messagesLoading && !Init) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 移除重复请求拦截,允许并发请求
|
||||
console.log(`loadChatMessages: 开始加载消息 (Init=${Init}, page=${nextPage}, contactId=${requestedContactId})`);
|
||||
set({
|
||||
messagesLoading: true,
|
||||
isLoadingData: Init,
|
||||
@@ -784,6 +784,8 @@ export const useWeChatStore = create<WeChatState>()(
|
||||
}) => {
|
||||
const state = useWeChatStore.getState();
|
||||
const contact = state.currentContract;
|
||||
|
||||
// 移除重复请求拦截,允许并发请求
|
||||
set({ messagesLoading: true });
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user