fix(table): 统一筛选交互并补齐移动视口覆盖
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import { useLocalTableFilters } from '@/hooks/common/useLocalTableFilters';
|
||||
import { useFilteredTableRows } from '@/hooks/common/useFilteredTableRows';
|
||||
import { useEffectEvent } from '@/hooks/common/useEffectEvent';
|
||||
import React, { useEffect, useMemo, useState, useCallback } from 'react';
|
||||
import {
|
||||
Modal,
|
||||
@@ -39,7 +42,9 @@ const UpstreamConflictModal = ({
|
||||
const [selections, setSelections] = useState({});
|
||||
const isMobile = useIsMobile();
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const [searchKeyword, setSearchKeyword] = useState('');
|
||||
const { draft, applied, changeFilters, submitSearch, resetFilters } =
|
||||
useLocalTableFilters({ searchKeyword: '' });
|
||||
const keyword = applied.searchKeyword.toLowerCase();
|
||||
|
||||
const formatValue = (v) => {
|
||||
if (v === null || v === undefined) return '-';
|
||||
@@ -51,6 +56,7 @@ const UpstreamConflictModal = ({
|
||||
}
|
||||
};
|
||||
|
||||
const resetSearch = useEffectEvent(resetFilters);
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
const init = {};
|
||||
@@ -59,11 +65,11 @@ const UpstreamConflictModal = ({
|
||||
});
|
||||
setSelections(init);
|
||||
setCurrentPage(1);
|
||||
setSearchKeyword('');
|
||||
resetSearch();
|
||||
} else {
|
||||
setSelections({});
|
||||
}
|
||||
}, [visible, conflicts]);
|
||||
}, [visible, conflicts, resetSearch]);
|
||||
|
||||
const toggleField = useCallback((modelName, field, checked) => {
|
||||
setSelections((prev) => {
|
||||
@@ -87,13 +93,11 @@ const UpstreamConflictModal = ({
|
||||
[conflicts],
|
||||
);
|
||||
|
||||
const filteredDataSource = useMemo(() => {
|
||||
const kw = (searchKeyword || '').toLowerCase();
|
||||
if (!kw) return dataSource;
|
||||
return dataSource.filter((item) =>
|
||||
(item.model_name || '').toLowerCase().includes(kw),
|
||||
);
|
||||
}, [dataSource, searchKeyword]);
|
||||
const matches = useCallback(
|
||||
(item) => (item.model_name || '').toLowerCase().includes(keyword),
|
||||
[keyword],
|
||||
);
|
||||
const filteredDataSource = useFilteredTableRows(dataSource, matches);
|
||||
|
||||
// 列头工具:当前过滤范围内可操作的行集合/勾选状态/批量设置
|
||||
const getPresentRowsForField = useCallback(
|
||||
@@ -261,21 +265,20 @@ const UpstreamConflictModal = ({
|
||||
<div className='flex items-center justify-end gap-2 w-full mb-4'>
|
||||
<Input
|
||||
placeholder={t('搜索模型...')}
|
||||
value={searchKeyword}
|
||||
onChange={(v) => {
|
||||
setSearchKeyword(v);
|
||||
setCurrentPage(1);
|
||||
}}
|
||||
value={draft.searchKeyword}
|
||||
onChange={(searchKeyword) => changeFilters({ searchKeyword })}
|
||||
onEnterPress={submitSearch}
|
||||
className='!w-full'
|
||||
prefix={<IconSearch />}
|
||||
showClear
|
||||
/>
|
||||
</div>
|
||||
{filteredDataSource.length > 0 ? (
|
||||
{filteredDataSource.length > 0 || currentPage > 1 ? (
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={pagedDataSource}
|
||||
pagination={{
|
||||
preservePage: true,
|
||||
currentPage: currentPage,
|
||||
pageSize: paginationSize,
|
||||
total: filteredDataSource.length,
|
||||
@@ -289,9 +292,7 @@ const UpstreamConflictModal = ({
|
||||
/>
|
||||
) : (
|
||||
<Empty
|
||||
description={
|
||||
searchKeyword ? t('未找到匹配的模型') : t('无冲突项')
|
||||
}
|
||||
description={keyword ? t('未找到匹配的模型') : t('无冲突项')}
|
||||
className='p-6'
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user