|
|
@ -13,21 +13,26 @@ import {
|
|
|
|
StepsForm,
|
|
|
|
StepsForm,
|
|
|
|
} from '@ant-design/pro-components';
|
|
|
|
} from '@ant-design/pro-components';
|
|
|
|
import {FormattedMessage, useIntl} from '@umijs/max';
|
|
|
|
import {FormattedMessage, useIntl} from '@umijs/max';
|
|
|
|
import { Modal, Switch, Transfer, Tree, message } from 'antd';
|
|
|
|
import {Modal, Switch, Transfer, Tree, message, UploadFile} from 'antd';
|
|
|
|
import type {TransferDirection} from 'antd/es/transfer';
|
|
|
|
import type {TransferDirection} from 'antd/es/transfer';
|
|
|
|
import {DataNode} from 'antd/es/tree';
|
|
|
|
import {DataNode} from 'antd/es/tree';
|
|
|
|
import React, {useEffect, useRef, useState} from 'react';
|
|
|
|
import React, {useEffect, useRef, useState} from 'react';
|
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
import cookie from 'react-cookies';
|
|
|
|
import cookie from 'react-cookies';
|
|
|
|
|
|
|
|
import {FormListActionType} from "@ant-design/pro-form/lib";
|
|
|
|
|
|
|
|
import yaml from "js-yaml";
|
|
|
|
|
|
|
|
|
|
|
|
interface RecordType {
|
|
|
|
interface RecordType {
|
|
|
|
key: string;
|
|
|
|
key: string;
|
|
|
|
title: string;
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
description: string;
|
|
|
|
chosen: boolean;
|
|
|
|
chosen: boolean;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface ProjectConfig {
|
|
|
|
interface ProjectConfig {
|
|
|
|
params: Array<object>;
|
|
|
|
params: Array<object>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export type FormValueType = {
|
|
|
|
export type FormValueType = {
|
|
|
|
target?: string;
|
|
|
|
target?: string;
|
|
|
|
template?: string;
|
|
|
|
template?: string;
|
|
|
@ -145,9 +150,37 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
const formRef = useRef<ProFormInstance>();
|
|
|
|
const formRef = useRef<ProFormInstance>();
|
|
|
|
const formRef3 = useRef<ProFormInstance>();
|
|
|
|
const formRef3 = useRef<ProFormInstance>();
|
|
|
|
const [current, setCurrent] = useState(0);
|
|
|
|
const [current, setCurrent] = useState(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [dataFormList, setDataFormList] = useState<any>([]);
|
|
|
|
|
|
|
|
const dataFormListRef = useRef(dataFormList)
|
|
|
|
|
|
|
|
const [fileList, setFileList] = useState<UploadFile<any>[]>([]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const actionFormListRef = useRef<
|
|
|
|
|
|
|
|
FormListActionType<{
|
|
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
|
|
}>
|
|
|
|
|
|
|
|
>();
|
|
|
|
|
|
|
|
const handleFileChange = ({file}: { file: UploadFile }) => {
|
|
|
|
|
|
|
|
let curFile: any;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (file.status) {
|
|
|
|
|
|
|
|
case 'uploading':
|
|
|
|
|
|
|
|
case 'done':
|
|
|
|
|
|
|
|
curFile = [file];
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'removed':
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
curFile = [];
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setFileList([...curFile]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getModelData = () => {
|
|
|
|
const getModelData = () => {
|
|
|
|
postAlgorithmModelGetAlgorithmModelFkSelect({keyword: ''}).then((res) => {
|
|
|
|
postAlgorithmModelGetAlgorithmModelFkSelect({keyword: ''}).then((res) => {
|
|
|
|
console.log(444, res);
|
|
|
|
|
|
|
|
let result = (res.data?.list || []).map((v: any) => {
|
|
|
|
let result = (res.data?.list || []).map((v: any) => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
key: v.id,
|
|
|
|
key: v.id,
|
|
|
@ -172,14 +205,14 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
.then((resp: API.Response) => {
|
|
|
|
.then((resp: API.Response) => {
|
|
|
|
setTreeData(resp.data.tree);
|
|
|
|
setTreeData(resp.data.tree);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
|
|
|
.catch(() => {
|
|
|
|
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
formRef.current?.resetFields();
|
|
|
|
formRef.current?.resetFields();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [props.createModalOpen]);
|
|
|
|
}, [props.createModalOpen]);
|
|
|
|
const handleSearch = (dir: TransferDirection, value: string) => {
|
|
|
|
const handleSearch = (dir: TransferDirection, value: string) => {
|
|
|
|
postAlgorithmModelGetAlgorithmModelFkSelect({keyword: value}).then((res) => {
|
|
|
|
postAlgorithmModelGetAlgorithmModelFkSelect({keyword: value}).then((res) => {
|
|
|
|
console.log(444, res);
|
|
|
|
|
|
|
|
let result = (res.data?.list || []).map((v: any) => {
|
|
|
|
let result = (res.data?.list || []).map((v: any) => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
key: v.id,
|
|
|
|
key: v.id,
|
|
|
@ -200,6 +233,7 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
current={current}
|
|
|
|
current={current}
|
|
|
|
onCurrentChange={setCurrent}
|
|
|
|
onCurrentChange={setCurrent}
|
|
|
|
onFinish={async () => {
|
|
|
|
onFinish={async () => {
|
|
|
|
|
|
|
|
setFileList([])
|
|
|
|
let formData = formRef.current?.getFieldsValue();
|
|
|
|
let formData = formRef.current?.getFieldsValue();
|
|
|
|
if (formData?.name) {
|
|
|
|
if (formData?.name) {
|
|
|
|
formData.inferConfig = {models: targetKeys, params: configData?.params || []};
|
|
|
|
formData.inferConfig = {models: targetKeys, params: configData?.params || []};
|
|
|
@ -230,6 +264,7 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
width={803}
|
|
|
|
width={803}
|
|
|
|
onCancel={() => {
|
|
|
|
onCancel={() => {
|
|
|
|
setCurrent(0);
|
|
|
|
setCurrent(0);
|
|
|
|
|
|
|
|
setFileList([])
|
|
|
|
formRef.current?.resetFields();
|
|
|
|
formRef.current?.resetFields();
|
|
|
|
formRef3.current?.resetFields();
|
|
|
|
formRef3.current?.resetFields();
|
|
|
|
props.handleModal();
|
|
|
|
props.handleModal();
|
|
|
@ -449,8 +484,54 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
>
|
|
|
|
>
|
|
|
|
{/* <Icon type="delete" /> */}
|
|
|
|
{/* <Icon type="delete" /> */}
|
|
|
|
{/* TODO 图标需要替换 */}
|
|
|
|
{/* TODO 图标需要替换 */}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<ProFormUploadDragger max={1}
|
|
|
|
|
|
|
|
label="配置文件上传"
|
|
|
|
|
|
|
|
value={fileList}
|
|
|
|
|
|
|
|
name="dragger"
|
|
|
|
|
|
|
|
fieldProps={{
|
|
|
|
|
|
|
|
onChange: handleFileChange,
|
|
|
|
|
|
|
|
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
|
|
|
|
<ProFormList
|
|
|
|
style={{width: stepFormItemStyleProps.width}}
|
|
|
|
style={{width: stepFormItemStyleProps.width}}
|
|
|
|
|
|
|
|
actionRef={actionFormListRef}
|
|
|
|
copyIconProps={{
|
|
|
|
copyIconProps={{
|
|
|
|
Icon: SnippetsOutlined,
|
|
|
|
Icon: SnippetsOutlined,
|
|
|
|
}}
|
|
|
|
}}
|
|
|
@ -459,13 +540,16 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
name="params"
|
|
|
|
name="params"
|
|
|
|
label="模型参数"
|
|
|
|
label="模型参数"
|
|
|
|
initialValue={[]}
|
|
|
|
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<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>
|
|
|
|
{/* 关联网点 */}
|
|
|
|
{/* 关联网点 */}
|
|
|
|