通过await
async handleFileChange(e) {
let files = Array.prototype.slice.call(e.target.files)
const videoTypes = [
'video/mp4',
'video/mov',
'video/quicktime'
// 'video/webm'
]
const videoFiles = files.filter(file => {
return videoTypes.indexOf(file.type) !== -1
})
if (videoFiles.length !== files.length) {
await this.$message.warning(this.$t('非mp4、mov类型视频文件已自动过滤'))
}
const newFiles = videoFiles.filter(file => {
return file.size / 1024 / 1024 <= 128
})
if (videoFiles.length !== newFiles.length) {
await this.$message.warning(
this.$t('文件大小不可超过128M,超过128M的文件已自动过滤')
)
}
if (!newFiles.length) {
return
}
if (newFiles.length > 100) {
await this.$message.warning(this.$t('一次最多上传100个文件'))
return
}
// this.$message(this.$t('文件已添加至上传列表'))
this.$notify.info({
title: this.$t('上传'),
message: this.$t('文件已添加至上传列表')
})
const {
project_id,
ad_id,
creative_id,
creative_version_id,
is_folder,
id
} = this.selectedFolder
let pathParam = {}
if (project_id && creative_id) {
pathParam.project_id = project_id
pathParam.ad_id = ad_id
pathParam.creative_id = creative_id
pathParam.creative_version_id = creative_version_id
}
if (is_folder) {
pathParam.folders_id = id
}
this.$store.commit('uploading/fileChange', {
files: newFiles,
pathParam: {
...pathParam
}
})
// 清空
this.$refs.fileInput.value = null
},