typical.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {getDataSet, getEventParam, throttle, toast} from "../../../../utils/utils";
  2. import Api from "../../../../model/api";
  3. import Config from "../../../../model/config";
  4. Component({
  5. properties: {
  6. categoryData: Array,
  7. },
  8. data: {
  9. type: '',
  10. msg: '',
  11. attachmentType: '',
  12. attachmentUrl: '',
  13. uploadPath: Config.UPLOAD_PATH.COMMUNITY_EXAMPLE
  14. },
  15. methods: {
  16. changeInfo(e) {
  17. let eventParam = getEventParam(e);
  18. this.setData({
  19. ...eventParam
  20. })
  21. },
  22. onChange(e) {
  23. const field = getDataSet(e, "field");
  24. this.setData({
  25. [field]: getEventParam(e)
  26. })
  27. },
  28. handleUpload(e) {
  29. const fileType = getEventParam(e, "fileType");
  30. const fileList = getEventParam(e, "fileList");
  31. const urls = fileList.map(item => item.url);
  32. const attachmentUrl = JSON.stringify(urls);
  33. this.setData({
  34. attachmentType: fileType, attachmentUrl
  35. })
  36. },
  37. publish: throttle(async function (e) {
  38. if (!this.data.type.trim()) {
  39. toast('请选择典型分类')
  40. return;
  41. }
  42. if (!this.data.msg.trim()) {
  43. toast('请输入要分享的内容')
  44. return;
  45. }
  46. const params = {
  47. type: this.data.type,
  48. details: this.data.msg,
  49. attachmentType: this.data.attachmentType,
  50. attachmentUrl: this.data.attachmentUrl
  51. }
  52. await Api.ReleaseExamples(params, true);
  53. this.triggerEvent("postFinish");
  54. })
  55. }
  56. })