From a104473e86e79fb5f44a0e9bf3c7c2d09f870b56 Mon Sep 17 00:00:00 2001 From: linxi Date: Wed, 27 Nov 2024 16:19:08 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A2712=20=E3=80=90=E5=9C=B0=E6=A0=87?= =?UTF-8?q?=E5=A5=BD=E7=89=A9=E3=80=91=E5=9C=B0=E6=A0=87=E5=A5=BD=E7=89=A9?= =?UTF-8?q?=E5=88=86=E4=BA=AB=E5=9B=BE=E7=89=87=E4=B8=8B=E6=96=B9=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=B8=80=E4=B8=AA=E4=BF=9D=E5=AD=98=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=8C=89=E9=92=AE=EF=BC=8C=E7=82=B9=E5=87=BB=E5=90=8E=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E4=BF=9D=E5=AD=98=E5=9B=BE=E7=89=87=EF=BC=8C=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E6=8E=89=E9=95=BF=E6=8C=89=E4=BF=9D=E5=AD=98=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/home/components/shareImg.vue | 53 +++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/pages/home/components/shareImg.vue b/pages/home/components/shareImg.vue index 17354d4..50ba6ec 100644 --- a/pages/home/components/shareImg.vue +++ b/pages/home/components/shareImg.vue @@ -14,10 +14,10 @@ :src="posterImage" alt="tp" class="poster-image" - show-menu-by-longpress + :show-menu-by-longpress="false" mode="widthFix" /> - 长按图片可以保存到手机 + 保存图片 @@ -28,15 +28,45 @@ import { getShareImg } from "@/api/product"; export default { name: "StorePoster", - data: function() { + data: function () { return { canvasStatus: false, posterImage: "", - posterImageStatus: false + posterImageStatus: false, }; }, - mounted: function() {}, + mounted: function () {}, methods: { + saveImg(url) { + uni.showLoading({ + mask:true, + }) + uni.downloadFile({ + url: url, // 文件的下载地址 + success(res) { + if (res.statusCode === 200) { + let tempFilePath = res.tempFilePath; // 临时文件路径 + uni.saveImageToPhotosAlbum({ + filePath: tempFilePath, + success:(success)=> { + uni.showToast({ + title: "保存成功", + icon: "none", + mask: true, + }); + }, + fail(err) { + uni.showToast({ + title: "保存失败,请重新尝试", + icon: "none", + mask: true, + }); + }, + }) + } + }, + }); + }, posterImageClose() { this.posterImageStatus = false; this.canvasStatus = false; @@ -44,9 +74,9 @@ export default { }, savePosterPath(id) { uni.showLoading({ title: "海报生成中", mask: true }); - + getShareImg(id) - .then(res => { + .then((res) => { this.canvasStatus = true; this.posterImage = res.data; this.posterImageStatus = true; @@ -54,12 +84,17 @@ export default { .finally(() => { uni.hideLoading(); }); - } - } + }, + }, };