29 lines
903 B
JavaScript
29 lines
903 B
JavaScript
|
|
|
|||
|
|
/**
|
|||
|
|
* 文件上传前格式大小校验 目前限定xls、xlsx、doc、docx、pdf、jpg 大小20M
|
|||
|
|
* @param {Object} data
|
|||
|
|
* @author Lee
|
|||
|
|
* @since 2021年9月9日 15点01分
|
|||
|
|
*/
|
|||
|
|
export function validBeforeUpload(file, that) {
|
|||
|
|
var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
|
|||
|
|
const isExcel = testmsg === 'xls' || testmsg === 'xlsx'
|
|||
|
|
const isDoc = testmsg === 'doc' || testmsg === 'docx'
|
|||
|
|
const isPdf = testmsg === 'pdf'
|
|||
|
|
const isJpg = testmsg === 'jpg'
|
|||
|
|
const isPng = testmsg === 'png'
|
|||
|
|
const isCom = testmsg === 'zip' || testmsg === '7z' || testmsg === 'rar'
|
|||
|
|
|
|||
|
|
const isLt20M = file.size / 1024 / 1024 < 20
|
|||
|
|
|
|||
|
|
const exAllow = isExcel || isDoc || isPdf || isJpg || isPng || isCom
|
|||
|
|
|
|||
|
|
if (!exAllow) {
|
|||
|
|
that.$message.error('不支持该上传格式!')
|
|||
|
|
}
|
|||
|
|
if (!isLt20M) {
|
|||
|
|
that.$message.error('上传附件大小不能超过 20MB!')
|
|||
|
|
}
|
|||
|
|
return exAllow && isLt20M
|
|||
|
|
}
|