Преглед на файлове

'update_2020.12.17_18.08'

zhangyu преди 4 години
родител
ревизия
75126dd643
променени са 3 файла, в които са добавени 91 реда и са изтрити 97 реда
  1. 85 91
      src/components/editview/basePlanEditer.vue
  2. 1 1
      src/components/editview/rightPropertyBar/BaseEquipment.vue
  3. 5 5
      src/lib/SPlanScene.ts

+ 85 - 91
src/components/editview/basePlanEditer.vue

@@ -27,23 +27,6 @@ import { equipQuery } from "@/api/equipcomponent";
 import { imgBaseUrl, imgServeUpload } from "@/api/imageservice";
 export default {
     components: { topoTooltip },
-    props: {
-        // 1.底图颜色
-        baseMapStyle: {
-            type: Object,
-            default: () => {
-                return {
-                    default: {
-                        strokeColor: "#F0F3F7",
-                        fillColor: "#F0F3F7",
-                        lineWidth: 1,
-                        effect: {},
-                    },
-                };
-            },
-            required: false,
-        }
-    },
     data() {
         return {
             scene: null, //场景
@@ -54,6 +37,17 @@ export default {
             showTooltip: false, //是否显示tooltip
             planContent: {}, // 读图后存储图所有数据
             autoSave: null, // 自动保存定时器
+            ruleNum: 0, //规则数量
+            loadedRuleNum: 0, //已加载规则数量
+            baseMapStyle: {
+                // 底图样式
+                default: {
+                    strokeColor: "#F0F3F7",
+                    fillColor: "#F0F3F7",
+                    lineWidth: 1,
+                    effect: {},
+                },
+            },
         };
     },
     computed: {
@@ -342,27 +336,10 @@ export default {
         },
         // 读图成功回调
         getDataSuc(res) {
-            // let anchorList = []; //保存锚点对象
             if (res.result == "failure") return;
             this.SETCATEGROY(res.content);
             this.planContent = res.content;
-            const parse = new SPlanParser();
-            parse.parseData(res.content.elements);
-            parse.markers.forEach((item) => {
-                item.selectable = true;
-                item.moveable = true;
-                item.connect("finishCreated", this.scene, this.scene.finishCreated);
-                item.connect("onContextMenu", this, this.scene.getItem);
-                // 判断如果是图,需要拼接路径
-                if (item.data.properties.type == "BaseImage") {
-                    if (item.data.style?.default?.url) {
-                        item.url = imgBaseUrl + item.data.style.default.url;
-                    }
-                }
-                this.scene.addItem(item);
-            });
-
-            // 保存设备位置信息
+            // 初始化对象实例信息
             if (res.content.elements.objExtInfo?.length) {
                 const objExtInfo = {};
                 if (res.content.elements.objExtInfo?.length) {
@@ -373,7 +350,7 @@ export default {
                 this.INITOBJEXTINFO(objExtInfo);
             }
 
-            // 保存样式信息
+            // 初始化样式信息
             if (res.content.style) {
                 // 拼接设备默认样式
                 this.INITSTYLE(res.content.style);
@@ -382,55 +359,11 @@ export default {
                 this.INITSTYLE(style);
             }
 
-            // parse.nodes.forEach((item) => {
-            //     item.connect("finishCreated", this.scene, this.scene.finishCreated);
-            //     item.connect("onContextMenu", this, this.scene.getItem);
-            //     this.scene.addItem(item);
-            //     // 如果为设备则存于vuex中便于联动
-            //     if (item instanceof SBaseEquipment) {
-            //         anchorList = anchorList.concat(item.anchorList);
-            //         this.ADDEQUIPITEM(item);
-            //     }
-            // });
-
-            // 管线元素最后添加
-            // parse.relations.forEach((t) => {
-            //     // 设置锚点
-            //     if (t.anchor1Id) {
-            //         let startAnc = null;
-            //         anchorList.forEach((aItem) => {
-            //             if (aItem.id == t.anchor1Id) {
-            //                 startAnc = aItem;
-            //             }
-            //         });
-
-            //         if (startAnc) {
-            //             startAnc.isConnected = true;
-            //             startAnc.parent?.connect("changePos", t, t.changePos);
-            //             t.startAnchor = startAnc || null;
-            //             console.log("startAnc", startAnc);
-            //         }
-            //     }
-            //     if (t.anchor12d) {
-            //         let endAnc = null;
-            //         anchorList.forEach((aItem) => {
-            //             if (aItem.id == t.anchor12d) {
-            //                 endAnc = aItem;
-            //             }
-            //         });
-            //         if (endAnc) {
-            //             endAnc.isConnected = true;
-            //             endAnc.parent?.connect("changePos", t, t.changePos);
-            //             t.endAnchor = endAnc || null;
-            //         }
-            //     }
-            //     t.connect("finishCreated", this.scene, this.scene.finishCreated);
-            //     t.connect("onContextMenu", this, this.scene.getItem);
-            //     this.scene.addItem(t);
-            // });
-
+            // 加载规则,显示实例数据
             if (res.content.ruleList?.length) {
+                this.ruleNum = res.content.ruleList.length;
                 res.content.ruleList.forEach(async (rule) => {
+                    this.loadedRuleNum++;
                     if (rule.commond && rule.commond === "query") {
                         if (rule.returnType && rule.returnType === "equip") {
                             const params = { ...rule.params, buildingId: this.buildingId, floorId: this.floorId };
@@ -439,10 +372,12 @@ export default {
                         } else if (rule.returnType && rule.returnType === "zone") {
                             setTimeout(() => {
                                 console.error("请求空间数据");
+                                if (this.ruleNum === this.loadedRuleNum) this.loadMarkRelation();
                             }, 1000);
                         } else if (rule.returnType && rule.returnType === "equipGroup") {
                             setTimeout(() => {
                                 console.error("请求设备组数据");
+                                if (this.ruleNum === this.loadedRuleNum) this.loadMarkRelation();
                             }, 1000);
                         }
                     } else if (rule.commond && rule.commond === "delete") {
@@ -450,6 +385,7 @@ export default {
                          * 暂未实现
                          */
                         console.error("删除命令!!!", rule);
+                        if (this.ruleNum === this.loadedRuleNum) this.loadMarkRelation();
                     }
                 });
             }
@@ -473,7 +409,7 @@ export default {
                         }
                     }
                     // 添加设备对象类型
-                    equip.properties = {type: "BaseEquipment"}
+                    equip.properties = { type: "BaseEquipment" };
                     const equipItem = new SPlanEquipment(null, equip);
                     equipItem.selectable = true;
                     equipItem.moveable = true;
@@ -482,7 +418,6 @@ export default {
                     if (this.styleMap[equip.id]) {
                         SPlanDecorator.equipDecorator(equipItem, this.styleMap[equip.id]);
                     } else if (this.styleMap[equip.classCode]) {
-                        console.log(this.styleMap[equip.classCode])
                         SPlanDecorator.equipDecorator(equipItem, this.styleMap[equip.classCode]);
                     } else {
                         SPlanDecorator.equipDecorator(equipItem, this.styleMap["defaultEquipStyle"]);
@@ -491,16 +426,75 @@ export default {
                     this.ADDEQUIP(equipItem);
                 }
             });
+            if (this.ruleNum === this.loadedRuleNum) this.loadMarkRelation();
+        },
+        // 加载通用元素和管线元素
+        loadMarkRelation() {
+            const anchorList = []; //保存锚点对象
+            const parse = new SPlanParser();
+            parse.parseData(this.planContent.elements);
+            parse.markers.forEach((item) => {
+                item.selectable = true;
+                item.moveable = true;
+                item.connect("finishCreated", this.scene, this.scene.finishCreated);
+                item.connect("onContextMenu", this, this.scene.getItem);
+                // 判断如果是图,需要拼接路径
+                if (item.data.properties.type == "BaseImage") {
+                    if (item.data.style?.default?.url) {
+                        item.url = imgBaseUrl + item.data.style.default.url;
+                    }
+                }
+                this.scene.addItem(item);
+            });
+            // 管线元素最后添加
+            parse.relations.forEach((t) => {
+                // 设置锚点
+                if (t.anchor1Id) {
+                    let startAnc = null;
+                    anchorList.forEach((aItem) => {
+                        if (aItem.id == t.anchor1Id) {
+                            startAnc = aItem;
+                        }
+                    });
+
+                    if (startAnc) {
+                        startAnc.isConnected = true;
+                        startAnc.parent?.connect("changePos", t, t.changePos);
+                        t.startAnchor = startAnc || null;
+                        console.log("startAnc", startAnc);
+                    }
+                }
+                if (t.anchor12d) {
+                    let endAnc = null;
+                    anchorList.forEach((aItem) => {
+                        if (aItem.id == t.anchor12d) {
+                            endAnc = aItem;
+                        }
+                    });
+                    if (endAnc) {
+                        endAnc.isConnected = true;
+                        endAnc.parent?.connect("changePos", t, t.changePos);
+                        t.endAnchor = endAnc || null;
+                    }
+                }
+                t.connect("finishCreated", this.scene, this.scene.finishCreated);
+                t.connect("onContextMenu", this, this.scene.getItem);
+                this.scene.addItem(t);
+            });
         },
 
         // 生成快照并保存草稿
         saveTopoDraft() {
-            const uuid = uuidv1();
-            return Promise.all([this.generateSnap(uuid), this.saveDraft(uuid)]).then((vals) => {
-                // 重设版本号
-                this.SETVERSION(vals[1].version);
-                this.$message.success(`保存成功${vals[1].version}`);
-            });
+            console.time(1);
+            const elements = this.scene.save();
+            console.timeEnd(1);
+            console.log(elements)
+            // const uuid = uuidv1();
+            // return Promise.all([this.generateSnap(uuid), this.saveDraft(uuid)]).then((vals) => {
+            //     // 重设版本号
+            //     this.SETVERSION(vals[1].version);
+            //     this.$message.success(`保存成功${vals[1].version}`);
+            // });
         },
         // 生成快照
         generateSnap(uuid) {

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

@@ -83,7 +83,7 @@
                 </div>
                 <div class="box-padding">
                     <p class="box-title">附加数据</p>
-                    <el-input type="textarea" v-model="EquipItem.anotherMsg" @change="setStyle" :rows="3" placeholder="请填写附加数据"> </el-input>
+                    <el-input type="textarea" v-model="EquipItem.anotherMsg" :rows="3" placeholder="请填写附加数据"> </el-input>
                 </div>
             </el-tab-pane>
         </el-tabs>

+ 5 - 5
src/lib/SPlanScene.ts

@@ -304,10 +304,10 @@ export class SPlanScene extends SBaseEditScene {
             "BaseRect",
             "BaseArrowPolygon",
         ];
-        const NodeType: string[] = ["BaseEquipment"];
+        const ObjExtInfoType: string[] = ["BaseEquipment"];
         const RelationType: string[] = ["BasePipe"];
         const markers: any = []; /**图例节点 */ // 与工程信息无关的标识对象(增加文本注释,图上的图片说明)
-        const nodes: any = []; /**图例节点 */ // 与工程信息无关的标识对象(增加文本注释,图上的图片说明)
+        const objExtInfo: any = []; /**图例节点 */ // 与工程信息无关的标识对象(增加文本注释,图上的图片说明)
         const relations: any = []; /**图例节点 */ // 与工程信息无关的标识对象(增加文本注释,图上的图片说明)
         let nodeList;
         if (isAll) {
@@ -323,8 +323,8 @@ export class SPlanScene extends SBaseEditScene {
                     markers.push(item.toData());
                 }
 
-                if (item.legendData && NodeType.includes(item.legendData.properties.type)) {
-                    nodes.push(item.toData());
+                if (item.legendData && ObjExtInfoType.includes(item.legendData.properties.type)) {
+                    objExtInfo.push(item.toData());
                 }
 
                 if (item.relationData && RelationType.includes(item.relationData.properties.type)) {
@@ -335,7 +335,7 @@ export class SPlanScene extends SBaseEditScene {
 
         return {
             markers,
-            nodes,
+            objExtInfo,
             relations,
         };
     }