function uploadimg(data,page = null) { var _page = page; // console.log(data.date) var that = this, i = data.i ? data.i : 0, success = data.success ? data.success : 0, fail = data.fail ? data.fail : 0; console.log(i); console.log(success); console.log(fail); wx.uploadFile({ url: data.url, filePath: data.path[i], name: data.name, formData: { // 同时上传userId和当前时间 key: wx.getStorageSync('access_key'), token: wx.getStorageSync('access_token') }, success: (resp) => { success++; console.log(resp); wx.showLoading({ title: '上传中', }) // app.globalData.xqimgList += resp.data + ","; }, fail: (res) => { fail++; console.log('fail:' + i + "fail:" + fail); }, complete: () => { i++; if (i == data.path.length) { // 图片传完时停止调用 if (_page){ page.setData({ picsItems:[], uploadImages:[] }) _page.demo(); } // this.onReady() // wx.navigateTo({ // url: '/pages/personal_core/Album/Album' // }) // wx.navigateTo({ // 成功后跳转个人信息 // url: '/pages/personal_core/personaldata/personaldata' // }) setTimeout(function () { wx.hideLoading() }, 2000) } else { // 图片还没有传完继续调用函数 data.i = i; data.success = success; data.fail = fail; that.uploadimg(data,_page); } } }); } module.exports = { uploadimg: uploadimg, }