Commit 639cece4 by zhangleyuan

feat:处理上传文件的限制

parent bd2043ff
......@@ -55,7 +55,7 @@ class NonCompliantFileModal extends React.Component {
<div className="tips">
<span className="icon iconfont">&#xe6f2;</span>
<span className="tips__text">
支持上传 Word(100M以内)、Excel(10M以内)、PPT(100M以内)、PDF(100M以内)、图片(50M以内)、音频(50M以内)、视频(500M以内)。
支持上传:Word(100M以内)、Excel(10M以内)、PPT(100M以内)、PDF(100M以内)、图片(5M以内)、音频(20M以内)、视频(500M以内)
</span>
</div>
</Modal>
......
......@@ -18,8 +18,9 @@ import { getFileTypeByName } from '@/domains/resource-disk/utils';
import {
DEFAULT_SIZE_UNIT,
FILE_TYPE_ICON_MAP,
FILR_VERIFY_MAP,
NON_COMPLIANT_FILE_MAP,
LOCAL_FILE_TYPE_MAP
SUPPORT_FILE_TYPE_MAP
} from "@/domains/resource-disk/constants";
import UploadProgressModal from '@/bu-components/UploadProgressModal';
......@@ -48,8 +49,8 @@ const FOLDERLIST_URL_MAP = {
};
// 支持本地上传的文件类型
const localFileTypeMap = LOCAL_FILE_TYPE_MAP.join(',');
const localFileTypeMap = SUPPORT_FILE_TYPE_MAP.join(',');
const FileVerifyMap = FILR_VERIFY_MAP;
// 合法的文件名后缀
const FILE_SUFFIX_LIST = ['docx', 'doc', 'ppt', 'pptx', 'pdf', 'xlsx', 'xls', 'jpg', 'jpeg', 'png', 'mp3', 'mp4'];
// 禁止选择的文件类型
......@@ -323,23 +324,22 @@ class SelectPrepareFileModal extends React.Component {
const _fileList = [...fileList];
_fileList.map((file, index) => {
let { size, type, name } = file;
console.log('file',file);
if (!type) {
type = getFileTypeByName(name);
}
if (type.indexOf('image') > -1 && size > 5 * DEFAULT_SIZE_UNIT) {
nonCompliantFileList.push(file);
_fileList.splice(index, 1);
}
if (type.indexOf('audio') > -1 && size > 20 * DEFAULT_SIZE_UNIT) {
nonCompliantFileList.push(file);
_fileList.splice(index, 1);
}
if (type.indexOf('video') > -1 && size > 500 * DEFAULT_SIZE_UNIT) {
nonCompliantFileList.push(file);
_fileList.splice(index, 1);
}
if (localFileTypeMap.indexOf(type) > -1 && size > 100 * DEFAULT_SIZE_UNIT) {
// if (!type) {
// type = getFileTypeByName(name);
// }
// if (type.indexOf('image') > -1 && size > 5 * DEFAULT_SIZE_UNIT) {
// nonCompliantFileList.push(file);
// _fileList.splice(index, 1);
// }
// if (type.indexOf('audio') > -1 && size > 20 * DEFAULT_SIZE_UNIT) {
// nonCompliantFileList.push(file);
// _fileList.splice(index, 1);
// }
// if (type.indexOf('video') > -1 && size > 500 * DEFAULT_SIZE_UNIT) {
// nonCompliantFileList.push(file);
// _fileList.splice(index, 1);
// }
if (localFileTypeMap.indexOf(type) > -1 && size > FileVerifyMap[type].maxSize * DEFAULT_SIZE_UNIT) {
nonCompliantFileList.push(file);
_fileList.splice(index, 1);
}
......
......@@ -42,11 +42,11 @@ const LocalFileType = [
const FileVerifyMap = {
"application/msword": {
type: "word",
maxSize: 10
maxSize: 100
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
type: "word",
maxSize: 10
maxSize: 100
},
"text/csv": {
type: "Excel",
......@@ -66,51 +66,51 @@ const FileVerifyMap = {
},
"application/vnd.ms-powerpoint": {
type: "PPT",
maxSize: 20
maxSize: 100
},
"application/vnd.openxmlformats-officedocument.presentationml.presentation": {
type: "PPT",
maxSize: 20
maxSize: 100
},
"application/pdf": {
type: "PDF",
maxSize: 50
maxSize: 100
},
"application/wps-office.pdf": {
type: "PDF",
maxSize: 50
maxSize: 100
},
"image/jpeg": {
type: "JPG",
maxSize: 10
maxSize: 5
},
"image/png": {
type: "JPG",
maxSize: 10
maxSize: 5
},
"image/jpg": {
type: "JPG",
maxSize: 10
maxSize: 5
},
"image/gif": {
type: "GIF",
maxSize: 10
maxSize: 5
},
"audio/mpeg": {
type: "MP3",
maxSize: 50
maxSize: 20
},
"audio/mp3": {
type: "MP3",
maxSize: 50
maxSize: 20
},
"audio/mp4": {
type: "MP4",
maxSize: 50
maxSize: 500
},
"video/mp4": {
type: "MP4",
maxSize: 50
maxSize: 500
}
};
......
/*
* @Author: 吴文洁
* @Date: 2020-08-20 09:21:40
* @LastEditors: 吴文洁
* @LastEditTime: 2020-10-13 14:55:24
* @LastEditors: zhangleyuan
* @LastEditTime: 2020-12-25 10:48:15
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
*/
......@@ -75,11 +75,11 @@ const LOCAL_FILE_TYPE_MAP: string[] = [
const FILR_VERIFY_MAP = {
"application/msword": {
type: "word",
maxSize: 10
maxSize: 100
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
type: "word",
maxSize: 10
maxSize: 100
},
"text/csv": {
type: "Excel",
......@@ -99,51 +99,51 @@ const FILR_VERIFY_MAP = {
},
"application/vnd.ms-powerpoint": {
type: "PPT",
maxSize: 20
maxSize: 100
},
"application/vnd.openxmlformats-officedocument.presentationml.presentation": {
type: "PPT",
maxSize: 20
maxSize: 100
},
"application/pdf": {
type: "PDF",
maxSize: 50
maxSize: 100
},
"application/wps-office.pdf": {
type: "PDF",
maxSize: 50
maxSize: 100
},
"image/jpeg": {
type: "JPG",
maxSize: 10
maxSize: 5
},
"image/png": {
type: "JPG",
maxSize: 10
maxSize: 5
},
"image/jpg": {
type: "JPG",
maxSize: 10
maxSize: 5
},
"image/gif": {
type: "GIF",
maxSize: 10
maxSize: 5
},
"audio/mpeg": {
type: "MP3",
maxSize: 50
maxSize: 20
},
"audio/mp3": {
type: "MP3",
maxSize: 50
maxSize: 20
},
"audio/mp4": {
type: "MP4",
maxSize: 50
maxSize: 500
},
"video/mp4": {
type: "MP4",
maxSize: 50
maxSize: 500
}
};
......
......@@ -62,7 +62,11 @@ class AddLiveIntro extends React.Component {
}else{
// 最多添加九图片
const { liveCourseMediaRequests } = this.props.data;
if (liveCourseMediaRequests.length > 8) {
const list = _.filter(liveCourseMediaRequests, (item) => {
return item.mediaType == "PICTURE";
});
if (list.length > 8) {
message.warning("最多添加9张图片");
return;
}
......
......@@ -379,7 +379,7 @@ class LiveCourseList extends React.Component {
className="icon iconfont default-confirm-icon"
style={{ color: "#FFBB54 !important" }}
>
&#xe6f1;
&#xe834;
</span>
),
});
......
......@@ -24,8 +24,7 @@ const DEL_FOLDER_URL_MAP = {
'COMMON': 'public/apollo/delCommonFolder'
}
// 支持本地上传的文件类型
const loaclFileType = SupportFileType.join(',');
let count = 0;
......
......@@ -55,7 +55,7 @@ class NonCompliantFileModal extends React.Component {
<div className="tips">
<span className="icon iconfont">&#xe6f2;</span>
<span className="tips__text">
支持上传 Word(100M以内)、Excel(10M以内)、PPT(100M以内)、PDF(100M以内)、图片(50M以内)、音频(50M以内)、视频(500M以内)。
支持上传:Word(100M以内)、Excel(10M以内)、PPT(100M以内)、PDF(100M以内)、图片(5M以内)、音频(20M以内)、视频(500M以内)
</span>
</div>
</Modal>
......
......@@ -46,7 +46,6 @@ const FOLDERLIST_URL_MAP = {
// 支持本地上传的文件类型
const supportFileType = SupportFileType.join(',');
const localFileType = LocalFileType.join(',');
// 合法的文件名后缀
const FILE_SUFFIX_LIST = ['docx', 'doc', 'ppt', 'pptx', 'pdf', 'xlsx', 'xls', 'jpg', 'jpeg', 'png', 'mp3', 'mp4'];
......@@ -327,19 +326,19 @@ class SelectPrepareFileModal extends React.Component {
if (!type) {
type = getFileTypeByName(name);
}
if (type.indexOf('image') > -1 && size > 5 * DEFAULT_SIZE_UNIT) {
nonCompliantFileList.push(file);
_fileList.splice(index, 1);
}
if (type.indexOf('audio') > -1 && size > 20 * DEFAULT_SIZE_UNIT) {
nonCompliantFileList.push(file);
_fileList.splice(index, 1);
}
if (type.indexOf('video') > -1 && size > 500 * DEFAULT_SIZE_UNIT) {
nonCompliantFileList.push(file);
_fileList.splice(index, 1);
}
if (localFileType.indexOf(type) > -1 && size > FileVerifyMap[type].maxSize * DEFAULT_SIZE_UNIT) {
// if (type.indexOf('image') > -1 && size > 5 * DEFAULT_SIZE_UNIT) {
// nonCompliantFileList.push(file);
// _fileList.splice(index, 1);
// }
// if (type.indexOf('audio') > -1 && size > 20 * DEFAULT_SIZE_UNIT) {
// nonCompliantFileList.push(file);
// _fileList.splice(index, 1);
// }
// if (type.indexOf('video') > -1 && size > 500 * DEFAULT_SIZE_UNIT) {
// nonCompliantFileList.push(file);
// _fileList.splice(index, 1);
// }
if (supportFileType.indexOf(type) > -1 && size > FileVerifyMap[type].maxSize * DEFAULT_SIZE_UNIT) {
nonCompliantFileList.push(file);
_fileList.splice(index, 1);
}
......
......@@ -13,7 +13,7 @@ import _ from 'underscore';
import Service from '@/common/js/service';
import { getEllipsText } from '@/domains/basic-domain/utils';
import { DEFAULT_SIZE_UNIT, LOCAL_FILE_TYPE_MAP } from '@/domains/resource-disk/constants';
import { DEFAULT_SIZE_UNIT, LOCAL_FILE_TYPE_MAP,FILR_VERIFY_MAP,SUPPORT_FILE_TYPE_MAP} from '@/domains/resource-disk/constants';
import { getFileTypeByName } from '@/domains/resource-disk/utils';
import UploadProgressModal from '@/bu-components/UploadProgressModal';
......@@ -29,7 +29,10 @@ const DEL_FOLDER_URL_MAP = {
'COMMON': 'public/hadesStore/delFolder'
}
// 支持本地上传的文件类型
const localFileTypeMap = LOCAL_FILE_TYPE_MAP.join(',');
// 支持本地上传的文件类型
const localFileTypeMap = SUPPORT_FILE_TYPE_MAP.join(',');
const FileVerifyMap = FILR_VERIFY_MAP;
let count = 0;
class OperateArea extends React.Component {
......@@ -114,30 +117,27 @@ class OperateArea extends React.Component {
// 准备上传
handleUpload = (event) => {
const fileList = event.target.files;
debugger
// 判断文件的大小是否超出了限制
const nonCompliantFileList = [];
const _fileList = [...fileList];
_fileList.map((file, index) => {
debugger
let { size, type, name } = file;
if (!type) {
type = getFileTypeByName(name);
}
if (type.indexOf('image') > -1 && size > 50 * DEFAULT_SIZE_UNIT) {
debugger
nonCompliantFileList.push(file);
_fileList.splice(index, 1);
}
if (type.indexOf('audio') > -1 && size > 50 * DEFAULT_SIZE_UNIT) {
nonCompliantFileList.push(file);
_fileList.splice(index, 1);
}
if (type.indexOf('video') > -1 && size > 500 * DEFAULT_SIZE_UNIT) {
nonCompliantFileList.push(file);
_fileList.splice(index, 1);
}
if (localFileTypeMap.indexOf(type) > -1 && size > 100 * DEFAULT_SIZE_UNIT) {
// if (type.indexOf('image') > -1 && size > 50 * DEFAULT_SIZE_UNIT) {
// nonCompliantFileList.push(file);
// _fileList.splice(index, 1);
// }
// if (type.indexOf('audio') > -1 && size > 50 * DEFAULT_SIZE_UNIT) {
// nonCompliantFileList.push(file);
// _fileList.splice(index, 1);
// }
// if (type.indexOf('video') > -1 && size > 500 * DEFAULT_SIZE_UNIT) {
// nonCompliantFileList.push(file);
// _fileList.splice(index, 1);
// }
if (localFileTypeMap.indexOf(type) > -1 && size > FileVerifyMap[type].maxSize * DEFAULT_SIZE_UNIT) {
nonCompliantFileList.push(file);
_fileList.splice(index, 1);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment