|
@@ -1,3 +1,4 @@
|
|
|
+import { nanoid } from "nanoid";
|
|
|
import { EditorModule } from "..";
|
|
|
import { CompObject } from "../../controllers/SelectCtrl/compObj";
|
|
|
import { Matrix } from "../../controllers/SelectCtrl/matrix";
|
|
@@ -16,7 +17,7 @@ export const helpers = EditorModule.helper({
|
|
|
designSizeToPx(value: number) {
|
|
|
return value / 2.0;
|
|
|
},
|
|
|
-
|
|
|
+
|
|
|
findComp(compId: string) {
|
|
|
const { compMap } = this.store.designData;
|
|
|
const comp = compMap[compId];
|
|
@@ -39,16 +40,16 @@ export const helpers = EditorModule.helper({
|
|
|
}
|
|
|
return false;
|
|
|
},
|
|
|
- isStreamCardChild(compId:string) {
|
|
|
- if (compId == "root" || this.helper.isStreamCard(compId) ) {
|
|
|
+ isStreamCardChild(compId: string) {
|
|
|
+ if (compId == "root" || this.helper.isStreamCard(compId)) {
|
|
|
return false;
|
|
|
}
|
|
|
- const cards = this.store.streamCardIds
|
|
|
+ const cards = this.store.streamCardIds;
|
|
|
let n = cards.length;
|
|
|
const compMap = this.store.designData.compMap;
|
|
|
- while(n--) {
|
|
|
- const childs = compMap[cards[n]].children.default || [];
|
|
|
- if (childs.indexOf(compId) > -1 ) return true;
|
|
|
+ while (n--) {
|
|
|
+ const childs = compMap[cards[n]].children.default || [];
|
|
|
+ if (childs.indexOf(compId) > -1) return true;
|
|
|
}
|
|
|
return false;
|
|
|
},
|
|
@@ -61,26 +62,26 @@ export const helpers = EditorModule.helper({
|
|
|
return this.store.designData.compMap["root"];
|
|
|
},
|
|
|
|
|
|
- getCompCard(compId:string) {
|
|
|
- const paths:DesignComp[] = this.helper.getCompTrees(compId);
|
|
|
- return paths[1]
|
|
|
+ getCompCard(compId: string) {
|
|
|
+ const paths: DesignComp[] = this.helper.getCompTrees(compId);
|
|
|
+ return paths[1];
|
|
|
},
|
|
|
|
|
|
- getCompWorlParentPos(compId:string, vx:number ,vy: number) {
|
|
|
- const paths:DesignComp[] = this.helper.getCompTrees(compId);
|
|
|
+ getCompWorlParentPos(compId: string, vx: number, vy: number) {
|
|
|
+ const paths: DesignComp[] = this.helper.getCompTrees(compId);
|
|
|
const m = new Matrix();
|
|
|
let n = paths.length;
|
|
|
let box = paths[1].$el.getBoundingClientRect();
|
|
|
- m.translate(box.left-vx, box.top-vy);
|
|
|
- for( let i=2; i<(n-1); i++) {//card开始遍历
|
|
|
+ m.translate(box.left - vx, box.top - vy);
|
|
|
+ for (let i = 2; i < n - 1; i++) {
|
|
|
+ //card开始遍历
|
|
|
const m1 = new Matrix();
|
|
|
- m1.setMatrixStr(paths[i].layout.transformMatrix || "matrix(1,0,0,1,0,0)")
|
|
|
+ m1.setMatrixStr(paths[i].layout.transformMatrix || "matrix(1,0,0,1,0,0)");
|
|
|
m.append(m1);
|
|
|
}
|
|
|
return m;
|
|
|
},
|
|
|
|
|
|
-
|
|
|
getCompTrees(compId: string) {
|
|
|
const comps: DesignComp[] = [];
|
|
|
const getParentComp = (compId: string) => {
|
|
@@ -93,7 +94,7 @@ export const helpers = EditorModule.helper({
|
|
|
getParentComp(compId);
|
|
|
return comps;
|
|
|
},
|
|
|
- createStyle(layout: Partial<Layout> & {size:any[]}) {
|
|
|
+ createStyle(layout: Partial<Layout> & { size: any[] }) {
|
|
|
return createCompStyle(this, layout);
|
|
|
},
|
|
|
isCurrComp(compId: string) {
|
|
@@ -148,8 +149,8 @@ export const helpers = EditorModule.helper({
|
|
|
};
|
|
|
},
|
|
|
|
|
|
- getCardCompBound(compId :string) {
|
|
|
- const compMap = this.store.designData.compMap
|
|
|
+ getCardCompBound(compId: string) {
|
|
|
+ const compMap = this.store.designData.compMap;
|
|
|
const c = compMap[compId];
|
|
|
const obj = new CompObject(c);
|
|
|
const bound = obj.getBox();
|
|
@@ -172,9 +173,24 @@ export const helpers = EditorModule.helper({
|
|
|
}
|
|
|
maxH = this.helper.pxToDesignSize(maxH);
|
|
|
|
|
|
- if (childs.length < 1 ) {
|
|
|
- maxH = 200
|
|
|
+ if (childs.length < 1) {
|
|
|
+ maxH = 200;
|
|
|
}
|
|
|
card.setH(maxH);
|
|
|
},
|
|
|
+
|
|
|
+ getClientId() {
|
|
|
+ let clientId = undefined;
|
|
|
+ try {
|
|
|
+ const userInfo = JSON.parse(localStorage.getItem("userInfo") || "{}");
|
|
|
+ clientId = userInfo._id || localStorage.getItem("clientId");
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error);
|
|
|
+ }
|
|
|
+ if (!clientId) {
|
|
|
+ clientId = nanoid();
|
|
|
+ localStorage.setItem("clientId", clientId);
|
|
|
+ }
|
|
|
+ return clientId;
|
|
|
+ },
|
|
|
});
|