|
@@ -11,6 +11,7 @@
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
import { reactive, watch, computed, onMounted, nextTick, type CSSProperties } from 'vue'
|
|
import { reactive, watch, computed, onMounted, nextTick, type CSSProperties } from 'vue'
|
|
import type { FurnitureItem, FurnitureType, LocalFurnitureItem } from '@/api/room/types'
|
|
import type { FurnitureItem, FurnitureType, LocalFurnitureItem } from '@/api/room/types'
|
|
|
|
+import { convert_furniture_r2c, rotateRect } from '@/utils/coordTransform'
|
|
|
|
|
|
defineOptions({ name: 'EditableFurniture' })
|
|
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 = () => {
|
|
const updateGeoPosition = () => {
|
|
// 直接转换左上角坐标
|
|
// 直接转换左上角坐标
|
|
@@ -222,8 +268,7 @@ onMounted(() => {
|
|
}
|
|
}
|
|
|
|
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
- updatePixelPosition()
|
|
|
|
- emit('update', { ...localItem })
|
|
|
|
|
|
+ initPixelPosition()
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
|