欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序 wx.uploadFile在安卓手機上面the same task is working問題解決

 更新時間:2016年12月14日 09:57:37   投稿:lqh  
這篇文章主要介紹了微信小程序 wx.uploadFile在安卓手機上面the same task is working問題解決的相關資料,需要的朋友可以參考下

微信小程序 wx.uploadFile在安卓手機上面the same task is working問題解決

微信小程序上傳圖片的時候,如果是多圖片上傳,一般都是直接用一個循環(huán)進行wx.uploadFile

這個在電腦上面測試與蘋果手機上面都不會有什么問題

但當用安卓測試的時候,你會發(fā)現(xiàn)小程序會提示一個the same task is working

wx.uploadFile不能并行,因為wx.uploadFile是一個異步函數(shù),所以循環(huán)的時候在安卓手機上會出現(xiàn)并行

解決的方法

做一個上傳完的標識,然后

用遞歸算法進行上傳

在上傳成功的回調(diào)函數(shù)里面,直接遞歸,標識滿足直接跳出,完成所有圖片上傳

貼上個代碼段

//上傳標識
var i=0
//imglist為要上傳圖片的路徑數(shù)組
uploadImg: function () {  
  var that = this
  if (i == imglist.length) {
  //清空還原
   news = ""
   city = ""
    i=0
   wait = true
   imglist = []
   serverImg = []
   retrunList = []
   that.setData({
    loding: false,
    src: [],
    disabled: false
   })
   return;
  }
   var imgcount = imglist.length;
   wx.uploadFile({
    url: config.serverUrl('index.php/user/uploadtu'),
    filePath: imglist[i],
    name: 'file',
    formData: { 'user': 'test' },
    success: function (res) {
     serverImg.push(res.data)
     if (imgcount == serverImg.length) {
      var serverImgStr = serverImg.join("|")
      wx.request({
       url: config.serverUrl('index.php/user/baobeiadd'),
       method: 'POST',
       data: Util.json2Form({
        imglist: serverImgStr,
        userId: userId,
        news: news,
        city: city,
        latitude: latitude,
        longitude: longitude
       }),
       header: {
        'content-type': 'application/x-www-form-urlencoded'
       },
       success: function (res2) {
        if (res2.data.state == "ok") {
 
         that.setData({
          loding: false,
          butTxt: "發(fā)布",
          disabled: false
         })
          
         Util.mesUrl("發(fā)布成功!", "../index/index")
        }
        else {
         Util.mes("描述至少10人字以上哦,還有圖片也要選哦!")
        }
       }
      })
     }else
     {
     //這里直接遞歸
     i++;
     that.uploadImg();
     }
    },
    fail: function (e) {
     console.log(e)
     Util.mes("圖片上傳失敗,請重新發(fā)布!" + i)
    }
   })
 
 },

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關文章

最新評論