init.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { EditorModule } from "..";
  2. import { CompObject } from "../../controllers/SelectCtrl/compObj";
  3. import { DesignComp } from "../../objects/DesignTemp/DesignComp";
  4. import { createProxyEffect } from "../../objects/ProxyStore/create";
  5. import { EditorMode } from "../../typings";
  6. import { editActions } from "./edit";
  7. export const initActions = EditorModule.action({
  8. // 模块初始化
  9. init() {
  10. const { historyCtrl } = this.controls;
  11. historyCtrl.bindActions(Object.keys(editActions));
  12. this.controls.compUICtrl.init();
  13. this.controls.mediaCtrl.init();
  14. createProxyEffect(this.store, (type, paths, value, oldValue) => {
  15. if (
  16. paths[0] === "designData" ||
  17. paths[0] === "currCompId" ||
  18. paths[0] === "selected" ||
  19. paths[0] === "currStreamCardId" ||
  20. paths[0] === "selectId"
  21. ) {
  22. historyCtrl.record(this.store, type, paths, value, oldValue);
  23. }
  24. });
  25. },
  26. // 初始化数据
  27. async initDesign(id: string, isSys = false) {
  28. const ret = await this.https.getDesignDetail(id, { isSys });
  29. this.store.setDesignData(ret.result);
  30. const root = this.helper.findRootComp() as DesignComp;
  31. this.controls.screenCtrl.state.useFor = root.value.useFor || "mobile";
  32. this.controls.screenCtrl.state.pageMode = root.value.pageMode || "long";
  33. this.controls.screenCtrl.state.pageSizeType = root.value.pageSizeType || "normal";
  34. //设置组件父子关系
  35. const ite = (root:any)=> {
  36. const cards = root.children?.default || [];
  37. cards.forEach((c:string)=>{
  38. this.store.setCompPid(c, root.id);
  39. const r = this.helper.findComp(c);
  40. if (r) {
  41. ite(r);
  42. }
  43. })
  44. }
  45. ite(this.store.rootPage);
  46. },
  47. async initWkDesign(id: string) {
  48. this.store.setWk(true);
  49. const ret = await this.https.getWkDesignDetail(id);
  50. this.store.setDesignData(ret.result);
  51. return ret.result;
  52. },
  53. // 切换模式
  54. switchMode(v: EditorMode) {
  55. this.store.setMode(v);
  56. },
  57. setWkFlag(v: boolean) {
  58. this.store.setWk(v);
  59. },
  60. onViewReady(pageEl, selEl, viewPort) {
  61. this.store.currStreamCardId = this.store.streamCardIds[0];
  62. this.controls.selectCtrl.initEvents(pageEl, selEl, viewPort);
  63. },
  64. onCompLayoutUpdated(comp: DesignComp) {
  65. if (this.helper.isCurrComp(comp.id)) {
  66. this.controls.selectCtrl.selecteObjs([new CompObject(comp)]);
  67. }
  68. },
  69. });