|
|
|
@ -5,6 +5,7 @@ import {beforeUploadFile} from '@/utils/common';
|
|
|
|
|
import { CloseOutlined, SnippetsOutlined } from '@ant-design/icons';
|
|
|
|
|
import type { ProFormInstance } from '@ant-design/pro-components';
|
|
|
|
|
import {
|
|
|
|
|
ProCard,
|
|
|
|
|
ProForm,
|
|
|
|
|
ProFormList,
|
|
|
|
|
ProFormSwitch,
|
|
|
|
@ -13,14 +14,14 @@ import {
|
|
|
|
|
StepsForm,
|
|
|
|
|
} from '@ant-design/pro-components';
|
|
|
|
|
import { FormattedMessage, useIntl } from '@umijs/max';
|
|
|
|
|
import {Modal, Switch, Transfer, Tree, message, UploadFile} from 'antd';
|
|
|
|
|
import { Modal, Switch, Transfer, Tree, UploadFile, message } from 'antd';
|
|
|
|
|
import type { TransferDirection } from 'antd/es/transfer';
|
|
|
|
|
import { DataNode } from 'antd/es/tree';
|
|
|
|
|
import React, { useEffect, useRef, useState } from 'react';
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
import { FormListActionType } from '@ant-design/pro-form/lib';
|
|
|
|
|
import yaml from 'js-yaml';
|
|
|
|
|
import cookie from 'react-cookies';
|
|
|
|
|
import {FormListActionType} from "@ant-design/pro-form/lib";
|
|
|
|
|
import yaml from "js-yaml";
|
|
|
|
|
|
|
|
|
|
interface RecordType {
|
|
|
|
|
key: string;
|
|
|
|
@ -56,7 +57,7 @@ const waitTime = (time: number = 100) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**styles 配置 */
|
|
|
|
|
const formContainerWidth: number = 755
|
|
|
|
|
const formContainerWidth: number = 755;
|
|
|
|
|
const stepFormItemStyleProps: Record<string, any> = {
|
|
|
|
|
width: formContainerWidth,
|
|
|
|
|
};
|
|
|
|
@ -152,7 +153,7 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
|
const [current, setCurrent] = useState(0);
|
|
|
|
|
|
|
|
|
|
const [dataFormList, setDataFormList] = useState<any>([]);
|
|
|
|
|
const dataFormListRef = useRef(dataFormList)
|
|
|
|
|
const dataFormListRef = useRef(dataFormList);
|
|
|
|
|
const [fileList, setFileList] = useState<UploadFile<any>[]>([]);
|
|
|
|
|
|
|
|
|
|
const actionFormListRef = useRef<
|
|
|
|
@ -176,8 +177,7 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setFileList([...curFile]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getModelData = () => {
|
|
|
|
|
postAlgorithmModelGetAlgorithmModelFkSelect({ keyword: '' }).then((res) => {
|
|
|
|
@ -205,8 +205,7 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
|
.then((resp: API.Response) => {
|
|
|
|
|
setTreeData(resp.data.tree);
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
});
|
|
|
|
|
.catch(() => {});
|
|
|
|
|
} else {
|
|
|
|
|
formRef.current?.resetFields();
|
|
|
|
|
}
|
|
|
|
@ -233,7 +232,7 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
|
current={current}
|
|
|
|
|
onCurrentChange={setCurrent}
|
|
|
|
|
onFinish={async () => {
|
|
|
|
|
setFileList([])
|
|
|
|
|
setFileList([]);
|
|
|
|
|
let formData = formRef.current?.getFieldsValue();
|
|
|
|
|
if (formData?.name) {
|
|
|
|
|
formData.inferConfig = { models: targetKeys, params: configData?.params || [] };
|
|
|
|
@ -264,7 +263,7 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
|
width={803}
|
|
|
|
|
onCancel={() => {
|
|
|
|
|
setCurrent(0);
|
|
|
|
|
setFileList([])
|
|
|
|
|
setFileList([]);
|
|
|
|
|
formRef.current?.resetFields();
|
|
|
|
|
formRef3.current?.resetFields();
|
|
|
|
|
props.handleModal();
|
|
|
|
@ -423,7 +422,6 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
|
dataSource={modalData}
|
|
|
|
|
showSearch
|
|
|
|
|
titles={['未选模型', '已选模型']}
|
|
|
|
|
|
|
|
|
|
locale={{ itemUnit: '项', itemsUnit: '项', searchPlaceholder: '请输入搜索内容' }}
|
|
|
|
|
targetKeys={targetKeys}
|
|
|
|
|
onChange={handleChange}
|
|
|
|
@ -485,7 +483,8 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
|
{/* <Icon type="delete" /> */}
|
|
|
|
|
{/* TODO 图标需要替换 */}
|
|
|
|
|
|
|
|
|
|
<ProFormUploadDragger max={1}
|
|
|
|
|
<ProFormUploadDragger
|
|
|
|
|
max={1}
|
|
|
|
|
label="配置文件上传"
|
|
|
|
|
value={fileList}
|
|
|
|
|
name="dragger"
|
|
|
|
@ -493,18 +492,23 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
|
onChange: handleFileChange,
|
|
|
|
|
onRemove: () => {
|
|
|
|
|
let index_ids = actionFormListRef.current?.getList()?.map((v, i) => {
|
|
|
|
|
return i
|
|
|
|
|
})
|
|
|
|
|
actionFormListRef.current?.remove(index_ids || [])
|
|
|
|
|
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
|
|
|
|
|
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) => {
|
|
|
|
|
let parsedData = {};
|
|
|
|
|
file
|
|
|
|
|
.text()
|
|
|
|
|
.then((text) => {
|
|
|
|
|
if (file.name.endsWith('.yaml') || file.name.endsWith('.yml')) {
|
|
|
|
|
parsedData = yaml.load(text) as Record<string, unknown>;
|
|
|
|
|
}
|
|
|
|
@ -514,17 +518,18 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
|
if (Object.keys(parsedData).length > 0) {
|
|
|
|
|
dataFormListRef.current = Object.entries(parsedData).map(([key, value]) => ({
|
|
|
|
|
name: key,
|
|
|
|
|
default: value
|
|
|
|
|
}))
|
|
|
|
|
default: value,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
dataFormListRef.current.forEach((v: any, i: number) => {
|
|
|
|
|
actionFormListRef.current?.add(v, i)
|
|
|
|
|
})
|
|
|
|
|
actionFormListRef.current?.add(v, i);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
return false
|
|
|
|
|
return true;
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
@ -543,11 +548,17 @@ const MyCreateForm: React.FC<CreateFormProps> = (props) => {
|
|
|
|
|
>
|
|
|
|
|
{(f, index, action) => {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<ProCard style={{padding: 0, margin: 0}} bodyStyle={{padding: 0, margin: 0 }}>
|
|
|
|
|
<ProCard style={{padding: 0, margin: 0}} bodyStyle={{padding: 0, marginRight: 10}}>
|
|
|
|
|
<ProFormText key="name" name="name" label="键名" />
|
|
|
|
|
</ProCard>
|
|
|
|
|
<ProCard style={{padding: 0, margin: 0}} bodyStyle={{padding: 0, marginRight: 10}}>
|
|
|
|
|
<ProFormText key="default" name="default" label="默认值" />
|
|
|
|
|
</ProCard>
|
|
|
|
|
<ProCard style={{padding: 0, margin: 0}} bodyStyle={{padding: 0, marginRight: 10}}>
|
|
|
|
|
<ProFormText key="remark" name="remark" label="备注" />
|
|
|
|
|
</>
|
|
|
|
|
</ProCard>
|
|
|
|
|
</ProCard>
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
</ProFormList>
|
|
|
|
|