|
@@ -1,4 +1,4 @@
|
|
|
-import { pick, set } from "lodash";
|
|
|
+import { cloneDeep, pick, set } from "lodash";
|
|
|
import { Exception, queenApi } from "queenjs";
|
|
|
import { EditorModule } from "..";
|
|
|
import { DesignComp } from "../../objects/DesignTemp/DesignComp";
|
|
@@ -49,28 +49,58 @@ export const editActions = EditorModule.action({
|
|
|
this.store.deleteComp(compId);
|
|
|
}
|
|
|
},
|
|
|
- // 保存容器为组件
|
|
|
- saveAsComp(comp: DesignComp) {
|
|
|
- // todo: 保存为组件
|
|
|
- console.log("comp: ", comp);
|
|
|
- },
|
|
|
+
|
|
|
// 移动组件顺序
|
|
|
moveComp(selIndex: number, targetIndex: number) {
|
|
|
if (selIndex === targetIndex) return;
|
|
|
this.store.moveComp(selIndex, targetIndex);
|
|
|
},
|
|
|
|
|
|
- // 保存项目
|
|
|
- async saveDesign() {
|
|
|
- // 清除无用组件
|
|
|
- this.store.clearUnusedComps();
|
|
|
+ // 保存容器为组件
|
|
|
+ async saveAsComp(comp: DesignComp) {
|
|
|
+ try {
|
|
|
+ // 组件封面
|
|
|
+ const blob = await this.helper.screenshot({
|
|
|
+ element: comp.$el,
|
|
|
+ });
|
|
|
+ const thumbnail = URL.createObjectURL(blob);
|
|
|
+ const title = await queenApi.showInput({
|
|
|
+ title: "保存到我的组件",
|
|
|
+ defaultValue: this.controls.compUICtrl.state.components.get(
|
|
|
+ comp.compKey
|
|
|
+ )?.name,
|
|
|
+ });
|
|
|
+
|
|
|
+ const data = {
|
|
|
+ title,
|
|
|
+ thumbnail,
|
|
|
+ compMap: cloneDeep(this.store.designData.compMap),
|
|
|
+ };
|
|
|
+ this.helper.clearUnusedComps(data.compMap, comp.id);
|
|
|
+ data.compMap.root = data.compMap[comp.id];
|
|
|
+ data.compMap.root.id = "root";
|
|
|
+ delete data.compMap[comp.id];
|
|
|
|
|
|
- // 封面截屏
|
|
|
- if (!this.store.designData.thumbnail) {
|
|
|
- await this.actions.updateThumbnailByScreenshot();
|
|
|
+ queenApi.showLoading("保存中");
|
|
|
+ await this.controls.uploader.uploadBlobs(data);
|
|
|
+ await this.https.createComp(data);
|
|
|
+ queenApi.messageSuccess("保存成功");
|
|
|
+ } catch (error: any) {
|
|
|
+ throw Exception.error(error.toString());
|
|
|
+ } finally {
|
|
|
+ queenApi.hideLoading();
|
|
|
}
|
|
|
+ },
|
|
|
|
|
|
+ // 保存项目
|
|
|
+ async saveDesign() {
|
|
|
try {
|
|
|
+ // 清除无用组件
|
|
|
+ this.helper.clearUnusedComps(this.store.designData.compMap);
|
|
|
+ // 封面截屏
|
|
|
+ if (!this.store.designData.thumbnail) {
|
|
|
+ await this.actions.updateThumbnailByScreenshot();
|
|
|
+ }
|
|
|
queenApi.showLoading("保存中");
|
|
|
await this.controls.uploader.uploadBlobs(this.store.designData);
|
|
|
await this.https[this.store.isEditPage ? "saveDesign" : "saveComp"](
|
|
@@ -87,8 +117,11 @@ export const editActions = EditorModule.action({
|
|
|
// 截屏保存封面
|
|
|
async updateThumbnailByScreenshot(autoSave?: boolean) {
|
|
|
try {
|
|
|
+ const rootComp = this.helper.findRootComp();
|
|
|
+ if (!rootComp) return;
|
|
|
queenApi.showLoading("截屏中");
|
|
|
const blob = await this.helper.screenshot({
|
|
|
+ element: rootComp.$el,
|
|
|
ratio: this.store.isEditComp ? 0 : 1,
|
|
|
});
|
|
|
const thumbnail = URL.createObjectURL(blob);
|