You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

355 lines
12 KiB
TypeScript

/*
* @Author: donghao donghao@supervision.ltd
* @Date: 2024-04-07 14:02:00
* @LastEditors: donghao donghao@supervision.ltd
* @LastEditTime: 2024-05-23 16:10:47
* @FilePath: \general-ai-manage\src\pages\ModelIndex\ModelIndex.tsx
* @Description:
* @
* 1.
* 2.
* 3.
* 4.
*
*/
import { CommButton } from '@/components/Button';
import { getDictIndustry } from '@/services/testApi/dict';
import { ReactComponent as ResetIcon } from '/public/home/reset_icon.svg';
import { ReactComponent as SearchIcon } from '/public/home/search_icon.svg';
import CategorizeUpdate from '@/components/CategorizeUpdate';
import TableActionCard from '@/components/TableActionCard';
import IsDelete from '@/components/TableActionCard/isDelete';
import { getModelList } from '@/services/testApi/model';
import { SearchOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { ProCard, ProForm, ProFormText, ProTable } from '@ant-design/pro-components';
import { Access, FormattedMessage, history, useAccess, useIntl } from '@umijs/max';
import { Button } from 'antd';
import React, { useEffect, useRef, useState } from 'react';
import { proTableCommonOptions, proTablePaginationOptions } from '../../../../config/defaultTable';
import CreateForm from './components/createForm';
import './index.less';
const ModelIndex: React.FC = () => {
const access = useAccess();
// eslint-disable-next-line react-hooks/rules-of-hooks
const intl = useIntl();
const actionRef = useRef<ActionType>();
const [querysData, setQuerysData] = useState<Record<string, any>>({}); // 列表查询参数
const [createModalOpen, setCreateModalOpen] = useState<boolean>(false);
// 设置分类
const [industryOpen, setIndustryOpen] = useState<boolean>(false);
// const [categoryFkIdIds, setCategoryFkIdIds] = useState([]);
// 动态设置每页数量
const [currentPageSize, setCurrentPageSize] = useState<number>(10);
// const [currentRow, setCurrentRow] = useState<Record<string,any>>({});
const [form] = ProForm.useForm(); // form 对象
/**新增 设置行业分类 删除 */
// 新增
const handleCreateModal = () => {
setCreateModalOpen(!createModalOpen);
};
// 设置行业分类
const handleSetIndustry = () => {
setIndustryOpen(!industryOpen);
};
/**
* @en-US The pop-up window of the distribution update window
* @zh-CN
* */
// const [updateModalOpen, setUpdateModalOpen] = useState<boolean>(false);
// const [showDetail, setShowDetail] = useState<boolean>(false);
const columns: ProColumns<Record<string, any>>[] = [
{
title: <FormattedMessage id="model_index.table.list.name" defaultMessage="$$$" />,
dataIndex: 'name',
hideInSearch: true,
key: 'fixedName',
fixed: 'left',
},
{
title: <FormattedMessage id="model_index.table.list.type" defaultMessage="$$$" />,
dataIndex: 'type',
hideInSearch: true,
render: (dom, record) => {
let activeName = 'active_primary';
switch (record.type) {
case '深度学习':
activeName = 'active3';
break;
default:
activeName = 'active_primary';
break;
}
return (
<div className={`gn_list_type_tag flex items-center justify-center ${activeName}`}>
<span className="dot"></span>
<span>{dom}</span>
</div>
);
},
},
{
title: <FormattedMessage id="model_index.table.list.industry" defaultMessage="$$$" />,
dataIndex: 'industry',
hideInSearch: true,
},
{
title: (
<FormattedMessage id="model_index.table.list.defaultVersionFkId" defaultMessage="$$$" />
),
dataIndex: 'defaultVersionFkId',
hideInSearch: true,
},
{
title: <FormattedMessage id="model_index.table.list.updateTime" defaultMessage="$$$" />,
dataIndex: 'updateTime',
sorter: true,
hideInSearch: true,
valueType: 'dateTime',
},
{
title: <FormattedMessage id="pages.searchTable.titleOption" defaultMessage="Operating" />,
dataIndex: 'option',
valueType: 'option',
fixed: 'right',
key: 'option',
render: (_, record) => [
<TableActionCard
key="TableActionCardRef"
renderActions={[
{
key: 'detail',
renderDom: (
<Button
key="detail"
type="link"
size="small"
onClick={() => {
// setCurrentRow(record);
history.push(`/home/model-detail/${record.id}`);
}}
>
<FormattedMessage id="model_index.table.list.detail" defaultMessage="详情配置" />
</Button>
),
},
// {
// key: 'update',
// renderDom: (
// <Button
// key="update"
// type="link"
// size="small"
// onClick={() => {
// setUpdateModalOpen(true);
// setCurrentRow(record);
// }}
// >
// <FormattedMessage id="pages.searchTable.update" defaultMessage="Update" />
// </Button>
// ),
// },
{
key: 'destroy',
renderDom: (
<IsDelete
deleteApi={() => {
// TODO 调用删除接口
// handleDestroy(record).then(() => {});
}}
></IsDelete>
),
},
]}
></TableActionCard>,
],
},
];
function reloadList() {
actionRef.current?.reload();
}
// 筛选查询
useEffect(() => {
if (actionRef) {
reloadList();
}
}, [actionRef, querysData]);
return (
<div className="modelIndex_page home_container gn_table_card_wrap">
<ProCard
className="gn_card"
style={{ backgroundColor: 'white' }}
title={
<div className="gn_form gn_table_query_filter">
<ProForm
className="gn_search_from"
form={form}
layout="horizontal"
submitter={{
render: () => (
<div style={{ textAlign: 'center', marginLeft: 12 }}>
<CommButton
type="primary"
htmlType="submit"
prevIcon={<SearchIcon />}
buttonLabel={
<FormattedMessage id="pages.searchTable.search" defaultMessage="查询" />
}
></CommButton>
<CommButton
style={{ marginLeft: 12 }}
htmlType="button"
prevIcon={<ResetIcon />}
buttonLabel={
<FormattedMessage id="pages.searchTable.reset" defaultMessage="重置" />
}
onClick={() => {
form.resetFields(); // 点击重置按钮时重置表单数据
setQuerysData(() => {}); // 清空筛选项
}}
></CommButton>
</div>
),
}}
onFinish={async (values) => {
console.log(values, 'filter_finish_values');
setQuerysData(() => values);
return true;
}}
>
<ProFormText
label={
<FormattedMessage id="model_index.table.list.name" defaultMessage="模型名称" />
}
labelClassName="label_set_1"
fieldProps={{
style: {
width: 280,
},
prefix: <SearchOutlined style={{ color: 'rgba(0,0,0,.25)' }} />,
}}
name="name"
placeholder="请输入模型名称"
/>
</ProForm>
</div>
}
extra={
<Access accessible={access.canUpdate(history.location.pathname)} key={`model-index-add`}>
<Button
type="primary"
key="primary"
onClick={() => {
setCreateModalOpen(true);
}}
>
<FormattedMessage id="model_index.table.list.add" defaultMessage="New" />
</Button>
<Button
className="ml-[12px]"
key="setIndustry"
onClick={() => {
setIndustryOpen(true);
}}
>
<FormattedMessage id="model_index.table.list.setIndustry" defaultMessage="行业类别" />
</Button>
</Access>
}
bodyStyle={{
maxHeight: 'calc(100vh - 250px)',
overflowY: 'scroll',
}}
>
<ProTable
className="gn_pro_table"
cardProps={{
bodyStyle: {
padding: '0',
},
}}
search={false}
scroll={{ x: proTableCommonOptions.commscrollX }}
options={{ fullScreen: false, setting: false, density: false, reload: false }}
actionRef={actionRef}
rowKey="id"
onDataSourceChange={(data) => {
console.log(data, 'onDataSourceChange_data');
// let CategoryFkIdIds: any = data.map((v) => {
// return v.categoryFkId;
// });
// setCategoryFkIdIds(CategoryFkIdIds);
}}
pagination={{
...proTablePaginationOptions,
pageSize: currentPageSize,
onChange: (pageNo, pageSize) => setCurrentPageSize(pageSize),
}}
columnsState={{
persistenceKey: 'algorithm_model_list',
persistenceType: 'localStorage',
}}
request={async (params = {}, sort) => {
const { current, ...rest } = params;
const reqParams = {
pageNo: current,
desc: false,
orderKey: '',
...rest,
};
if (sort && Object.keys(sort).length) {
reqParams.orderKey = Object.keys(sort)[0];
let sort_select = sort[reqParams.orderKey];
reqParams.desc = sort_select === 'descend';
}
let resp = await getModelList({ ...reqParams, ...querysData });
return {
data: resp.data.data,
success: resp.success,
total: resp.data.count,
current: current,
pageSize: currentPageSize,
};
}}
columns={columns}
/>
</ProCard>
<CreateForm
createModalOpen={createModalOpen}
handleModal={handleCreateModal}
reload={reloadList}
/>
<CategorizeUpdate
visible={industryOpen}
handleModal={handleSetIndustry}
values={{ industry: [{ name: '', value: '' }] }}
apiSource={getDictIndustry}
modalFormProps={{
categorizeFormProps: {
label: (
<FormattedMessage id="model_index.create.form.industry" defaultMessage="行业类别" />
),
name: 'industry',
},
categorizeModelProps: {
title: intl.formatMessage({
id: 'model_index.table.list.setIndustry',
defaultMessage: '新建',
}),
},
}}
/>
</div>
);
};
export default ModelIndex;