|
@@ -6,6 +6,14 @@ import { CompObject } from "../../controllers/SelectCtrl/compObj";
|
|
|
import { DesignComp } from "../../objects/DesignTemp/DesignComp";
|
|
|
import { ICompKeys, Layout } from "../../typings";
|
|
|
import CompSave from "../../components/CompSave";
|
|
|
+import { ObjsContainer } from "../../controllers/SelectCtrl/ObjsContainer";
|
|
|
+import { getKeyThenIncreaseKey } from "ant-design-vue/lib/message";
|
|
|
+import { Matrix } from "../../controllers/SelectCtrl/matrix";
|
|
|
+import { nanoid } from "nanoid";
|
|
|
+import { string } from "vue-types";
|
|
|
+
|
|
|
+
|
|
|
+let ctrlcselected:string[] = [];
|
|
|
|
|
|
export const editActions = EditorModule.action({
|
|
|
pickComp(compId: string, selected = true) {
|
|
@@ -53,6 +61,7 @@ export const editActions = EditorModule.action({
|
|
|
compKey != "Triangle" &&
|
|
|
compKey != "Ellipse" &&
|
|
|
compKey != "Polygon" &&
|
|
|
+ compKey != "PolygonNormal" &&
|
|
|
compKey != "Curve";
|
|
|
|
|
|
let yOffset = 0;
|
|
@@ -110,34 +119,21 @@ export const editActions = EditorModule.action({
|
|
|
},
|
|
|
|
|
|
// 通过点击添加组件到画布
|
|
|
- async clickCompUserToDesign(id: string) {
|
|
|
+ async clickCompUserToDesign(id: string, isSys) {
|
|
|
if (!this.store.currStreamCardId) {
|
|
|
queenApi.messageError("请先选中一个卡片");
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- const { result } = await this.https.getCompDetail(id);
|
|
|
-
|
|
|
-
|
|
|
- let yOffset = 0;
|
|
|
- if (
|
|
|
- this.store.currCompId != this.store.currStreamCardId &&
|
|
|
- this.store.currCompId != "root"
|
|
|
- ) {
|
|
|
- const bound = this.helper.getCardCompBound(this.store.currCompId);
|
|
|
- yOffset = bound.y + bound.h;
|
|
|
- }
|
|
|
-
|
|
|
- let currCard = this.store.currStreamCard;
|
|
|
+ const { result } = await this.https.getCompDetail(id, isSys);
|
|
|
|
|
|
//先创建卡片
|
|
|
- const currCardIndex = this.store.streamCardIds.indexOf(this.store.currStreamCardId) + 1;
|
|
|
- const cardId = await this.store.insertDesignContent(
|
|
|
- "Container",
|
|
|
- currCardIndex
|
|
|
- );
|
|
|
- currCard = this.helper.findComp(cardId) as DesignComp;
|
|
|
-
|
|
|
+ // const currCardIndex = this.store.streamCardIds.indexOf(this.store.currStreamCardId) + 1;
|
|
|
+ // const cardId = await this.store.insertDesignContent(
|
|
|
+ // "Container",
|
|
|
+ // currCardIndex
|
|
|
+ // );
|
|
|
+ // const currCard = this.helper.findComp(cardId) as DesignComp;
|
|
|
+ const currCard = this.store.currStreamCard;
|
|
|
const comp = this.store.addUserCard(result);
|
|
|
|
|
|
const compId = comp.id;
|
|
@@ -145,54 +141,100 @@ export const editActions = EditorModule.action({
|
|
|
childIds.push(compId);
|
|
|
currCard.children.default = childIds;
|
|
|
|
|
|
+ this.store.setCompPid(compId, currCard.id);
|
|
|
+
|
|
|
const addedComp = this.store.compMap[compId];
|
|
|
addedComp.layout.position = "absolute";
|
|
|
|
|
|
- const currComp = this.helper.findComp(compId) as DesignComp;
|
|
|
+ this.actions.initAddedCompPos(this.store.currCompId, compId, currCard.id);
|
|
|
+
|
|
|
+ this.actions.pickComp(compId);
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ initAddedCompPos(currId: string, addedId:string, cardId:string) {
|
|
|
+
|
|
|
+ let yOffset = 0;
|
|
|
+ if (
|
|
|
+ currId != this.store.currStreamCardId &&
|
|
|
+ currId != "root"
|
|
|
+ ) {
|
|
|
+ const paths = this.helper.getCompTrees(currId)
|
|
|
+ const bound = this.helper.getCardCompBound(paths[2].id);
|
|
|
+ yOffset = bound.y + bound.h;
|
|
|
+ }
|
|
|
+
|
|
|
+ const currComp = this.helper.findComp(addedId) as DesignComp;
|
|
|
|
|
|
//添加组件到当前选中的组件下面
|
|
|
let xOffset = this.helper.designSizeToPx(
|
|
|
375 - (currComp.layout.size?.[0] || 750) / 2
|
|
|
);
|
|
|
const obj = new CompObject(currComp);
|
|
|
+
|
|
|
+ const currCard = this.helper.findComp(cardId) as DesignComp;
|
|
|
+
|
|
|
//没有选中组件添加到当前卡片最后
|
|
|
const children = currCard.children.default || [];
|
|
|
if (yOffset == 0 && children.length >= 2) {
|
|
|
- const prevCompIndex = children.indexOf(compId) - 1;
|
|
|
+ const prevCompIndex = children.indexOf(addedId) - 1;
|
|
|
const bound = this.helper.getCardCompBound(children[prevCompIndex]);
|
|
|
yOffset = bound.y + bound.h;
|
|
|
}
|
|
|
obj.worldTransform.translate(xOffset, yOffset);
|
|
|
currComp.layout.transformMatrix = obj.worldTransform.getMatrixStr();
|
|
|
-
|
|
|
- this.actions.pickComp(compId);
|
|
|
this.helper.extendStreamCard(currCard.id);
|
|
|
this.controls.cropCtrl.close();
|
|
|
-},
|
|
|
+ },
|
|
|
|
|
|
|
|
|
// 通过拖拽添加组件到画布
|
|
|
- async dragCompToDesign(event: MouseEvent, compKey: ICompKeys) {
|
|
|
- await this.actions.addCompToDesign(compKey);
|
|
|
+ async dragCompToDesign(event: MouseEvent, compKey: string, data:any) {
|
|
|
|
|
|
- const cardPoints = this.helper.getPointOffsetWith(
|
|
|
- event,
|
|
|
- this.store.currStreamCard.$el
|
|
|
- );
|
|
|
- const { currComp } = this.store;
|
|
|
- let selCtrl = this.controls.selectCtrl;
|
|
|
- selCtrl.translate(
|
|
|
- this.helper.designSizeToPx(375 - (currComp.layout.size?.[0] || 750) / 2),
|
|
|
- cardPoints.y
|
|
|
- );
|
|
|
+ const currCardDom = this.store.currStreamCard.$el;
|
|
|
|
|
|
- this.helper.extendStreamCard(this.store.currStreamCardId);
|
|
|
+ if (compKey == "CompCard") {
|
|
|
+ const { result } = await this.https.getCompDetail(data.id, data.isSys);
|
|
|
+ const comp = this.store.addUserCard(result);
|
|
|
|
|
|
- if (compKey == "Text") {
|
|
|
- this.actions.selectObjs([]);
|
|
|
- this.actions.textFocus(currComp.id, true);
|
|
|
+ const currCard = this.store.currStreamCard;
|
|
|
+ const compId = comp.id;
|
|
|
+ const childIds = [...(currCard.children.default || [])];
|
|
|
+ childIds.push(compId);
|
|
|
+ currCard.children.default = childIds;
|
|
|
+
|
|
|
+ const addedComp = this.store.compMap[compId];
|
|
|
+ addedComp.layout.position = "absolute";
|
|
|
+ this.store.setCompPid(compId, currCard.id);
|
|
|
+
|
|
|
+ this.actions.pickComp(compId);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ await this.actions.addCompToDesign(compKey as any);
|
|
|
}
|
|
|
- this.controls.cropCtrl.close();
|
|
|
+
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ const cardPoints = this.helper.getPointOffsetWith(
|
|
|
+ event,
|
|
|
+ currCardDom
|
|
|
+ );
|
|
|
+ const { currComp } = this.store;
|
|
|
+ let selCtrl = this.controls.selectCtrl;
|
|
|
+ selCtrl.translate(
|
|
|
+ this.helper.designSizeToPx(375 - (currComp.layout.size?.[0] || 750) / 2),
|
|
|
+ cardPoints.y
|
|
|
+ );
|
|
|
+
|
|
|
+ this.helper.extendStreamCard(this.store.currStreamCardId);
|
|
|
+
|
|
|
+ if (compKey == "Text") {
|
|
|
+ this.actions.selectObjs([]);
|
|
|
+ this.actions.textFocus(currComp.id, true);
|
|
|
+ }
|
|
|
+ this.controls.cropCtrl.close();
|
|
|
+
|
|
|
+ }, 100);
|
|
|
},
|
|
|
|
|
|
async selectObjs(ids: string[]) {
|
|
@@ -268,6 +310,62 @@ export const editActions = EditorModule.action({
|
|
|
parentComp && this.store.setCurrComp(parentComp.id);
|
|
|
},
|
|
|
|
|
|
+ ctrlc() {
|
|
|
+ // console.log("contrc ", this.store.selected);
|
|
|
+ ctrlcselected = this.store.selected.slice(0);
|
|
|
+ },
|
|
|
+
|
|
|
+ ctrlv() {
|
|
|
+ console.log("ctrlv ", this.store.selected);
|
|
|
+ if (ctrlcselected.length < 1) return;
|
|
|
+
|
|
|
+ const news :string[] = [];
|
|
|
+
|
|
|
+ const deepCopy = (c:DesignComp) => {
|
|
|
+ const childs = c.children.default || [];
|
|
|
+ if (childs.length > 0 ) {
|
|
|
+ childs.forEach((id, index)=>{
|
|
|
+ const cp = this.helper.findComp(id) as DesignComp;
|
|
|
+ const cp1 = cloneDeep(cp);
|
|
|
+ cp1.id = nanoid();
|
|
|
+ this.store.compMap[cp1.id] = cp1;
|
|
|
+ this.store.setCompPid(cp1.id, c.id);
|
|
|
+ childs[index] = cp1.id;
|
|
|
+
|
|
|
+ deepCopy(cp);
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ctrlcselected.forEach(c=>{
|
|
|
+ const cp = this.helper.findComp(c) as DesignComp;
|
|
|
+ const cp1 = cloneDeep(cp);
|
|
|
+ cp1.id = nanoid();
|
|
|
+ news.push(cp1.id);
|
|
|
+
|
|
|
+ this.store.compMap[cp1.id] = cp1;
|
|
|
+ this.store.setCompPid(cp1.id, this.store.currStreamCardId);
|
|
|
+
|
|
|
+ deepCopy(cp);
|
|
|
+ })
|
|
|
+
|
|
|
+ this.actions.addComps(news);
|
|
|
+
|
|
|
+ this.actions.selectObjs(news);
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ this.controls.selectCtrl.translate(20, 20);
|
|
|
+ }, 100);
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ addComps(ids:string[]) {
|
|
|
+ const childs = this.store.currStreamCard.children.default?.slice(0) || [];
|
|
|
+ childs.push(...ids);
|
|
|
+ this.store.currStreamCard.children.default = childs;
|
|
|
+ },
|
|
|
+
|
|
|
// 删除组件
|
|
|
removeSelectComps() {
|
|
|
const selected = this.store.selected.slice(0);
|
|
@@ -280,12 +378,16 @@ export const editActions = EditorModule.action({
|
|
|
|
|
|
// 删除组件
|
|
|
removeComp(compId: string) {
|
|
|
+
|
|
|
+ const paths = this.helper.getCompTrees(compId);
|
|
|
+ if (!paths[2]) return;
|
|
|
+ compId = paths[2].id;
|
|
|
+
|
|
|
if (this.helper.isCompCanDelete(compId)) {
|
|
|
if (this.helper.isStreamCard(compId)) {
|
|
|
this.actions.removeStreamCard(compId);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
const cardid = this.store.currStreamCardId;
|
|
|
if (compId === this.store.currCompId) {
|
|
|
this.store.setCurrComp(this.store.currStreamCardId);
|
|
@@ -369,6 +471,13 @@ export const editActions = EditorModule.action({
|
|
|
this.helper.clearUnusedComps(data.compMap, comp.id);
|
|
|
data.compMap.root = data.compMap[comp.id];
|
|
|
data.compMap.root.id = "root";
|
|
|
+
|
|
|
+ //清除平移距离
|
|
|
+ const mtx = Matrix.createFromMatrixStr(data.compMap.root.layout.transformMatrix as string);
|
|
|
+ mtx.tx = 0;
|
|
|
+ mtx.ty = 0;
|
|
|
+ data.compMap.root.layout.transformMatrix = mtx.getMatrixStr();
|
|
|
+
|
|
|
delete data.compMap[comp.id];
|
|
|
|
|
|
queenApi.showLoading("保存中");
|
|
@@ -514,8 +623,60 @@ export const editActions = EditorModule.action({
|
|
|
},
|
|
|
// 取消打组
|
|
|
cancelGroupComps(groupComp: DesignComp) {
|
|
|
- this.controls.transferCtrl.groupCtrl.cancelGroup(groupComp);
|
|
|
- this.store.setCurrComp(groupComp.children.default?.[0] as string);
|
|
|
+ console.log("cancel group");
|
|
|
+
|
|
|
+ const childs = groupComp.children.default || [];
|
|
|
+ const objC = this.controls.selectCtrl.objContainer as ObjsContainer;
|
|
|
+ const parentMtrx = objC.parent.worldTransform.clone();
|
|
|
+ childs.forEach(o=>{
|
|
|
+ const obj = this.helper.findComp(o) as DesignComp;
|
|
|
+ const mxt = Matrix.createFromMatrixStr(obj.layout.transformMatrix as string);
|
|
|
+ mxt.prepend(parentMtrx);
|
|
|
+ obj.layout.transformMatrix = mxt.getMatrixStr();
|
|
|
+ })
|
|
|
+ const paths = this.helper.getCompTrees(groupComp.id)
|
|
|
+ const card = paths[1];
|
|
|
+ const parentChilds = (card.children.default || []).filter(item=>item != groupComp.id);
|
|
|
+ parentChilds.push(...childs);
|
|
|
+ card.children.default = childs;
|
|
|
+
|
|
|
+ this.actions.selectObjs([childs[0]]);
|
|
|
+ },
|
|
|
+
|
|
|
+ createGroupComps() {
|
|
|
+ const selectCtrl = this.controls.selectCtrl;
|
|
|
+ const Objc = this.controls.selectCtrl.objContainer as ObjsContainer;
|
|
|
+ const id = this.controls.compUICtrl.createCompId("Group");
|
|
|
+ const comp = this.helper.findComp(id) as DesignComp;
|
|
|
+ comp.layout.position = "absolute";
|
|
|
+
|
|
|
+ //先删除现有的节点
|
|
|
+ const sels = this.store.selected.slice(0);
|
|
|
+ const chils = this.store.currStreamCard.children.default || [];
|
|
|
+ const newChilds :any = [];
|
|
|
+ chils.forEach(c=>{
|
|
|
+ if (sels.indexOf(c) == -1) newChilds.push(c);
|
|
|
+ })
|
|
|
+
|
|
|
+ newChilds.push(id);
|
|
|
+ this.store.currStreamCard.children.default = newChilds;
|
|
|
+
|
|
|
+ //更新节点的新位置
|
|
|
+ Objc.parent.children.forEach(obj=>{
|
|
|
+ const cobj = obj as CompObject;
|
|
|
+ const comp = cobj.comp;
|
|
|
+ comp.layout.transformMatrix = cobj.localTransform.getMatrixStr();
|
|
|
+ })
|
|
|
+
|
|
|
+ //再添加新的节点
|
|
|
+ comp.layout.size = [this.helper.pxToDesignSize(Objc.width), this.helper.pxToDesignSize(Objc.height)];
|
|
|
+ comp.layout.transformMatrix = selectCtrl.transferStyle.matrix;
|
|
|
+ comp.children.default = sels;
|
|
|
+
|
|
|
+ this.actions.selectObjs([])
|
|
|
+ setTimeout(() => {
|
|
|
+ this.actions.pickComp(comp.id);
|
|
|
+ }, 0);
|
|
|
},
|
|
|
|
|
|
handleSelectMoving(key: string) {
|