diff --git a/src/components/base-upload/index.vue b/src/components/base-upload/index.vue index 6d6d681..48a4096 100644 --- a/src/components/base-upload/index.vue +++ b/src/components/base-upload/index.vue @@ -8,8 +8,10 @@ :file-list="fileList" :on-preview="handleDownload" :on-remove="handleRemove" + :before-upload="/.*?image.*?/i.test(extraParams.typeCode) ? validateImage : validateFile" :before-remove="beforeRemove" > + {{ buttonContent }}
{{ tip }}
@@ -93,17 +95,36 @@ export default { }) }, - /** 大小验证 */ + /** 大小验证,由配置文件开启 */ validateFile(file) { - this.extraUploadParams.typeCode = 'equipmentInfoFile' + console.log("[*] 验证文件大小") - const isRightSize = file.size / 1024 / 1024 < 10 + const isRightSize = file.size / 1024 / 1024 < 2 if (!isRightSize) { - this.$message.error(this.$t('upload.picSizeAlarm')) + // this.$message.error(this.$t('upload.picSizeAlarm')) + this.$message.error('文件不应超过 2MB') } return isRightSize }, + /** 图片验证,由配置文件开启 */ + validateImage(file) { + console.log("[*] 验证图片") + + const isRightSize = file.size / 1024 / 1024 < 2 + if (!isRightSize) { + this.$message.error('文件不应超过 2MB') + // this.$message.error(this.$t('upload.picSizeAlarm')) + } + + const isAccept = new RegExp('image/*').test(file.type) + if (!isAccept) { + // this.$message.error(this.$t('upload.picAlarm')) + this.$message.error('只允许上传图片') + } + return isRightSize && isAccept + }, + /** 点击下载 */ handleDownload({ id: fileId, name: fileName }) { const type = { @@ -142,9 +163,9 @@ export default { }) }, - beforeRemove(file, filelist) { - return this.$confirm(`确定移除 ${file.name}?`) - }, + // beforeRemove(file, filelist) { + // return this.$confirm(`确定移除 ${file.name}?`) + // }, handleRemove(file, filelist) { // 把更新后的 fileList 传递出去 diff --git a/src/views/modules/monitoring/equipment.vue b/src/views/modules/monitoring/equipment.vue index 3920699..cdbb5ee 100644 --- a/src/views/modules/monitoring/equipment.vue +++ b/src/views/modules/monitoring/equipment.vue @@ -114,10 +114,6 @@ const addOrUpdateConfigs = { extraParams: { typeCode: 'EquipmentInfoFile' }, buttonContent: '点击上传', tip: '上传文件大小不要超过 2mb (2048kb)' - }, - validators: { - size: () => {}, // 上传大小设置 - image: () => {} // 上传图片认证 } }, { @@ -130,11 +126,7 @@ const addOrUpdateConfigs = { url: '/monitoring/attachment/uploadFileFormData', extraParams: { typeCode: 'EquipmentInfoImage' }, buttonContent: '点击上传', - tip: '上传文件大小不要超过 2mb (2048kb)' - }, - validators: { - size: () => {}, // 上传大小设置 - image: () => {} // 上传图片认证 + tip: '上传图片文件,且大小不要超过 2mb (2048kb)' } } ],