import { Exception, queenApi } from "queenjs"; import { EditorModule } from ".."; import { ICompKeys } from "../typings"; export const editActions = EditorModule.action({ // 添加组件到画布 addCompToDesign(compKey: ICompKeys, index?: number) { let compId: string; if (index === undefined && this.store.currComp?.compKey === "Container") { compId = this.store.insertCompContainer(compKey, this.store.currComp); } else { compId = this.store.insertDesignContent(compKey, index); } this.actions.pickComp(compId); }, // 切换当前组件 pickComp(compId: string) { this.store.setCurrComp(compId); }, // 切换到父组件 pickParentComp(compId: string) { const parentComp = this.helper.findParentComp(compId); parentComp && this.store.setCurrComp(parentComp.id); }, // 删除组件 removeComp(compId: string) { if (compId === this.store.currCompId) { this.store.setCurrComp(""); } this.store.deleteComp(compId); }, // 移动组件 moveComp(selIndex: number, targetIndex: number) { if (selIndex === targetIndex) return; this.store.moveComp(selIndex, targetIndex); }, // 保存项目 async saveDesign() { try { queenApi.showLoading("保存中"); this.store.clearUnusedComps(); await this.https.saveDesign(this.store.designData); queenApi.messageSuccess("保存成功"); } catch (error: any) { throw Exception.error(error.toString()); } finally { queenApi.hideLoading(); } }, });