lastUpDate:
2018-8-12 請把請求地址加入到downLoadFile
提示:首先得要在公眾號設置對應的downLoadFile地址.
downImg : 下載圖片
wxml
js
1 downImg: function(e) { 2 var _this = this; 3
4 // 獲取圖片地址(http://www.playsort.cn/...)
5 var img = e.currentTarget.dataset.src; 6
7 // 下載監聽進度
8 const downloadTask = wx.downloadFile({ 9 url: img, 10 success: function(res) { 11 // 只要服務器有響應數據,就會把響應內容寫入文件並進入 success 回調,業務需要自行判斷是否下載到了想要的內容
12 console.log(res) 13 if (res.statusCode === 200) { 14 wx.saveImageToPhotosAlbum({ 15 filePath: res.tempFilePath, 16 success: function(res) { 17 wx.showToast({ 18 title: '保存圖片成功!~', 19 }); 20 }, 21 fail: function(res) { 22 wx.showToast({ 23 title: '保存圖片失敗!~', 24 }); 25 } 26 }) 27 } 28 } 29 }); 30 downloadTask.onProgressUpdate((res) => { 31 if (res.progress === 100) { 32 this.setData({ 33 progress: ''
34 }); 35 } else { 36 this.setData({ 37 progress: res.progress + '%'
38 }); 39 } 40 }); 41 }