dedsudiyu il y a 14 heures
Parent
commit
957449693d
3 fichiers modifiés avec 128 ajouts et 8 suppressions
  1. 28 2
      src/components/DwgD3/DwgD3.vue
  2. 87 6
      src/components/DwgD3/things/Warehouse.js
  3. 13 0
      src/router/index.js

+ 28 - 2
src/components/DwgD3/DwgD3.vue

@@ -141,6 +141,10 @@ export default {
     ...mapState(storeCore, ["focusedWarehouse"])
   },
   created() {
+    // 项目传参相关修改开始
+    // 可由外层页面在 iframe 地址中通过 parentOrigin 参数指定 postMessage 的目标域名。
+    window.gisParentOrigin = this.$route.query.parentOrigin || "*";
+    // 项目传参修改相关结束
     const id = this.$route.query.id;
     if(!id || !id.trim()) {
       PluginNotification.tip("缺少参数,已跳转到首页");
@@ -150,6 +154,14 @@ export default {
     this.idAreaGlobal = id;
     this.getDataAreaGlobal();
   },
+  // 项目传参相关修改开始
+  beforeDestroy() {
+    // 路由直接离开三维园区时,Warehouse.blur() 不一定会执行,这里补发一次离开通知。
+    const targetFocusedWarehouse = this.qt?.areaGlobal?.warehouses?.find(warehouse => warehouse.isFocused);
+    targetFocusedWarehouse && targetFocusedWarehouse.notifyParentState("GIS_WAREHOUSE_LEAVE", "route");
+    delete window.gisParentOrigin;
+  },
+  // 项目传参修改相关结束
   methods: {
     toHome() {
       this.$router.replace({ name: "home" });
@@ -448,10 +460,24 @@ export default {
       }
       // 动画入场
       await qt.plugin("PluginAnimation").animationInAsync();
-      // 切换默认视角
+      // 项目传参修改之前旧代码开始
+      // // 切换默认视角
+      // await qt.flyToDefaultPerspective(qt.debug);
+      // // 触发准备就绪事件
+      // this.$emit("ready", qt);
+      // 项目传参修改之前旧代码结束
+
+      // 项目传参相关修改开始
+      // 切换默认视角。status=1 时停留在园区,status=2 时在模型解析完成后自动进入第一个库房。
       await qt.flyToDefaultPerspective(qt.debug);
+      const status = String(this.$route.query.status || "");
+      if(status === "2") {
+        const firstWarehouse = qt.areaGlobal.warehouses[0];
+        firstWarehouse && await firstWarehouse.focus(false, "url");
+      }
       // 触发准备就绪事件
       this.$emit("ready", qt);
+      // 项目传参修改相关结束
     },
     createHelper(qt) {
       const { d3Config } = this;
@@ -539,4 +565,4 @@ export default {
     z-index: 9;
   }
 }
-</style>
+</style>

+ 87 - 6
src/components/DwgD3/things/Warehouse.js

@@ -22,6 +22,10 @@ export default class Warehouse extends ThingInner {
     this.isWarehouse = true;
     this.isFocused = false;
     this.shelves = [];
+    // 项目传参相关修改开始
+    // 记录是否已经向外层页面发送过进入事件,避免离开事件重复发送。
+    this.hasNotifiedParentEntered = false;
+    // 项目传参修改相关结束
   }
 
   afterInstantiation() {
@@ -43,9 +47,21 @@ export default class Warehouse extends ThingInner {
         storeCore().focusedWarehouse = null;
       }
     });
-    this.addEventListener(ThingEvents.Dblclick, () => {
-      !this.isFocused ? this.focus() : this.blur();
+    // 项目传参修改之前旧代码开始
+    // this.addEventListener(ThingEvents.Dblclick, () => {
+    //   !this.isFocused ? this.focus() : this.blur();
+    // });
+    // 项目传参修改之前旧代码结束
+
+    // 项目传参相关修改开始
+    this.addEventListener(ThingEvents.Dblclick, async () => {
+      if(!this.isFocused) {
+        await this.focus(false, "user");
+      } else {
+        await this.blur(true, "user");
+      }
     });
+    // 项目传参修改相关结束
   }
 
   createLabel() {
@@ -73,10 +89,31 @@ export default class Warehouse extends ThingInner {
     this.shelves.forEach(shelf => shelf.warehouse = this);
   }
 
-  async focus(immediate = false) {
+  // 项目传参修改之前旧代码开始
+  // async focus(immediate = false) {
+  //   const { qt } = this;
+  //   this.isFocused = true;
+  //   qt.areaGlobal.warehouses.forEach(warehouse => warehouse !== this && warehouse.isFocused && warehouse.blur(false));
+  //   qt.effectOutline.delete(this.o3);
+  //   qt.areaGlobal.hideRoof();
+  //   this.sleep();
+  //   this.shelves.forEach(shelf => shelf.wakeUp());
+  //   storeCore().focusedWarehouse = {
+  //     wgAreaId: this.extData.wgAreaId,
+  //     wgWarehouseName: this.extData.wgWarehouseName
+  //   };
+  //   await this.flyToMe(immediate);
+  // }
+  // 项目传参修改之前旧代码结束
+
+  // 项目传参相关修改开始
+  async focus(immediate = false, trigger = "user") {
+    if(this.isFocused) return;
     const { qt } = this;
     this.isFocused = true;
-    qt.areaGlobal.warehouses.forEach(warehouse => warehouse !== this && warehouse.isFocused && warehouse.blur(false));
+    qt.areaGlobal.warehouses.forEach(warehouse => {
+      warehouse !== this && warehouse.isFocused && warehouse.blur(false, "switch");
+    });
     qt.effectOutline.delete(this.o3);
     qt.areaGlobal.hideRoof();
     this.sleep();
@@ -85,16 +122,36 @@ export default class Warehouse extends ThingInner {
       wgAreaId: this.extData.wgAreaId,
       wgWarehouseName: this.extData.wgWarehouseName
     };
+    this.notifyParentState("GIS_WAREHOUSE_ENTER", trigger);
     await this.flyToMe(immediate);
   }
+  // 项目传参修改相关结束
 
   async flyToMe(immediate = false) {
     return super.flyToMe(new Vector3(0, 20, 2), new Vector3(), immediate);
   }
 
-  async blur(enableFlyToDefaultPerspective = true) {
+  // 项目传参修改之前旧代码开始
+  // async blur(enableFlyToDefaultPerspective = true) {
+  //   const { qt } = this;
+  //   this.isFocused = false;
+  //   this.shelves.forEach(shelf => shelf.sleep());
+  //   this.wakeUp();
+  //   const targetFocusedShelf = this.shelves.find(shelf => shelf.isFocused);
+  //   targetFocusedShelf && targetFocusedShelf.blur(false);
+  //   if(enableFlyToDefaultPerspective) {
+  //     qt.areaGlobal.showRoof();
+  //     await qt.flyToDefaultPerspective();
+  //   }
+  // }
+  // 项目传参修改之前旧代码结束
+
+  // 项目传参相关修改开始
+  async blur(enableFlyToDefaultPerspective = true, trigger = "back") {
+    if(!this.isFocused) return;
     const { qt } = this;
     this.isFocused = false;
+    this.notifyParentState("GIS_WAREHOUSE_LEAVE", trigger);
     this.shelves.forEach(shelf => shelf.sleep());
     this.wakeUp();
     const targetFocusedShelf = this.shelves.find(shelf => shelf.isFocused);
@@ -105,6 +162,30 @@ export default class Warehouse extends ThingInner {
     }
   }
 
+  notifyParentState(type, trigger) {
+    const isEnter = type === "GIS_WAREHOUSE_ENTER";
+    if(isEnter && this.hasNotifiedParentEntered) return;
+    if(!isEnter && !this.hasNotifiedParentEntered) return;
+    this.hasNotifiedParentEntered = isEnter;
+    if(window.parent === window) return;
+    const warehouseIndex = this.qt.areaGlobal.warehouses.indexOf(this);
+    window.parent.postMessage(
+      {
+        source: "warehouse-gis",
+        type,
+        data: {
+          areaId: this.extData.wgAreaId,
+          areaName: this.extData.wgAreaName,
+          warehouseName: this.extData.wgWarehouseName,
+          warehouseIndex,
+          trigger
+        }
+      },
+      window.gisParentOrigin || "*"
+    );
+  }
+  // 项目传参修改相关结束
+
   hasFocusedWarehouse() {
     return this.qt.areaGlobal.warehouses.some(warehouse => warehouse.isFocused);
   }
@@ -115,4 +196,4 @@ export default class Warehouse extends ThingInner {
     !this.label.isDestroyed && this.label.destroy();
     return super.destroy(force);
   }
-}
+}

+ 13 - 0
src/router/index.js

@@ -17,6 +17,19 @@ const router = new VueRouter({
   ]
 });
 
+// 项目传参相关修改开始
+// iframe 地址仍指向首页时,根据 status 和园区 id 自动进入三维园区。
+router.beforeEach((to, from, next) => {
+  const status = String(to.query.status || "");
+  const enableAutoEnterArea = ["1", "2"].includes(status) && to.query.id && to.name !== "area";
+  if(enableAutoEnterArea) {
+    next({ name: "area", query: { ...to.query } });
+    return;
+  }
+  next();
+});
+// 项目传参修改相关结束
+
 // 路由导航前处理     标题设置
 beforeEachForTitle(router, Package["name-zh"]);
 // 路由导航前处理     中断所有未完成请求