diff --git a/flossom-ui/src/views/system/instrument/index.vue b/flossom-ui/src/views/system/instrument/index.vue index 02ddfbd..fa3d5ca 100644 --- a/flossom-ui/src/views/system/instrument/index.vue +++ b/flossom-ui/src/views/system/instrument/index.vue @@ -408,6 +408,7 @@ :on-success="manualUploadSuccess" :on-error="uploadError" :file-list="manualFile.fileList" + :before-upload="handleBeforeUpload" > 点击上传
@@ -425,6 +426,7 @@ :on-success="scanUploadSuccess" :on-error="uploadError" :file-list="scanFile.fileList" + :before-upload="handleBeforeUpload" > 点击上传
@@ -1502,6 +1504,15 @@ export default { sortMode: [], }, newModeOptionList: [], + fileType: { + type: Array, + default: () => ["bmp", "gif", "jpg", "jpeg", "png", "mp4", "avi", "rmvb"], + }, + // 大小限制(MB) + fileSize: { + type: Number, + default: 1, + }, } }, created() { @@ -2430,6 +2441,29 @@ export default { } this.newModeOptionList = temp }, + // 上传前校检格式和大小 + handleBeforeUpload(file) { + // 校检文件类型 + if (this.fileType) { + const fileName = file.name.split('.'); + const fileExt = fileName[fileName.length - 1]; + const isTypeOk = this.fileType.default().indexOf(fileExt) >= 0; + if (!isTypeOk) { + this.$modal.msgError(`文件格式不正确`); + return false; + } + } + + // 校检文件大小 + if (this.fileSize) { + const isLt = file.size / 1024 / 1024 < this.fileSize; + if (!isLt) { + this.$modal.msgError(`上传文件大小不能超过 ${this.fileSize.default} MB!`); + return false; + } + } + return true; + }, }, }