Fix:2712 【地标好物】地标好物分享图片下方增加一个保存图片按钮,点击后直接保存图片,替换掉长按保存图片功能

This commit is contained in:
linxi
2024-11-27 16:19:08 +08:00
parent d0fd7cb653
commit a104473e86
+44 -9
View File
@@ -14,10 +14,10 @@
:src="posterImage" :src="posterImage"
alt="tp" alt="tp"
class="poster-image" class="poster-image"
show-menu-by-longpress :show-menu-by-longpress="false"
mode="widthFix" mode="widthFix"
/> />
<view class="keep">长按图片可以保存到手机</view> <view class="v12-primary v12-white-text v12-radius-100 share-btn" @click="saveImg(posterImage)">保存图片</view>
</view> </view>
<view class="mask"></view> <view class="mask"></view>
</view> </view>
@@ -28,15 +28,45 @@ import { getShareImg } from "@/api/product";
export default { export default {
name: "StorePoster", name: "StorePoster",
data: function() { data: function () {
return { return {
canvasStatus: false, canvasStatus: false,
posterImage: "", posterImage: "",
posterImageStatus: false posterImageStatus: false,
}; };
}, },
mounted: function() {}, mounted: function () {},
methods: { 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() { posterImageClose() {
this.posterImageStatus = false; this.posterImageStatus = false;
this.canvasStatus = false; this.canvasStatus = false;
@@ -44,9 +74,9 @@ export default {
}, },
savePosterPath(id) { savePosterPath(id) {
uni.showLoading({ title: "海报生成中", mask: true }); uni.showLoading({ title: "海报生成中", mask: true });
getShareImg(id) getShareImg(id)
.then(res => { .then((res) => {
this.canvasStatus = true; this.canvasStatus = true;
this.posterImage = res.data; this.posterImage = res.data;
this.posterImageStatus = true; this.posterImageStatus = true;
@@ -54,12 +84,17 @@ export default {
.finally(() => { .finally(() => {
uni.hideLoading(); uni.hideLoading();
}); });
} },
} },
}; };
</script> </script>
<style scoped lang="less" lang="less"> <style scoped lang="less" lang="less">
.share-btn{
text-align: center;
padding: 10rpx 0;
font-size: 24rpx;
}
.poster-first { .poster-first {
overscroll-behavior: contain; overscroll-behavior: contain;
} }