fix(table): 统一筛选交互并补齐移动视口覆盖
This commit is contained in:
@@ -38,6 +38,7 @@ import { ShieldCheck } from 'lucide-react';
|
||||
import Joyride, { STATUS, ACTIONS, EVENTS } from 'react-joyride';
|
||||
import { useTokensData } from '../../hooks/tokens/useTokensData';
|
||||
import { useFilterSearch } from '../../hooks/common/useFilterSearch';
|
||||
import { filterTableRows } from '@/components/common/table/filterTableRows';
|
||||
import { collectPagedItems } from '../../helpers/paging';
|
||||
import EditTokenModal from '../../components/table/tokens/modals/EditTokenModal';
|
||||
import {
|
||||
@@ -737,44 +738,56 @@ const KeyManagement = ({ embedded = false }) => {
|
||||
if (!handled) showInfo(t('暂无可用客服'));
|
||||
};
|
||||
|
||||
const displayedPage = searchResult?.page ?? activePage;
|
||||
const displayedPageSize = searchResult?.pageSize ?? pageSize;
|
||||
const listLoading = loading || searchLoading;
|
||||
|
||||
const runSearch = async (value, page = 1) => {
|
||||
const runSearch = async (value, page, signal) => {
|
||||
const id = ++searchRequest.current;
|
||||
const query = value.trim().toLowerCase();
|
||||
if (!query) {
|
||||
setSearchLoading(false);
|
||||
setSearchResult(null);
|
||||
return loadTokens(1, displayedPageSize);
|
||||
return loadTokens(page, displayedPageSize, signal);
|
||||
}
|
||||
setSearchLoading(true);
|
||||
try {
|
||||
const { items, total, message, truncated } = await collectPagedItems(
|
||||
(p, size) => API.get('/api/token/', { params: { p, page_size: size } }),
|
||||
{ shouldAbort: () => id !== searchRequest.current },
|
||||
(p, size) =>
|
||||
API.get('/api/token/', { params: { p, page_size: size }, signal }),
|
||||
{ shouldAbort: () => signal?.aborted || id !== searchRequest.current },
|
||||
);
|
||||
if (id !== searchRequest.current) return;
|
||||
if (signal?.aborted || id !== searchRequest.current) return;
|
||||
if (message || truncated || items.length < total) {
|
||||
showError(message || originalT('加载失败'));
|
||||
return;
|
||||
}
|
||||
const matches = items.filter((token) =>
|
||||
[token.name, token.key, token.group].some((value) =>
|
||||
value?.toLowerCase().includes(query),
|
||||
),
|
||||
const matches = await filterTableRows(
|
||||
items,
|
||||
(token) =>
|
||||
[
|
||||
token.name,
|
||||
token.key,
|
||||
...(Array.isArray(token.group) ? token.group : [token.group]),
|
||||
].some(
|
||||
(value) =>
|
||||
typeof value === 'string' && value.toLowerCase().includes(query),
|
||||
),
|
||||
signal,
|
||||
);
|
||||
if (id !== searchRequest.current) return;
|
||||
setSearchResult({
|
||||
query,
|
||||
items: matches,
|
||||
page: Math.min(
|
||||
page,
|
||||
Math.max(1, Math.ceil(matches.length / displayedPageSize)),
|
||||
),
|
||||
page,
|
||||
pageSize: displayedPageSize,
|
||||
});
|
||||
} catch (error) {
|
||||
if (id === searchRequest.current && !error?.isAxiosError) {
|
||||
if (
|
||||
!signal?.aborted &&
|
||||
id === searchRequest.current &&
|
||||
!error?.isAxiosError
|
||||
) {
|
||||
showError(originalT('加载失败'));
|
||||
}
|
||||
} finally {
|
||||
@@ -783,7 +796,7 @@ const KeyManagement = ({ embedded = false }) => {
|
||||
};
|
||||
|
||||
const { scheduleSearch, submitSearch, cancelPendingSearch } = useFilterSearch(
|
||||
(value = searchValue) => runSearch(value),
|
||||
(value = searchValue, signal) => runSearch(value, displayedPage, signal),
|
||||
);
|
||||
|
||||
useEffect(
|
||||
@@ -796,13 +809,12 @@ const KeyManagement = ({ embedded = false }) => {
|
||||
const resetSearch = () => {
|
||||
cancelPendingSearch();
|
||||
setSearchValue('');
|
||||
runSearch('');
|
||||
runSearch('', 1);
|
||||
};
|
||||
|
||||
const refreshKeyList = () =>
|
||||
searchResult ? runSearch(searchResult.query, searchResult.page) : refresh();
|
||||
|
||||
const displayedPage = searchResult?.page ?? activePage;
|
||||
const displayedTotal = searchResult?.items.length ?? tokenCount;
|
||||
const displayedTokens = searchResult
|
||||
? searchResult.items.slice(
|
||||
@@ -1027,8 +1039,9 @@ const KeyManagement = ({ embedded = false }) => {
|
||||
t={t}
|
||||
/>
|
||||
|
||||
{displayedTotal > 0 ? (
|
||||
{displayedTotal > 0 || displayedPage > 1 ? (
|
||||
<Pagination
|
||||
preservePage
|
||||
className='km-pagination'
|
||||
total={displayedTotal}
|
||||
currentPage={displayedPage}
|
||||
|
||||
Reference in New Issue
Block a user