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

This commit is contained in:
zhanjunhao
2026-11-24 20:14:10 +08:00
parent 471d7843de
commit 2cbbf0839b
83 changed files with 2094 additions and 1355 deletions
+55 -56
View File
@@ -130,25 +130,18 @@ export const useModelsData = () => {
}
};
// Load models data
const loadModels = async (
page = 1,
size = pageSize,
vendorKey = activeVendorKey,
) => {
setLoading(true);
const listRequest = useRef(0);
const fetchModels = async (url, params, page, signal, isSearch = false) => {
const id = ++listRequest.current;
setLoading(!isSearch);
setSearching(isSearch);
try {
let url = `/api/models/?p=${page}&page_size=${size}`;
if (vendorKey && vendorKey !== 'all') {
// Filter by vendor ID
url = `/api/models/search?vendor=${vendorKey}&p=${page}&page_size=${size}`;
}
const res = await API.get(url);
const res = await API.get(url, { params, signal });
if (signal?.aborted || id !== listRequest.current) return;
const { success, message, data } = res.data;
if (success) {
const newPageData = extractItems(data);
setActivePage(data.page || page);
setActivePage(signal ? page : data.page || page);
setModelCount(data.total || newPageData.length);
setModelFormat(newPageData);
} else {
@@ -156,16 +149,39 @@ export const useModelsData = () => {
setModels([]);
}
} catch (error) {
console.error(error);
showError(t('获取模型列表失败'));
if (signal?.aborted || id !== listRequest.current) return;
if (!error.isAxiosError)
showError(t(isSearch ? '搜索模型失败' : '获取模型列表失败'));
setModels([]);
} finally {
if (id === listRequest.current) {
setLoading(false);
setSearching(false);
}
}
setLoading(false);
};
// Refresh data
const loadModels = (
page = 1,
size = pageSize,
vendorKey = activeVendorKey,
signal,
) => {
const vendor = vendorKey && vendorKey !== 'all' ? vendorKey : undefined;
return fetchModels(
vendor ? '/api/models/search' : '/api/models/',
{
p: page,
page_size: size,
vendor,
},
page,
signal,
);
};
const refresh = async (page = activePage) => {
await Promise.all([loadModels(page, pageSize), loadVendorCounts()]);
await Promise.all([searchModels(page, pageSize), loadVendorCounts()]);
};
// Sync upstream models/vendors for missing models only
@@ -255,41 +271,24 @@ export const useModelsData = () => {
}
};
// Search models with keyword and vendor
const searchModels = async () => {
const {
searchKeyword = '',
searchVendor = '',
searchCategory = '',
} = getFormValues();
if (searchKeyword === '' && searchVendor === '' && searchCategory === '') {
// If all filters are blank, load models instead
await loadModels(1, pageSize);
return;
const searchModels = (page = activePage, size = pageSize, signal) => {
const { searchKeyword, searchVendor, searchCategory } = getFormValues();
if (!searchKeyword && !searchVendor && !searchCategory) {
return loadModels(page, size, activeVendorKey, signal);
}
setSearching(true);
try {
const res = await API.get(
`/api/models/search?keyword=${searchKeyword}&vendor=${searchVendor}&category=${searchCategory}&p=1&page_size=${pageSize}`,
);
const { success, message, data } = res.data;
if (success) {
const newPageData = extractItems(data);
setActivePage(data.page || 1);
setModelCount(data.total || newPageData.length);
setModelFormat(newPageData);
} else {
showError(message);
setModels([]);
}
} catch (error) {
console.error(error);
showError(t('搜索模型失败'));
setModels([]);
}
setSearching(false);
return fetchModels(
'/api/models/search',
{
keyword: searchKeyword,
vendor: searchVendor,
category: searchCategory,
p: page,
page_size: size,
},
page,
signal,
true,
);
};
// Manage model (enable/disable/delete)
@@ -333,7 +332,7 @@ export const useModelsData = () => {
// Handle page change
const handlePageChange = (page) => {
setActivePage(page);
loadModels(page, pageSize, activeVendorKey);
searchModels(page, pageSize);
};
// Reload models when activeVendorKey changes
@@ -346,7 +345,7 @@ export const useModelsData = () => {
const handlePageSizeChange = async (size) => {
setPageSize(size);
setActivePage(1);
await loadModels(1, size, activeVendorKey);
await searchModels(1, size);
};
// Handle row click and styling