import React, { useRef } from 'react' import { Button, Form, message } from 'antd' import { ModalForm, ProFormDependency, ProFormRadio, ProFormSelect, ProFormText } from '@ant-design/pro-form' import RighEditor from './RighEditor' import { Plus } from '@icon-park/react' export const msgTypeEnum = { NotificationOne: 'notification', Message: 'message' } export const mediaType = { VersionUpdate: 1, HolidayNotice: 2 } const AddMessage = props => { const { onConfirm } = props const formRef = useRef(null) const handleFormValues = values => { const newValues = { ...values } switch (values.msgType) { case msgTypeEnum.NotificationOne: switch (values.media) { case mediaType.VersionUpdate: newValues.avatar = (isDevMode() ? 'http://cld2qa.com' : 'http://127.0.0.1') + '/resource/notice_email.png' break case mediaType.HolidayNotice: newValues.avatar = (isDevMode() ? 'http://cld2qa.com' : 'http://127.0.0.1') + '/resource/notice_airplane.png' break default: break } break default: break } return newValues } return ( 新建通知 } initialValues={{ msgType: 'notification', refresh: 0 }} onFinish={async values => { try { const nValues = handleFormValues(values) await onConfirm(nValues) formRef.current?.resetFields() message.success('添加成功') return true } catch (error) { return false } }}> {({ msgType }) => msgType === msgTypeEnum.NotificationOne ? ( ) : null } {({ msgType, media }) => msgType === msgTypeEnum.NotificationOne && media === mediaType.VersionUpdate ? ( ) : null } ) } export default AddMessage