publish-iv.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. mask: true
  29. });
  30. await Upload.uploadRes(this.data.uploadPath, file);
  31. wx.hideLoading();
  32. if ("image" == file.type) {
  33. this.setData({
  34. accept: 'image',
  35. maxCount: 9
  36. });
  37. } else {
  38. this.setData({
  39. accept: 'video',
  40. maxCount: 1
  41. });
  42. }
  43. const {fileList = []} = this.data;
  44. fileList.push({...file});
  45. this.setData({fileList});
  46. this.triggerEvent('upload', {
  47. fileType: this.data.dict[this.data.accept],
  48. fileList: fileList
  49. })
  50. },
  51. deleteImg(e) {
  52. const index = getEventParam(e, "index");
  53. const {fileList = []} = this.data;
  54. fileList.splice(index, 1);
  55. if (fileList.length == 0) {
  56. this.setData({
  57. accept: 'media',
  58. fileList
  59. }, () => {
  60. this.triggerEvent('upload', {
  61. fileType: this.data.dict[this.data.accept],
  62. fileList: fileList
  63. })
  64. });
  65. } else {
  66. this.setData({
  67. fileList
  68. }, () => {
  69. this.triggerEvent('upload', {
  70. fileType: this.data.dict[this.data.accept],
  71. fileList: fileList
  72. })
  73. });
  74. }
  75. },
  76. },
  77. })