|
@@ -1,11 +1,34 @@
|
|
|
import { cloneDeep, pick, set } from "lodash";
|
|
|
import { Exception, queenApi } from "queenjs";
|
|
|
import { EditorModule } from "..";
|
|
|
+import { ScreenshotCtrl } from "../../controllers/ScreenshotCtrl";
|
|
|
import { DesignComp } from "../../objects/DesignTemp/DesignComp";
|
|
|
-import { Matrix } from "../../controllers/TransferCtrl/Matrix";
|
|
|
import { ICompKeys, Layout } from "../../typings";
|
|
|
|
|
|
export const editActions = EditorModule.action({
|
|
|
+ // 通过拖拽添加组件到画布
|
|
|
+ async dragCompToDesign(event: MouseEvent, compKey: ICompKeys) {
|
|
|
+ await this.actions.addCompToDesign(compKey);
|
|
|
+ const cardPoints = this.helper.getPointOffsetWith(
|
|
|
+ event,
|
|
|
+ this.store.currStreamCard.$el
|
|
|
+ );
|
|
|
+ const { currComp } = this.store;
|
|
|
+ currComp.translate(
|
|
|
+ 375 - (currComp.layout.size?.[0] || 750) / 2,
|
|
|
+ this.helper.pxToDesignSize(cardPoints.y)
|
|
|
+ );
|
|
|
+ },
|
|
|
+ // 通过点击添加组件到画布
|
|
|
+ async clickCompToDesign(compKey: ICompKeys) {
|
|
|
+ await this.actions.addCompToDesign(compKey);
|
|
|
+ const { currStreamCard, currComp } = this.store;
|
|
|
+
|
|
|
+ const y = currStreamCard.getH();
|
|
|
+ currStreamCard.setH(y + currComp.getH());
|
|
|
+ currComp.translate(0, y);
|
|
|
+ },
|
|
|
+
|
|
|
// 添加组件到画布
|
|
|
async addCompToDesign(compKey: ICompKeys, index?: number) {
|
|
|
if (!this.store.currStreamCardId) {
|
|
@@ -68,7 +91,7 @@ export const editActions = EditorModule.action({
|
|
|
if (this.store.currCompId == compId) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
this.store.setCurrComp(compId);
|
|
|
if (this.store.currCompId == this.store.currStreamCardId) {
|
|
|
this.controls.transferCtrl.destroy();
|
|
@@ -116,7 +139,7 @@ export const editActions = EditorModule.action({
|
|
|
async saveAsComp(comp: DesignComp) {
|
|
|
try {
|
|
|
// 组件封面
|
|
|
- const blob = await this.helper.screenshot({
|
|
|
+ const blob = await new ScreenshotCtrl().snap({
|
|
|
element: comp.$el,
|
|
|
});
|
|
|
const thumbnail = URL.createObjectURL(blob);
|
|
@@ -176,7 +199,7 @@ export const editActions = EditorModule.action({
|
|
|
const rootComp = this.helper.findRootComp();
|
|
|
if (!rootComp) return;
|
|
|
queenApi.showLoading("截屏中");
|
|
|
- const blob = await this.helper.screenshot({
|
|
|
+ const blob = await new ScreenshotCtrl().snap({
|
|
|
element: rootComp.$el,
|
|
|
ratio: this.store.isEditComp ? 0 : 1,
|
|
|
});
|
|
@@ -256,133 +279,16 @@ export const editActions = EditorModule.action({
|
|
|
},
|
|
|
// 关闭组合模式
|
|
|
async disableGroupMode() {
|
|
|
- const groupId = await this.actions.combineGroupComps();
|
|
|
+ const groupId = await this.controls.transferCtrl.groupCtrl.combineGroup();
|
|
|
if (groupId) {
|
|
|
this.store.setCurrComp(groupId);
|
|
|
}
|
|
|
this.store.setGroupIds([]);
|
|
|
this.store.setGroupMode(false);
|
|
|
},
|
|
|
- // 合并组件
|
|
|
- async combineGroupComps() {
|
|
|
- const { helper, store } = this;
|
|
|
- const { groupIds } = store;
|
|
|
- if (groupIds.length < 2) return;
|
|
|
- const compsRect: Record<
|
|
|
- string,
|
|
|
- { t: number; l: number; r: number; b: number }
|
|
|
- > = {};
|
|
|
- const parentComp = helper.findParentComp(groupIds[0]) as DesignComp;
|
|
|
- const parentRect = parentComp.$el.getBoundingClientRect();
|
|
|
- groupIds.forEach((id) => {
|
|
|
- const comp = helper.findComp(id) as DesignComp;
|
|
|
- const itemRect = comp.$el.getBoundingClientRect();
|
|
|
- compsRect[id] = {
|
|
|
- t: itemRect.top - parentRect.top,
|
|
|
- l: itemRect.left - parentRect.left,
|
|
|
- r: itemRect.right - parentRect.left,
|
|
|
- b: itemRect.bottom - parentRect.top,
|
|
|
- };
|
|
|
- });
|
|
|
-
|
|
|
- const confVals = Object.values(compsRect);
|
|
|
- const groupConf = {
|
|
|
- t: Math.min(...confVals.map((d) => d.t)),
|
|
|
- l: Math.min(...confVals.map((d) => d.l)),
|
|
|
- r: Math.max(...confVals.map((d) => d.r)),
|
|
|
- b: Math.max(...confVals.map((d) => d.b)),
|
|
|
- };
|
|
|
-
|
|
|
- const groupId = await this.store.insertCompContainer("Group", parentComp);
|
|
|
-
|
|
|
- const groupComp = helper.findComp(groupId) as DesignComp;
|
|
|
-
|
|
|
- groupComp.layout = {
|
|
|
- size: [
|
|
|
- helper.pxToDesignSize(groupConf.r - groupConf.l),
|
|
|
- helper.pxToDesignSize(groupConf.b - groupConf.t),
|
|
|
- ],
|
|
|
- position: "absolute",
|
|
|
- transform: {
|
|
|
- x: helper.pxToDesignSize(groupConf.l),
|
|
|
- y: helper.pxToDesignSize(groupConf.t),
|
|
|
- },
|
|
|
- };
|
|
|
-
|
|
|
- groupIds.forEach((id) => {
|
|
|
- const comp = helper.findComp(id) as DesignComp;
|
|
|
- comp.layout.transform || (comp.layout.transform = {});
|
|
|
- comp.layout.transform.x =
|
|
|
- (comp.layout.transform.x || 0) - (groupComp.layout.transform?.x || 0);
|
|
|
-
|
|
|
- comp.layout.transform.y =
|
|
|
- (comp.layout.transform.y || 0) - (groupComp.layout.transform?.y || 0);
|
|
|
- });
|
|
|
-
|
|
|
- groupComp.children.default = parentComp.children.default?.filter((d) =>
|
|
|
- groupIds.includes(d)
|
|
|
- );
|
|
|
- parentComp.children.default = parentComp.children.default?.filter(
|
|
|
- (d) => !groupIds.includes(d)
|
|
|
- );
|
|
|
-
|
|
|
- return groupId;
|
|
|
- },
|
|
|
// 取消打组
|
|
|
cancelGroupComps(groupComp: DesignComp) {
|
|
|
- const { helper } = this;
|
|
|
- const groupChildIds = groupComp.children.default as string[];
|
|
|
-
|
|
|
- const parentComp = helper.findParentComp(groupComp.id) as DesignComp;
|
|
|
-
|
|
|
- const parentMatrix = new Matrix();
|
|
|
-
|
|
|
- groupChildIds.forEach((id) => {
|
|
|
- const comp = helper.findComp(id) as DesignComp;
|
|
|
-
|
|
|
- parentMatrix.setFormDiv(groupComp.$el);
|
|
|
- const originArr = window
|
|
|
- .getComputedStyle(groupComp.$el)
|
|
|
- .transformOrigin.split(" ")
|
|
|
- .map(parseFloat);
|
|
|
-
|
|
|
- const porigin = new Matrix();
|
|
|
- porigin.translate(originArr[0], originArr[1]);
|
|
|
- const invOrigin = new Matrix();
|
|
|
- invOrigin.translate(-originArr[0], -originArr[1]);
|
|
|
-
|
|
|
- const childOrigArr = window
|
|
|
- .getComputedStyle(comp.$el)
|
|
|
- .transformOrigin.split(" ")
|
|
|
- .map(parseFloat);
|
|
|
- const corigin = new Matrix();
|
|
|
- corigin.translate(childOrigArr[0], childOrigArr[1]);
|
|
|
- const cinvOrigin = new Matrix();
|
|
|
- cinvOrigin.translate(-childOrigArr[0], -childOrigArr[1]);
|
|
|
-
|
|
|
- const childMatrix = new Matrix();
|
|
|
- childMatrix.setFormDiv(comp.$el);
|
|
|
-
|
|
|
- const result = cinvOrigin
|
|
|
- .multipy(porigin)
|
|
|
- .multipy(parentMatrix)
|
|
|
- .multipy(invOrigin)
|
|
|
- .multipy(corigin)
|
|
|
- .multipy(childMatrix);
|
|
|
-
|
|
|
- comp.layout.transform || (comp.layout.transform = {});
|
|
|
- comp.layout.transform.x = helper.pxToDesignSize(result.getX());
|
|
|
- comp.layout.transform.y = helper.pxToDesignSize(result.getY());
|
|
|
- comp.layout.transform.s = result.getScale();
|
|
|
- comp.layout.transform.r = result.getRotate();
|
|
|
- });
|
|
|
-
|
|
|
- const childIds = [...(parentComp.children.default as string[])];
|
|
|
-
|
|
|
- const groupIndex = childIds.findIndex((id) => groupComp.id === id);
|
|
|
- childIds.splice(groupIndex, 1, ...groupChildIds);
|
|
|
-
|
|
|
- parentComp.children.default = childIds;
|
|
|
- this.store.setCurrComp(groupChildIds[0]);
|
|
|
+ this.controls.transferCtrl.groupCtrl.cancelGroup(groupComp);
|
|
|
+ this.store.setCurrComp(groupComp.children.default?.[0] as string);
|
|
|
},
|
|
|
});
|