fix(table): 统一筛选交互并补齐移动视口覆盖
This commit is contained in:
@@ -282,7 +282,8 @@ export const useLogsData = () => {
|
||||
};
|
||||
|
||||
// Statistics functions
|
||||
const getLogSelfStat = async () => {
|
||||
const statRequest = useRef(0);
|
||||
const getLogSelfStat = async (signal, requestId) => {
|
||||
const {
|
||||
token_name,
|
||||
model_name,
|
||||
@@ -304,7 +305,8 @@ export const useLogsData = () => {
|
||||
group,
|
||||
});
|
||||
const url = `/api/log/self/stat?${params.toString()}`;
|
||||
let res = await API.get(url);
|
||||
const res = await API.get(url, { signal });
|
||||
if (signal?.aborted || requestId !== statRequest.current) return;
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
setStat(data);
|
||||
@@ -313,7 +315,7 @@ export const useLogsData = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const getLogStat = async () => {
|
||||
const getLogStat = async (signal, requestId) => {
|
||||
const {
|
||||
username,
|
||||
token_name,
|
||||
@@ -341,7 +343,8 @@ export const useLogsData = () => {
|
||||
user_id,
|
||||
});
|
||||
const url = `/api/log/stat?${params.toString()}`;
|
||||
let res = await API.get(url);
|
||||
const res = await API.get(url, { signal });
|
||||
if (signal?.aborted || requestId !== statRequest.current) return;
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
setStat(data);
|
||||
@@ -350,18 +353,19 @@ export const useLogsData = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleEyeClick = async () => {
|
||||
if (loadingStat) {
|
||||
return;
|
||||
}
|
||||
const handleEyeClick = async (signal) => {
|
||||
const requestId = ++statRequest.current;
|
||||
setLoadingStat(true);
|
||||
if (isAdminUser) {
|
||||
await getLogStat();
|
||||
} else {
|
||||
await getLogSelfStat();
|
||||
try {
|
||||
const getStat = isAdminUser ? getLogStat : getLogSelfStat;
|
||||
await getStat(signal, requestId);
|
||||
if (!signal?.aborted && requestId === statRequest.current)
|
||||
setShowStat(true);
|
||||
} catch (error) {
|
||||
if (!signal?.aborted && !error.isAxiosError) showError(error);
|
||||
} finally {
|
||||
if (requestId === statRequest.current) setLoadingStat(false);
|
||||
}
|
||||
setShowStat(true);
|
||||
setLoadingStat(false);
|
||||
};
|
||||
|
||||
// User info function
|
||||
@@ -491,7 +495,7 @@ export const useLogsData = () => {
|
||||
const logsRequestIdRef = useRef(0);
|
||||
|
||||
// Load logs function
|
||||
const loadLogs = async (startIdx, pageSize, customLogType = null) => {
|
||||
const loadLogs = async (startIdx, pageSize, customLogType = null, signal) => {
|
||||
const reqId = ++logsRequestIdRef.current;
|
||||
setLoading(true);
|
||||
|
||||
@@ -553,13 +557,13 @@ export const useLogsData = () => {
|
||||
url = `/api/log/self?${params.toString()}`;
|
||||
}
|
||||
try {
|
||||
const res = await API.get(url);
|
||||
const res = await API.get(url, { signal });
|
||||
// 丢弃过期响应,只处理仍然是最新的请求
|
||||
if (reqId !== logsRequestIdRef.current) return;
|
||||
if (reqId !== logsRequestIdRef.current || signal?.aborted) return;
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
const newPageData = Array.isArray(data?.items) ? data.items : [];
|
||||
setActivePage(data?.page || 1);
|
||||
setActivePage(signal ? startIdx : data?.page || 1);
|
||||
setPageSize(data?.page_size || pageSize);
|
||||
setLogCount(data?.total || 0);
|
||||
|
||||
@@ -581,7 +585,8 @@ export const useLogsData = () => {
|
||||
showError(message);
|
||||
}
|
||||
} catch (error) {
|
||||
if (reqId === logsRequestIdRef.current) showError(error.message || error);
|
||||
if (!signal?.aborted && reqId === logsRequestIdRef.current)
|
||||
showError(error.message || error);
|
||||
} finally {
|
||||
if (reqId === logsRequestIdRef.current) setLoading(false);
|
||||
}
|
||||
@@ -624,11 +629,13 @@ export const useLogsData = () => {
|
||||
};
|
||||
|
||||
// Refresh function
|
||||
const refresh = async () => {
|
||||
const refresh = async ({ page = 1, signal } = {}) => {
|
||||
syncFiltersToUrl();
|
||||
setActivePage(1);
|
||||
// 并行触发但等待两者完成,避免 stat 与 list 结果基于不同过滤条件导致错乱
|
||||
await Promise.all([handleEyeClick(), loadLogs(1, pageSize)]);
|
||||
await Promise.all([
|
||||
handleEyeClick(signal),
|
||||
loadLogs(page, pageSize, null, signal),
|
||||
]);
|
||||
};
|
||||
|
||||
// Copy text function
|
||||
|
||||
Reference in New Issue
Block a user