index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. function e(e, t, a) {
  2. return t in e ? Object.defineProperty(e, t, {
  3. value: a,
  4. enumerable: !0,
  5. configurable: !0,
  6. writable: !0
  7. }) : e[t] = a, e;
  8. }
  9. var t = [],
  10. a = 0,
  11. r = [];
  12. var app = getApp();
  13. Component({
  14. properties: {
  15. imgMax: {
  16. type: Number,
  17. value: 0
  18. },
  19. token: String,
  20. key: {
  21. type: String,
  22. value: "wx-upload"
  23. }
  24. },
  25. data: {
  26. imgGroup: [],
  27. progressList: []
  28. },
  29. methods: {
  30. addImg: function() {
  31. var s = this,
  32. i = this.data.imgGroup;
  33. wx.chooseImage({
  34. count: this.data.imgMax - i.length,
  35. success: function(n) {
  36. s.triggerEvent("on-chooseImage", {key: s.data.key}), (i = i.concat(n.tempFilePaths)).length > s.data.imgMax && i.splice(s.data.imgMax),
  37. s.setData({
  38. imgGroup: i
  39. });
  40. var o = n.tempFilePaths.length;
  41. a = i.length;
  42. for (var g = 0; g < n.tempFilePaths.length; g++) ! function(i) {
  43. var g = n.tempFilePaths[i].split(".")[n.tempFilePaths[i].split(".").length - 1],
  44. l = new Date().getTime(),
  45. p = Math.round(1e6 * Math.random());
  46. r[i + a - o] = wx.uploadFile({
  47. url: app.util.url('entry/wxapp/index', {
  48. 'm': 'lionfish_comshop',
  49. 'controller': 'goods.doPageUpload'
  50. }),
  51. filePath: n.tempFilePaths[i],
  52. name: "upfile",
  53. header: {
  54. "Content-Type": "multipart/form-data"
  55. },
  56. formData: {
  57. token: s.data.token,
  58. key: s.data.key + "-" + l + "-" + p + "." + g
  59. },
  60. success: function(r) {
  61. t[i + a - o] = JSON.parse(r.data).image_o, s.setData(e({}, "progressList[" + (i + a - o) + "]", 100)),
  62. s.triggerEvent("on-changeImage", {
  63. value: t,
  64. len: a,
  65. key: s.data.key
  66. });
  67. }
  68. }), r[i + a - o].onProgressUpdate(function(t) {
  69. var r = t.progress;
  70. s.setData(e({}, "progressList[" + (i + a - o) + "]", r));
  71. });
  72. }(g);
  73. }
  74. });
  75. },
  76. remove: function(e) {
  77. var s = e.currentTarget.dataset.idx,
  78. i = this.data.imgGroup,
  79. n = this.data.progressList;
  80. n[s] < 100 && r[s].abort(), i.splice(s, 1), r.splice(s, 1), n.splice(s, 1), t.splice(s, 1),
  81. a = i.length, this.setData({
  82. imgGroup: i,
  83. progressList: n
  84. }), this.triggerEvent("on-changeImage", {
  85. value: t,
  86. len: a,
  87. key: this.data.key
  88. });
  89. },
  90. bigImg: function(e) {
  91. var t = e.currentTarget.dataset.src,
  92. a = e.currentTarget.dataset.list;
  93. wx.previewImage({
  94. current: t,
  95. urls: a
  96. });
  97. }
  98. },
  99. detached: function() {
  100. console.log("detached"), t = [], a = 0, r = [];
  101. }
  102. });