Browse Source

修改楼层

wangfumin 5 days ago
parent
commit
15c535c2d7
2 changed files with 62 additions and 22 deletions
  1. 59 22
      src/layout/model-list/floor-tab.vue
  2. 3 0
      src/sdk/sdk.ts

+ 59 - 22
src/layout/model-list/floor-tab.vue

@@ -1,5 +1,5 @@
 <template>
-  <div class="floor-btn">
+  <div class="floor-btn" v-if="floorList.length > 2">
     <div v-for="item in floorList" :key="item.key" :class="['quisk-item', item.key == nowSelect ? 'active' : '']" @click="floor(item.key)">
       <span>{{ item.text }}</span>
     </div>
@@ -11,47 +11,84 @@ import { custom } from "@/env";
 import { getSupperPanoModel } from "@/sdk/association";
 import { currentModel, fuseModel } from "@/model";
 import { flyModel } from "@/hook/use-fly";
-import { ref } from "vue";
-import { SDK, sdk as _sdk } from "@/sdk";
+import { ref, onMounted, watch } from "vue";
+import { SDK, sdk } from "@/sdk";
+import { useViewStack } from "@/hook";
 
 const nowSelect = ref('all');
-const floorList = [{
+const floorList = ref([{
   key: "all",
   text: "全部"
-},{
-  key: 0,
-  text: "1楼"
-},{
-  key: 1,
-  text: "2楼"
-},{
-  key: 2,
-  text: "3楼"
-}] as any[];
+}] as any[]);
 
 const floor = (num: any) => {
   sdk.goFloor(num);
   nowSelect.value = num;
 }
+const floorCount = ref(0);
 
+// floorCount.value = sdk.getFloorCount()
+
+// sdk.sceneBus.on("floorCount", (num: any) => {
+//   floorCount.value = num;
+//   console.log(floorCount.value, 'floorCount')
+// });
+
+watch(floorCount, (newVal) => {
+  console.log(newVal, 'newVal')
+  for(let i = 0; i < newVal; i++) {
+    floorList.value.push({
+      key: i,
+      text: `${i + 1}楼`
+    })
+  }
+}, {immediate: true})
+
+
+let timer: any = null;
+let previousFloorCount = 0;
+
+onMounted(() => {
+  sdk.sceneBus.on("floorCount", (num: any) => {
+    floorCount.value = num;
+  });
+  
+  // 初始化上一次的值
+  previousFloorCount = sdk.getFloorCount();
+  
+  timer = setInterval(() => {
+    const currentCount = sdk.getFloorCount();
+    console.log(currentCount, 'setInterval');
+    
+    // 检查值是否发生变化
+    if (currentCount !== previousFloorCount) {
+      floorCount.value = currentCount;
+      console.log('floorCount changed, clearing interval');
+      clearInterval(timer);
+      timer = null;
+    }
+    
+    previousFloorCount = currentCount;
+  }, 1000);
+});
 </script>
 
 <style lang="scss" scoped>
 .floor-btn{
   position: absolute;
-  bottom          : calc(var(--editor-menu-bottom, 0px) + 10px);
-  left            : calc(var(--left-pano-left) + var(--left-pano-width));
-  margin-left     : 24px;
-  display: flex;
-  flex-direction: column;
-  align-items: center;
+  bottom: calc(var(--editor-menu-bottom, 0px) + 10px);
+  left: calc(var(--left-pano-left) + var(--left-pano-width));
+  margin-left: 24px;
+  // display: flex;
+  // flex-direction: column;
+  // align-items: center;
   z-index:100;
   width: 60px;
-  height: 176px;
+  min-height: 126px;
   background: rgba(27, 27, 28, 0.8);
   border-radius: 20px;
   padding: 8px;
-  transition      : all .3s ease;
+  transition: all .3s ease;
   .active{
     background: #00c8af;
   }

+ 3 - 0
src/sdk/sdk.ts

@@ -162,6 +162,7 @@ export interface SDK {
   layout: HTMLDivElement;
   sceneBus: Emitter<{
     cameraChange: SceneLocalPos;
+    floorCount: number;
     monitorError: void
     watchMonitor: void;
     panoModelChange: SceneModel;
@@ -223,6 +224,8 @@ export interface SDK {
 
   createAnimationGroup: () => AnimationGroup;
 
+  goFloor: (num: number) => void;
+  getFloorCount: () => number;
   generateAniPathData: () => any
   setFollowDevice: (macId: any) => void
 }