欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

将图片下载到手机的 uniapp 微信应用程序

最编程 2024-10-13 19:47:28
...
const downImage = (imgUrl) => {
        uni.getImageInfo({
            src: imgUrl,
            success: res => {
                uni.saveImageToPhotosAlbum({
                    filePath: res.path,
                    success: res => {
                        console.log(res)
                    },
                    fail: err => {
                        if (openSetting.value == "openSetting:ok") {
                            return
                        }
                        uni.showModal({
                            title: "提示",
                            content: "需要授权保存到相册",
                            success: res => {
                                if (res.confirm) {
                                    uni.openSetting({
                                        success: res => {
                                            console.log(999, res
                                                .errMsg)
                                            if (res.authSetting[
                                                    'scope.writePhotosAlbum'
                                                ]) {
                                                uni.showModal({
                                                    title: "获取授权成功",
                                                    icon: "none"
                                                })
                                                openSetting.value =
                                                    "openSetting:ok"
                                            } else {
                                                uni.showModal({
                                                    title: "获取权限失败",
                                                    icon: "none"
                                                })
                                            }
                                        }
                                    })
                                }
                            }
                        })
                    }
                })
            }
        })
    }

推荐阅读