0

//获取授权
saveImg(){

       let that = this;
       uni.getSetting({
           success: function(res){
               //不存在相册授权
               if (!res.authSetting['scope.writePhotosAlbum']){
                   uni.authorize({
                       scope: 'scope.writePhotosAlbum',
                       success: function(){
                           that.savePhoto();
                           that.isPic = false;
                       },
                       fail: function(err){
                           that.isPic = true;
                       }
                   })
               }else{
                   that.savePhoto(); 
               }
           }
       })
    },

//授权被拒绝后重新获取

    handleSetting(e){
        this.share = true;
        var that = this;
        uni.openSetting({
          success(res) {
            that.savePhoto(); 

// uni.showToast({
// title: '保存成功'
// })

            that.isPic = false;
          },
          fail(res) {
            uni.showModal({
                title: '警告',
                content: '不授权无法保存',
                showCancel: false
            })
            that.isPic = true;
          }
        });
    },

//下载图片

    savePhoto(){
        console.log('执行保存函数')
        let urlStr = this.imgSrc;
        var that = this;
        console.log(urlStr);
        uni.getImageInfo({
            src: ''+that.imgSrc+'',
            success: function (res) {
                console.log('图片信息');
                console.log(res);
                uni.saveImageToPhotosAlbum({
                    filePath: res.path,
                    success: function (data) {
                        uni.showToast({
                            title: '保存成功',
                            icon: 'success',
                            duration: 1500
                        })
                    }
                })
            },
            fail() {
                console.log(that.imgSrc)
                console.log('下载失败')
            }
        })
    },
1 个回答
0

一般情况应该是,没设置合法域名
可以真机调试试试看

撰写答案

推广链接