init.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. createProxyEffect(this.store, (type, paths, value, oldValue) => {
  14. if (paths[0] === "designData" ||
  15. paths[0] === "currCompId" ||
  16. paths[0] === "selected" ||
  17. paths[0] === "currStreamCardId" ||
  18. paths[0] === "selectId"
  19. ) {
  20. historyCtrl.record(this.store, type, paths, value, oldValue);
  21. }
  22. });
  23. },
  24. // 初始化数据
  25. async initDesign(id: string) {
  26. const ret = await this.https[
  27. this.store.isEditComp ? "getCompDetail" : "getDesignDetail"
  28. ](id);
  29. this.store.setDesignData(ret.result);
  30. },
  31. // 切换模式
  32. switchMode(v: EditorMode) {
  33. this.store.setMode(v);
  34. },
  35. onViewReady(pageEl, selEl, viewPort) {
  36. this.store.currStreamCardId = this.store.streamCardIds[0];
  37. this.controls.selectCtrl.initEvents(pageEl, selEl, viewPort);
  38. },
  39. onCompLayoutUpdated(comp: DesignComp) {
  40. if (this.helper.isCurrComp(comp.id)) {
  41. this.controls.selectCtrl.selecteObjs([new CompObject(comp)]);
  42. }
  43. },
  44. });