Explorar el Código

提交指示灯问题

wangming hace 1 día
padre
commit
50ec287069

+ 5 - 0
src/pagesA/adDevice/adDevice.vue

@@ -605,6 +605,11 @@ export default {
             } else if (this.northAngle == 270) {
                 this.northAngleIndex = 3;
             }
+            if (this.northAngle == "" || this.northAngle == null) {
+                this.northAngleIndex = 0;
+                this.northAngle = 0;
+            }
+
             this.mountPlain = devInfo.mountPlain;
             if (this.northAngle == "Wall") {
                 this.mountPlainIndex = 0;

+ 6 - 9
src/pagesA/deviceDetail/deviceDetail.vue

@@ -319,7 +319,7 @@ import * as echarts from "../../uni_modules/lime-echart/static/echarts.min";
 import MqttService from "../../utils/globalMqtt.js";
 import {
     convert_region_r2c,
-    rotateRect,
+    rotateRect_cw,
     convert_furniture_r2c,
 } from "../../utils/changezb.js";
 
@@ -483,16 +483,13 @@ export default {
                     console.log(this.modules, 88888);
                     this.modules.forEach((item) => {
                         const rect = convert_furniture_r2c(item, pRadar);
-                        const rotatedRect = rotateRect(
+                        const rotatedRect = rotateRect_cw(
                             rect,
                             pRadar,
                             pRadar.angle
                         );
-                        // console.log(rotatedRect, 999999);
-                        item.top = rotatedRect.top;
-                        item.left = rotatedRect.left;
-                        item.width = rotatedRect.width;
-                        item.height = rotatedRect.height;
+                        item.name = item.name;
+                        item.type = item.type;
                     });
                     console.log(this.modules, 99999);
                 });
@@ -911,7 +908,7 @@ export default {
                 this.targetPoints = points.map((p) => {
                     return this.rotatePoint(p, radar, northAngle);
                 });
-                console.log(this.targetPoints, "更新后的点位数据333");
+                // console.log(this.targetPoints, "更新后的点位数据333");
             }
         },
         createNewTargetPoint(x, y, z, id) {
@@ -991,7 +988,7 @@ export default {
                 mountPlain: this.devInfo.mountPlain,
             };
             const rect = convert_region_r2c(trackingRegion, pRadar);
-            this.rotatedRect = rotateRect(rect, pRadar, pRadar.angle);
+            this.rotatedRect = rotateRect_cw(rect, pRadar, pRadar.angle);
             console.log(this.rotatedRect, "rotatedRect");
         },
 

+ 30 - 24
src/pagesA/roomSetting/roomSetting.vue

