aiccs/src/api/fileUpload.js

29 lines
903 B
JavaScript
Raw Normal View History

2025-12-27 16:40:23 +08:00
/**
* 文件上传前格式大小校验 目前限定xlsxlsxdocdocxpdfjpg 大小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
}