index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import api from '../../api/api'
  2. Component({
  3. properties: {
  4. list: {
  5. value: '',
  6. type: Array
  7. },
  8. isdelete: {
  9. type: Boolean,
  10. value: true
  11. },
  12. },
  13. data: {
  14. visible: false,
  15. showIndex: false,
  16. closeBtn: false,
  17. deleteBtn: false,
  18. images2: [],
  19. gridConfig: {
  20. column: 5,
  21. width: 120,
  22. height: 120,
  23. },
  24. },
  25. observers: {
  26. "list": function (list) {
  27. this.setData({
  28. images2: list.map(e => {
  29. return {
  30. url: e.url,
  31. type: this.validateImageType(e.postfix),
  32. linksid: e.linksid
  33. }
  34. })
  35. })
  36. }
  37. },
  38. methods: {
  39. validateImageType(file) {
  40. const allowedTypes = /(\jpg|\jpeg|\png|\gif)$/i;
  41. const allowedTypes1 = /(\mp4|\mov|\3gp|\3g2)$/i;
  42. if (allowedTypes.test(file)) {
  43. return 'image'
  44. } else if (allowedTypes1.test(file)) {
  45. return 'video'
  46. } else {
  47. return 'file'
  48. }
  49. },
  50. async deleteFile(data) {
  51. const res = await api._post({
  52. "classname": "system.attachment.Attachment",
  53. "method": "deleteFileLink",
  54. "content": {
  55. "linksids": [data.detail.file.linksid]
  56. }
  57. })
  58. if (res.code == 1) {
  59. this.setData({
  60. images2: this.data.images2.filter(e => {
  61. return e.linksid !== data.detail.file.linksid
  62. })
  63. })
  64. } else {
  65. wx.showToast({
  66. title: res.data,
  67. icon: 'none'
  68. })
  69. }
  70. }
  71. }
  72. })