Commit 639cece4 by zhangleyuan

feat:处理上传文件的限制

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