From 566c900a244814bb747d36b6f5979f1563f687a0 Mon Sep 17 00:00:00 2001 From: g7hoo Date: Tue, 16 Aug 2022 16:11:46 +0800 Subject: [PATCH] =?UTF-8?q?update=20dialog:=20=E4=B8=8A=E4=BC=A0=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E6=A0=BC=E5=BC=8F=E5=92=8C=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/base-upload/index.vue | 35 +++++++++++++++++----- src/views/modules/monitoring/equipment.vue | 10 +------ 2 files changed, 29 insertions(+), 16 deletions(-) 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)' } } ],