Przeglądaj źródła

equip<fix>:新增设备类

YaolongHan 4 lat temu
rodzic
commit
f480c96572

+ 2 - 1
persagy-web-big/package.json

@@ -44,6 +44,7 @@
         "@persagy-web/graph": "2.2.26",
         "axios": "^0.18.0",
         "pako": "^1.0.10",
+        "crypto-js": "^4.0.0",
         "polybooljs": "^1.2.0"
     }
-}
+}

+ 88 - 5
persagy-web-big/src/items/SEquipItem.ts

@@ -17,18 +17,101 @@
  *          i888888N'      I888Y          ]88;/EX*IFKFK88X  K8R  .l8W  88Y  ~88}'88E&%8W.X8N``]88!.$8K  .:W8I
  *        .i888888N;        I8Y          .&8$  .X88!  i881.:%888>I88  ;88]  +88+.';;;;:.Y88X  18N.,88l  .+88/
  *      .:R888888I
- *      .&888888I                                          Copyright (c) 2009-2020.  博锐尚格科技股份有限公司
+ *      .&888888I                                          Copyright (c) 2016-2020.  博锐尚格科技股份有限公司
  *        ~8888'
  *        .!88~                                                                     All rights reserved.
  *
  * *********************************************************************************************************************
  */
 
-import { SIconTextItem } from "./SIconTextItem";
+import { SGraphItem, SAnchorItem } from "@persagy-web/graph/lib";
+import { SIconTextItem } from "@persagy-web/big";
+import { STextItem, } from "@persagy-web/graph"
+import { SColor } from '@persagy-web/draw/lib';
+import { svgTobase64 } from "./../until/svgTobase64"
 
 /**
- * 设备 item
+ * 编辑基础设备类
  *
- * @author 郝建龙 <haojianlong@sagacloud.cn>
+ * @author 韩耀龙 <han_yao_long@163.com>
  */
-export class SEquipItem extends SIconTextItem {}
+export class SEquipItem extends SIconTextItem {
+    /** 图例节点 id */
+    nodeId: string | null = null;
+
+    /** 信息点存储 */
+    _infoPointList: any[] = []
+    set infoPointList(val) {
+        this._infoPointList = val;
+    } // set infoPointList()
+    get infoPointList(): any[] {
+        return this._infoPointList
+    } // get infoPointList()
+
+    /** 图得url */
+    _url: string = '';
+    set url(val) {
+        this._url = val;
+        this.initUrl()
+    } // set url()
+    get url(): string {
+        return this._url
+    } // get url()
+
+    //  设备附加数据
+    anotherMsg: string = ''
+
+    /**
+     * 构造函数
+     *
+     * @param parent    指向父对象
+     * @param data      数据
+     */
+    constructor(parent: SGraphItem | null) {
+        super(parent);
+        this.showSelect = false
+    } // Constructor
+
+    /**
+     * 初始化 url;
+     *
+     */
+    initUrl() {
+        svgTobase64(this.url).then((res) => {
+            this.img.url = res ? res : '';
+        }).catch((res) => {
+            this.img.url = res;
+        })
+    }
+
+    /**
+     * 根据选中状态增加 textItem
+     *
+     * @params obj	textItem 文本信息
+     * @params index 文本索引
+     */
+    setTextItem(val: any, index: number): void {
+        if (val.checked) {
+            let item = new STextItem(this);
+            item.data = val;
+            item.text = val.name;
+            if (val.pos) {
+                item.moveTo(val.pos.x, val.pos.x)
+            } else {
+                item.moveTo(
+                    this.img.width * 0.5,
+                    -(this.font.size * 1.25 * 0.5) + (index) * 10
+                );
+            }
+
+            item.font.size = val.font ? val.font : 12;
+            item.isTransform = false;
+            item.showSelect = false;
+            item.color = val.color ? new SColor(val.color) : new SColor('#000000');
+            this.textItemList.push(item)
+        } else {
+            this.textItemList.splice(index, 1)
+            this.scene ? this.scene.removeItem(this.textItemList[index]) : '';
+        }
+    }
+}

+ 30 - 0
persagy-web-big/src/utils/svgTobase64.ts

@@ -0,0 +1,30 @@
+import axios from "axios";
+import crypto from "crypto-js";
+/**
+ * svg流转换为base64字符串
+ *
+ * @param url 获取base的路径
+ */
+export function svgTobase64(url: string) {
+    let baseUrl: string = ''
+    return new Promise((relve, res) => {
+        if (url.includes(".svg")) {
+            axios.get(url).then((res) => {
+                if (res.data) {
+                    const index = res.data.indexOf('"UTF-8"?>');
+                    const str = res.data.substr(index + 9);
+                    const a = crypto.enc.Utf8.parse(str);
+                    baseUrl =
+                        "data:image/svg+xml;base64," + crypto.enc.Base64.stringify(a);
+                }
+                relve(baseUrl)
+            }).catch((err) => {
+                res(err)
+            });
+        } else {
+            baseUrl = url;
+            relve(baseUrl)
+        }
+    })
+
+}