From 8b934766c6aa6b982a5275811e92f1b656e9cb51 Mon Sep 17 00:00:00 2001 From: MarSeventh <1193267292@qq.com> Date: Sat, 28 Sep 2024 21:13:26 +0800 Subject: [PATCH] fix a serious bug --- src/components/UploadForm.vue | 29 ++++++++++++++++------------- src/views/UploadHome.vue | 6 +++--- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/components/UploadForm.vue b/src/components/UploadForm.vue index 6c70edd..f663765 100644 --- a/src/components/UploadForm.vue +++ b/src/components/UploadForm.vue @@ -19,7 +19,7 @@
拖拽 点击Ctrl + V 粘贴上传
@@ -85,18 +85,18 @@ {{ file.name }}
- + - +
- + - +
@@ -202,7 +202,7 @@ computed: { mounted() { document.addEventListener('paste', this.handlePaste) }, -beforeDestroy() { +beforeUnmount() { document.removeEventListener('paste', this.handlePaste) }, methods: { @@ -323,9 +323,9 @@ methods: { }, beforeUpload(file) { return new Promise((resolve, reject) => { - // 客户端压缩条件:1.文件类型为图片 2.开启客户端压缩,且文件大小大于压缩阈值;或文件大小大于50MB - const needCustomCompress = file.type.includes('image') && (this.customerCompress && file.size / 1024 / 1024 > this.compressBar || file.size / 1024 / 1024 > 50) - const isLt50M = file.size / 1024 / 1024 < 50 + // 客户端压缩条件:1.文件类型为图片 2.开启客户端压缩,且文件大小大于压缩阈值;或文件大小大于20MB + const needCustomCompress = file.type.includes('image') && (this.customerCompress && file.size / 1024 / 1024 > this.compressBar || file.size / 1024 / 1024 > 20) + const isLt20M = file.size / 1024 / 1024 < 20 const pushFileToQueue = (file, serverCompress) => { const fileUrl = URL.createObjectURL(file) @@ -347,8 +347,8 @@ methods: { if (needCustomCompress) { //尝试压缩图片 imageConversion.compressAccurately(file, 1024 * this.compressQuality).then((res) => { - //如果压缩后大于50MB,则不上传 - if (res.size / 1024 / 1024 > 50) { + //如果压缩后大于20MB,则不上传 + if (res.size / 1024 / 1024 > 20) { this.$message.error(file.name + '压缩后文件过大,无法上传!') reject('文件过大') } @@ -374,7 +374,7 @@ methods: { this.$message.error(file.name + '压缩失败,无法上传!') reject(err) }) - } else if (isLt50M) { + } else if (isLt20M) { this.uploading = true const myUploadCount = this.uploadCount++ @@ -470,6 +470,10 @@ methods: { } }, handlePaste(event) { + // 当粘贴位置是文本框时,不执行该操作 + if (event.target.tagName === 'INPUT' || event.target.tagName === 'TEXTAREA') { + return + } const items = event.clipboardData.items for (let i = 0; i < items.length; i++) { if (items[i].kind === 'file') { @@ -587,7 +591,6 @@ methods: { } }, selectAllText(event) { - event.target.select(); // 复制到剪贴板 navigator.clipboard.writeText(event.target.value) .then(() => { diff --git a/src/views/UploadHome.vue b/src/views/UploadHome.vue index 6d6b313..7a8feb7 100644 --- a/src/views/UploadHome.vue +++ b/src/views/UploadHome.vue @@ -63,7 +63,7 @@ /> - + @@ -82,8 +82,8 @@
*Tips:
1.本设置仅针对图片文件,单位为MB
2.客户端压缩指上传前压缩,服务端压缩指Telegram端压缩 -
3.若图片大小>10MB,或压缩后图片大小>10MB,服务端压缩将自动失效! -
4.若图片大小>50MB,将自动进行客户端压缩! +
3.若图片大小>10MB,或压缩后图片大小>10MB,服务端压缩将自动失效 +
4.若图片大小>20MB,将自动进行客户端压缩

确定