|
@@ -29,6 +29,7 @@ import { Legend } from "./../types/Legend";
|
|
|
import { SBaseIconTextEdit, SBaseTextEdit } from "@persagy-web/edit";
|
|
|
import { SColor } from '@persagy-web/draw/lib';
|
|
|
import { svgTobase64, uuid } from "./../until"
|
|
|
+
|
|
|
/**
|
|
|
* 编辑基础设备类
|
|
|
*
|
|
@@ -37,24 +38,25 @@ import { svgTobase64, uuid } from "./../until"
|
|
|
export class SBaseEquipment extends SBaseIconTextEdit {
|
|
|
/** 图例节点 id */
|
|
|
nodeId: string | null = null;
|
|
|
+
|
|
|
/** 设备图例 */
|
|
|
_legendData: Legend | null = null;
|
|
|
set legendData(val) {
|
|
|
this._legendData = val;
|
|
|
this.initData()
|
|
|
- } // set legendData()
|
|
|
+ }
|
|
|
get legendData(): Legend | null {
|
|
|
return this._legendData
|
|
|
- } // get legendData()
|
|
|
+ }
|
|
|
|
|
|
/** 信息点存储 */
|
|
|
_infoPointList: any[] = []
|
|
|
set infoPointList(val) {
|
|
|
this._infoPointList = val;
|
|
|
- } // set infoPointList()
|
|
|
+ }
|
|
|
get infoPointList(): any[] {
|
|
|
return this._infoPointList
|
|
|
- } // get infoPointList()
|
|
|
+ }
|
|
|
|
|
|
defaultUrl: string = '';
|
|
|
/** 图得url */
|
|
@@ -62,64 +64,78 @@ export class SBaseEquipment extends SBaseIconTextEdit {
|
|
|
set url(val) {
|
|
|
this._url = val;
|
|
|
this.initUrl()
|
|
|
- } // set infoPointList()
|
|
|
+ }
|
|
|
get url(): string {
|
|
|
return this._url
|
|
|
- } // get infoPointList()
|
|
|
+ }
|
|
|
|
|
|
- // 设备附加数据
|
|
|
+ /** 设备附加数据 */
|
|
|
anotherMsg: string = ''
|
|
|
|
|
|
/**
|
|
|
* 构造函数
|
|
|
*
|
|
|
- * @param parent 指向父对象
|
|
|
+ * @param parent 指向父 Item
|
|
|
* @param data 数据
|
|
|
*/
|
|
|
constructor(parent: SGraphItem | null, data: Legend) {
|
|
|
super(parent);
|
|
|
this.legendData = data;
|
|
|
- } // Constructor
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 设置 legendData 时对 item 做设置
|
|
|
*/
|
|
|
initData() {
|
|
|
+ // this.legendData 不能为空
|
|
|
if (!this.legendData) return;
|
|
|
|
|
|
- this.nodeId = this.legendData?.nodeId
|
|
|
+ this.nodeId = this.legendData?.nodeId;
|
|
|
+ // 判断 size 是否存在
|
|
|
if (this.legendData.size) {
|
|
|
this.sWidth = this.legendData.size.width;
|
|
|
this.sHeight = this.legendData.size.height;
|
|
|
}
|
|
|
|
|
|
this.img.connect("onMove", this, this.changeAnchorPoint.bind(this));
|
|
|
+
|
|
|
+ // 判断是否有锚点数据
|
|
|
if (this.legendData.anchorList && this.legendData.anchorList.length) {
|
|
|
+ // 对锚点数据遍历生成对应的锚点
|
|
|
this.anchorList = this.legendData.anchorList.map(t => {
|
|
|
let item = new SAnchorItem(this);
|
|
|
+
|
|
|
+ // 是否存在 anchorId
|
|
|
if (t.anchorId) {
|
|
|
item.id = t.anchorId;
|
|
|
}
|
|
|
+
|
|
|
item.moveTo(t.pos.x, t.pos.y);
|
|
|
return item;
|
|
|
});
|
|
|
+
|
|
|
} else {
|
|
|
const anchorPoint = [
|
|
|
{ x: this.img.x, y: this.img.y, anchorId: uuid() },
|
|
|
];
|
|
|
+
|
|
|
+ // 没锚点则默认中心点为锚点
|
|
|
this.anchorList = anchorPoint.map(t => {
|
|
|
let item = new SAnchorItem(this);
|
|
|
+ // 是否存在 anchorId
|
|
|
if (t.anchorId) {
|
|
|
item.id = t.anchorId;
|
|
|
}
|
|
|
+
|
|
|
item.moveTo(t.x, t.y);
|
|
|
return item;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- // 存储信息点
|
|
|
+ // 该设备是否有信息点
|
|
|
if (this.legendData.properties && this.legendData.properties.infoPointList) {
|
|
|
const infoPointList = this.legendData.properties.infoPointList;
|
|
|
+ // 将信息点数据转换为实例
|
|
|
if (infoPointList.length) {
|
|
|
this.infoPointList = infoPointList;
|
|
|
this.infoPointList.forEach((obj, i) => {
|
|
@@ -128,6 +144,7 @@ export class SBaseEquipment extends SBaseIconTextEdit {
|
|
|
} else {
|
|
|
this.infoPointList = []
|
|
|
}
|
|
|
+
|
|
|
} else {
|
|
|
this.infoPointList = []
|
|
|
}
|
|
@@ -141,7 +158,11 @@ export class SBaseEquipment extends SBaseIconTextEdit {
|
|
|
this.selectable = true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据 url 获取图片
|
|
|
+ */
|
|
|
initUrl() {
|
|
|
+ // 获取图数据转换为 base64
|
|
|
svgTobase64(this.url).then((res) => {
|
|
|
this.img.url = res ? res : '';
|
|
|
}).catch((res) => {
|
|
@@ -161,10 +182,15 @@ export class SBaseEquipment extends SBaseIconTextEdit {
|
|
|
this.setTextItem(val, (this._infoPointList.length - 1))
|
|
|
} else {
|
|
|
let deleteItemIndex: number = -1;
|
|
|
+
|
|
|
+ // 遍历信息点数组删除 checked 为 false 的信息点
|
|
|
this._infoPointList.forEach((item, index) => {
|
|
|
+
|
|
|
+ // 通过 id 对比定位对象
|
|
|
if (val.id == item.id) {
|
|
|
deleteItemIndex = index;
|
|
|
}
|
|
|
+
|
|
|
});
|
|
|
this._infoPointList.splice(deleteItemIndex, 1);
|
|
|
this.setTextItem(val, deleteItemIndex)
|
|
@@ -178,10 +204,13 @@ export class SBaseEquipment extends SBaseIconTextEdit {
|
|
|
* @params index 文本索引
|
|
|
*/
|
|
|
setTextItem(val: any, index: number): void {
|
|
|
+ // 该状态时否选中如果选中生成实例并维护
|
|
|
if (val.checked) {
|
|
|
let item = new SBaseTextEdit(this, null);
|
|
|
item.propertyData = val;
|
|
|
item.text = val.name;
|
|
|
+
|
|
|
+ // 是否存在pos
|
|
|
if (val.pos) {
|
|
|
item.moveTo(val.pos.x, val.pos.y)
|
|
|
} else {
|
|
@@ -204,6 +233,7 @@ export class SBaseEquipment extends SBaseIconTextEdit {
|
|
|
this.textItemList.splice(index, 1)
|
|
|
this.update()
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -212,7 +242,10 @@ export class SBaseEquipment extends SBaseIconTextEdit {
|
|
|
* @return 对象储存的相关数据
|
|
|
*/
|
|
|
toData(): any {
|
|
|
+
|
|
|
+ // this.legendData 必须存在
|
|
|
if (this.legendData) {
|
|
|
+ // 遍历锚点获取需要存储的数据格式
|
|
|
const list = this.anchorList.map((item) => {
|
|
|
return {
|
|
|
anchorId: item.id,
|
|
@@ -222,6 +255,7 @@ export class SBaseEquipment extends SBaseIconTextEdit {
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
this.legendData.anchorList = list;
|
|
|
// 反馈大小
|
|
|
if (this.legendData.size) {
|
|
@@ -239,8 +273,10 @@ export class SBaseEquipment extends SBaseIconTextEdit {
|
|
|
x: this.x,
|
|
|
y: this.y
|
|
|
};
|
|
|
+
|
|
|
// 存储信息点
|
|
|
- const infoPoinList: any[] = []
|
|
|
+ const infoPoinList: any[] = [];
|
|
|
+ // 获取信息点对应参数
|
|
|
this.textItemList.forEach(item => {
|
|
|
let obj = Object.assign(item.propertyData, {
|
|
|
pos: { x: item.x, y: item.y },
|
|
@@ -256,6 +292,8 @@ export class SBaseEquipment extends SBaseIconTextEdit {
|
|
|
this.legendData.properties.infoPointList = infoPoinList;
|
|
|
this.legendData.properties.anotherMsg = this.anotherMsg;
|
|
|
this.legendData.style.default.base64Url = "";
|
|
|
+
|
|
|
+ // 判断 defaultUrl 是否存在
|
|
|
if (this.defaultUrl) {
|
|
|
this.legendData.style.default.url = this.defaultUrl;
|
|
|
}
|