import React, {useEffect, useState} from 'react'; import { Alert, Col, Collapse, Form, Input, InputNumber, Modal, Radio, Row, Select, Switch, Tooltip, Typography } from "antd/lib/index"; import {isEmpty} from "../../utils/utils"; import request from "../../common/request"; const {TextArea} = Input; const {Option} = Select; const {Text} = 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 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 [sshMode, setSshMode] = useState(model['ssh-mode']); let initAccountTypes = [] if (model.protocol) { initAccountTypes = protocolMapping[model.protocol]; } let [accountTypes, setAccountTypes] = useState(initAccountTypes); let [useSSL, setUseSSL] = useState(model['use-ssl']); 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; case 'kubernetes': port = 6443; break default: port = 65535; } form.setFieldsValue({ port: port, }); }; const handleAccountTypeChange = v => { setAccountType(v); model.accountType = v; } let [enableDrive, setEnableDrive] = useState(model['enable-drive']); let [socksProxyEnable, setSocksProxyEnable] = useState(model['socks-proxy-enable']); let [storages, setStorages] = useState([]); useEffect(() => { const getStorages = async () => { const result = await request.get('/storages/shares'); if (result.code === 1) { setStorages(result['data']); } } getStorages(); }, []); let [accessGateways, setAccessGateways] = useState([]); useEffect(() => { const getAccessGateways = async () => { const result = await request.get('/access-gateways'); if (result.code === 1) { setAccessGateways(result['data']); } } getAccessGateways(); }, []); return ( { form .validateFields() .then(values => { form.resetFields(); handleOk(values); }) .catch(info => { }); }} centered={true} width={1040} onCancel={handleCancel} confirmLoading={confirmLoading} okText='确定' cancelText='取消' >
RDP SSH VNC Telnet Kubernetes { protocol === 'kubernetes' ? <> : <> { accountType === 'credential' ? <> {protocol === 'ssh' ? : null} : null } { accountType === 'custom' ? <> : null } { accountType === 'private-key' ? <>