import React, { useEffect, useState } from 'react' ; import { Modal, Form, Select, Grid, Slider, Switch, Input, Message } from '@arco-design/web-react'; import EditableTable from '@/components/EditableTable'; import { getComponentClassify } from '@/api/componentClassify'; import { getHostList } from '@/api/componentDeployEnv'; import { createInstance, localStart } from '@/api/componentInstance'; const FormItem = Form.Item; const Option = Select.Option; const runTypes = [ { label: '本地运行', value: 'local' }, { label: '线上运行', value: 'online' } ]; const portColumns = [ { title: '主机端口', dataIndex: 'name', editable: true }, { title: '容器端口', dataIndex: 'salary', editable: true }, { title: '备注', dataIndex: 'email', editable: true } ]; const directoryColumns = [ { title: '主机路径', dataIndex: 'name', editable: true }, { title: '容器路径', dataIndex: 'salary', editable: true }, { title: '备注', dataIndex: 'email', editable: true } ]; const deviceColumns = [ { title: '主机路径', dataIndex: 'name', editable: true }, { title: '容器路径', dataIndex: 'salary', editable: true }, { title: '权限', dataIndex: 'email', editable: true }, { title: '备注', dataIndex: 'email', editable: true } ]; const AddModal = ({ addItem, visible, setVisible, onSuccess }) => { const [form] = Form.useForm(); const [currentRunType, setCurrentRunType] = useState('local'); const [envType, setEnvType] = useState([]); // 环境类型 const [hostOptions, setHostOptions] = useState([]); // 主机 const [tableData, setTableData] = useState([]); const [loading, setLoading] = useState(false); const getEnvOptions = async () => { const res: any = await getComponentClassify('docker-env'); if (res.code === 200) setEnvType(res.data); }; const getHostOptions = async () => { const res: any = await getHostList({ // type: 'docker-env', componentBaseId: addItem.componentBaseId }); if (res.code === 200) setHostOptions(res.data); }; useEffect(() => { if (visible) { getHostOptions(); getEnvOptions(); } else { // 关闭时重置表单 form.resetFields(); setCurrentRunType('local'); setTableData([]); } }, [visible]); // 处理取消 const handleCancel = () => { form.resetFields(); setCurrentRunType('local'); setTableData([]); setVisible(false); }; // 处理确认 const handleOk = async () => { try { setLoading(true); const values = await form.validate(); // 整理参数 const params = { deployEnvId: values.deployEnvId, componentBaseId: addItem.componentBaseId }; const apiMap = { 'local': localStart, // 本地运行 'online': createInstance // 线上运行 }; const res: any = await apiMap[currentRunType](params); if (res.code === 200) { Message.success('新增实例成功'); handleCancel(); // 关闭弹窗并重置表单 // 调用成功回调刷新数据 if (onSuccess) { onSuccess(); } } else { Message.error(res.msg || '新增实例失败'); } } catch (error) { console.error('表单校验失败:', error); } finally { setLoading(false); } }; return (
{ currentRunType === 'online' && ( <> {/**/} {/* */} {/* */} {/* {envType.map((option, index) => (*/} {/* */} {/* ))}*/} {/* */} {/* */} {/**/} { if (!value) { return cb('请选择主机'); } return cb(null); } } ]} > {/**/} {/* */} {/* */} {/* */} {/* */} {/* */} {/* */} {/* */} {/* */} {/* */} {/* */} {/**/} {/**/} {/* */} {/**/} {/**/} {/* */} {/* */} {/* */} {/* {runTypes.map((option, index) => (*/} {/* */} {/* ))}*/} {/* */} {/* */} {/* */} {/* */} {/* */} {/* */} {/* {runTypes.map((option, index) => (*/} {/* */} {/* ))}*/} {/* */} {/* */} {/* */} {/* */} {/* */} {/* */} {/* */} {/* */} {/**/} {/**/} {/* setTableData(newData)}*/} {/* showAddButton={true}*/} {/* addButtonText="添加行"*/} {/* showDeleteButton={true}*/} {/* deleteButtonText="删除"*/} {/* tableProps={{*/} {/* pagination: { pageSize: 5 },*/} {/* scroll: { y: 400 }*/} {/* }}*/} {/* />*/} {/**/} {/**/} {/* setTableData(newData)}*/} {/* showAddButton={true}*/} {/* addButtonText="添加行"*/} {/* showDeleteButton={true}*/} {/* deleteButtonText="删除"*/} {/* tableProps={{*/} {/* pagination: { pageSize: 5 },*/} {/* scroll: { y: 400 }*/} {/* }}*/} {/* />*/} {/**/} {/**/} {/* setTableData(newData)}*/} {/* showAddButton={true}*/} {/* addButtonText="添加行"*/} {/* showDeleteButton={true}*/} {/* deleteButtonText="删除"*/} {/* tableProps={{*/} {/* pagination: { pageSize: 5 },*/} {/* scroll: { y: 400 }*/} {/* }}*/} {/* />*/} {/**/} ) }
); }; export default AddModal;