fix(table): 统一筛选交互并补齐移动视口覆盖

This commit is contained in:
zhanjunhao
2026-11-24 20:14:10 +08:00
parent 437a0345e8
commit dd4da99f1d
83 changed files with 2094 additions and 1355 deletions
@@ -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 }}
/>