init.ts 931 B

12345678910111213141516171819202122232425262728293031
  1. import { EditorModule } from "..";
  2. import { createProxyEffect } from "../../objects/ProxyStore/create";
  3. import { EditorMode } from "../../typings";
  4. import { editActions } from "./edit";
  5. export const initActions = EditorModule.action({
  6. // 模块初始化
  7. init() {
  8. const { historyCtrl } = this.controls;
  9. historyCtrl.bindActions(Object.keys(editActions));
  10. this.controls.compUICtrl.init();
  11. createProxyEffect(this.store, (type, paths, value, oldValue) => {
  12. if (paths[0] === "designData" || paths[0] === "currCompId") {
  13. historyCtrl.record(this.store, type, paths, value, oldValue);
  14. }
  15. });
  16. },
  17. // 初始化数据
  18. async initDesign(id: string) {
  19. const ret = await this.https[
  20. this.store.isEditComp ? "getCompDetail" : "getDesignDetail"
  21. ](id);
  22. this.store.initDesignData(ret.result);
  23. },
  24. // 切换模式
  25. switchMode(v: EditorMode) {
  26. this.store.setMode(v);
  27. },
  28. });