Browse Source

显示设备信息点

zhangyu 4 years ago
parent
commit
dd91bfe8c4

+ 1 - 1
src/components/editview/rightPropertyBar/property.vue

@@ -105,7 +105,7 @@ export default {
             //         this.itemType = "BaseEquipmentMsg";
             //     }
             // }
-            console.log(`this.itemType: ,${this.itemType}`);
+            console.log(`this.itemType: ,${this.itemType}`, this.itemObj);
             // 同步联动样式
             this.linkStyle(itemList);
         },

+ 40 - 6
src/lib/item/SPlanEquipment.ts

@@ -28,6 +28,7 @@ import { SGraphItem, SAnchorItem } from "@persagy-web/graph/lib";
 import { Example } from "../index";
 import { SBaseIconTextEdit, SBaseTextEdit } from "@persagy-web/edit";
 import { svgTobase64, uuid } from "@persagy-web/big-edit/lib/until";
+import { SColor, SFont } from "@persagy-web/draw/lib";
 /**
  * 编辑基础设备类
  *
@@ -60,6 +61,45 @@ export class SPlanEquipment extends SBaseIconTextEdit {
     private _formula: string = "";
     set formula(val) {
         this._formula = val;
+        try {
+            const textList = JSON.parse(this._formula);
+            const font = this.textItemList[0]?.font ? this.textItemList[0]?.font : new SFont("sans-serif", 12);
+            const color = this.textItemList[0]?.color ? this.textItemList[0]?.color : new SColor("#1F2429");
+            if (this.scene) {
+                this.textItemList.forEach((textItem) => {
+                    this.scene.removeItem(textItem);
+                });
+            }
+            if (textList.length) {
+                const textItemList: any[] = [];
+                textList.forEach((item: any, index: number) => {
+                    let obj = new SBaseTextEdit(this, null);
+                    // obj.propertyData = item;
+                    obj.text = item;
+                    // if (item.pos) {
+                    //     obj.moveTo(item.pos.x, item.pos.x)
+                    // } else {
+                    //     obj.moveTo(
+                    //         this.img.width * 0.5,
+                    //         -(this.font.size * 1.25 * 0.5) + (index) * 10
+                    //     );
+                    // }
+                    // TODO: obj.moveTo(this.img.width * 0.5, -(this.font.size * 1.25 * 0.5) + (index * this.font.size) - (textList.length - 1) * 0.5 * this.font.size);
+                    obj.moveTo(this.img.width * 0.5, this.font.size * (index - 0.125 - 0.5 * textList.length));
+                    obj.font = font;
+                    obj.color = color;
+                    obj.isTransform = false;
+                    obj.showSelect = false;
+                    textItemList.push(obj);
+                });
+                this.textItemList = textItemList;
+            } else {
+                this.textItemList = [];
+            }
+            this.update();
+        } catch (error) {
+            console.error("公式数据错误", error);
+        }
     } // set formula()
     get formula(): string {
         return this._formula;
@@ -80,12 +120,6 @@ export class SPlanEquipment extends SBaseIconTextEdit {
         this.isTransform = false;
         this.sWidth = 32;
         this.sHeight = 32;
-        const textItem = new SBaseTextEdit(this, null);
-        textItem.text = "";
-        textItem.font.size = 12;
-        // 偏移二分之一文本高度
-        textItem.moveTo(this.img.width * 0.5, -(this.font.size * 1.25 * 0.5));
-        this.textItemList.push(textItem);
         this.moveable = true;
         this.selectable = true;
         this.legendData = data;