save_share_img:function(img){ var that = this; let { result } = that.data; getData.getData( "save_share_img", { id : result.id, share_img_link : img, method : "POST" }, function(data) { if (data.errno){ console.log(data.errdesc); return; } result.share_img = img; that.setData({ result: result }); } ); }, download:function(){ var that = this; let { urls,result } = that.data; console.log(result); if (result.share_img == ‘‘){ // 临时图片上传cdn wx.uploadFile({ // 需要传到cdn 才可以下载!!!!! url : "https://a.squmo.com/partybuild/Public/upload_more_img", filePath : urls, name : "file", success : res => { }, fail : res => { }, complete: res => { var imgdata = JSON.parse(res.data); var img = imgdata.data[0]; that.save_share_img(img); urls = img; } }) } else { urls = result.share_img; } console.log(‘download---start‘); console.log(urls); wx.downloadFile({ url: urls, //url:‘https://cdn.caomall.net/avatar_3.png‘, // canvas 生成的临时图片不可 success: function(res) { // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容 console.log(res) if (res.statusCode == 200) { wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success: function(res) { console.log(res); console.log(‘succ‘); wx.showToast({ title: ‘保存图片成功!~‘, }); that.setData({ mask_btn: 0, share_btn: false, canvas_btn:false }); }, fail: function(res) { console.log(res); console.log(‘fail‘); wx.showToast({ title: ‘保存图片失败!~‘ }); }, complete:function(res){ console.log(res); console.log(‘complete‘); } }) } else { console.log(‘下载图片发生错误----‘); wx.showToast({ title: ‘保存图片发生错误!~‘ }); } }, fail: function(res){ console.log(‘下载图片发生错误‘); console.log(res); } }); console.log(‘download---over‘); }, previewImg: function() { var that = this; wx.getSetting({ success(res) { console.log(‘-------------‘); console.log(res); if (!res.authSetting[‘scope.writePhotosAlbum‘]) { // 获取授权!!!! wx.authorize({ scope:‘scope.writePhotosAlbum‘, success() { that.download(); console.log(‘授权成功‘) } }); } else { that.download(); console.log(‘已授权‘); } } })