index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // commpents/mobile-frame/mobile-main.js
  2. const app = getApp()
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. options: { multipleSlots: true },
  8. properties: {
  9. list: { type: 'array', value: [] },
  10. count: { type: Number, value: 1 },
  11. previewSize: { type: String, value: '60' }
  12. },
  13. // 生命周期函数,可以为函数,或一个在methods段中定义的方法名
  14. attached: function () { }, // 此处attached的声明会被lifetimes字段中的声明覆盖
  15. ready: function () { },
  16. pageLifetimes: {
  17. // 组件所在页面的生命周期函数
  18. show: function () { },
  19. hide: function () { },
  20. resize: function () { },
  21. },
  22. /**
  23. * 组件的初始数据
  24. */
  25. data: {
  26. },
  27. /**
  28. * 组件的方法列表
  29. */
  30. methods: {
  31. // 图片上传
  32. imgUpload(event) {
  33. const { file } = event.detail;
  34. wx.uploadFile({
  35. url: `${app.globalData.imageUrl}/files/court/elimg/upload`,
  36. filePath: file.url,
  37. name: 'file',
  38. formData: {},
  39. success: (res) => {
  40. let arr = JSON.parse(res.data);
  41. if (res.statusCode == 200) {
  42. this.triggerEvent('imgUpload', { name: arr.name, url: `${app.globalData.imageUrl}` + arr.uri, uri: arr.uri })
  43. } else {
  44. wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 })
  45. }
  46. }
  47. })
  48. },
  49. // 图片删除
  50. imgDel(e) {
  51. this.triggerEvent('imgDel', { file: e.detail.file, index: e.detail.index })
  52. }
  53. }
  54. })