Эх сурвалжийг харах

fix: 修复家具坐标转换和初始化问题

调整EditableFurniture组件中家具坐标的初始化逻辑,使用convert_furniture_r2c和rotateRect进行坐标转换和旋转计算。同时修改MQTT超时时间和雷达编辑器的子区域显示延迟。

- 在EditableFurniture中实现initPixelPosition方法处理坐标转换
- 将MQTT超时时间从1000ms调整为2000ms
- 延迟500ms显示雷达编辑器的子区域
- 移除deviceAreaConfig中rotate的类型限制
liujia 5 өдөр өмнө
parent
commit
15e04a7

+ 47 - 2
src/components/EditableFurniture/index.vue

@@ -11,6 +11,7 @@
 <script setup lang="ts">
 import { reactive, watch, computed, onMounted, nextTick, type CSSProperties } from 'vue'
 import type { FurnitureItem, FurnitureType, LocalFurnitureItem } from '@/api/room/types'
+import { convert_furniture_r2c, rotateRect } from '@/utils/coordTransform'
 
 defineOptions({ name: 'EditableFurniture' })
 
@@ -190,6 +191,51 @@ const updatePixelPosition = () => {
   })
 }
 
+const initPixelPosition = () => {
+  const { x, y, width, length } = props.item
+  // === 1️⃣ 将房间坐标转换为画布坐标 ===
+  const itemConvert = convert_furniture_r2c(
+    {
+      x: x,
+      y: y,
+      width: width,
+      height: length,
+    },
+    {
+      x_radar: 250,
+      y_radar: 250,
+    }
+  )
+
+  // === 2️⃣ 再根据雷达朝向旋转 ===
+  const rotatedRect = rotateRect(
+    {
+      left: itemConvert.left,
+      top: itemConvert.top,
+      width: width,
+      height: length,
+    },
+    { x: 250, y: 250 },
+    props.angle
+  )
+
+  // === 3️⃣ 应用最终位置 ===
+  pixelPosition.left = rotatedRect.left
+  pixelPosition.top = rotatedRect.top
+
+  // 同步像素位置到 localItem(方便 emit)
+  localItem.left = rotatedRect.left
+  localItem.top = rotatedRect.top
+
+  console.log('✅ Init pixel position (after convert & rotate):', {
+    angle: props.angle,
+    geo: { x: localItem.x, y: localItem.y },
+    itemConvert,
+    rotatedRect,
+    final: { left: pixelPosition.left, top: pixelPosition.top },
+  })
+}
+
 // 更新地理坐标(从像素位置转换)- 左上角基准
 const updateGeoPosition = () => {
   // 直接转换左上角坐标
@@ -222,8 +268,7 @@ onMounted(() => {
   }
 
   nextTick(() => {
-    updatePixelPosition()
-    emit('update', { ...localItem })
+    initPixelPosition()
   })
 })
 

+ 4 - 0
src/components/RadarEditor/index.vue

@@ -532,6 +532,10 @@ const showPanel = ref(true)
 const showSubregion = ref(false)
 const showFurniture = ref(true)
 
+setTimeout(() => {
+  showSubregion.value = true
+}, 500)
+
 onUnmounted(() => {
   // 组件销毁时清除缓存
   localStorage.removeItem('subRegions')

+ 1 - 1
src/views/device/detail/components/deviceAreaConfig/index.vue

@@ -175,7 +175,7 @@ const saveAllConfig = () => {
       type: item.type,
       width: item.width,
       length: item.length,
-      rotate: item.rotate as 0 | 90 | 180 | 270,
+      rotate: item.rotate,
       x: item?.x || 0,
       y: item?.y || 0,
     }

+ 1 - 1
src/views/device/detail/index.vue

@@ -431,7 +431,7 @@ const THRESHOLD = 2 // 去抖阈值
 
 let mqttClient: MqttClient | null = null
 let mqttTimeout: number | null = null
-const MQTT_TIMEOUT_MS = 1000 // 调整为1
+const MQTT_TIMEOUT_MS = 2000 // 超时消失时间 
 
 const resetMqttTimeout = () => {
   if (mqttTimeout) clearTimeout(mqttTimeout)