uniapp实现微信小程序分享、保存图片、收藏

 1. 微信小程序分享 (识别图中二维码不会,有会的评论发一下文章链接)

 // #ifdef MP-WEIXIN
    // 显示弹窗,提供“转发”、“保存图片”、“收藏”等选项
    wx.showActionSheet({
        itemList: ['转发', '保存图片', '收藏'],
        // itemList: ['转发', '保存图片', '收藏', '识别图中二维码'],
        success: (res) => {
            // 用户选择了一个选项后的处理逻辑
            console.log('用户选择了:', res.tapIndex);
            switch (res.tapIndex) {
                case 0:// 转发
                    onShareImgClick()
                    break;
                case 1:// 保存图片
                    wx.saveImageToPhotosAlbum({
                        filePath: imgPath.value, // 传入获取到的临时文件路径
                        success: function () {
                            // 保存成功后的回调函数,可以在这里进行相应的处理
                            console.log('保存图片成功');
                            proxy.$API(proxy).Toast("保存图片成功");
                        },
                        fail: function (err) {
                            // 保存失败的处理逻辑,可以在这里进行相应的处理
                            console.error('保存图片失败:', err);
                            proxy.$API(proxy).Toast("保存图片失败");
                        }
                    });
                    break;
                case 2://收藏
                    wx.addFileToFavorites({
                        filePath: imgPath.value,
                        success: function () {
                            console.log('收藏成功');
                            proxy.$API(proxy).Toast("收藏成功");
                        },
                        fail: function (err) {
                            console.error('收藏失败:', err);
                            proxy.$API(proxy).Toast("收藏失败");
                        }
                    })
                    break;
                case 3:// 识别图中二维码
                    // webUrl.value = "https://work.weixin.qq.com/gm/xxxxxxx"
                    break;
            }
        },
        fail: (err) => {
            // 显示弹窗失败的处理逻辑
            console.error('显示弹窗失败:', err);
        }
    });
    // #endif
//弹出微信小程序系统框分享
const onShareImgClick = () => {
    console.log("点击")
    // #ifdef MP-WEIXIN
    wx.showShareImageMenu({ //分享给朋友
        path: imgPath.value,
        success: (res) => {
            console.log("分享成功:", res);
        },
        fail: (err) => {
            console.log("分享取消:", err);
        },
    })
    // #endif
}

 2. APP 分享

    //uniapp 打包APP 分享

    // #ifdef APP-PLUS
    //分享
    uni.share({
        provider: "weixin",
        scene: shareType, //WXSceneSession 分享到聊天界面   WXSceneTimeline	分享到朋友圈
        type: 0,
        href: qrcodeUrl,
        title: "",
        summary: "",
        imageUrl: "../static/image/share_logo.png",
        success: function (res) {
            console.log("success:" + JSON.stringify(res));
        },
        fail: function (err) {
            console.log("fail:" + JSON.stringify(err));
        }
    });
    //#endif