微信小程序进度条

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

    // 获取图片地址(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?id=' + Math.floor(Math.random() * 100000);
    // 下载监听进度
    const downloadTask = wx.downloadFile({
      url: img,
      success: function (res) {
        // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
 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 + '%' }); } }); }

 

转载于:https://www.cnblogs.com/CryOnMyShoulder/p/11524994.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值