美文网首页
微信小程序循环等待加载图片 - Wait and Load Im

微信小程序循环等待加载图片 - Wait and Load Im

作者: YichengYe | 来源:发表于2018-06-23 20:28 被阅读0次
    {
      load_activity: function () {
        var that = this;
        wx.showLoading({
          title: '图片生成中',
        })
        wx.request({
          url: app.globalData.webservice_url + 'biz/activity/saveSharePic',
          data: JSON.stringify(app.encode({
            activityId: that.data.activityid,
            width: that.data.width,
            height: that.data.height
          })),
          header: {
            'X-Token': wx.getStorageSync('token')
          },
          method: 'POST',
          success: function (res) {
            if (res.data.code === 1) {
              if (res.data.data) {
              that.setData({
                activity: res.data.data
              }, function () {
                that.timer_helper(res.data.data.shareActivityPath);
              })
              } else {
                app.showModal('提示', res.data.desc);
              }
            } else {
              app.showModal('提示', res.data.desc);
            }
          },
          fail: function (res) {
            app.showModal('提示', res.errMsg);
          },
          complete: function (res) {
            console.log(res);
          }
        })
      },
    
      timer_helper: function (path) {
        var that = this;
        app.globalData.timer_canvas = setInterval(function () {
          clearInterval(app.globalData.timer_canvas);
          wx.getImageInfo({
            src: app.globalData.file_url_server + path,
            success(res1) {
              that.setData({
                path: res1.path
              }, function () {
                wx.saveImageToPhotosAlbum({
                  filePath: res1.path,
                  success(res) {
                    wx.showToast({
                      title: '已保存到本地相册',
                    })
                  }
                })
              })
            },
            fail(res1) {
              that.timer_helper(path);
            },
            complete(res1) {
            }
          })
        }, 2000)
      }
    }
    

    相关文章

      网友评论

          本文标题:微信小程序循环等待加载图片 - Wait and Load Im

          本文链接:https://www.haomeiwen.com/subject/lsydyftx.html