import { ModalForm, ProFormDependency, ProFormTextArea, } from '@ant-design/pro-components'; import React from 'react'; import Icon from '../../../components/Icon'; interface SvgEditFormProps { title: string; trigger: JSX.Element; onOk: (fileContent: string) => void; } const isSvg = (svg: string) => /([\S\s]*?)<\/svg>/.test(svg); const clearSvgColor = (svg: string) => svg.replace(/fill="([\S\s]*?)"/g, ''); // 清除svg的填充色 const getSvgContent = (svg: string) => svg.replace( /([\S\s]*?)<\/svg>/, '$1', ); const SvgEditForm: React.FC = ({ trigger, title, onOk }) => { return ( layout="horizontal" title={title} trigger={trigger} autoFocusFirstInput modalProps={{ destroyOnClose: true, }} width={1200} submitTimeout={2000} onFinish={async ({ fileContent = '' }) => { onOk(clearSvgColor(getSvgContent(fileContent))); return true; }} > { if (!isSvg(value)) { throw new Error('svg内容格式不正确!'); } }, }, ]} /> {({ fileContent = '' }) => { if (isSvg(fileContent)) { return ( <>
预览图
); } }}
); }; export default SvgEditForm;