@@ -253,10 +253,10 @@
 import MqttService from "../../utils/globalMqtt.js";
 import {
     convert_region_r2c,
-    rotateRect,
+    rotateRect_cw,
     convert_furniture_r2c,
-    convert_furniture_save,
-    rotateRectReverse,
+    rotateRect_ccw,
+    convert_region_c2r,
 } from "../../utils/changezb.js";
 
 export default {
@@ -650,7 +650,6 @@ export default {
 
         saveRoom() {
             console.log(this.modules, 88888);
-
             const pRadar = {
                 x: this.x_radar,
                 y: this.y_radar,
@@ -658,20 +657,31 @@ export default {
                 mountPlain: "wall",
             };
             let copyModule = JSON.parse(JSON.stringify(this.modules));
-
             copyModule.forEach((item) => {
-                const rect = convert_furniture_save(item, pRadar);
-                const rotatedRect = rotateRectReverse(
-                    rect,
-                    pRadar,
-                    pRadar.angle
-                );
-                console.log(rotatedRect, 999999);
-                item.x = rotatedRect.x;
-                item.y = rotatedRect.y;
-                item.width = rotatedRect.width;
-                item.length = rotatedRect.length;
+                const rect = rotateRect_ccw(item, pRadar, pRadar.angle);
+                const rotatedRect = convert_region_c2r(rect, pRadar);
+                // item.x = rotatedRect.x;
+                // item.y = rotatedRect.y;
+                // item.width = rotatedRect.width;
+                // item.length = rotatedRect.length;
             });
+            for (const item of copyModule) {
+                if (
+                    item.top < 0 ||
+                    item.left < 0 ||
+                    item.top + item.length > 500 ||
+                    item.left + item.width > 500
+                ) {
+                    uni.showToast({
+                        title: `${item.name}超出画布区域,请调整位置后再保存`,
+                        icon: "none",
+                        duration: 1500,
+                    });
+                    return; // 这里能真正退出整个函数
+                }
+            }
+
+            console.log(copyModule, 999999);
             this.$http
                 .post(
                     "wap/room/saveRoom",
@@ -762,7 +772,7 @@ export default {
                 mountPlain: this.devInfo.mountPlain,
             };
             const rect = convert_region_r2c(trackingRegion, pRadar);
-            this.rotatedRect = rotateRect(rect, pRadar, pRadar.angle);
+            this.rotatedRect = rotateRect_cw(rect, pRadar, pRadar.angle);
             console.log(this.rotatedRect, "rotatedRect");
         },
         getRoomInfo(devId) {
@@ -790,18 +800,14 @@ export default {
                     console.log(this.modules, 88888);
                     this.modules.forEach((item) => {
                         const rect = convert_furniture_r2c(item, pRadar);
-                        const rotatedRect = rotateRect(
+                        const rotatedRect = rotateRect_cw(
                             rect,
                             pRadar,
                             pRadar.angle
                         );
                         console.log(rotatedRect, 999999);
-                        item.top = rotatedRect.x;
-                        item.left = rotatedRect.y;
-                        item.x = rotatedRect.x;
-                        item.y = rotatedRect.y;
-                        item.width = rotatedRect.width;
-                        item.height = rotatedRect.height;
+                        item.name = item.name;
+                        item.type = item.type;
                     });
                     console.log(this.modules, 99999);
                 });

+ 51 - 74
src/utils/changezb.js

@@ -119,7 +119,7 @@ export function convert_point_r2c(src_point, pRadar, angle) {
  * @param {number} angle - 顺时针旋转角度 0, 90, 180, 270
  * @returns {Object} 旋转后的矩形 { left, top, width, height }
  */
-export function rotateRect(src_rect, pRadar, angle) {
+export function rotateRect_cw(src_rect, pRadar, angle) {
     if (![0, 90, 180, 270].includes(angle)) angle = 0
 
     const { left, top, width, height } = src_rect
@@ -169,80 +169,31 @@ export function rotateRect(src_rect, pRadar, angle) {
     }
 }
 
-
-
 /**
- * 坐标系:x正轴朝右→, y正轴朝上↑
- * 将 src_point 绕 point 旋转 angle 度
- * @param {{x: number, y: number}} src_point - 原始点
- * @param {{x: number, y: number}} point - 旋转中心点
- * @param {number} angle - 旋转角度(度数)
- * @returns {{x: number, y: number}} - 旋转后的点
+ * 逆时针旋转矩形(家具/检测区域)
+ * @param {Object} src_rect - 输入矩形 { left, top, width, height }
+ * @param {Object} pRadar - 雷达中心坐标 { x, y }
+ * @param {number} angle - 逆时针旋转角度 0, 90, 180, 270
+ * @returns {Object} 旋转后的矩形 { left, top, width, height }
  */
-export function rotatePoint(src_point, point, angle) {
-    // console.log('rotatePoint 输入:', { src_point, point, angle });
-    const rad = (-angle * Math.PI) / 180; // 顺时针旋转
-    const cosA = Math.cos(rad);
-    const sinA = Math.sin(rad);
-
-    const x = src_point.x - point.x;
-    const y = src_point.y - point.y;
-
-    const xRot = x * cosA - y * sinA;
-    const yRot = x * sinA + y * cosA;
-
-    const result = {
-        x: parseFloat((xRot + point.x).toFixed(6)),
-        y: parseFloat((yRot + point.y).toFixed(6)),
-    };
-
-    // console.log('rotatePoint 返回:', result);
-    return result;
-}
-
-// 正向保存家具的方法
-
-// 从画布坐标系(c)转换为雷达坐标系(r)
-export function convert_furniture_save(furniture, p_radar) {
-    const x = furniture.left - p_radar.x;
-    const y = p_radar.y - furniture.top;
-    const width = furniture.width;
-    const length = furniture.length;
-
-    return {
-        x,
-        y,
-        width,
-        length
-    };
-}
-
-// 反向旋转:将画布坐标系的矩形,按指定角度反旋转回雷达坐标
-// 把画布坐标的家具位置旋转回雷达坐标系(用于保存)
-
-export function rotateRectReverse(src_rect, pRadar, angle) {
-    console.log('rotateRectReverse 输入:', { src_rect, pRadar, angle });
+export function rotateRect_ccw(src_rect, pRadar, angle) {
     if (![0, 90, 180, 270].includes(angle)) angle = 0;
 
-    // ✅ 注意这里要用 length
-    let { x, y, width, length } = src_rect;
+    const { left, top, width, height } = src_rect;
+    const cx = left + width / 2;
+    const cy = top + height / 2;
 
-    // 计算中心点
-    const cx = pRadar.x + x + width / 2;
-    const cy = pRadar.y - y - length / 2;
+    const dx = cx - pRadar.x;
+    const dy = cy - pRadar.y;
 
-    // 相对雷达点偏移
-    let dx = cx - pRadar.x;
-    let dy = cy - pRadar.y;
     let new_dx, new_dy;
 
-    // 与 rotateRect 方向相反(逆旋转)
     switch (angle) {
         case 0:
             new_dx = dx;
             new_dy = dy;
             break;
-        case 90: // 原来顺时针90°,现在逆时针90°
+        case 90: // 逆时针 90°
             new_dx = dy;
             new_dy = -dx;
             break;
@@ -250,7 +201,7 @@ export function rotateRectReverse(src_rect, pRadar, angle) {
             new_dx = -dx;
             new_dy = -dy;
             break;
-        case 270: // 原来顺时针270°(=逆时针90°)
+        case 270: // 逆时针 270° = 顺时针 90°
             new_dx = -dy;
             new_dy = dx;
             break;
@@ -259,23 +210,49 @@ export function rotateRectReverse(src_rect, pRadar, angle) {
     const new_cx = pRadar.x + new_dx;
     const new_cy = pRadar.y + new_dy;
 
-    // 对于 90/270,宽高要交换回来
     let new_width = width;
-    let new_length = length;
+    let new_height = height;
     if (angle === 90 || angle === 270) {
-        new_width = length;
-        new_length = width;
+        new_width = height;
+        new_height = width;
     }
 
-    // ⚠️ 注意:这里是雷达坐标系
-    const new_x = new_cx - pRadar.x;
-    const new_y = pRadar.y - new_cy;
-
     return {
-        x: new_x,
-        y: new_y,
+        left: new_cx - new_width / 2,
+        top: new_cy - new_height / 2,
         width: new_width,
-        length: new_length
+        height: new_height
     };
 }
 
+
+
+/**
+ * 坐标系:x正轴朝右→, y正轴朝上↑
+ * 将 src_point 绕 point 旋转 angle 度
+ * @param {{x: number, y: number}} src_point - 原始点
+ * @param {{x: number, y: number}} point - 旋转中心点
+ * @param {number} angle - 旋转角度(度数)
+ * @returns {{x: number, y: number}} - 旋转后的点
+ */
+export function rotatePoint(src_point, point, angle) {
+    // console.log('rotatePoint 输入:', { src_point, point, angle });
+    const rad = (-angle * Math.PI) / 180; // 顺时针旋转
+    const cosA = Math.cos(rad);
+    const sinA = Math.sin(rad);
+
+    const x = src_point.x - point.x;
+    const y = src_point.y - point.y;
+
+    const xRot = x * cosA - y * sinA;
+    const yRot = x * sinA + y * cosA;
+
+    const result = {
+        x: parseFloat((xRot + point.x).toFixed(6)),
+        y: parseFloat((yRot + point.y).toFixed(6)),
+    };
+
+    // console.log('rotatePoint 返回:', result);
+    return result;
+}
+