import React, {useEffect, useState} from 'react'; import {Form, Input, InputNumber, Modal, Radio, Select, Tooltip} from "antd/lib/index"; const {TextArea} = Input; const {Option} = Select; // 子级页面 // Ant form create 表单内置方法 const protocolMapping = { 'ssh': [ {text: '自定义', value: 'custom'}, {text: '授权凭证', value: 'credential'}, {text: '私钥', value: 'private-key'} ], 'rdp': [{text: '自定义', value: 'custom'}, {text: '授权凭证', value: 'credential'}], 'vnc': [{text: '自定义', value: 'custom'}, {text: '授权凭证', value: 'credential'}], 'telnet': [{text: '自定义', value: 'custom'}, {text: '授权凭证', value: 'credential'}] } const AssetModal = function ({title, visible, handleOk, handleCancel, confirmLoading, credentials, model}) { const [form] = Form.useForm(); let [accountType, setAccountType] = useState(model.accountType); let initAccountTypes = [] if (model.protocol) { initAccountTypes = protocolMapping[model.protocol]; } let [accountTypes, setAccountTypes] = useState(initAccountTypes); useEffect(() => { setAccountType(model.accountType); }); for (let key in model) { if (model.hasOwnProperty(key)) { if (model[key] === '-') { model[key] = ''; } } } const formItemLayout = { labelCol: {span: 6}, wrapperCol: {span: 14}, }; const handleProtocolChange = e => { let port; switch (e.target.value) { case 'ssh': port = 22; setAccountTypes(protocolMapping['ssh']); form.setFieldsValue({ accountType: 'custom', }); handleAccountTypeChange('custom'); break; case 'rdp': port = 3389; setAccountTypes(protocolMapping['rdp']); form.setFieldsValue({ accountType: 'custom', }); handleAccountTypeChange('custom'); break; case 'vnc': port = 5901; setAccountTypes(protocolMapping['vnc']); form.setFieldsValue({ accountType: 'custom', }); handleAccountTypeChange('custom'); break; case 'telnet': port = 23; setAccountTypes(protocolMapping['telnet']); form.setFieldsValue({ accountType: 'custom', }); handleAccountTypeChange('custom'); break; default: port = 65535; } form.setFieldsValue({ port: port, }); }; const handleAccountTypeChange = v => { setAccountType(v); model.accountType = v; } return ( { form .validateFields() .then(values => { form.resetFields(); handleOk(values); }) .catch(info => { }); }} onCancel={handleCancel} confirmLoading={confirmLoading} okText='确定' cancelText='取消' >
rdp ssh vnc telnet { accountType === 'credential' ? : null } { accountType === 'custom' ? <> : null } { accountType === 'private-key' ? <>