限制图片上传大小

This commit is contained in:
red-deng-deng 2021-11-28 14:44:13 +08:00
parent b74cd53d91
commit 3e7676879b
2 changed files with 32 additions and 10 deletions

View File

@ -162,7 +162,15 @@ export default class adduserinfo extends React.Component{
_self.setState({headImg:''})
}
};
onUploadError = (type, data) => {
if (type === 'overMaxAmount') {
Notify.clear();
Notify.error(`最多可上传 ${data.maxAmount} 张图片`);
} else if (type === 'overMaxSize') {
Notify.clear();
Notify.error(`图片大小不能超过 ${data.formattedMaxSize}`);
}
};
//选择销售人员
onsaleChange(e){
let model2 = this.state.model
@ -829,19 +837,21 @@ this.setState({pwdtype:e});
{
this.state.defaultFileList[0].src.includes('lsxd')?(<ImageUpload
className="zent-image-upload-demo"
maxSize={5 * 1024 * 1024}
tips="建议尺寸 30*30图片不超过 500kb"
maxSize={500* 1024}
tips="建议尺寸 80*80图片不超过 500kb"
maxAmount={1}
onChange={(e)=>{this.onUploadChange(e)}}
onUpload={this.onUpload}
defaultFileList={this.state.defaultFileList}
defaultFileList={this.state.defaultFileList}
onError={this.onUploadError}
/>):(<ImageUpload
className="zent-image-upload-demo"
maxSize={5 * 1024 * 1024}
tips="建议尺寸 30*30图片不超过 500kb"
maxSize={500 * 1024}
tips="建议尺寸 80*80图片不超过 500kb"
maxAmount={1}
onChange={(e)=>{this.onUploadChange(e)}}
onUpload={this.onUpload}
onUpload={this.onUpload}
onError={this.onUploadError}
/>)
}
</div>

View File

@ -160,6 +160,16 @@ export default class adduserinfo extends React.Component{
Notify.error('请完善表单数据');
}
}
onUploadError = (type, data) => {
if (type === 'overMaxAmount') {
Notify.clear();
Notify.error(`最多可上传 ${data.maxAmount} 张图片`);
} else if (type === 'overMaxSize') {
Notify.clear();
Notify.error(`图片大小不能超过 ${data.formattedMaxSize}`);
}
};
//选择图片
onUploadChange(files){
let _self=this;
@ -475,20 +485,22 @@ export default class adduserinfo extends React.Component{
{
this.state.defaultFileList[0].src==''?<ImageUpload
className="zent-image-upload-demo"
maxSize={5 * 1024 * 1024}
maxSize={500 * 1024}
tips="建议尺寸 80*80图片不超过 500kb"
maxAmount={1}
onChange={(e)=>{this.onUploadChange(e)}}
onUpload={this.onUpload}
onError={this.onUploadError}
/>:<ImageUpload
className="zent-image-upload-demo"
maxSize={5 * 1024 * 1024}
tips="建议尺寸 30*30图片不超过 500kb"
maxSize={500 * 1024}
tips="建议尺寸 80*80图片不超过 500kb"
maxAmount={1}
onChange={(e)=>{this.onUploadChange(e)}}
onUpload={this.onUpload}
defaultFileList={this.state.defaultFileList}
onError={this.onUploadError}
/>
}