import React, { useState } from 'react'; import { Dropdown } from 'antd'; import { WifiOutlined, LeftOutlined, UserOutlined, MenuOutlined } from '@ant-design/icons'; import Style from './web.module.less'; import { Editor } from '@wangeditor/editor-for-react'; import ShowNews from '../showNews'; export default function Render(props) { const { button } = props.data; const { getMaterialImgAndVoice, getArticle, getMaterialVideo, setMessage } = props.methods; const [sendMsg, setSendMsg] = useState([]); const editorConfig = { readOnly: true, autoFocus: true, scroll: false, }; const onClick = ({ key }) => { const index = Math.floor(Number(key) / 10); const index2 = Number(key) % 10; menuAction(button[index].sub_button[index2]); }; const isValidUrl = (url) => { const urlPattern = /^(https?:\/\/)([\w-]+\.)+[a-z]{2,6}(\S*)$/; return urlPattern.test(url); }; const menuAction = async (menu) => { if (menu.type === 'view' && menu.url) { if (isValidUrl(menu.url)) { window.open(menu.url); } else { setMessage({ type: 'warning', content: 'URL无效' }); } return; } if (menu.type === 'miniprogram' && menu.url) { setSendMsg([...sendMsg, { type: 'miniprogram', content: '不支持查看小程序,请前往微信公众号平台查看' }]); return; } if (menu.subType === 'text' && menu.content) { setSendMsg([...sendMsg, { type: 'text', content: menu.content }]); return; } if (menu.subType === 'image' && menu.media_id) { const result = await getMaterialImgAndVoice('image', menu.media_id); setSendMsg([...sendMsg, { type: 'image', content: result }]); return; } if (menu.type === 'article_id' && menu.article_id) { const result = await getArticle(menu.article_id); setSendMsg([...sendMsg, { type: 'article_id', content: result }]); return; } if (menu.subType === 'voice' && menu.media_id) { const result = await getMaterialImgAndVoice('voice', menu.media_id); setSendMsg([...sendMsg, { type: 'voice', content: { url: result, media_id: menu.media_id } }]); return; } if (menu.subType === 'video' && menu.media_id) { const result = await getMaterialVideo(menu.media_id); setSendMsg([...sendMsg, { type: 'video', content: { url: result.url, media_id: menu.media_id } }]); return; } }; return (