import React, { useEffect, useRef, useState } from 'react'; import { Input } from 'antd'; import IconFont from '../../extra/iconFont'; import styles from './styles.less'; import { ApolloLinkProps } from '../editInterface'; const Link = (props: ApolloLinkProps) => { const { onEmitChange } = props; const [value, setValue] = useState(props.value); const dom = useRef(value); const changeText = (i, e) => { const newValue = (value && value.slice()) || []; newValue[i].text = e.target.value; setValue(newValue); dom.current = newValue; }; const changeValue = (i, e) => { const newValue = (value && value.slice()) || []; newValue[i].value = e.target.value; setValue(newValue); dom.current = newValue; }; const addLink = () => { const newValue = (value && value.slice()) || []; newValue.push({ text: '', value: '' }); setValue(newValue); dom.current = newValue; }; const delLink = (i) => { let newValue = (value && value.slice()) || []; newValue.splice(i, 1); setValue(newValue); dom.current = newValue; }; const emitChange = (value) => { if (typeof onEmitChange === 'function') { onEmitChange(value); } }; const onBlur = () => { emitChange(dom.current); }; useEffect(() => { document.addEventListener('click', onBlur, false); return () => { document.removeEventListener('click', onBlur, false); }; }, []); const onClick = (e) => { e.stopPropagation(); //阻止事件冒泡 e.nativeEvent.stopImmediatePropagation(); }; return (