index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const app = getApp()
  2. Component({
  3. properties: {
  4. list: { type: Array, value: [] },
  5. name: { type: String },
  6. count: { type: Number, value: 1 },
  7. },
  8. data: {},
  9. methods: {
  10. // 图片上传
  11. imgUpload() {
  12. const that = this;
  13. const name = that.data.name;
  14. wx.chooseImage({
  15. count: 1,
  16. sizeType: ['original', 'compressed'],
  17. sourceType: ['album', 'camera'],
  18. async success(chooseRes) {
  19. const file = chooseRes.tempFilePaths;
  20. let res = await app.$apifile('files/ball/team/upload', null, file[0])
  21. res = JSON.parse(res);
  22. if (res.errcode == '0') {
  23. that.triggerEvent('imgUpload', { name: res.name, url: `${app.globalData.fileserverUrl}` + res.uri, uri: res.uri })
  24. } else {
  25. wx.showToast({ title: `${res.errmsg}`, icon: 'error' })
  26. }
  27. }
  28. })
  29. },
  30. imgDel(e) {
  31. const that = this;
  32. const name = that.data.name;
  33. const { item, index } = e.currentTarget.dataset;
  34. that.triggerEvent('imgDel', { file: item, index: index })
  35. },
  36. // 预览
  37. toView: function (e) {
  38. const { item } = e.currentTarget.dataset;
  39. wx.previewImage({ current: '', urls: [item.url] })
  40. }
  41. }
  42. })