import React, {useState} from 'react'; import { Col, Collapse, Form, Input, InputNumber, Modal, Radio, Row, Select, Switch, Tooltip, Typography } from "antd/lib/index"; import {ExclamationCircleOutlined} from "@ant-design/icons"; const {TextArea} = Input; const {Option} = Select; const {Text, Title} = Typography; const {Panel} = Collapse; // 子级页面 // Ant form create 表单内置方法 const protocolMapping = { 'ssh': [ {text: '密码', value: 'custom'}, {text: '密钥', value: 'private-key'}, {text: '授权凭证', value: 'credential'}, ], 'rdp': [{text: '密码', value: 'custom'}, {text: '授权凭证', value: 'credential'}], 'vnc': [{text: '密码', value: 'custom'}, {text: '授权凭证', value: 'credential'}], 'telnet': [{text: '密码', value: 'custom'}, {text: '授权凭证', value: 'credential'}] } const formLayout = { labelCol: {span: 6}, wrapperCol: {span: 18}, }; const RDPFormItemLayout = { labelCol: {span: 12}, wrapperCol: {span: 12}, }; const TELENETFormItemLayout = { labelCol: {span: 8}, wrapperCol: {span: 16}, }; const AssetModal = function ({title, visible, handleOk, handleCancel, confirmLoading, credentials, tags, model}) { const [form] = Form.useForm(); if (model.accountType === undefined) { model.accountType = 'rdp'; } let [accountType, setAccountType] = useState(model.accountType); let [protocol, setProtocol] = useState(model.protocol); let initAccountTypes = [] if (model.protocol) { initAccountTypes = protocolMapping[model.protocol]; } let [accountTypes, setAccountTypes] = useState(initAccountTypes); for (let key in model) { if (model.hasOwnProperty(key)) { if (model[key] === '-') { model[key] = ''; } } } const handleProtocolChange = e => { setProtocol(e.target.value) 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 = 5900; 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 => { }); }} width={1040} onCancel={handleCancel} confirmLoading={confirmLoading} okText='确定' cancelText='取消' >
rdp ssh vnc telnet { accountType === 'credential' ? : null } { accountType === 'custom' ? <> : null } { accountType === 'private-key' ? <>