index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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: '30' }
  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: function () {
  33. const that = this;
  34. wx.chooseImage({
  35. count: 1,
  36. sizeType: ['original', 'compressed'],
  37. sourceType: ['album', 'camera'],
  38. success(res) {
  39. const file = res.tempFilePaths;
  40. wx.uploadFile({
  41. url: `${app.globalData.fileUrl}/files/court/elimg/upload`,
  42. filePath: file[0],
  43. name: 'file',
  44. formData: {},
  45. success: (arr) => {
  46. let aee = JSON.parse(arr.data);
  47. if (arr.statusCode == 200) {
  48. that.triggerEvent('imgUpload', { name: aee.name, url: `${app.globalData.fileUrl}` + aee.uri, uri: aee.uri })
  49. } else {
  50. wx.showToast({ title: `${arr.errMsg}`, icon: 'error', duration: 2000 })
  51. }
  52. }
  53. })
  54. }
  55. })
  56. },
  57. // 图片删除
  58. imgDel: function (e) {
  59. const that = this;
  60. const { item, index } = e.currentTarget.dataset;
  61. that.triggerEvent('imgDel', { file: item, index: index })
  62. },
  63. // 预览
  64. toView: function (e) {
  65. const { item } = e.currentTarget.dataset;
  66. wx.previewImage({
  67. current: '',
  68. urls: [item.url]
  69. })
  70. }
  71. }
  72. })