common.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. function uploadimg(data,page = null) {
  2. var _page = page;
  3. // console.log(data.date)
  4. var that = this,
  5. i = data.i ? data.i : 0,
  6. success = data.success ? data.success : 0,
  7. fail = data.fail ? data.fail : 0;
  8. console.log(i);
  9. console.log(success);
  10. console.log(fail);
  11. wx.uploadFile({
  12. url: data.url,
  13. filePath: data.path[i],
  14. name: data.name,
  15. formData: {
  16. // 同时上传userId和当前时间
  17. key: wx.getStorageSync('access_key'),
  18. token: wx.getStorageSync('access_token')
  19. },
  20. success: (resp) => {
  21. success++;
  22. console.log(resp);
  23. wx.showLoading({
  24. title: '上传中',
  25. })
  26. // app.globalData.xqimgList += resp.data + ",";
  27. },
  28. fail: (res) => {
  29. fail++;
  30. console.log('fail:' + i + "fail:" + fail);
  31. },
  32. complete: () => {
  33. i++;
  34. if (i == data.path.length) { // 图片传完时停止调用
  35. if (_page){
  36. page.setData({
  37. picsItems:[],
  38. uploadImages:[]
  39. })
  40. _page.demo();
  41. }
  42. // this.onReady()
  43. // wx.navigateTo({
  44. // url: '/pages/personal_core/Album/Album'
  45. // })
  46. // wx.navigateTo({ // 成功后跳转个人信息
  47. // url: '/pages/personal_core/personaldata/personaldata'
  48. // })
  49. setTimeout(function () {
  50. wx.hideLoading()
  51. }, 2000)
  52. } else { // 图片还没有传完继续调用函数
  53. data.i = i;
  54. data.success = success;
  55. data.fail = fail;
  56. that.uploadimg(data,_page);
  57. }
  58. }
  59. });
  60. }
  61. module.exports = {
  62. uploadimg: uploadimg,
  63. }