第一步:公共方法
/*----------------------------------------- 文件上传 -----------------------------------------*/
export const beforeUpload = (file, _this, fileType) => {
if (fileType === "audio") {
const isLt5M = file.size / 1024 / 1024 < 5;
if (!isLt5M) {
message.error('文件不能大于5M');
}
reqwestUploadToken(_this);
return isLt5M;
} else {
const isIMG = file.type === 'image/jpeg' || file.type === 'image/png';
if (!isIMG) {
message.error('文件类型错误');
}
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) {
message.error('文件不能大于2M');
}
reqwestUploadToken(_this);
return isIMG && isLt2M;
}
};
export const uploadButton = (num, loading) => {
if (num === 1) {
return (
<div>
<Icon type={loading ? 'loading' : 'plus'}/>
<div className="ant-upload-text" style={
{display: loading ? "none" : "block"}}>选择图片</div>
</div>
);
} else if (num === 2) {
return (
<div>
<Icon style={
{fontSize: "50px"}} type={loading ? 'loading' : 'video-camera'}/>
<div className="ant-upload-text" style={
{display: loading ? "none" : "block"}}>添加视频</div>
</div>
);
} else if (num === 3) {
return (
<div>
<Icon type={loading ? 'loading' : 'plus'}/>