init.ts 1.4 KB

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