From e65c5049ce602793f791655d1a23d0b192cd3583 Mon Sep 17 00:00:00 2001 From: "wu.jian2" Date: Sun, 8 Oct 2023 14:13:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=BC=80=E5=8F=91=E6=97=B6=EF=BC=8C=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=B8=B2=E6=9F=93=E5=87=BA=E9=94=99=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=97=A0=E6=B3=95=E4=BF=9D=E5=AD=98=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5=EF=BC=8C=E4=BB=85=E5=B0=86=E5=B0=81=E9=9D=A2?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=95=B0=E6=8D=AE=E4=BC=A0=E5=85=A5=E7=A9=BA?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data-room-ui/packages/BizComponent/index.vue | 105 +++++++++---------- 1 file changed, 47 insertions(+), 58 deletions(-) diff --git a/data-room-ui/packages/BizComponent/index.vue b/data-room-ui/packages/BizComponent/index.vue index e0f33cfd..1fa20d71 100644 --- a/data-room-ui/packages/BizComponent/index.vue +++ b/data-room-ui/packages/BizComponent/index.vue @@ -339,69 +339,57 @@ export default { } }) }, - save (pageJump = false) { + async save (pageJump = false) { this.loading = true + let dataUrl = '' const node = document.querySelector('.remote-preview-inner-wrap') // 获取node下的第一个子节点 const childrenNode = node.children[0] - toJpeg(childrenNode, { quality: 0.2 }) - .then((dataUrl) => { - const that = this - if (showSize(dataUrl) > 200) { - const url = dataURLtoBlob(dataUrl) - // 压缩到500KB,这里的500就是要压缩的大小,可自定义 - imageConversion - .compressAccurately(url, { - size: 200, // 图片大小压缩到100kb - width: 1280, // 宽度压缩到1280 - height: 720 // 高度压缩到720 - }) - .then((res) => { - translateBlobToBase64(res, function (e) { - this.form.coverPicture = e.result - updateBizComponent(this.form) - .then(() => { - this.$message({ - message: '保存成功', - type: 'success', - duration: 800, - onClose: () => { - // 此处写提示关闭后需要执行的函数 - if (pageJump) { - this.pageJump() - } - } - }) - }) - .finally(() => { - that.loading = false - }) - }) - }) - } else { - this.form.coverPicture = dataUrl - updateBizComponent(this.form) - .then(() => { - this.$message({ - message: '保存成功', - type: 'success', - duration: 800, - onClose: () => { - // 此处写提示关闭后需要执行的函数 - if (pageJump) { - this.pageJump() - } - } - }) - }) - .finally(() => { - this.loading = false - }) + try { + dataUrl = await toJpeg(childrenNode, { quality: 0.2 }) + } catch (error) { + console.info(error) + } + console.log(dataUrl) + if (dataUrl) { + if (showSize(dataUrl) > 200) { + const url = dataURLtoBlob(dataUrl) + // 压缩到500KB,这里的500就是要压缩的大小,可自定义 + imageConversion.compressAccurately( + url, + { + size: 200, // 图片大小压缩到100kb + width: 1280, // 宽度压缩到1280 + height: 720 // 高度压缩到720 + } + ).then((res) => { + translateBlobToBase64(res, (e) => { + this.form.coverPicture = e.result + }) + }) + } else { + this.form.coverPicture = dataUrl + } + } else { + this.form.coverPicture = '' + } + updateBizComponent(this.form).then(() => { + this.$message({ + message: '保存成功', + type: 'success', + duration: 800, + onClose: () => { + // 此处写提示关闭后需要执行的函数 + if (pageJump) { + this.pageJump() + } } }) - .catch(() => { - this.loading = false - }) + this.loading = false + }).catch((error) => { + console.info(error) + this.loading = false + }) }, createdImg () { this.loading = true @@ -421,7 +409,8 @@ export default { }) this.loading = false }) - .catch(() => { + .catch((error) => { + console.info(error) this.$message.warning('出现未知错误,请重试') this.loading = false })