import React, { useEffect, useState } from 'react'; import { Tooltip, Button, Space, Modal } from 'antd'; import { PlusOutlined, SwapOutlined, DeleteOutlined, DownloadOutlined } from '@ant-design/icons'; import Style from './web.module.less'; import "@wangeditor/editor/dist/css/style.css"; // 引入 css import Preview from './preview'; import WechatMaterialLibrary from '../wechatMaterialLibrary'; import Text from './text'; const toolbarConfig = { excludeKeys: [ "blockquote", "fullScreen", "headerSelect", "|", "bold", "group-more-style", "bgColor", "bulletedList", "numberedList", "todo", "group-image", "group-video", "insertTable", "codeBlock", ], }; // TS 语法 const types = [ { key: 'text', value: '文本', }, { key: 'image', value: '图片', }, { key: 'video', value: '视频', }, { key: 'voice', value: '音频', }, ]; export default function Render(props) { const { id, content, type, applicationId } = props.data; const { t, save, changeType, updateItem, setMessage, getMaterialImgAndVoice, getMaterialVideo } = props.methods; const [open, setOpen] = useState(false); const [previewOpen, setPreviewOpen] = useState(false); const [replyContent, setReplyContent] = useState({ text: '', image: '', video: '', voice: '' }); const [mediaUrl, setMediaUrl] = useState(''); const [onlyOne, setOnlyOne] = useState(false); const getContent = async (value) => { let updateData = {}; let contentKey = ''; switch (type) { case 'text': updateData = { content: { text: value } }; contentKey = 'text'; setReplyContent({ ...replyContent, [contentKey]: value }); break; case 'image': case 'voice': updateData = { content: { mediaId: value } }; contentKey = type; setReplyContent({ ...replyContent, [contentKey]: await getMaterialImgAndVoice(type, value) }); break; case 'video': const video = await getMaterialVideo(value); updateData = { content: { title: video.title, description: video.description, mediaId: value } }; contentKey = 'video'; setReplyContent({ ...replyContent, [contentKey]: video.url }); break; default: break; } updateItem(updateData, id); }; const getMedia = (media) => { setMediaUrl(media.media_id); }; useEffect(() => { const fetchData = async (id, type) => { if (type === 'video') { const video = await getMaterialVideo(id); return video.url; } if (type === 'image' || type === 'voice') { const url = await getMaterialImgAndVoice(type, id); return url; } }; if (onlyOne) { return; } else { let contentKey = ''; if (type && type === 'text' && content && content.text) { contentKey = 'text'; setReplyContent({ ...replyContent, [contentKey]: content.text }); setOnlyOne(true); } ; if (type && type !== 'text' && type !== 'video' && content && content.mediaId) { switch (type) { case 'image': case 'voice': contentKey = type; break; default: break; } setReplyContent({ ...replyContent, [contentKey]: fetchData(content.mediaId, type) }); setOnlyOne(true); } ; if (type && type === 'video' && content && content.mediaId) { contentKey = type; setReplyContent({ ...replyContent, [contentKey]: fetchData(content.mediaId, type) }); } } }, [type, content]); return (