|
|
@ -2,18 +2,19 @@ import {
|
|
|
|
ProForm,
|
|
|
|
ProForm,
|
|
|
|
ProFormInstance,
|
|
|
|
ProFormInstance,
|
|
|
|
ProFormList,
|
|
|
|
ProFormList,
|
|
|
|
|
|
|
|
ProFormSelect,
|
|
|
|
|
|
|
|
ProFormSwitch,
|
|
|
|
|
|
|
|
ProFormText,
|
|
|
|
|
|
|
|
ProFormUploadDragger,
|
|
|
|
StepsForm
|
|
|
|
StepsForm
|
|
|
|
} from '@ant-design/pro-components';import {ProFormSelect} from '@ant-design/pro-components';
|
|
|
|
} from '@ant-design/pro-components';
|
|
|
|
import {ProFormText} from '@ant-design/pro-components';
|
|
|
|
|
|
|
|
import {ProFormSwitch} from '@ant-design/pro-components';
|
|
|
|
|
|
|
|
import {FormattedMessage, useIntl} from '@umijs/max';
|
|
|
|
import {FormattedMessage, useIntl} from '@umijs/max';
|
|
|
|
import {postAlgorithmModelGetAlgorithmModelFkSelect} from "@/services/resource/AlgorithmModel";
|
|
|
|
import {postAlgorithmModelGetAlgorithmModelFkSelect} from "@/services/resource/AlgorithmModel";
|
|
|
|
import {postModelVersionCreateModelVersion} from "@/services/resource/ModelVersion";
|
|
|
|
import {postModelVersionCreateModelVersion} from "@/services/resource/ModelVersion";
|
|
|
|
import React, {useState} from 'react';
|
|
|
|
import React, {useRef, useState} from 'react';
|
|
|
|
import {Form, message, Modal} from 'antd';
|
|
|
|
import {Form, message, Modal, UploadFile} from 'antd';
|
|
|
|
|
|
|
|
import yaml from 'js-yaml';
|
|
|
|
import { CloseOutlined, SnippetsOutlined } from '@ant-design/icons';
|
|
|
|
import {FormListActionType} from "@ant-design/pro-form/lib";
|
|
|
|
import { useRef } from 'react';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type FormValueType = {
|
|
|
|
export type FormValueType = {
|
|
|
@ -41,13 +42,36 @@ interface ProjectConfig {
|
|
|
|
params: Array<object>;
|
|
|
|
params: Array<object>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const MyCreateForm: React.FC<MyCreateFormProps> = (props) => {
|
|
|
|
const MyCreateForm: React.FC<MyCreateFormProps> = (props) => {
|
|
|
|
|
|
|
|
const actionFormListRef = useRef<
|
|
|
|
|
|
|
|
FormListActionType<{
|
|
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
|
|
}>
|
|
|
|
|
|
|
|
>(); const handleChange = ({ file }: { file: UploadFile }) => {
|
|
|
|
|
|
|
|
let curFile: any;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (file.status) {
|
|
|
|
|
|
|
|
case 'uploading':
|
|
|
|
|
|
|
|
case 'done':
|
|
|
|
|
|
|
|
curFile = [file];
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'removed':
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
curFile = [];
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setFileList([...curFile]);
|
|
|
|
|
|
|
|
}
|
|
|
|
const intl = useIntl();
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
const [dataFormList, setDataFormList] = useState<any>([]);
|
|
|
|
|
|
|
|
const dataFormListRef = useRef(dataFormList)
|
|
|
|
|
|
|
|
const [fileList, setFileList] = useState<UploadFile<any>[]>([]);
|
|
|
|
|
|
|
|
|
|
|
|
const [form] = Form.useForm<API.ModelVersion>();
|
|
|
|
const [form] = Form.useForm<API.ModelVersion>();
|
|
|
|
const [current, setCurrent] = useState(0);
|
|
|
|
const [current, setCurrent] = useState(0);
|
|
|
|
const formRef = useRef<ProFormInstance>();
|
|
|
|
const formRef = useRef<ProFormInstance>();
|
|
|
|
const [configData, setConfigData] = useState<ProjectConfig>({params: []});
|
|
|
|
const [configData, setConfigData] = useState<ProjectConfig>({params: []});
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
|
|
|
|
|
|
|
|
<StepsForm<{
|
|
|
|
<StepsForm<{
|
|
|
@ -56,21 +80,6 @@ const MyCreateForm: React.FC<MyCreateFormProps> = (props) => {
|
|
|
|
stepsProps={{}}
|
|
|
|
stepsProps={{}}
|
|
|
|
current={current}
|
|
|
|
current={current}
|
|
|
|
onCurrentChange={setCurrent}
|
|
|
|
onCurrentChange={setCurrent}
|
|
|
|
onFinish={async () => {
|
|
|
|
|
|
|
|
let formData = formRef.current?.getFieldsValue();
|
|
|
|
|
|
|
|
if (formData?.modelFkId) {
|
|
|
|
|
|
|
|
formData.modelConfig = {params: configData?.params || []};
|
|
|
|
|
|
|
|
postModelVersionCreateModelVersion(formData).then(()=>{
|
|
|
|
|
|
|
|
message.success(intl.formatMessage({id: 'common.success', defaultMessage: '$$$'}))
|
|
|
|
|
|
|
|
props.handleModal();
|
|
|
|
|
|
|
|
props.reload()
|
|
|
|
|
|
|
|
}).catch(()=>{
|
|
|
|
|
|
|
|
message.error(intl.formatMessage({id: 'common.failure', defaultMessage: '$$$'}))
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
formProps={{
|
|
|
|
formProps={{
|
|
|
|
validateMessages: {
|
|
|
|
validateMessages: {
|
|
|
|
required: '此项为必填项',
|
|
|
|
required: '此项为必填项',
|
|
|
@ -84,6 +93,7 @@ const MyCreateForm: React.FC<MyCreateFormProps> = (props) => {
|
|
|
|
onCancel={()=>{
|
|
|
|
onCancel={()=>{
|
|
|
|
setCurrent(0)
|
|
|
|
setCurrent(0)
|
|
|
|
formRef.current?.resetFields()
|
|
|
|
formRef.current?.resetFields()
|
|
|
|
|
|
|
|
setFileList([])
|
|
|
|
props.handleModal();
|
|
|
|
props.handleModal();
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
open={props.createModalOpen}
|
|
|
|
open={props.createModalOpen}
|
|
|
@ -151,28 +161,83 @@ const MyCreateForm: React.FC<MyCreateFormProps> = (props) => {
|
|
|
|
description: '业务参数配置',
|
|
|
|
description: '业务参数配置',
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
onFinish={async (values: any) => {
|
|
|
|
onFinish={async (values: any) => {
|
|
|
|
setConfigData(values)
|
|
|
|
let formData = formRef.current?.getFieldsValue();
|
|
|
|
|
|
|
|
if (formData?.modelFkId) {
|
|
|
|
|
|
|
|
await waitTime(500)
|
|
|
|
|
|
|
|
formData.modelConfig = {params: values?.params || []};
|
|
|
|
|
|
|
|
postModelVersionCreateModelVersion(formData).then(()=>{
|
|
|
|
|
|
|
|
message.success(intl.formatMessage({id: 'common.success', defaultMessage: '$$$'}))
|
|
|
|
|
|
|
|
props.handleModal();
|
|
|
|
|
|
|
|
props.reload()
|
|
|
|
|
|
|
|
}).catch(()=>{
|
|
|
|
|
|
|
|
message.error(intl.formatMessage({id: 'common.failure', defaultMessage: '$$$'}))
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<ProFormList
|
|
|
|
<ProFormUploadDragger max={1}
|
|
|
|
copyIconProps={{
|
|
|
|
label="配置文件上传"
|
|
|
|
Icon: SnippetsOutlined,
|
|
|
|
value={fileList}
|
|
|
|
}}
|
|
|
|
name="dragger"
|
|
|
|
deleteIconProps={{
|
|
|
|
fieldProps={{
|
|
|
|
Icon: CloseOutlined,
|
|
|
|
onChange: handleChange,
|
|
|
|
|
|
|
|
onRemove: ()=>{
|
|
|
|
|
|
|
|
let index_ids = actionFormListRef.current?.getList()?.map((v, i)=>{
|
|
|
|
|
|
|
|
return i
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
actionFormListRef.current?.remove(index_ids || [])
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeUpload: (file, fileList)=>{
|
|
|
|
|
|
|
|
if ( !file.name.endsWith('.yaml') && !file.name.endsWith('.yml') && !file.name.endsWith('.json')) {
|
|
|
|
|
|
|
|
message.error('请上传yaml或json文件').then(()=>{})
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
let parsedData = {}
|
|
|
|
|
|
|
|
file.text().then((text)=>{
|
|
|
|
|
|
|
|
if (file.name.endsWith('.yaml') || file.name.endsWith('.yml')) {
|
|
|
|
|
|
|
|
parsedData = yaml.load(text) as Record<string, unknown>;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file.name.endsWith('.json')) {
|
|
|
|
|
|
|
|
parsedData = JSON.parse(text) as Record<string, unknown>;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Object.keys(parsedData).length > 0) {
|
|
|
|
|
|
|
|
dataFormListRef.current = Object.entries(parsedData).map(([key, value]) => ({
|
|
|
|
|
|
|
|
name: key,
|
|
|
|
|
|
|
|
default: value
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataFormListRef.current.forEach((v:any, i:number)=>{
|
|
|
|
|
|
|
|
actionFormListRef.current?.add(v, i)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}).catch(()=>{
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
<ProFormList
|
|
|
|
name="params"
|
|
|
|
name="params"
|
|
|
|
label="模型参数"
|
|
|
|
label="模型参数"
|
|
|
|
initialValue={[
|
|
|
|
actionRef={actionFormListRef}
|
|
|
|
]}
|
|
|
|
itemContainerRender={(doms) => {
|
|
|
|
|
|
|
|
return <ProForm.Group>{doms}</ProForm.Group>;
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
alwaysShowItemLabel
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<ProForm.Group>
|
|
|
|
{(f, index, action) => {
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<>
|
|
|
|
<ProFormText key="name" name="name" label="键名" />
|
|
|
|
<ProFormText key="name" name="name" label="键名" />
|
|
|
|
<ProFormText key="default" name="default" label="默认值" />
|
|
|
|
<ProFormText key="default" name="default" label="默认值" />
|
|
|
|
<ProFormText key="remark" name="remark" label="备注" />
|
|
|
|
<ProFormText key="remark" name="remark" label="备注" />
|
|
|
|
</ProForm.Group>
|
|
|
|
</>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}}
|
|
|
|
</ProFormList>
|
|
|
|
</ProFormList>
|
|
|
|
</StepsForm.StepForm>
|
|
|
|
</StepsForm.StepForm>
|
|
|
|
</StepsForm>
|
|
|
|
</StepsForm>
|
|
|
|