antd的upload可以实现上传,但是其上传之后,图片列表展示都是其组件里面已经封装好的,也没有vue那种提供插槽solt的功能,但是我司需要实现在每张图片下方有个radio标签来设置主图,左思右想,是不是得直接把upload组件拿过来再自己封装一层呢?实力不允许也没办法。
so 我的解决办法是,封装一个组件,里面有upload组件,上传成功的话,将fileList filter出来,用图片展示,图片和radio可以封装的把,这并不难,直接放下代码把:
import React, { Component } from 'react';
import { Upload, message, Icon, Modal, Radio, Card } from 'antd';
import config from '../../../../config';
import { getCookie } from 'Utils/publicFunc';
import './UploadPhoto.scss';
class UploadPhoto extends Component {
constructor(props) {
super(props);
this.state = {
showModal: false,
previewImage: '',
fileList: [],
value:''
};
this.handleChange = this.handleChange.bind(this);
this.handleCancel = this.handleCancel.bind(this);
this.beforeUpload = this.beforeUpload.bind(this);
this.onChangeRadioSelect=this.onChangeRadioSelect.bind(this);
}
handleChange(info) {
let { file, fileList } = info;
if (file.status == 'error') {
Modal.error({
centered: true,
title: '上传失败',
content: file.response.message
});
return;
}
fileList = fileList.map((file) => {
if (file.response) {
file.url = file.response.downloadPath;
}
return file;
});
fileList = fileList.filter((file) => {
return file.status === 'done';
});
this.setState({
fileList: [.