fix(table): 统一筛选交互并补齐移动视口覆盖
This commit is contained in:
@@ -9,12 +9,14 @@ const ModelsFilters = ({
|
||||
formInitValues,
|
||||
setFormApi,
|
||||
searchModels,
|
||||
activePage,
|
||||
setSelectedKeys,
|
||||
loading,
|
||||
searching,
|
||||
t,
|
||||
}) => {
|
||||
const { scheduleSearch, submitSearch, cancelPendingSearch } = useFilterSearch(
|
||||
() => searchModels(),
|
||||
(_, signal) => searchModels(activePage, undefined, signal),
|
||||
);
|
||||
|
||||
// Handle form reset and immediate search
|
||||
@@ -24,9 +26,8 @@ const ModelsFilters = ({
|
||||
if (!formApiRef.current) return;
|
||||
formApiRef.current.reset();
|
||||
cancelPendingSearch();
|
||||
setTimeout(() => {
|
||||
searchModels();
|
||||
}, 100);
|
||||
setSelectedKeys([]);
|
||||
searchModels(1);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -86,6 +86,8 @@ const ModelsPage = () => {
|
||||
formInitValues={formInitValues}
|
||||
setFormApi={setFormApi}
|
||||
searchModels={searchModels}
|
||||
activePage={modelsData.activePage}
|
||||
setSelectedKeys={setSelectedKeys}
|
||||
loading={loading}
|
||||
searching={searching}
|
||||
t={t}
|
||||
@@ -114,6 +116,7 @@ const ModelsPage = () => {
|
||||
</div>
|
||||
}
|
||||
paginationArea={createCardProPagination({
|
||||
preservePage: true,
|
||||
currentPage: modelsData.activePage,
|
||||
pageSize: modelsData.pageSize,
|
||||
total: modelsData.modelCount,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { useLocalTableFilters } from '@/hooks/common/useLocalTableFilters';
|
||||
import { useFilteredTableRows } from '@/hooks/common/useFilteredTableRows';
|
||||
import { Trans } from 'react-i18next';
|
||||
import { useEffectEvent } from '../../../../hooks/common/useEffectEvent';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import {
|
||||
Modal,
|
||||
Table,
|
||||
@@ -23,7 +25,9 @@ const MissingModelsModal = ({ visible, onClose, onConfigureModel, t }) => {
|
||||
const [paginationSize, setPaginationSize] = useState(MODEL_TABLE_PAGE_SIZE);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [missingModels, setMissingModels] = useState([]);
|
||||
const [searchKeyword, setSearchKeyword] = useState('');
|
||||
const { draft, applied, changeFilters, submitSearch, resetFilters } =
|
||||
useLocalTableFilters({ searchKeyword: '' });
|
||||
const keyword = applied.searchKeyword.toLowerCase();
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
@@ -45,7 +49,7 @@ const MissingModelsModal = ({ visible, onClose, onConfigureModel, t }) => {
|
||||
const onVisibilityChange = useEffectEvent(() => {
|
||||
if (visible) {
|
||||
fetchMissing();
|
||||
setSearchKeyword('');
|
||||
resetFilters();
|
||||
setCurrentPage(1);
|
||||
} else {
|
||||
setMissingModels([]);
|
||||
@@ -54,9 +58,11 @@ const MissingModelsModal = ({ visible, onClose, onConfigureModel, t }) => {
|
||||
useEffect(() => onVisibilityChange(), [onVisibilityChange, visible]);
|
||||
|
||||
// 过滤和分页逻辑
|
||||
const filteredModels = missingModels.filter((model) =>
|
||||
model.toLowerCase().includes(searchKeyword.toLowerCase()),
|
||||
const matches = useCallback(
|
||||
(model) => model.toLowerCase().includes(keyword),
|
||||
[keyword],
|
||||
);
|
||||
const filteredModels = useFilteredTableRows(missingModels, matches);
|
||||
|
||||
const dataSource = (() => {
|
||||
const start = (currentPage - 1) * paginationSize;
|
||||
@@ -137,11 +143,9 @@ const MissingModelsModal = ({ visible, onClose, onConfigureModel, t }) => {
|
||||
<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
|
||||
@@ -149,7 +153,7 @@ const MissingModelsModal = ({ visible, onClose, onConfigureModel, t }) => {
|
||||
</div>
|
||||
|
||||
{/* 表格 */}
|
||||
{filteredModels.length > 0 ? (
|
||||
{filteredModels.length > 0 || currentPage > 1 ? (
|
||||
<Table
|
||||
// 列宽合计远超窄屏视口;没有 scroll 时表格会压缩到 min-content 硬塞进去,
|
||||
// 末尾的操作列落在视口外,且 iOS 上滚动条不可见、毫无可拖动提示
|
||||
@@ -157,6 +161,7 @@ const MissingModelsModal = ({ visible, onClose, onConfigureModel, t }) => {
|
||||
columns={columns}
|
||||
dataSource={dataSource}
|
||||
pagination={{
|
||||
preservePage: true,
|
||||
currentPage: currentPage,
|
||||
pageSize: paginationSize,
|
||||
total: filteredModels.length,
|
||||
@@ -178,7 +183,7 @@ const MissingModelsModal = ({ visible, onClose, onConfigureModel, t }) => {
|
||||
/>
|
||||
}
|
||||
description={
|
||||
searchKeyword ? t('未找到匹配的模型') : t('暂无缺失模型')
|
||||
keyword ? t('未找到匹配的模型') : t('暂无缺失模型')
|
||||
}
|
||||
style={{ padding: 20 }}
|
||||
/>
|
||||
|
||||
@@ -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