1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
| /* * @Author: Derrick * @Date: 2019-04-04 16:53:05 * @Last Modified by: Derrick * @Last Modified time: 2019-04-28 15:48:04 */ import React, { PureComponent } from 'react'; import { Modal, Form, Button, Table, Upload, message, Row, Select } from 'antd'; import { connect } from 'dva'; import PropTypes from 'prop-types'; import componentAuth from '@/common/ComponentAuth'; import FormSelect from '@/common/FormItems/FormSelect'; import FormInput from '@/common/FormItems/FormInput'; import FormDataPicker from '@/common/FormItems/FormDataPicker'; import FormCascader from '@/common/FormItems/FormCascader'; import FormTextArea from '@/common/FormItems/FormTextArea'; import FormImageUpload from '@/common/FormItems/FormImageUpload'; import { HEADER_BASE, SEVER_URL_BASE } from '@/utils/constant'; import Col from 'antd/es/col';
const formItemLayout = { labelCol: { xs: { span: 24 }, sm: { span: 5 }, }, wrapperCol: { xs: { span: 24 }, sm: { span: 16 }, }, }; const { Item } = Form; const { Option } = Select;
@connect(({ mIdentifyCenter }) => ({ mIdentifyCenter })) class ModalView extends PureComponent { state = { data: [], storeId: '', };
// 返回title caseCategory = category => { switch (category) { case 'check': return { title: '查看' }; case 'import': return { title: '导入', import: true }; case 'create': return { title: '新增' }; case 'edit': return { title: '编辑' }; default: return { title: '查看' }; } };
showLabel = (type, label) => { const { category } = this.props;
if (category === 'search') { if (type !== 'datePicker') { return undefined; } return label; } return label; };
showRequire = disabled => { const { category } = this.props; if (category === 'search') { return false; } if (disabled) { return false; } return true; };
form = () => { const { form: { getFieldDecorator }, data, showData, category, } = this.props;
let ShowType;
return data.map(value => { const { label, key, type, Message, option, disabled, pattern } = value; if (!value) { return null; } switch (type) { case 'input': ShowType = FormInput; break; case 'select': ShowType = FormSelect; break; case 'datePicker': ShowType = FormDataPicker; break; case 'cascader': ShowType = FormCascader; showData.region = [showData.provinceId, showData.cityId, showData.countyId]; break; case 'textArea': ShowType = FormTextArea; break; case 'imageUpload': ShowType = FormImageUpload; break; default: ShowType = null; } return ( <Item label={this.showLabel(type, label)} key={key}> {getFieldDecorator(key, { rules: [ { required: this.showRequire(disabled), message: Message, pattern: pattern || undefined, type: type === 'cascader' ? 'array' : 'string', }, ], initialValue: showData[key] ? showData[key] : undefined, })( <ShowType option={option} message={Message} disabled={!!(disabled || category === 'check')} /> )} </Item> ); }); };
checkOk = () => { const { onOk, form } = this.props; form.validateFields((err, fieldsValue) => { if (!err) { onOk(fieldsValue); } }); }; closeModal = () => { const { onCancel, form: { resetFields } } = this.props; resetFields(); onCancel(); }
render() { const { data } = this.state; const { show, category = '', importColums, downloadUrl } = this.props; const modalData = this.caseCategory(category); return ( <Modal visible={show} onCancel={this.closeModal} onOk={category === 'import' ? this.importOk : this.checkOk} title={modalData.title} width="70%" footer={modalData.title === '查看' ? null : undefined} > <Form style={{ paddingTop: '20px' }} {...formItemLayout}> {this.form()} </Form> </Modal> ); } }
ModalView.propTypes = { onOk: PropTypes.func.isRequired, // 弹框点击确定 onCancel: PropTypes.func.isRequired, // 隐藏弹框 show: PropTypes.bool, // 是否显示弹窗 category: PropTypes.string, // 弹框的类型(title显示 data: PropTypes.arrayOf(PropTypes.object).isRequired, // 数据类型; 位置:'@/common/constant/sormView.js' 记得写注释; 格式: `s${文件名}` showData: PropTypes.object, // 查看或者编辑时的默认数据 importCallBack: PropTypes.func, // 导入之后,点击确定的回调函数 importColums: PropTypes.array, // 导入时候显示表格的表头 downloadUrl: PropTypes.string, // 下载的模板的文件名 };
ModalView.defaultProps = { show: false, category: 'check', showData: {}, importCallBack: () => {}, importColums: [], downloadUrl: '', };
export default Form.create()(ModalView);
|