Micro letter applet progress bar

<button class='down-img' bindtap='downImg' data-scr='{{imageUrl}}'>下载图片{{progress}}</button>
downImg: function (E) { 
    var = _this the this ; 

    // get image address (HTTP: //www.playsort.cn / ...) 
    // = var IMG e.currentTarget.dataset.src; 
    // var IMG = '../pic/U1513P28T52D3414F872DT20081124143718.jpg?id=' + Math.floor (Math.random () * 100000) ;; 
    var = IMG 'http://i0.sinaimg.cn/ent/y/w/2008- ? 11-24 / U1513P28T52D3414F872DT20081124143718.jpg the above mentioned id = '+ Math.floor (Math.random () * 100000 ); 
    // download monitor progress 
    const downloadTask = wx.downloadFile ({  url: img,  Success: function (RES) {  / / As long as there is a server response data, the response will write the contents of the file and enter the success callback, business needs to judge for themselves whether to download the desired content console.log (res) if (res.statusCode === 200
) { // wx.saveImageToPhotosAlbum({ // filePath: res.tempFilePath, // success: function (res) { // wx.showToast({ // title: '保存图片成功!~', // }); // }, // fail: function (res) { // wx.showToast({ // title: '保存图片失败!~', // }); // } // }) console.log('code:' + res.statusCode ) }else{ console.log('code:' + res.statusCode ) } } }); downloadTask.onProgressUpdate((res) => { if (res.progress === 100) { this.setData({ progress: '100%' }); var st = getApp().globalData.st var et = new Date() console.log(et-st) console.log(410.45 * 1000 / (et - st)) }else if(res.progress === 1){ getApp().globalData.st = new Date() console.log(getApp().globalData.st); } else { this.setData({ progress: res.progress + '%' }); } }); }

 

Guess you like

Origin www.cnblogs.com/CryOnMyShoulder/p/11524994.html