controller.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. export function createPromotinController(
  8. resource: ResourceModule,
  9. editor: EditorModule
  10. ) {
  11. const ctrl = new PromotionController();
  12. ctrl.ListCtrl = new PageListController(resource.config?.httpConfig);
  13. ctrl.ListCtrl.setCrudPrefix("/h5");
  14. ctrl.createPromotion = resource.actions.createPromotion;
  15. ctrl.changeThumbnail = resource.helper.uploadResource;
  16. ctrl.updateDesign = (record: any, data: any) => {
  17. if (data.title == "") {
  18. queenApi.messageError("标题不能为空!");
  19. return;
  20. }
  21. if (record.desc && data.desc == "") {
  22. queenApi.messageError("描述不能为空!");
  23. return;
  24. }
  25. for (const [key, value] of Object.entries(data)) {
  26. record[key] = value;
  27. }
  28. editor.https.saveDesign(data);
  29. queenApi.messageSuccess("保存成功!");
  30. };
  31. async function sharePromotion(record: any) {
  32. editor.actions.initDesign(record._id);
  33. editor.actions.switchMode("preview");
  34. resource.showModal(
  35. <ShareModal record={record} controller={ctrl}>
  36. {{
  37. preview: () => <editor.components.Preview />,
  38. }}
  39. </ShareModal>,
  40. {
  41. title: "编辑分享",
  42. width: "1000px",
  43. }
  44. );
  45. }
  46. ctrl.onMenuClick = async (name, record) => {
  47. switch (name) {
  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. }
  59. };
  60. return ctrl;
  61. }