提交 542ffc66 authored 作者: chscls@163.com's avatar chscls@163.com

修改bug

上级 331c5659
import React from 'react'
import { Upload,message } from 'antd';
import config from '@/config/config'
export default class ImgUploadCom extends React.Component {
constructor(props){
super(props)
const value = props.value
this.state = {
url:value
}
}
triggerChange = (changedValue) => {
// Should provide an event to pass value to Form.
const onChange = this.props.onChange;
if (onChange) {
onChange( changedValue);
}
}
componentWillReceiveProps(nextProps) {
// Should be a controlled component.
if ('value' in nextProps) {
const value = nextProps.value;
this.setState({url:value});
}
}
changeUrl = (info, key) => {
if (info.file.status === 'done') {
message.success(`图片上传成功`);
if (!('value' in this.props)) {
this.setState({url: info.file.response });
}
this.triggerChange(info.file.response);
} else if (info.file.status === 'error') {
message.error(`图片上传失败`);
}
}
changePos=(obj)=>{
if (!('value' in this.props)) {
this.setState({...obj});
}
this.triggerChange({...obj});
}
render() {
const{json,disabled}=this.props
const {url}=this.state
return (
<Upload.Dragger disabled={disabled} accept={"image/*"} url={url} showUploadList={false} name="file" action={config.uploadUrl} onChange={this.changeUrl} multiple={false} style={{ padding: 0 }}>
{url ? <img src={config.httpServer + (url )} style={{ height: json.height, width: json.width }} /> : <div style={{ height: json.height, width: json.width }}>
</div>}
</Upload.Dragger>
);
}
}
\ No newline at end of file
......@@ -49,6 +49,7 @@ import TableSelect from '../libs/TableSelect';
import LocationCom from '../libs/LocationCom'
import MobileDate from '../libs/MobileDate';
import ChildForm from '../libs/ChildForm';
import ImgUploadCom from '../libs/ImgUploadCom';
import moment from 'moment';
import router from 'umi/router';
import TableList from '../libs/TableList';
......@@ -115,13 +116,6 @@ const errorHandler = error => {
}
};
let oldProps = {}
const normFile = (e) => {
if (Array.isArray(e)) {
return e;
}
return e && e.fileList[0];
}
@connect(({ DataColumn, SqlManageEntity, formList, loading }) => ({
DataColumn, SqlManageEntity, formList,
loading: loading.models.DataColumn || loading.models.SqlManageEntity || loading.models.formList
......@@ -1469,16 +1463,7 @@ export default class tableCom extends Component {
return dataColumn;
};
changeUrl = (info, key) => {
if (info.file.status === 'done') {
message.success(`图片上传成功`);
this.setState({ url: info.file.response })
} else if (info.file.status === 'error') {
message.error(`图片上传失败`);
}
}
render() {
/**
* json为申请表单
......@@ -2706,15 +2691,9 @@ export default class tableCom extends Component {
break;
case 'ImgUploadCom':
cm = getFieldDecorator("img$" + dataColumn.base52, {
valuePropName: 'fileList[0]',
getValueFromEvent: normFile,
})(<Upload.Dragger disabled={disabled} accept={"image/*"} url={this.state.url || initValue} showUploadList={false} name="file" action={config.uploadUrl} onChange={info => this.changeUrl(info, dataColumn.base52)} multiple={false} style={{ padding: 0 }}>
{this.state.url || initValue ? <img src={config.httpServer + (this.state.url || initValue)} style={{ height: json.height, width: json.width }} /> : <div style={{ height: json.height, width: json.width }}>
</div>}
</Upload.Dragger>);
cm = getFieldDecorator(dataColumn.base52, {
initialValue: initValue,
})(<ImgUploadCom json={json} disabled={disabled}/>);
if (get === 'mobile' && json.isLabel && title) {
cm = <Form.Item
labelCol={{ span: json.labelSpan }}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论