import React, { useEffect, useState, useRef } from "react";
import { Switch, Alert, Typography, Form, Input, Radio, Tag, Tooltip, Flex } from 'antd';
import Styles from './web.module.less';
import '@wangeditor/editor/dist/css/style.css'; // 引入 css
import { Editor, Toolbar } from "@wangeditor/editor-for-react";
import { PlusOutlined, CloseOutlined } from '@ant-design/icons';
const { TextArea } = Input;
const { Text } = Typography;
function RenderEmailSuffix(props) {
const { emailSuffix, onChange, t } = props;
const [inputVisible, setInputVisible] = useState(false);
const [inputValue, setInputValue] = useState('');
const inputRef = useRef(null);
const tagInputStyle = {
width: 100,
height: 22,
marginInlineEnd: 8,
verticalAlign: 'top',
};
const tagPlusStyle = {
height: 22,
borderStyle: 'dashed',
};
const handleInputChange = (e) => {
setInputValue(e.target.value);
};
const handleInputConfirm = () => {
if (inputValue && !emailSuffix?.includes(inputValue)) {
onChange([...emailSuffix || [], inputValue]);
}
setInputVisible(false);
setInputValue('');
};
const handleClose = (removedTag) => {
const emailSuffix2 = emailSuffix.filter((tag) => tag !== removedTag);
onChange(emailSuffix2);
};
const showInput = () => {
setInputVisible(true);
};
return (
{(emailSuffix || []).map((tag, index) => {
const isLongTag = tag.length > 20;
const tagElem = (} key={tag} onClose={() => handleClose(tag)}>
{isLongTag ? `${tag.slice(0, 20)}...` : tag}
);
return isLongTag ? (
{tagElem}
) : (tagElem);
})}
{inputVisible ? () : (} onClick={showInput}>
{t('common::action.add')}
)}
);
}
export default function Email(props) {
const { passport, t, changeEnabled, updateConfig } = props;
const { id, type, enabled, stateColor } = passport;
const config = passport.config || {};
const [subject, setSubject] = useState(config?.subject || '');
const [eContentType, setEContentType] = useState('text');
const [htmlType, setHtmlType] = useState('html');
const [text, setText] = useState(config?.text || '');
const [html, setHtml] = useState(config?.html || '');
const [emailCodeDuration, setEmailCodeDuration] = useState(config?.codeDuration || '');
const [emailDigit, setEmailDigit] = useState(config?.digit || '');
const [emailSuffix, setEmailSuffix] = useState(config?.emailSuffix || []);
// editor 实例
const [editor, setEditor] = useState(null); // TS 语法
// 工具栏配置
const toolbarConfig = {}; // TS 语法
// 编辑器配置
const editorConfig = {
autoFocus: false,
placeholder: '请输入内容...',
};
// 及时销毁 editor
useEffect(() => {
return () => {
if (editor == null)
return;
editor.destroy();
setEditor(null);
};
}, [editor]);
useEffect(() => {
setSubject(config?.subject || '');
setText(config?.text || '');
setHtml(config?.html || '');
setEmailCodeDuration(config?.codeDuration || '');
setEmailDigit(config?.digit || '');
setEmailSuffix(config?.emailSuffix || []);
if (config?.html) {
setEContentType('html');
}
else {
setEContentType('text');
}
}, [config]);
return (
{t(`passport:v.type.${type}`)}
{
changeEnabled(checked);
}}/>
{enabled &&
} type="info" style={{ marginBottom: 12 }}/>
{eContentType === 'text' ? (
}
);
}