提交 b7e8c250 authored 作者: 钟是志's avatar 钟是志

文件上传组件 限制上传文件类型

上级 231d0199
......@@ -151,7 +151,6 @@ export const zipImage = (path, fileName, limitWidth = 1200) => {
image.setAttribute("crossOrigin",'Anonymous');
image.src = imageUrl;
image.onload = () => {
// console.log('123');
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
const imageWidth = limitWidth;
......
......@@ -61,7 +61,9 @@ class UploadCom extends React.Component {
try {
this.otherProps = new Function(this.otherProps)();
// console.log(this.otherProps);
} catch (e) {}
} catch (e) {
console.log(e);
}
}
}
......@@ -75,10 +77,22 @@ class UploadCom extends React.Component {
//图片上传之前进行判断
beforeUpload = (file) => {
return this.isSize(file).then((res) => {
message.info('正在上传中,请等待');
return true;
});
console.log(this.otherProps);
const { limitImageSize, onlyPdf } = this.otherProps;
if(limitImageSize){ // 限制上传图片大小
return this.isSize(file).then((res) => {
message.info('正在上传中,请等待');
return true;
});
}else if(onlyPdf){ // 限制只能上传pdf文件
let name = file.name;
if(!name || !name.endsWith('.pdf')){
message.warn('请上传pdf文件');
return false;
}
}
return true;
};
//检测尺寸
......@@ -164,7 +178,8 @@ class UploadCom extends React.Component {
action: config.uploadUrl,
showUploadList: false,
onChange: this.changeUrl,
beforeUpload: this.otherProps?.limitImageSize ? this.beforeUpload : undefined,
// beforeUpload: this.otherProps?.limitImageSize ? this.beforeUpload : undefined,
beforeUpload: this.beforeUpload
};
return (
<div data-mes={dataKey}>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论