publish-iv.js 2.2 KB

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