init.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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) {
  28. const ret = await this.https[
  29. this.store.isEditComp ? "getCompDetail" : "getDesignDetail"
  30. ](id);
  31. this.store.setDesignData(ret.result);
  32. },
  33. // 切换模式
  34. switchMode(v: EditorMode) {
  35. this.store.setMode(v);
  36. },
  37. onViewReady(pageEl, selEl, viewPort) {
  38. this.store.currStreamCardId = this.store.streamCardIds[0];
  39. this.controls.selectCtrl.initEvents(pageEl, selEl, viewPort);
  40. },
  41. onCompLayoutUpdated(comp: DesignComp) {
  42. if (this.helper.isCurrComp(comp.id)) {
  43. this.controls.selectCtrl.selecteObjs([new CompObject(comp)]);
  44. }
  45. },
  46. });