123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import { EditorModule } from "..";
- import { CompObject } from "../../controllers/SelectCtrl/compObj";
- import { DesignComp } from "../../objects/DesignTemp/DesignComp";
- import { createProxyEffect } from "../../objects/ProxyStore/create";
- import { EditorMode } from "../../typings";
- import { editActions } from "./edit";
- export const initActions = EditorModule.action({
- // 模块初始化
- init() {
- const { historyCtrl } = this.controls;
- historyCtrl.bindActions(Object.keys(editActions));
- this.controls.compUICtrl.init();
- this.controls.mediaCtrl.init();
- createProxyEffect(this.store, (type, paths, value, oldValue) => {
- if (
- paths[0] === "designData" ||
- paths[0] === "currCompId" ||
- paths[0] === "selected" ||
- paths[0] === "currStreamCardId" ||
- paths[0] === "selectId"
- ) {
- historyCtrl.record(this.store, type, paths, value, oldValue);
- }
- });
- },
- // 初始化数据
- async initDesign(id: string, isSys = false) {
- const ret = await this.https.getDesignDetail(id, { isSys });
- this.store.setDesignData(ret.result);
- const root = this.helper.findRootComp() as DesignComp;
- this.controls.screenCtrl.state.useFor = root.value.useFor || "mobile";
- this.controls.screenCtrl.state.pageMode = root.value.pageMode || "long";
- this.controls.screenCtrl.state.pageSizeType = root.value.pageSizeType || "normal";
-
- //设置组件父子关系
- const ite = (root:any)=> {
- const cards = root.children?.default || [];
- cards.forEach((c:string)=>{
- this.store.setCompPid(c, root.id);
- const r = this.helper.findComp(c);
- if (r) {
- ite(r);
- }
- })
- }
- ite(this.store.rootPage);
- },
- async initWkDesign(id: string) {
- this.store.setWk(true);
- const ret = await this.https.getWkDesignDetail(id);
- this.store.setDesignData(ret.result);
- return ret.result;
- },
- // 切换模式
- switchMode(v: EditorMode) {
- this.store.setMode(v);
- },
- setWkFlag(v: boolean) {
- this.store.setWk(v);
- },
- onViewReady(pageEl, selEl, viewPort) {
- this.store.currStreamCardId = this.store.streamCardIds[0];
- this.controls.selectCtrl.initEvents(pageEl, selEl, viewPort);
- },
- onCompLayoutUpdated(comp: DesignComp) {
- if (this.helper.isCurrComp(comp.id)) {
- this.controls.selectCtrl.selecteObjs([new CompObject(comp)]);
- }
- },
- });
|