import { getAccessToken } from '@/access'; import { addModelsVersionDetail, deleteModelVersion, getModelById, getModelVersionIdList, getModelVersionsById, } from '@/services/dataset/index.js'; import { downLoadZip } from '@/utils/downloadfile'; import { DeleteOutlined, PlusCircleOutlined, UploadOutlined } from '@ant-design/icons'; import { Button, Form, Input, Modal, Select, Table, Tabs, Upload, message } from 'antd'; import moment from 'moment'; import { useEffect, useRef, useState } from 'react'; import { useParams } from 'react-router-dom'; import Styles from './index.less'; const { Search } = Input; const { TabPane } = Tabs; const Dataset = () => { const props = { action: '/api/mmp/dataset/upload', // headers: { // 'X-Requested-With': null // }, headers: { Authorization: getAccessToken(), 'X-Requested-With': null, }, onChange({ file, fileList }) { if (file.status !== 'uploading') { console.log(file, fileList); setFormList( fileList.map((item) => { return { ...form.getFieldsValue(), models_id: locationParams.id, file_name: item.response.data[0].fileName, file_size: item.response.data[0].fileSize, url: item.response.data[0].url, }; }), ); } }, defaultFileList: [], }; const [form] = Form.useForm(); const [formList, setFormList] = useState([]); const [dialogTitle, setDialogTitle] = useState('新建版本'); const [isModalOpen, setIsModalOpen] = useState(false); const [datasetDetailObj, setDatasetDetailObj] = useState({}); const [version, setVersion] = useState(''); const [versionList, setVersionList] = useState([]); const locationParams = useParams(); //新版本获取路由参数接口 console.log(locationParams); const [wordList, setWordList] = useState([]); const getModelByDetail = () => { getModelById(locationParams.id).then((ret) => { console.log(ret); if (ret.code == 200) { setDatasetDetailObj(ret.data); } }); }; const getModelVersionsList = () => { getModelVersionsById(locationParams.id).then((ret) => { console.log(ret); if (ret.code == 200 && ret.data && ret.data.length > 0) { setVersionList( ret.data.map((item) => { return { label: item, value: item, }; }), ); } }); }; useEffect(() => { getModelByDetail(); getModelVersionsList(); return () => {}; }, []); const showModal = () => { form.resetFields(); form.setFieldsValue({ name: datasetDetailObj.name }); setDialogTitle('创建新版本'); setIsModalOpen(true); }; const handleCancel = () => { setIsModalOpen(false); }; const deleteDataset = () => { Modal.confirm({ title: '删除', content: '确定删除模型版本?', okText: '确认', cancelText: '取消', onOk: () => { deleteModelVersion({ models_id: locationParams.id, version }).then((ret) => { if (ret.code == 200) { message.success('删除成功'); getModelVersions({ version, models_id: locationParams.id }); } else { message.error(ret.msg); } }); }, }); }; const onFinish = () => { addModelsVersionDetail(formList).then((ret) => { console.log(ret); getModelVersionsList(); setIsModalOpen(false); }); }; const getModelVersions = (params) => { getModelVersionIdList(params).then((ret) => { console.log(ret); if (ret.code == 200) { setWordList(ret.data); } }); }; const handleExport = async () => { const hide = message.loading('正在下载'); hide(); downLoadZip(`/api/mmp/models/downloadAllFiles`, { models_id: locationParams.id, version }); }; const downloadAlone = (e, record) => { console.log(record); const hide = message.loading('正在下载'); hide(); downLoadZip(`/api/mmp/models/download_model/${record.id}`); }; const handleChange = (value) => { console.log(value); if (value) { getModelVersions({ version: value, models_id: locationParams.id }); setVersion(value); } else { setVersion(null); } }; const onFinishFailed = (errorInfo) => { console.log('Failed:', errorInfo); }; const columns = [ // { // title: '序号', // dataIndex: 'index', // key: 'index', // width: 80, // render(text, record, index) { // return ( // {(pageOption.current.page - 1) * 10 + index + 1} // ) // } // // render: (text, record, index) => `${((curPage-1)*10)+(index+1)}`, // }, { title: '文件名称', dataIndex: 'file_name', key: 'file_name', render: (text, record) => downloadAlone(e, record)}>{text}, }, { title: '版本号', dataIndex: 'version', key: 'version', }, { title: '文件大小', dataIndex: 'file_size', key: 'file_size', }, { title: '更新时间', dataIndex: 'update_time', key: 'update_time', render: (text) => {moment(text).format('YYYY-MM-DD HH:mm:ss')}, }, ]; const pageOption = useRef({ page: 1, size: 10 }); // 当前页面切换 const paginationChange = async (current, size) => { console.log('page', current, size); pageOption.current = { page: current, size: size, }; // getList() }; return (