/* * << * Davinci * == * Copyright (C) 2016 - 2017 EDP * == * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * >> */ import React, { useEffect, useState, useCallback, useImperativeHandle, forwardRef } from 'react' import { Form, Row, Col, Input, Select, Icon, InputNumber, Spin } from 'antd' const FormItem = Form.Item const { Option } = Select import MailTag from './MailTag' import { FormComponentProps } from 'antd/lib/form' import { IScheduleMailConfig, IUserInfo } from './types' import { FormItemStyle, LongFormItemStyle, DefaultMailImageWidth, DefaultEmailContent } from './constants' import { RichText, RichTextNode } from 'components/RichText' interface IScheduleMailConfigProps extends FormComponentProps { config: IScheduleMailConfig loading: boolean onLoadMailList: (keyword: string) => void mailList: IUserInfo[] } export const ScheduleMailConfig: React.FC = ( props, ref ) => { const { form, config, loading, mailList, onLoadMailList } = props const { getFieldDecorator } = form const [showBcc, setShowBcc] = useState(false) const ccLabel = ( 抄送 setShowBcc(!showBcc)} /> ) const resetMailList = useCallback( () => { onLoadMailList('') }, [onLoadMailList] ) useEffect( () => { if (config.bcc) { setShowBcc(true) } form.setFieldsValue({ content: config.content || DefaultEmailContent }) }, [config] ) const checkContentMaxLength = ( _, value: RichTextNode[], callback: (msg?: string) => void ) => { if (new Blob([JSON.stringify(value)]).size / 1024 > 60) { callback('邮件内容长度过长(不超过 64Kb)') return } callback() } useImperativeHandle(ref, () => ({ form })) return (
{getFieldDecorator('subject', { rules: [{ required: true, message: '主题不能为空' }], initialValue: config.subject })()} {getFieldDecorator('type', { rules: [{ required: true }], initialValue: config.type })( )} {form.getFieldValue('type') !== 'excel' && ( {getFieldDecorator('imageWidth', { rules: [{ required: true }], initialValue: config.imageWidth || DefaultMailImageWidth })()}{' '} 像素 )} {getFieldDecorator('to', { rules: [{ required: true, message: '请选择收件人' }], initialValue: config.to })( )} {getFieldDecorator('cc', { initialValue: config.cc })( )} {showBcc && ( {getFieldDecorator('bcc', { initialValue: config.bcc })( )} )} {loading ? ( ) : ( getFieldDecorator('content', { validateFirst: true, rules: [ { required: true, message: '请输入邮件文本内容' }, { validator: checkContentMaxLength } ], initialValue: config.content })( ) )}
) } export default Form.create()( forwardRef(ScheduleMailConfig) )