Bläddra i källkod

修改业务空间平面图重复加载问题

haojianlong 5 år sedan
förälder
incheckning
e5e8c880e3
1 ändrade filer med 99 tillägg och 70 borttagningar
  1. 99 70
      src/components/business_space/newGraphy/graphy.vue

+ 99 - 70
src/components/business_space/newGraphy/graphy.vue

@@ -105,7 +105,7 @@ export default {
       type: 1, // 默认操作模式
       search: '',//搜索
       num: 0, // 未关联空间的业务空间条数
-      buildFloor: [],
+      buildFloor: ['', ''],
       FloorObj: {}, //楼层对象
       FloorMap: '', //楼层底图
       tab: {},
@@ -123,6 +123,7 @@ export default {
       BIMIDToSID: {}, //bimid映射元空间id
       curZoneItem: {}, //当前选中的业务空间item
       allUnRelatISP: [], //
+      zoneList: [], // 业务空间-canvas图中
     }
   },
   computed: {
@@ -136,10 +137,21 @@ export default {
   },
   methods: {
     // 初始化
-    init() {
+    init(initType) {
       this.type = 1;
-      // 获取当前分区下的业务空间
-      this.getBusinessSpace();
+      if (this.scene) {
+        this.scene.isZoneSelectable = true;
+        this.scene.isSpaceSelectable = true;
+        this.scene.clearSpaceSelection();
+        this.scene.clearZoneSelection();
+      }
+      if (initType == 1) {
+        // 底图
+        this.getGraphy();
+      } else {
+        // 业务空间
+        this.getBusinessSpace();
+      }
       // 获取未关联平面图的业务空间统计
       this.getUnrelateCount();
       // 获取当前楼层的元空间
@@ -165,8 +177,8 @@ export default {
     },
     // 搜索
     querySearch(queryString, cb) {
-      var restaurants = this.zoneList;
-      var results = queryString ?
+      let restaurants = this.zoneList;
+      let results = queryString ?
         restaurants.filter(this.createFilter(queryString)) :
         restaurants;
       // 调用 callback 返回建议列表的数据
@@ -190,12 +202,16 @@ export default {
     },
     // 父组件调用
     getData(buildFloor, FloorObj, tab) {
+      let initType = 1;
+      if (FloorObj.FloorID == this.FloorObj.FloorID) {
+        initType = 2;
+      }
       this.buildFloor = buildFloor;
       this.FloorObj = FloorObj;
       this.FloorMap = FloorObj.StructureInfo ? FloorObj.StructureInfo.FloorMap : ''
       this.tab = tab;
       console.log(arguments)
-      this.init();
+      this.init(initType);
     },
     // 获取未关联平面图的业务空间统计
     getUnrelateCount() {
@@ -237,18 +253,6 @@ export default {
           return;
         }
         that.view.scene = that.scene;
-        // 绘制业务空间
-        let tempArr = this.BSPRelaISPList.map((t, i) => {
-          return {
-            RoomLocalName: t.RoomLocalName,
-            OutLine: t.Outline,
-            RoomID: t.RoomID,
-            Color: new SColor(colorArr[i % colorArr.length]),
-          }
-        })
-        that.scene.addZoneList(tempArr);
-        that.scene.click(that, that.canvasClick);
-        that.zoneList = that.scene.zoneList;
         // 蒙版
         if (this.FloorObj.Outline) {
           let newArr = this.FloorObj.Outline.map(t => {
@@ -256,6 +260,8 @@ export default {
           })
           this.scene.addSceneMark(newArr)
         }
+        // 绘制业务空间
+        that.getBusinessSpace();
         that.view.fitSceneToView();
         that.view.maxScale = that.view.scale * 10;
         that.view.minScale = that.view.scale;
@@ -264,20 +270,27 @@ export default {
         }
       })
     },
+    // 清空绘制业务空间
+    clearZoneCanvas() {
+      this.zoneList.map(t => {
+        this.scene.removeItem(t);
+      })
+    },
     // 获取当前分区下的业务空间
     getBusinessSpace() {
-      this.isLoading = true
+      this.canvasLoading = true
       let pa = {
         zone: this.tab.code,
         data: {
           Filters: ``,
           Orders: "createTime desc, RoomID asc",
-          PageSize: 500
+          PageSize: 1000
         }
       }
       if (this.buildFloor.length && this.buildFloor.length > 1) {
         pa.data.Filters = `BuildingId='${this.buildFloor[0]}';FloorId='${this.buildFloor[1]}'`
       }
+      this.clearZoneCanvas();
       queryZone(pa, res => {
         // 所有业务空间
         this.businessSpaceList = res.Content;
@@ -292,9 +305,20 @@ export default {
             this.BSPUnrelaISPList.push(t)
           }
         })
-        // 获取底图
-        this.getGraphy();
-        this.isLoading = false;
+        // 绘制业务空间
+        let tempArr = this.BSPRelaISPList.map((t, i) => {
+          return {
+            RoomLocalName: t.RoomLocalName,
+            OutLine: t.Outline,
+            RoomID: t.RoomID,
+            Color: new SColor(colorArr[i % colorArr.length]),
+          }
+        })
+        this.scene.zoneList = [];
+        this.scene.addZoneList(tempArr);
+        this.scene.click(this, this.canvasClick);
+        this.zoneList = this.scene.zoneList;
+        this.canvasLoading = false;
       })
     },
     // canvas点击事件
@@ -332,8 +356,7 @@ export default {
     },
     // 取消(所有取消公用)
     cancelGraphy() {
-      this.type = 1;
-      this.init();
+      this.init(2);
     },
     // 批量创建业务空间
     groupCreateBSpace() {
@@ -348,53 +371,57 @@ export default {
           FloorId: this.buildFloor[1]
         }
       });
-      this.$confirm(
-        "<p>确定根据未关联业务空间的空间批量创建业务空间</p>" +
-        "<p>涉及的空间:</p>" +
-        "<p style='line-height:20px;max-height:60px;overflow-y:auto;'>" +
-        text.toString() +
-        "</p>",
-        "提示", {
-        dangerouslyUseHTMLString: true,
-        confirmButtonText: "确定",
-        cancelButtonText: "取消",
-        type: "warning"
-      }
-      ).then(() => {
-        let pa = {
-          zone: this.tab.code,
-          data: {
-            Content: Spaces
-          }
+      if(Spaces.length){
+        this.$confirm(
+          "<p>确定根据未关联业务空间的空间批量创建业务空间</p>" +
+          "<p>涉及的空间:</p>" +
+          "<p style='line-height:20px;max-height:60px;overflow-y:auto;'>" +
+          text.toString() +
+          "</p>",
+          "提示", {
+          dangerouslyUseHTMLString: true,
+          confirmButtonText: "确定",
+          cancelButtonText: "取消",
+          type: "warning"
         }
-        this.canvasLoading = true;
-        createZone(pa, res => {
-          res.EntityList.map(t => {
-            Spaces = Spaces.map(item => {
-              if (t.RoomLocalName == item.RoomLocalName) {
-                item.SpaceId = t.RoomID
-              }
-              return item;
-            })
-          })
-          let param = {
+        ).then(() => {
+          let pa = {
+            zone: this.tab.code,
             data: {
               Content: Spaces
-            },
-            type: this.tab.code
+            }
           }
-          groupCreRelaZoneAndISp(param, res => {
-            this.$message.success('创建成功')
-            this.canvasLoading = false;
-            this.init()
+          this.canvasLoading = true;
+          createZone(pa, res => {
+            res.EntityList.map(t => {
+              Spaces = Spaces.map(item => {
+                if (t.RoomLocalName == item.RoomLocalName) {
+                  item.SpaceId = t.RoomID
+                }
+                return item;
+              })
+            })
+            let param = {
+              data: {
+                Content: Spaces
+              },
+              type: this.tab.code
+            }
+            groupCreRelaZoneAndISp(param, res => {
+              this.$message.success('创建成功')
+              this.canvasLoading = false;
+              this.init(2)
+            })
           })
-        })
-      }).catch(() => {
-        this.$message({
-          type: "info",
-          message: "已取消批量创建"
+        }).catch(() => {
+          this.$message({
+            type: "info",
+            message: "已取消批量创建"
+          });
         });
-      });
+      }else{
+        this.$message('没有未关联的元空间')
+      }
     },
     // 创建新的业务空间
     createNewZone() {
@@ -446,7 +473,7 @@ export default {
       }
       updateZone(pa, res => {
         this.$message.success('更新成功');
-        this.init();
+        this.init(2);
       })
     },
     // 编辑空间详情
@@ -460,6 +487,8 @@ export default {
     // 重新划分业务空间
     refactorBSP() {
       this.type = 4;
+      // 清空选中空间
+      this.scene.clearSpaceSelection();
       // 设置空间可选
       this.scene.isSpaceSelectable = true;
       // 将已关联的设置不可选,并将当前选的隐藏
@@ -497,7 +526,7 @@ export default {
       }
       createRelateInZoneAndISp(pa, res => {
         this.$message.success('创建成功');
-        this.init();
+        this.init(2);
       })
     },
     // canvas 获取焦点
@@ -506,7 +535,7 @@ export default {
     },
     // 清除canvas
     clearGraphy() {
-      if (this.view) {
+      if (this.view && this.view.scene) {
         this.view.scene = null;
         return
       }