controller.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { EditorModule } from "@/modules/editor/module";
  2. import { ResourceModule } from "@/modules/resource";
  3. import { PromotionController } from "@/modules/resource/controllers/PromotionController";
  4. import { PageListController } from "@queenjs/controllers";
  5. import { queenApi } from "queenjs";
  6. import ShareModal from "./components/ShareModal";
  7. import { sendPromotion } from "./components/SendPromotion";
  8. import { AuthModule } from "@queenjs-modules/auth";
  9. import { SelectOneImage } from "../Material2/modal";
  10. export function createPromotinController(
  11. auth: AuthModule,
  12. resource: ResourceModule,
  13. editor: EditorModule
  14. ) {
  15. const ctrl = new PromotionController();
  16. ctrl.ListCtrl = new PageListController(resource.config?.httpConfig);
  17. ctrl.ListCtrl.setCrudPrefix("/h5");
  18. ctrl.createPromotion = resource.actions.createPromotion;
  19. ctrl.changeThumbnail = resource.helper.uploadResource;
  20. ctrl.updateDesign = (record: any, data: any) => {
  21. if (data.title == "") {
  22. queenApi.messageError("标题不能为空!");
  23. return;
  24. }
  25. if (record.desc && data.desc == "") {
  26. queenApi.messageError("描述不能为空!");
  27. return;
  28. }
  29. for (const [key, value] of Object.entries(data)) {
  30. record[key] = value;
  31. }
  32. editor.https.saveDesign(data);
  33. queenApi.messageSuccess("保存成功!");
  34. };
  35. async function sharePromotion(record: any) {
  36. resource.showModal(<ShareModal record={record} controller={ctrl} />, {
  37. title: "编辑分享",
  38. width: "1000px",
  39. destroyOnClose: true,
  40. });
  41. }
  42. let url = "";
  43. ctrl.onMenuClick = async (name, record) => {
  44. switch (name) {
  45. case "stat":
  46. window.open("https://show.3dqueen.cloud/stat/#/count?id=" + record._id);
  47. break;
  48. case "delete":
  49. await resource.actions.deletePromotion(record);
  50. ctrl.ListCtrl.fresh();
  51. break;
  52. case "rename":
  53. await resource.actions.renamePromotion(record);
  54. break;
  55. case "share":
  56. sharePromotion(record);
  57. break;
  58. case "send":
  59. sendPromotion(resource, record);
  60. break;
  61. case "publish":
  62. await resource.actions.publishPromotion(record, true);
  63. break;
  64. case "unpublish":
  65. await resource.actions.publishPromotion(record, false);
  66. break;
  67. case "thumbnail":
  68. url = (await SelectOneImage()) as string;
  69. if (!url) return;
  70. await resource.https.updatePromotion({
  71. _id: record._id,
  72. thumbnail: url,
  73. });
  74. record.thumbnail = url;
  75. queenApi.messageSuccess("替换成功");
  76. break;
  77. }
  78. };
  79. return ctrl;
  80. }