From 53aad5698fb113201e79b5cca981bdfb13d23d97 Mon Sep 17 00:00:00 2001
From: jinglun-cloud <jinglun2019@foxmail.com>
Date: 星期二, 05 五月 2026 14:45:44 +0800
Subject: [PATCH] 简化设备长宽计算的实现

---
 src/main/webapp/components/MapCanvas.js              |   53 ++++++-----------
 src/main/webapp/static/js/basMap/mapTrackGeometry.js |   41 +++++++++++++
 src/main/webapp/static/js/basMap/editor.js           |   62 ++++++++------------
 3 files changed, 83 insertions(+), 73 deletions(-)

diff --git a/src/main/webapp/components/MapCanvas.js b/src/main/webapp/components/MapCanvas.js
index 4571ca3..70fc985 100644
--- a/src/main/webapp/components/MapCanvas.js
+++ b/src/main/webapp/components/MapCanvas.js
@@ -1325,23 +1325,7 @@
       return (value * 100).toFixed(1) + '%';
     },
     /******************setDeviceInfo浣跨敤鐨勫嚱鏁�:******************/
-    getAnnulusAwarePoint(trackInfo, x, y, path) {
-      return trackInfo.type === 'annulus'
-        ? G.snapToAnnulusOuterPath(x, y, path)
-        : { x, y };
-    },
-    /** 鐜┛锛氭妸 getPositionAfterMove 鐨勭粨鏋滃帇鍒拌建甯︿腑绾匡紱闈炵幆绌垮師鏍疯繑鍥� */
-    applyAnnulusBandCenterToPosition(trackInfo, position) {
-      if (!position || trackInfo.type !== 'annulus') {
-        return position;
-      }
-      const c = G.centerAnnulusBandPoint(trackInfo, position.x, position.y, position.path);
-      return { ...position, x: c.x, y: c.y };
-    },
-    computeFinalPosition(trackInfo, point, pathList, path, deltaDistance, angle) {
-      const position = G.getPositionAfterMove({ point, pathList, path, deltaDistance, angle });
-      return this.applyAnnulusBandCenterToPosition(trackInfo, position);
-    },
+    // 鐜┛鏉$爜鍦ㄦ�婚暱涓婄殑鏈夌鍙锋宸�
     calcSignedSegmentDelta(fromBarcode, toBarcode, trackInfo, totalSegmentCount) {
       const from = Number(fromBarcode);
       const to = Number(toBarcode);
@@ -1452,20 +1436,21 @@
     ) {
       sprite.barcode = device.rgvPos;
       sprite.time = nowMs();
-      let tmpPassedSegmentCount = device.rgvPos - minBarcode;
-      const passedSegmentCount =
-        tmpPassedSegmentCount < 0
-          ? tmpPassedSegmentCount + totalSegmentCount
-          : tmpPassedSegmentCount;
+      const passedSegmentCount = this.calcSignedSegmentDelta(
+        minBarcode,
+        device.rgvPos,
+        sprite.trackInfo,
+        totalSegmentCount
+      );
       const deltaDistance = (allDistance * passedSegmentCount) / totalSegmentCount;
       const initPath = sprite.path;
-      const initMovePoint = this.getAnnulusAwarePoint(
+      const initMovePoint = G.snapToAnnulusOuterPath(
         sprite.trackInfo,
         sprite.x,
         sprite.y,
         initPath
       );
-      let mappingInfo = this.computeFinalPosition(
+      let mappingInfo = G.computeFinalPosition(
         sprite.trackInfo,
         initMovePoint,
         pathList,
@@ -1479,7 +1464,7 @@
       sprite.rotation = G.getRotate(mappingInfo, mappingInfo.path) || sprite.rotation;
       sprite.currentAngle = mappingInfo.angle;
       sprite.mappingInfo = mappingInfo;
-      const anchorPoint = this.getAnnulusAwarePoint(
+      const anchorPoint = G.snapToAnnulusOuterPath(
         sprite.trackInfo,
         mappingInfo.x,
         mappingInfo.y,
@@ -1577,25 +1562,25 @@
       } else {
         smoothDistance = stepCap;
       }
-      const movePointBarcode = this.getAnnulusAwarePoint(
+      const movePointBarcode = G.snapToAnnulusOuterPath(
         sprite.trackInfo,
         sprite.x,
         sprite.y,
         path
       );
       const angle = Math.atan2(sprite.y - path.y, sprite.x - path.x);
-      const raw = G.getPositionAfterMove({
-        point: movePointBarcode,
+      const p = G.computeFinalPosition(
+        sprite.trackInfo,
+        movePointBarcode,
         pathList,
         path,
-        deltaDistance: smoothDistance,
+        smoothDistance,
         angle
-      });
-      const p = this.applyAnnulusBandCenterToPosition(sprite.trackInfo, raw);
+      );
       sprite.path = p.path;
       sprite.x = p.x;
       sprite.y = p.y;
-      sprite.rotation = G.getRotate(raw, raw.path) || sprite.rotation;
+      sprite.rotation = G.getRotate(p, p.path) || sprite.rotation;
       const restDistanceAfter = G.calcDistance({ x: sprite.x, y: sprite.y }, sprite.mappingInfo);
       if (restDistanceAfter <= EPSILON || Math.abs(smoothDistance) >= restDistance - EPSILON) {
         this.finishDeviceMotion(sprite);
@@ -1625,7 +1610,7 @@
         anchor.totalSegmentCount !== totalSegmentCount;
       if (needResetAnchor) {
         const anchorPath = sprite.path;
-        const anchorPoint = this.getAnnulusAwarePoint(
+        const anchorPoint = G.snapToAnnulusOuterPath(
           sprite.trackInfo,
           sprite.x,
           sprite.y,
@@ -1653,7 +1638,7 @@
       const deltaDistance = (allDistance * passedSegmentCount) / totalSegmentCount;
       const path = anchor.path || sprite.path;
       const barcodeMovePoint = { x: anchor.x, y: anchor.y };
-      let finalPosition = this.computeFinalPosition(
+      let finalPosition = G.computeFinalPosition(
         sprite.trackInfo,
         barcodeMovePoint,
         pathList,
diff --git a/src/main/webapp/static/js/basMap/editor.js b/src/main/webapp/static/js/basMap/editor.js
index f164257..0d65549 100644
--- a/src/main/webapp/static/js/basMap/editor.js
+++ b/src/main/webapp/static/js/basMap/editor.js
@@ -2108,13 +2108,13 @@
           barCodeStart: 0,
           barCodeEnd: 100000,
           deviceList: [
-            {
-              valueKey: '',
-              deviceNo: '',
-              progress: 0,
-              deviceLength: '',
-              deviceWidth: ''
-            }
+            // {
+            //   valueKey: '',
+            //   deviceNo: '',
+            //   progress: 0,
+            //   deviceLength: '',
+            //   deviceWidth: ''
+            // }
           ]
         };
       },
@@ -2176,11 +2176,11 @@
       },
       getDeviceLengthPlaceholder: function () {
         var box = this.getAutoTrackDeviceBox();
-        return box && box.along ? '榛樿: ' + box.along : '';
+        return box && box.along ? '鍙傝��: ' + box.along : '';
       },
       getDeviceWidthPlaceholder: function () {
         var box = this.getAutoTrackDeviceBox();
-        return box && box.across ? '榛樿: ' + box.across : '';
+        return box && box.across ? '鍙傝��: ' + box.across : '';
       },
       loadDeviceForm: function (type, value) {
         this.resetDeviceForm();
@@ -2193,13 +2193,13 @@
           barCodeStart: 0,
           barCodeEnd: 100000,
           deviceList: [
-            {
-              valueKey: '',
-              deviceNo: '',
-              progress: 0,
-              deviceLength: '',
-              deviceWidth: ''
-            }
+            // {
+            //   valueKey: '',
+            //   deviceNo: '',
+            //   progress: 0,
+            //   deviceLength: '',
+            //   deviceWidth: ''
+            // }
           ],
           ...json
         };
@@ -2326,12 +2326,13 @@
         });
       },
       addDeviceForm: function () {
+        const defaultDeviceBox = this.getAutoTrackDeviceBox();
         this.deviceForm.deviceList.push({
           valueKey: '',
           deviceNo: '',
           progress: 0,
-          deviceLength: '',
-          deviceWidth: ''
+          deviceLength: "",
+          deviceWidth: ""
         });
       },
       applyDeviceForm: function () {
@@ -2348,7 +2349,7 @@
         if (
           !this.deviceForm.deviceList ||
           this.deviceForm.deviceList.length === 0 ||
-          this.deviceForm.deviceList.some((item) => item.deviceNo === '')
+          this.deviceForm.deviceList.some((item) => item.deviceNo === '' || item.deviceLength === '' || item.deviceWidth === '')
         ) {
           this.showMessage('warning', '璁惧鍒楄〃涓嶈兘涓虹┖');
           return;
@@ -2361,19 +2362,6 @@
           delete payload.rgvNo;
           self.deviceForm.deviceList.forEach((item) => {
             item.valueKey = valueKey;
-            // 鍏佽閫氳繃灞炴�ч潰鏉胯鐩栭粯璁よ澶囧儚绱犲昂瀵革紙娌胯建閬�/鍨傜洿杞ㄩ亾锛�
-            var deviceLength = toInt(item.deviceLength, 0);
-            var deviceWidth = toInt(item.deviceWidth, 0);
-            if (deviceLength > 0) {
-              item.deviceLength = String(deviceLength);
-            } else {
-              delete item.deviceLength;
-            }
-            if (deviceWidth > 0) {
-              item.deviceWidth = String(deviceWidth);
-            } else {
-              delete item.deviceWidth;
-            }
           });
           self.deviceForm.trackId = String(trackId);
           self.deviceForm.barCodeStart = toInt(self.deviceForm.barCodeStart, 0);
@@ -4595,11 +4583,11 @@
               newElement.value = JSON.stringify({
                 trackId: this.getNextDeviceTrackId(null),
                 deviceList: [
-                  {
-                    valueKey: '',
-                    deviceNo: '',
-                    progress: 0
-                  }
+                  // {
+                  //   valueKey: '',
+                  //   deviceNo: '',
+                  //   progress: 0
+                  // }
                 ]
               });
             }
diff --git a/src/main/webapp/static/js/basMap/mapTrackGeometry.js b/src/main/webapp/static/js/basMap/mapTrackGeometry.js
index 1fe8db3..6545496 100644
--- a/src/main/webapp/static/js/basMap/mapTrackGeometry.js
+++ b/src/main/webapp/static/js/basMap/mapTrackGeometry.js
@@ -1000,6 +1000,41 @@
   }
 
   /**
+   * 鐜┛锛氭妸 getPositionAfterMove 绛夎繑鍥炵殑 position 鍘嬪埌杞ㄥ甫涓嚎锛涢潪鐜┛鎴栨棤鏁� position 鍘熸牱杩斿洖銆�
+   * @param {{ type: string }} trackInfo
+   * @param {{ x: number, y: number, path?: object }|null|undefined} position
+   * @returns {typeof position}
+   */
+  function applyAnnulusBandCenterToPosition(trackInfo, position) {
+    if (!position || !trackInfo || trackInfo.type !== 'annulus') {
+      return position;
+    }
+    var c = centerAnnulusBandPoint(trackInfo, position.x, position.y, position.path);
+    return Object.assign({}, position, { x: c.x, y: c.y });
+  }
+
+  /**
+   * 娌� pathList 绉诲姩鍚庡啀瀵圭幆绌垮仛杞ㄥ甫涓嚎淇锛堜笌 getPositionAfterMove + applyAnnulusBandCenterToPosition 绛変环锛夈��
+   * @param {{ type: string }} trackInfo
+   * @param {{ x: number, y: number }} point 璧风偣锛涚幆绌夸笂搴斿湪澶栧湀 path 涓�
+   * @param {object[]} pathList
+   * @param {object} path
+   * @param {number} deltaDistance
+   * @param {number} [angle]
+   * @returns {{ x: number, y: number, path: object, angle?: number }} 涓� getPositionAfterMove 杩斿洖褰㈡�佷竴鑷�
+   */
+  function computeFinalPosition(trackInfo, point, pathList, path, deltaDistance, angle) {
+    var position = getPositionAfterMove({
+      point: point,
+      pathList: pathList,
+      path: path,
+      deltaDistance: deltaDistance,
+      angle: angle
+    });
+    return applyAnnulusBandCenterToPosition(trackInfo, position);
+  }
+
+  /**
    * 灏嗗潗鏍囧帇鍥炵幆绌垮鍦� path锛堢洿绾挎鎶曞奖銆佸渾寮ф钀藉埌鍗婂緞涓婏級銆�
    * sprite 宸插仛 centerAnnulusBandPoint 鏃朵笉鑳界洿鎺ヤ綔涓� getPositionAfterMove 鐨勮捣鐐癸紝鍚﹀垯浼氭部銆岀偣鈫掓缁堢偣銆嶆枩绉绘紓绉汇��
    * @param {number} x
@@ -1007,8 +1042,8 @@
    * @param {{ type: string, startX?: number, startY?: number, x?: number, y?: number, radius?: number }|null|undefined} path
    * @returns {{ x: number, y: number }}
    */
-  function snapToAnnulusOuterPath(x, y, path) {
-    if (!path) {
+  function snapToAnnulusOuterPath(trackInfo, x, y, path) {
+    if (!path || trackInfo.type !== 'annulus') {
       return { x: x, y: y };
     }
     if (path.type === 'line') {
@@ -1191,6 +1226,8 @@
     snapToAnnulusOuterPath: snapToAnnulusOuterPath,
     startDrawSmoothedPath: startDrawSmoothedPath,
     getRotate: getRotate,
+    computeFinalPosition:computeFinalPosition,
+    applyAnnulusBandCenterToPosition:applyAnnulusBandCenterToPosition,
     drawCrnDeviceGraphics: drawCrnDeviceGraphics,
     drawRgvDeviceGraphics: drawRgvDeviceGraphics
   };

--
Gitblit v1.9.1