publish-iv.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {getEventParam} from "../../../../utils/utils";
  2. import Upload from "../../../../model/upload";
  3. import {uploadResTypes} from "../../../../model/enum";
  4. Component({
  5. properties: {
  6. uploadPath: String,
  7. },
  8. data: {
  9. dict: {
  10. "image": uploadResTypes.IMAGE,
  11. "video": uploadResTypes.VIDEO,
  12. },
  13. fileList: [],
  14. maxCount: 9,
  15. accept: 'media',
  16. isPC: false
  17. },
  18. attached() {
  19. let app = getApp();
  20. let isPC = app.globalData.isPC;
  21. this.setData({isPC})
  22. },
  23. methods: {
  24. async afterRead(e) {
  25. const file = getEventParam(e, "file")
  26. wx.showLoading({
  27. title: '正在上传...',
  28. });
  29. await Upload.uploadRes(this.data.uploadPath, file);
  30. wx.hideLoading();
  31. if ("image" == file.type) {
  32. this.setData({
  33. accept: 'image',
  34. maxCount: 9
  35. });
  36. } else {
  37. this.setData({
  38. accept: 'video',
  39. maxCount: 1
  40. });
  41. }
  42. const {fileList = []} = this.data;
  43. fileList.push({...file});
  44. this.setData({fileList});
  45. this.triggerEvent('upload', {
  46. fileType: this.data.dict[this.data.accept],
  47. fileList: fileList
  48. })
  49. },
  50. deleteImg(e) {
  51. const index = getEventParam(e, "index");
  52. const {fileList = []} = this.data;
  53. fileList.splice(index, 1);
  54. if (fileList.length == 0) {
  55. this.setData({
  56. accept: 'media',
  57. fileList
  58. }, () => {
  59. this.triggerEvent('upload', {
  60. fileType: this.data.dict[this.data.accept],
  61. fileList: fileList
  62. })
  63. });
  64. } else {
  65. this.setData({
  66. fileList
  67. }, () => {
  68. this.triggerEvent('upload', {
  69. fileType: this.data.dict[this.data.accept],
  70. fileList: fileList
  71. })
  72. });
  73. }
  74. },
  75. },
  76. })