element-plus 上传组件判断文件格式

图片:
.jpeg格式:image/jpeg
.png格式: image/png
.gif格式: image/gif


音频:
.mp3格式:audio/mpeg


视频:
.mp4格式:video/mp4
.m3u8格式:application/x-mpegURL
.mov格式:video/x-ms-wmv
.avi格式:video/x-msvideo
.flv格式:video/x-flv
.wmv格式:video/x-ms-wmv


文本:
.xls格式:application/vnd.ms-excel
.xlsx格式:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.doc格式:application/msword
.docx格式:application/vnd.openxmlformats-officedocument.wordprocessingml.document
.txt格式:text/plain
.pdf格式:application/pdf
.ppt格式:application/vnd.ms-powerpoint
.zip格式:application/zip
.rar格式:application/x-rar
 //校验版块
        //校验---{上传成员头像}前图片格式及大小
        AvatarUpload(file) {
            const isJPG = file.type === 'image/jpeg';
            const isLt2M = file.size / 1024 / 1024 < 2;
            if(['image/jpeg','image/PNG'].indexOf(File.type) == -1) {
                this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
                return false;
            }
            if (!isLt2M) {
                this.$message.error('上传头像图片大小不能超过 2MB!');
            }
            return isJPG && isLt2M; 
        },
        //校验---{上传视频}前进行格式校验
        videoUpload(file) {
            const isLt50M = file.size / 1024 / 1024  < 50;
            if (['video/mp4', 'video/ogg', 'video/flv','video/avi','video/wmv','video/rmvb'].indexOf(file.type) == -1) {
                this.$message.error('请上传正确的视频格式');
                return false;
            }
            if (!isLt50M) {
                this.$message.error('上传视频大小不能超过50MB哦!');
                return false;
            }
        },
        //校验---{上传ppt}前进行格式校验
        pptUpload(file) {
        if (['application/vnd.ms-powerpoint'].indexOf(file.type) == -1) {
                this.$message.error('请上传正确的ppt格式');
                return false;
            }  
        },
        //校验---{上传商业企划书}前进行格式校验
        doxrUpload(file) {
            if (['application/vnd.ms-powerpoint', 'application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/pdf' ].indexOf(file.type) == -1) {
                this.$message.error('请上传正确类型的文件格式');
                return false;
            } 
        },

 

posted @ 2022-04-09 09:41  郑州谷多软件  阅读(841)  评论(0编辑  收藏  举报