fix(table): 统一筛选交互并补齐移动视口覆盖
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { useLocalTableFilters } from '@/hooks/common/useLocalTableFilters';
|
||||
import { useFilteredTableRows } from '@/hooks/common/useFilteredTableRows';
|
||||
import {
|
||||
RefreshCcw as ActionRefreshCcw,
|
||||
CheckSquare as ActionCheckSquare,
|
||||
} from '@/components/common/icons/ActionIcons';
|
||||
import React, { useState, useCallback, useMemo, useEffect } from 'react';
|
||||
import React, { useState, useCallback, useMemo } from 'react';
|
||||
import {
|
||||
Button,
|
||||
Table,
|
||||
@@ -87,10 +89,10 @@ export default function UpstreamRatioSync(props) {
|
||||
const [pageSize, setPageSize] = useState(10);
|
||||
|
||||
// 搜索相关状态
|
||||
const [searchKeyword, setSearchKeyword] = useState('');
|
||||
|
||||
// 倍率类型过滤
|
||||
const [ratioTypeFilter, setRatioTypeFilter] = useState('');
|
||||
const { draft, applied, changeFilters, submitSearch } = useLocalTableFilters({
|
||||
searchKeyword: '',
|
||||
ratioTypeFilter: '',
|
||||
});
|
||||
|
||||
// 冲突确认弹窗相关
|
||||
const [confirmVisible, setConfirmVisible] = useState(false);
|
||||
@@ -98,10 +100,6 @@ export default function UpstreamRatioSync(props) {
|
||||
|
||||
const channelSelectorRef = React.useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
setCurrentPage(1);
|
||||
}, [ratioTypeFilter, searchKeyword]);
|
||||
|
||||
const fetchAllChannels = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
@@ -432,19 +430,21 @@ export default function UpstreamRatioSync(props) {
|
||||
<Input
|
||||
prefix={<IconSearch size={14} />}
|
||||
placeholder={t('搜索模型名称')}
|
||||
value={searchKeyword}
|
||||
onChange={setSearchKeyword}
|
||||
value={draft.searchKeyword}
|
||||
onChange={(searchKeyword) => changeFilters({ searchKeyword })}
|
||||
onEnterPress={submitSearch}
|
||||
className='w-full sm:w-64'
|
||||
showClear
|
||||
/>
|
||||
|
||||
<Select
|
||||
placeholder={t('按倍率类型筛选')}
|
||||
value={ratioTypeFilter}
|
||||
onChange={setRatioTypeFilter}
|
||||
value={draft.ratioTypeFilter}
|
||||
onChange={(value) =>
|
||||
changeFilters({ ratioTypeFilter: value ?? '' })
|
||||
}
|
||||
className='w-full sm:w-48'
|
||||
showClear
|
||||
onClear={() => setRatioTypeFilter('')}
|
||||
>
|
||||
<Select.Option value='model_ratio'>{t('模型倍率')}</Select.Option>
|
||||
<Select.Option value='completion_ratio'>
|
||||
@@ -489,22 +489,15 @@ export default function UpstreamRatioSync(props) {
|
||||
return tmp;
|
||||
}, [differences]);
|
||||
|
||||
const filteredDataSource = useMemo(() => {
|
||||
if (!searchKeyword.trim() && !ratioTypeFilter) {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
return dataSource.filter((item) => {
|
||||
const matchesKeyword =
|
||||
!searchKeyword.trim() ||
|
||||
item.model.toLowerCase().includes(searchKeyword.toLowerCase().trim());
|
||||
|
||||
const matchesRatioType =
|
||||
!ratioTypeFilter || item.ratioType === ratioTypeFilter;
|
||||
|
||||
return matchesKeyword && matchesRatioType;
|
||||
});
|
||||
}, [dataSource, searchKeyword, ratioTypeFilter]);
|
||||
const keyword = applied.searchKeyword.toLowerCase().trim();
|
||||
const { ratioTypeFilter } = applied;
|
||||
const matches = useCallback(
|
||||
(item) =>
|
||||
(!keyword || item.model.toLowerCase().includes(keyword)) &&
|
||||
(!ratioTypeFilter || item.ratioType === ratioTypeFilter),
|
||||
[keyword, ratioTypeFilter],
|
||||
);
|
||||
const filteredDataSource = useFilteredTableRows(dataSource, matches);
|
||||
|
||||
const upstreamNames = useMemo(() => {
|
||||
const set = new Set();
|
||||
@@ -754,6 +747,7 @@ export default function UpstreamRatioSync(props) {
|
||||
pagination={{
|
||||
currentPage: currentPage,
|
||||
pageSize: pageSize,
|
||||
preservePage: true,
|
||||
total: filteredDataSource.length,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
|
||||
Reference in New Issue
Block a user