2aa9d73325
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
131 lines
3.2 KiB
React
131 lines
3.2 KiB
React
import TableEmpty from '../../common/table/TableEmpty';
|
|
import React, { useMemo, useState } from 'react';
|
|
import { Descriptions } from 'antd';
|
|
import { Modal } from '@/components/ui';
|
|
import CardTable from '../../common/ui/CardTable';
|
|
|
|
import { getModelsColumns } from './ModelsColumnDefs';
|
|
import { useModelCategories } from '../../../hooks/models/useModelCategories';
|
|
import './models-vendor-tabs.css';
|
|
|
|
const ModelsTable = (modelsData) => {
|
|
const [detailModel, setDetailModel] = useState(null);
|
|
const {
|
|
models,
|
|
loading,
|
|
activePage,
|
|
pageSize,
|
|
modelCount,
|
|
compactMode,
|
|
handlePageChange,
|
|
handlePageSizeChange,
|
|
rowSelection,
|
|
handleRow,
|
|
manageModel,
|
|
setEditingModel,
|
|
setShowEdit,
|
|
refresh,
|
|
vendorMap,
|
|
copyText,
|
|
t,
|
|
} = modelsData;
|
|
|
|
// 加载分类名称映射
|
|
const { categoryNames } = useModelCategories();
|
|
|
|
// Get all columns
|
|
const columns = useMemo(() => {
|
|
return getModelsColumns({
|
|
t,
|
|
manageModel,
|
|
setEditingModel,
|
|
setShowEdit,
|
|
refresh,
|
|
vendorMap,
|
|
categoryNames,
|
|
setDetailModel,
|
|
copyText,
|
|
});
|
|
}, [
|
|
t,
|
|
manageModel,
|
|
setEditingModel,
|
|
setShowEdit,
|
|
refresh,
|
|
vendorMap,
|
|
categoryNames,
|
|
copyText,
|
|
]);
|
|
|
|
// Handle compact mode by removing fixed positioning
|
|
const tableColumns = useMemo(() => {
|
|
return compactMode
|
|
? columns.map((col) => {
|
|
if (col.dataIndex === 'operate') {
|
|
const { fixed, ...rest } = col;
|
|
return rest;
|
|
}
|
|
return col;
|
|
})
|
|
: columns;
|
|
}, [compactMode, columns]);
|
|
|
|
return (
|
|
<>
|
|
<Modal
|
|
title={t('详情')}
|
|
visible={Boolean(detailModel)}
|
|
onCancel={() => setDetailModel(null)}
|
|
maskClosable
|
|
footer={null}
|
|
width={720}
|
|
>
|
|
<Descriptions
|
|
className='models-detail-descriptions'
|
|
bordered
|
|
column={1}
|
|
items={
|
|
detailModel
|
|
? columns
|
|
.filter((column) => column.dataIndex !== 'operate')
|
|
.map((column, key) => ({
|
|
key,
|
|
label: column.title,
|
|
children: column.render
|
|
? column.render(
|
|
detailModel[column.dataIndex],
|
|
detailModel,
|
|
)
|
|
: (detailModel[column.dataIndex] ?? '-'),
|
|
}))
|
|
: []
|
|
}
|
|
/>
|
|
</Modal>
|
|
<CardTable
|
|
columns={tableColumns}
|
|
dataSource={models}
|
|
scroll={compactMode ? undefined : { x: 'max-content' }}
|
|
pagination={{
|
|
currentPage: activePage,
|
|
pageSize: pageSize,
|
|
total: modelCount,
|
|
showSizeChanger: true,
|
|
pageSizeOptions: [10, 20, 50, 100],
|
|
onPageSizeChange: handlePageSizeChange,
|
|
onPageChange: handlePageChange,
|
|
}}
|
|
hidePagination={true}
|
|
loading={loading}
|
|
rowSelection={rowSelection}
|
|
onRow={handleRow}
|
|
empty={<TableEmpty />}
|
|
className='rounded-xl overflow-hidden'
|
|
size='middle'
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default ModelsTable;
|