yx 4 年之前
父节点
当前提交
793f1d6d80

+ 7 - 1
src/components/baseEditer.vue

@@ -145,6 +145,7 @@ export default {
          * @param data json数据
          */
         loadJSON(data) {
+            console.log(JSON.stringify(data,null,2))
             const parserData = new STopologyParser(null);
             parserData.parseData(data.Elements);
             let Markers = data.Elements.Markers;
@@ -152,7 +153,7 @@ export default {
             const itemMap = {};
             // 使用 SEquipmentParser 解析器增加设备
             let parserData1 = new SEquipmentParser(null);
-            let Equipmnet = Nodes.filter(node => node.GraphElementType === "Equipmnet");
+            let Equipmnet = Nodes.filter(node => node.GraphElementType === "Equipment");
             parserData1.parseData(Equipmnet);
             parserData1.equipmentItem.map(item => {
                 item.selectable = true;
@@ -672,6 +673,11 @@ export default {
             bus.$on("changeInfoName", val => {
                 this.scene.updateEquipmentInfoName(val);
             });
+            // 添加信息点
+            bus.$on('addEquipmentInfo',()=>{
+                console.log('baseEditer addEquipmentInfo')
+                 this.scene.addEquipmentInfo();
+            })
             // 改变图例名称
             bus.$on("changeImageNum", val => {
                 this.scene.upadatImageNum(val);

+ 6 - 2
src/components/edit/equipmentAttr.vue

@@ -63,6 +63,7 @@ export default {
         focusItemList: {
             handler(newV, oldV) {
                 if (newV !== oldV) {
+                    console.log('%c===================', 'color:blue', newV)
                     this.init()
                 }
             },
@@ -75,13 +76,16 @@ export default {
     mounted() {},
     methods: {
         addInfo() {
-            this.info.push('')
+            bus.$emit('addEquipmentInfo')
+            console.log(this.focusItemList)
+            this.init()
         },
         init() {
             // 设置设备名称
-            window._focusItem =  this.focusItemList.itemList[0]
+            window._focusItem = this.focusItemList.itemList[0]
             this.equipmentData = this.focusItemList.itemList[0].toData()
             this.equipmentName = this.equipmentData.Name
+            this.equipmentName = this.equipmentData.Name
             this.InfoList = this.equipmentData.InfoList
             this.info = []
             this.InfoList.map((item) => {

+ 5 - 1
src/components/mapClass/EditScence.ts

@@ -693,11 +693,15 @@ export class EditScence extends SGraphScene {
      */
     updateEquipmentInfoName(val: object): void {
         console.log(val)
-        if (this.focusItem){
+        if (this.focusItem) {
             // @ts-ignore
             this.focusItem.info = val
         }
     }
+    addEquipmentInfo(): void {
+        // @ts-ignore
+        this.focusItem.addEquipmentInfo()
+    }
 
     /**
      * 更改item Num数量

+ 24 - 24
src/components/mockData1.js

@@ -34,30 +34,30 @@ let eqipList = [
                 Type: 'equipment',
                 Url: '57781a40684e4f1383a60bb86c681a20',
                 InfoList: [
-                    {
-                        Code: '',
-                        Name: '温度',
-                        X: 30,
-                        Y: 20,
-                        Width: 100,
-                        Height: 25,
-                        FontSize: 12,
-                        Background: '#ffffff',
-                        TextAlign: '',
-                        Color: '#000000',
-                    },
-                    {
-                        Code: '',
-                        Name: '湿度',
-                        X: 40,
-                        Y: 28,
-                        Width: 100,
-                        Height: 25,
-                        FontSize: 12,
-                        Background: '#ffffff',
-                        TextAlign: '',
-                        Color: '#000000',
-                    },
+                    // {
+                    //     Code: '',
+                    //     Name: '温度',
+                    //     X: 30,
+                    //     Y: 20,
+                    //     Width: 100,
+                    //     Height: 25,
+                    //     FontSize: 12,
+                    //     Background: '#ffffff',
+                    //     TextAlign: '',
+                    //     Color: '#000000',
+                    // },
+                    // {
+                    //     Code: '',
+                    //     Name: '湿度',
+                    //     X: 40,
+                    //     Y: 28,
+                    //     Width: 100,
+                    //     Height: 25,
+                    //     FontSize: 12,
+                    //     Background: '#ffffff',
+                    //     TextAlign: '',
+                    //     Color: '#000000',
+                    // },
                 ],
                 Properties: {
                     StatusImage: [

+ 63 - 6
src/lib/items/SEquipmentItem.ts

@@ -3,6 +3,7 @@ import { ItemOrder } from "@saga-web/big/lib";
 import { SColor, SPainter, SRect } from "@saga-web/draw/lib";
 import { SMouseEvent } from "@saga-web/base/lib";
 import { EquipmentData } from "../types/EquipmentData";
+import { uuid } from '@/components/mapClass/until';
 enum StatusType {
     /** 普通态    */
     Normal,
@@ -99,7 +100,7 @@ export class SEquipmentItem extends SObjectItem {
             textItem.pos.y = lastText.Y + 20;
             this.textArr.push(textItem)
         } */
-         if (this.epData && index < this.epData.InfoList.length) {
+        if (this.epData && index < this.epData.InfoList.length) {
             this.textArr[index + 1].text = name
             this.epData.InfoList[index + 1].Name = name
         }
@@ -149,6 +150,7 @@ export class SEquipmentItem extends SObjectItem {
      * @param epData 设备信息
      */
     loadEquipment(epData: EquipmentData): void {
+        console.log('============loadEquipment')
         // 位置
         this.x = epData.Pos.X;
         this.y = epData.Pos.Y;
@@ -170,11 +172,7 @@ export class SEquipmentItem extends SObjectItem {
         this.textArr.push(nameItem);
         // 信息点
         let { InfoList } = epData;
-        console.log('===================')
-        console.log('===================')
-        console.log('===================')
-        console.log(InfoList)
-        console.log('===================')
+
         InfoList.map(({ Name, X, Y, Width, Height, FontSize, Background, Color, TextAlign }) => {
             let textItem = new STextItem(this);
             textItem.backgroundColor = new SColor(Background);
@@ -247,9 +245,68 @@ export class SEquipmentItem extends SObjectItem {
             arr[index].Y = this.textArr[index + 1].pos.y;
             arr[index].Name = this.textArr[index + 1].text;
         });
+        this.epData.GraphElementType = 'Equipment'
+        // @ts-ignore
+        this.epData.Type = 'equipment'
         return this.epData;
     }
+    /**
+     * 添加信息点
+     */
+    addEquipmentInfo() {
+        let { InfoList } = this.epData;
+        let textItem = new STextItem(this);
+        let Name, X, Y, Width, Height, FontSize, Background, Color, TextAlign
+        if (InfoList.length > 1) {
+            let info = InfoList[InfoList.length - 1]
+            Background = info.Background
+            X = info.X
+            Y = info.Y
+            Width = info.Width
+            Height = info.Height
+            FontSize = info.FontSize
+            Background = info.Background
+            Color = info.Color
+            TextAlign = info.TextAlign
+            Name = info.Name
+            // { Name, X, Y, Width, Height, FontSize, Background, Color, TextAlign } = InfoList[InfoList.length - 1]
+        } else {
+            // 默认设置
+            Background = '#ffffff'
+            X = this.img.width + 10
+            Y = this.img.height / 2 - 6
+            Width = 100
+            Height = 25
+            FontSize = 12
+            Background = '#ffffff'
+            Color = '#000000'
+            TextAlign = 'center'
+            Name = '请输入'
+        }
 
+        textItem.backgroundColor = new SColor(Background);
+        textItem.width = Width;
+        textItem.height = Height;
+        textItem.text = '请输入';
+        textItem.font.size = FontSize;
+        textItem.color = new SColor(Color);
+        textItem.pos.x = X;
+        textItem.pos.y = Y + 20;
+        this.textArr.push(textItem);
+        InfoList.push({
+            Code: uuid(),
+            Name: '请输入',
+            X,
+            Y: Y + 20,
+            Width,
+            Height,
+            FontSize,
+            Background,
+            TextAlign,
+            Color,
+        })
+        this.update()
+    }
     /**
      * Item绘制操作
      *