From 33dbc6a161554f3a897f9e9273feb4f2c1b47381 Mon Sep 17 00:00:00 2001
From: chenlu <1320612696@qq.com>
Date: 星期一, 15 十二月 2025 17:04:27 +0800
Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10105/r/ERP_override

---
 north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue |  729 +++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 512 insertions(+), 217 deletions(-)

diff --git a/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue b/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue
index df8057f..5a9490e 100644
--- a/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue
+++ b/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue
@@ -1,16 +1,80 @@
 <template>
   <div style="display: flex; height: 90vh;">
     <!-- Sidebar -->
-    <div class="sidebar" style="width: 200px; background: #f4f4f4; padding: 10px;">
-      <div
-        v-for="(layout, layoutIndex) in layouts"
-        :key="layoutIndex"
-        class="sidebar-item"
-        @click="selectLayout(layoutIndex)"
-        :class="{ 'selected': selectedLayoutIndex === layoutIndex }"
-      >
-        {{ layout.realWidth }} 脳 {{ layout.realHeight }} 脳 {{ layout.quantity  }}
+    <div class="sidebar" style="width: 200px; background: #f4f4f4; padding: 10px; height: 93%; overflow-y: auto; max-height: 90vh; border-radius: 8px;">
+      <div class="folder">
+        <div
+          class="folder-header"          style="padding: 8px; background: #e0e0e0; margin-bottom: 5px; border-radius: 4px; user-select: none; display: flex; justify-content: space-between; align-items: center;"
+        >
+          <span @click="toggleFolder('pending')" style="flex: 1; cursor: pointer;">寰呭垏鍓插師鐗�</span>
+          <button
+            @click="toggleFolder('pending')"            style="background: none; border: none; cursor: pointer; font-size: 14px; padding: 2px 5px; border-radius: 3px;"
+            :title="openFolders.pending ? '鏀惰捣' : '灞曞紑'"
+          >
+            <el-icon v-if="openFolders.pending"><ArrowUp /></el-icon>
+            <el-icon v-else><ArrowDown /></el-icon>
+          </button>
+        </div>
+        <div v-show="openFolders.pending" class="folder-content" style="padding-left: 15px;">
+          <div
+            v-for="(layout, layoutIndex) in layouts"
+            :key="layoutIndex"
+            class="sidebar-item"
+            @click="selectLayout(layoutIndex)"
+            :class="{ 'selected': selectedLayoutIndex === layoutIndex }"            style="margin-bottom: 5px;"
+          >
+            {{ layout.realWidth }} 脳 {{ layout.realHeight }} 脳 {{ layout.quantity }}
+          </div>
+        </div>
       </div>
+
+<!-- 寰呰ˉ鐗囬槦鍒楁枃浠跺す -->
+      <div class="folder">
+        <div
+          class="folder-header"          style="padding: 8px; background: #e0e0e0; margin-bottom: 5px; border-radius: 4px; user-select: none; display: flex; justify-content: space-between; align-items: center;"
+        >
+          <span @click="toggleFolder('patchQueue')" style="flex: 1; cursor: pointer;">寰呰ˉ鐗囬槦鍒�</span>
+          <button
+            @click="toggleFolder('patchQueue')"            style="background: none; border: none; cursor: pointer; font-size: 14px; padding: 2px 5px; border-radius: 3px;"
+            :title="openFolders.patchQueue ? '鏀惰捣' : '灞曞紑'"
+          >
+            <el-icon v-if="openFolders.patchQueue"><ArrowUp /></el-icon>
+            <el-icon v-else><ArrowDown /></el-icon>
+          </button>
+        </div>
+        <div v-show="openFolders.patchQueue" class="folder-content" style="padding-left: 15px;">
+          <div style="padding: 10px; color: #666; font-style: italic;">
+            鏆傛棤琛ョ墖浠诲姟
+          </div>
+        </div>
+      </div>
+
+      <!-- 娣诲姞鑷畾涔夊昂瀵告枃浠跺す -->
+      <div class="folder">
+        <div
+          class="folder-header"          style="padding: 8px; background: #e0e0e0; margin-bottom: 5px; border-radius: 4px; user-select: none; display: flex; justify-content: space-between; align-items: center;"
+        >
+          <span @click="toggleFolder('customSize')" style="flex: 1; cursor: pointer;">娣诲姞鑷畾涔夊昂瀵�</span>
+          <button
+            @click="toggleFolder('customSize')"            style="background: none; border: none; cursor: pointer; font-size: 14px; padding: 2px 5px; border-radius: 3px;"
+            :title="openFolders.customSize ? '鏀惰捣' : '灞曞紑'"
+          >
+            <el-icon v-if="openFolders.customSize"><ArrowUp /></el-icon>
+            <el-icon v-else><ArrowDown /></el-icon>
+          </button>
+        </div>
+        <div v-show="openFolders.customSize" class="folder-content" style="padding-left: 15px;">
+          <div style="padding: 10px;">
+            <button
+              @click="showAddCustomSizeDialog"              style="width: 100%; padding: 8px; background: #409eff; color: white; border: none; border-radius: 4px; cursor: pointer;"
+            >
+              + 娣诲姞鑷畾涔夊昂瀵�
+            </button>
+          </div>
+        </div>
+      </div>
+
+
     </div>
 
     <!-- Main Layout Panel -->
@@ -53,10 +117,6 @@
             class="layout-glassDetail"
             :style="rectStyle(glassDetail, layoutIndex)"
             @contextmenu.prevent="handleRectRightClick(layoutIndex, rectIndex)"
-            @mousedown="handleRectDragStart(layoutIndex, rectIndex)"
-            @mousemove="handleRectDragging"
-            @mouseup="handleRectDragEnd"
-            @mouseleave="handleRectDragEnd"
             @click="handleRectClick(layoutIndex, rectIndex)"
           >
             <div class="glassDetail-content">
@@ -71,8 +131,7 @@
       </div>
     </div>
 
-    <!-- 鎻愪氦鎸夐挳 -->
-    <button @click="submitLayouts" style="position: fixed; bottom: 20px; right: 20px; padding: 10px; background: #4CAF50; color: white; border: none; border-radius: 5px; cursor: pointer;">
+    <button @click="submitLayouts" style="position: fixed; top: 90px; right: 20px; padding: 10px; background: #409eff; color: white; border: none; border-radius: 5px; cursor: pointer;">
       淇濆瓨璋冩暣
     </button>
   </div>
@@ -80,9 +139,10 @@
 
 <script setup>
 import { ref, reactive, onMounted, onUnmounted } from 'vue';
-import { useRouter } from 'vue-router'; // 娣诲姞杩欒
+import { useRouter } from 'vue-router';
+import { ArrowUp, ArrowDown } from '@element-plus/icons-vue'
 import request from "@/utils/request";
-const router = useRouter(); // 娣诲姞杩欒
+const router = useRouter();
 import { useI18n } from "vue-i18n";
 import { ElMessage, ElMessageBox } from "element-plus";
 import useUserInfoStore from "@/stores/userInfo";
@@ -109,9 +169,9 @@
 const rectClass = ref('layout-glassDetail');
 const selectedLayoutIndex = ref(0);
 const currentRect = ref(null);
-const dragging = ref(false);
-const dragStartPos = ref({ x: 0, y: 0 });
-const dragRect = ref(null);
+// const dragging = ref(false);
+// const dragStartPos = ref({ x: 0, y: 0 });
+// const dragRect = ref(null);
 const showJiaHao = ref(false);
 const showProcessId = ref(false);
 const themeColor = ref(null);
@@ -120,10 +180,10 @@
 const submitLayouts = async () => {
   layouts.value.forEach(layout => {
     layout.glassDetails.forEach(glassDetail => {
-      glassDetail.x = Math.round(glassDetail.x);
-      glassDetail.y = Math.round(glassDetail.y);
-      glassDetail.width = Math.round(glassDetail.width);
-      glassDetail.height = Math.round(glassDetail.height);
+      glassDetail.x = parseFloat(glassDetail.x.toFixed(2));
+      glassDetail.y = parseFloat(glassDetail.y.toFixed(2));
+      glassDetail.width = parseFloat(glassDetail.width.toFixed(2));
+      glassDetail.height = parseFloat(glassDetail.height.toFixed(2));
     });
   });
   const savedProjectNo = localStorage.getItem('projectNo');
@@ -153,6 +213,30 @@
       ElMessage.warning(res.msg);
     }
   });
+};
+
+const openFolders = ref({
+  pending: true,  // 榛樿灞曞紑"寰呭垏鍓插師鐗�"鏂囦欢澶�
+   patchQueue: false,   // 榛樿鏀惰捣"寰呰ˉ鐗囬槦鍒�"鏂囦欢澶�
+  customSize: false   // 榛樿鏀惰捣"娣诲姞鑷畾涔夊昂瀵�"鏂囦欢澶�
+});
+
+// 鍒囨崲鏂囦欢澶瑰睍寮�/鏀惰捣鐘舵��
+const toggleFolder = (folderName) => {
+  openFolders.value[folderName] = !openFolders.value[folderName];
+};
+
+
+
+const showAddCustomSizeDialog = () => {
+  // 妫�鏌ユ槸鍚﹂�夋嫨浜嗙増鍥�
+  if (selectedLayoutIndex.value === null || layouts.value.length === 0) {
+    ElMessage.warning('璇峰厛閫夋嫨涓�涓増鍥�');
+    return;
+  }
+
+  // 浣跨敤鐜版湁鐨勬坊鍔犳垚鍝侀�昏緫锛屼紶鍏ュ綋鍓嶉�変腑鐨勭増鍥剧储寮�
+  showAddDialog(selectedLayoutIndex.value);
 };
 
 //鏌ヨ璁剧疆鐨勫熀纭�淇℃伅鏋跺彿锛岀煩褰㈤鑹诧紝璁㈠崟搴忓彿绛�
@@ -258,6 +342,12 @@
   return bestFit;
 };
 
+const isSelected = (layoutIndex, rectIndex) => {
+  return focusIndex.value &&
+         focusIndex.value.layoutIndex === layoutIndex &&
+         focusIndex.value.rectIndex === rectIndex;
+};
+
 //鐗堝浘鍐呭鏍峰紡鍔犺浇
 const layoutContainerStyle = (layoutIndex) => {
   const layout = layouts.value[layoutIndex];
@@ -309,9 +399,10 @@
 //鐗堝浘鍐呭灏忕墖鏍峰紡鍔犺浇
 const rectStyle = (glassDetail, layoutIndex) => {
   const layout = layouts.value[layoutIndex];
-  const scale = Math.min(0.25
-  );
-  return {
+  const scale = Math.min(0.25);
+  const isSelectedRect = isSelected(layoutIndex, layout.glassDetails.indexOf(glassDetail));
+
+  let style = {
     position: 'absolute',
     left: `${glassDetail.x * scale}px`,
     top: `${glassDetail.y * scale}px`,
@@ -323,13 +414,21 @@
     draggable: !glassDetail.isRemain,
     zIndex: glassDetail.isRemain ? 1 : 2
   };
+
+  // 濡傛灉琚�変腑锛屽垯娣诲姞鍐呬晶绾㈡
+  if (isSelectedRect) {
+    style.boxShadow = 'inset 0 0 0 2px red';
+  }
+
+  return style;
 };
 
 const rectStyle1 = (glassDetail, layoutIndex) => {
   const layout = layouts.value[layoutIndex];
-  const scale = Math.min(0.25
-  );
-  return {
+  const scale = Math.min(0.25);
+  const isSelectedRect = isSelected(layoutIndex, layout.glassDetails.indexOf(glassDetail));
+
+  let style = {
     position: 'absolute',
     left: `${glassDetail.x * scale}px`,
     top: `${glassDetail.y * scale}px`,
@@ -341,10 +440,21 @@
     draggable: !glassDetail.isRemain,
     zIndex: glassDetail.isRemain ? 1 : 2
   };
+
+  // 濡傛灉琚�変腑锛屽垯娣诲姞鍐呬晶绾㈡
+  if (isSelectedRect) {
+    style.boxShadow = 'inset 0 0 0 2px red';
+  }
+
+  return style;
 };
 
 //鐐瑰嚮灏忕墖
 const handleRectClick = (layoutIndex, rectIndex) => {
+  // if (dragging.value) {
+  //   return;
+  // }
+
   focusIndex.value = { layoutIndex, rectIndex };
   emit('rectClicked', layoutIndex, rectIndex);
 };
@@ -353,12 +463,13 @@
 const handleRectRightClick = (layoutIndex, rectIndex) => {
   const glassDetail = layouts.value[layoutIndex].glassDetails[rectIndex];
   if (glassDetail.isRemain) return;
+  document.querySelectorAll('.context-menu').forEach(el => el.remove());
 
   const contextMenu = document.createElement('div');
   contextMenu.className = 'context-menu';
   contextMenu.style.position = 'absolute';
   contextMenu.style.left = `${event.clientX}px`;
-  contextMenu.style.bottom = `${event.clientY}px`;
+  contextMenu.style.top = `${event.clientY}px`;
   contextMenu.style.backgroundColor = '#fff';
   contextMenu.style.border = '1px solid #ccc';
   contextMenu.style.padding = '5px';
@@ -376,7 +487,7 @@
   moveUpAndRotateItem.textContent = '鍚戜笂绉诲姩骞舵棆杞�';
   moveUpAndRotateItem.style.cursor = 'pointer';
   moveUpAndRotateItem.addEventListener('click', () => {
-    moveRectAndRotate(layoutIndex, rectIndex, 'up');
+    moveRectAndRotate(layoutIndex, rectIndex, 'down');
     document.body.removeChild(contextMenu);
   });
 
@@ -384,7 +495,7 @@
   moveDownAndRotateItem.textContent = '鍚戜笅绉诲姩骞舵棆杞�';
   moveDownAndRotateItem.style.cursor = 'pointer';
   moveDownAndRotateItem.addEventListener('click', () => {
-    moveRectAndRotate(layoutIndex, rectIndex, 'down');
+    moveRectAndRotate(layoutIndex, rectIndex, 'up');
     document.body.removeChild(contextMenu);
   });
 
@@ -408,7 +519,7 @@
   moveUpItem.textContent = '鍚戜笂绉诲姩';
   moveUpItem.style.cursor = 'pointer';
   moveUpItem.addEventListener('click', () => {
-    moveRect(layoutIndex, rectIndex, 'up');
+    moveRect(layoutIndex, rectIndex, 'down');
     document.body.removeChild(contextMenu);
   });
 
@@ -416,7 +527,7 @@
   moveDownItem.textContent = '鍚戜笅绉诲姩';
   moveDownItem.style.cursor = 'pointer';
   moveDownItem.addEventListener('click', () => {
-    moveRect(layoutIndex, rectIndex, 'down');
+    moveRect(layoutIndex, rectIndex, 'up');
     document.body.removeChild(contextMenu);
   });
 
@@ -489,12 +600,13 @@
 const handleGrayRectRightClick = (layoutIndex, rectIndex,glassDetails) => {
   //const glassDetail = glassDetails[rectIndex];
   if (!glassDetails.isRemain) return;
+  document.querySelectorAll('.context-menu').forEach(el => el.remove());
 
   const contextMenu = document.createElement('div');
   contextMenu.className = 'context-menu';
   contextMenu.style.position = 'absolute';
   contextMenu.style.left = `${event.clientX}px`;
-  contextMenu.style.bottom = `${event.clientY}px`;
+  contextMenu.style.top = `${event.clientY}px`;
   contextMenu.style.backgroundColor = '#fff';
   contextMenu.style.border = '1px solid #ccc';
   contextMenu.style.padding = '5px';
@@ -532,85 +644,122 @@
 };
 
 //灏忕墖榧犳爣鎸変笅浜嬩欢
-const handleRectDragStart = (layoutIndex, rectIndex) => {
-  const layout = layouts.value[layoutIndex];
-  const glassDetail = layout.glassDetails[rectIndex];
-  if (glassDetail.isRemain) return;
+// const handleRectDragStart = (layoutIndex, rectIndex) => {
+//   const layout = layouts.value[layoutIndex];
+//   const glassDetail = layout.glassDetails[rectIndex];
+//   if (glassDetail.isRemain) return;
+//
+//   dragRect.value = { layoutIndex, rectIndex };
+//   dragStartPos.value = {
+//     x: event.clientX,
+//     y: event.clientY
+//   };
+// };
 
-  dragging.value = true;
-  dragRect.value = { layoutIndex, rectIndex };
-  dragStartPos.value = {
-    x: event.clientX,
-    y: event.clientY
-  };
-};
+// //灏忕墖榧犳爣绉诲姩浜嬩欢
+// const handleRectDragging = (event) => {
+//   if (!dragRect.value) return;
+//
+//   // 濡傛灉杩樻病纭鏄嫋鎷斤紝鍒欏厛鍒ゆ柇鏄惁杈惧埌鎷栨嫿闃堝��(渚嬪5鍍忕礌)
+//   if (!dragging.value) {
+//     const deltaX = event.clientX - dragStartPos.value.x;
+//     const deltaY = event.clientY - dragStartPos.value.y;
+//     const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+//
+//     // 濡傛灉绉诲姩璺濈灏忎簬闃堝�硷紝鍒欒涓烘槸鐐瑰嚮鑰岄潪鎷栨嫿
+//     if (distance < 5) {
+//       return;
+//     }
+//
+//     // 杈惧埌闃堝�硷紝纭鏄嫋鎷芥搷浣�
+//     dragging.value = true;
+//   }
+//
+//   const layoutIndex = dragRect.value.layoutIndex;
+//   const rectIndex = dragRect.value.rectIndex;
+//   const layout = layouts.value[layoutIndex];
+//   const glassDetail = layout.glassDetails[rectIndex];
+//
+//   // 淇濆瓨鍘熷鍧愭爣鐢ㄤ簬璁$畻鍋忕Щ閲�
+//   const originalX = glassDetail.x;
+//   const originalY = glassDetail.y;
+//
+//   const scale = Math.min(
+//     (props.gw - 100) / layout.width,
+//     (props.gh - 100) / layout.height
+//   );
+//
+//   const deltaX = event.clientX - dragStartPos.value.x;
+//   const deltaY = event.clientY - dragStartPos.value.y;
+//
+//   const newRect = { ...glassDetail };
+//   newRect.x += deltaX / scale;
+//   newRect.y += deltaY / scale;
+//
+//   const otherRects = layout.glassDetails.filter(r => !r.isRemain && r !== glassDetail);
+//   let isValidMove = true;
+//
+//   otherRects.forEach(otherRect => {
+//     if (checkOverlap(newRect, otherRect)) {
+//       isValidMove = false;
+//     }
+//   });
+//
+//   if (newRect.x < 0 || newRect.y < 0 ||
+//       newRect.x + newRect.width > layout.width ||
+//       newRect.y + newRect.height > layout.height) {
+//     isValidMove = false;
+//   }
+//
+//   if (isValidMove) {
+//     glassDetail.x = newRect.x;
+//     glassDetail.y = newRect.y;
+//
+//     // 鏇存柊glassPoint鍧愭爣
+//     if (glassDetail.glassPoint && Array.isArray(glassDetail.glassPoint)) {
+//       const offsetX = glassDetail.x - originalX;
+//       const offsetY = glassDetail.y - originalY;
+//
+//       glassDetail.glassPoint.forEach(point => {
+//         point.X += offsetX;
+//         point.Y += offsetY;
+//         // 娣诲姞绮惧害鎺у埗
+//         point.X = parseFloat(point.X.toFixed(2));
+//         point.Y = parseFloat(point.Y.toFixed(2));
+//       });
+//     }
+//
+//     dragStartPos.value = {
+//       x: event.clientX,
+//       y: event.clientY
+//     };
+//     adjustGrayRectangles(layoutIndex);
+//   }
+// };
 
-//灏忕墖榧犳爣绉诲姩浜嬩欢
-const handleRectDragging = (event) => {
-  if (!dragging.value || !dragRect.value) return;
-
-  const layoutIndex = dragRect.value.layoutIndex;
-  const rectIndex = dragRect.value.rectIndex;
-  const layout = layouts.value[layoutIndex];
-  const glassDetail = layout.glassDetails[rectIndex];
-  const scale = Math.min(
-    (props.gw - 100) / layout.width,
-    (props.gh - 100) / layout.height
-  );
-
-  const deltaX = event.clientX - dragStartPos.value.x;
-  const deltaY = event.clientY - dragStartPos.value.y;
-
-  const newRect = { ...glassDetail };
-  newRect.x += deltaX / scale;
-  newRect.y += deltaY / scale;
-
-  const otherRects = layout.glassDetails.filter(r => !r.isRemain && r !== glassDetail);
-  let isValidMove = true;
-
-  otherRects.forEach(otherRect => {
-    if (checkOverlap(newRect, otherRect)) {
-      isValidMove = false;
-    }
-  });
-
-  if (newRect.x < 0 || newRect.y < 0 ||
-      newRect.x + newRect.width > layout.width ||
-      newRect.y + newRect.height > layout.height) {
-    isValidMove = false;
-  }
-
-  if (isValidMove) {
-    glassDetail.x = newRect.x;
-    glassDetail.y = newRect.y;
-    dragStartPos.value = {
-      x: event.clientX,
-      y: event.clientY
-    };
-    adjustGrayRectangles(layoutIndex);
-  }
-};
-
-//灏忕墖榧犳爣鏉惧紑浜嬩欢
-const handleRectDragEnd = () => {
-  if (dragRect.value) {
-    const layoutIndex = dragRect.value.layoutIndex;
-    const rectIndex = dragRect.value.rectIndex;
-    const glassDetail = layouts.value[layoutIndex].glassDetails[rectIndex];
-    const layout = layouts.value[layoutIndex];
-    const scale = Math.min(
-      (props.gw - 100) / layout.width,
-      (props.gh - 100) / layout.height
-    );
-
-    glassDetail.x = Math.round(glassDetail.x);
-    glassDetail.y = Math.round(glassDetail.y);
-    adjustAlignmentPosition(layoutIndex, rectIndex);
-  }
-
-  dragging.value = false;
-  dragRect.value = null;
-};
+// //灏忕墖榧犳爣鏉惧紑浜嬩欢
+// const handleRectDragEnd = () => {
+//   dragging.value = false;
+//   dragRect.value = null;
+//   dragStartPos.value = { x: 0, y: 0 };
+//   if (dragRect.value) {
+//     const layoutIndex = dragRect.value.layoutIndex;
+//     const rectIndex = dragRect.value.rectIndex;
+//     const glassDetail = layouts.value[layoutIndex].glassDetails[rectIndex];
+//     const layout = layouts.value[layoutIndex];
+//     const scale = Math.min(
+//       (props.gw - 100) / layout.width,
+//       (props.gh - 100) / layout.height
+//     );
+//
+//     glassDetail.x = parseFloat(glassDetail.x.toFixed(2));
+//     glassDetail.y = parseFloat(glassDetail.y.toFixed(2));
+//     adjustAlignmentPosition(layoutIndex, rectIndex);
+//   }
+//
+//   dragging.value = false;
+//   dragRect.value = null;
+// };
 
 const adjustAlignmentPosition = (layoutIndex, rectIndex) => {
   const layout = layouts.value[layoutIndex];
@@ -648,97 +797,152 @@
   adjustGrayRectangles(layoutIndex);
 };
 
-const mergeAdjacentGrayRects = (glassDetails,totalWidth,totalHeight) => {
+const mergeAdjacentGrayRects = (glassDetails, totalWidth, totalHeight) => {
   const grayRects = glassDetails.filter(r => r.isRemain);
-  const grayRects2 = glassDetails.filter(r => r.isRemain);
-  let merged = [];
+  const nonGrayRects = glassDetails.filter(r => !r.isRemain);
 
+  // 鎸夊潗鏍囨帓搴忥紝浼樺厛鎸墆鍧愭爣锛屽叾娆℃寜x鍧愭爣锛堣繖鏍锋洿绗﹀悎浠庝笂鍒颁笅銆佷粠宸﹀埌鍙崇殑闃呰涔犳儻锛�
   grayRects.sort((a, b) => {
-    if (a.x !== b.x) return a.x - b.x;
-    return a.y - b.y;
+    if (a.y !== b.y) return a.y - b.y;
+    return a.x - b.x;
   });
 
   if (grayRects.length === 0) return;
 
-  merged.push({ ...grayRects[0] });
+  const merged = [];
+  let current = { ...grayRects[0] };
 
+  // 閬嶅巻鎵�鏈変綑鏂欑煩褰㈣繘琛屽悎骞�
   for (let i = 1; i < grayRects.length; i++) {
-      const last = merged[merged.length-1];
-      const current = grayRects[i];
+    const next = grayRects[i];
 
-
-    if (current.x === last.x + last.width &&
-        current.y === last.y &&
-        current.height === last.height) {
-      last.width += current.width;
-      last.x = Math.round(last.x);
-      last.y = Math.round(last.y);
-      last.width = Math.round(last.width);
-      last.height = Math.round(last.height);
-    } else if (current.y === last.y + last.height &&
-               current.x === last.x &&
-               current.width === last.width) {
-      last.height += current.height;
-      last.x = Math.round(last.x);
-      last.y = Math.round(last.y);
-      last.width = Math.round(last.width);
-      last.height = Math.round(last.height);
-    } else {
+    // 妫�鏌ユ槸鍚﹀彲浠ユ按骞冲悎骞讹紙鍚屼竴琛岋紝楂樺害鐩稿悓锛岀浉閭伙級
+    if (current.y === next.y &&
+        current.height === next.height &&
+        current.x + current.width === next.x) {
+      // 姘村钩鍚堝苟
+      current.width += next.width;
+    }
+    // 妫�鏌ユ槸鍚﹀彲浠ュ瀭鐩村悎骞讹紙鍚屼竴鍒楋紝瀹藉害鐩稿悓锛岀浉閭伙級
+    else if (current.x === next.x &&
+        current.width === next.width &&
+        current.y + current.height === next.y) {
+      // 鍨傜洿鍚堝苟
+      current.height += next.height;
+    }
+    else {
+      // 鏃犳硶鍚堝苟锛屼繚瀛樺綋鍓嶇煩褰紝寮�濮嬫柊鐨勫悎骞�
       merged.push({
-        x: Math.round(current.x),
-        y: Math.round(current.y),
-        width: Math.round(current.width),
-        height: Math.round(current.height),
+        x: current.x,
+        y: current.y,
+        width: current.width,
+        height: current.height,
         isRemain: true
       });
+      current = { ...next };
     }
   }
 
-  const nonGray = glassDetails.filter(r => !r.isRemain);
-  //鍒犻櫎鍘熸暟缁勬嫾鎺ユ柊鐨勫皬鐗囪窡浣欐枡
-  glassDetails.splice(0, glassDetails.length, ...nonGray, ...merged);
+  // 娣诲姞鏈�鍚庝竴涓煩褰�
+  merged.push({
+    x: current.x,
+    y: current.y,
+    width: current.width,
+    height: current.height,
+    isRemain: true
+  });
+
+  // 閲嶆柊鏋勫缓鏁扮粍锛氶潪浣欐枡 + 鍚堝苟鍚庣殑浣欐枡
+  glassDetails.splice(0, glassDetails.length, ...nonGrayRects, ...merged);
 };
+
+// 纭繚杩斿洖鐨勫尯鍩熶笉閲嶅彔
+const calculateRemainingAreas = (totalWidth, totalHeight, obstacles) => {
+  // 浠庢暣涓師鐗囧紑濮�
+  let remaining = [{ x: 0, y: 0, width: totalWidth, height: totalHeight }];
+
+  // 閫愪釜澶勭悊闅滅鐗╋紙宸叉斁缃殑鐜荤拑鐗囷級
+  obstacles.forEach(obstacle => {
+    remaining = cutRemainingAreas(remaining, obstacle, totalWidth, totalHeight);
+  });
+
+  // 瀵圭粨鏋滆繘琛屾帓搴忥紝纭繚涓�鑷存��
+  remaining.sort((a, b) => {
+    if (a.x !== b.x) return a.x - b.x;
+    return a.y - b.y;
+  });
+
+  return remaining;
+};
+
 
 // 璋冩暣鍚庨噸鏂拌绠楃伆鑹蹭綑鏂�
 const adjustGrayRectangles = (layoutIndex) => {
   const layout = layouts.value[layoutIndex];
   const glassDetails = layout.glassDetails;
-  //灏忕墖鐨勬暟鎹�
+
+  // 1. 绛涢�夊嚭闈炰綑鏂欑殑鐜荤拑鐗囷紙鍗冲疄闄呰鍒囧壊鐨勭幓鐠冪墖锛�
   const nonGrayRects = glassDetails.filter(glassDetail => !glassDetail.isRemain);
 
-  //鎵�鏈夌殑灏忕墖浣欐枡鍧愭爣璺熷昂瀵�
+  // 2. 璁$畻鍓╀綑鍙敤鍖哄煙
   let remainingAreas = calculateRemainingAreas(layout.width, layout.height, nonGrayRects);
-  const uniqueArr = Array.from(
-      new Set(remainingAreas.map(item => JSON.stringify(item)))
-  ).map(item => JSON.parse(item));
-  //浣欐枡鐨勬暟鎹�
+
+  // 3. 鍘婚噸澶勭悊 - 鏇翠弗鏍肩殑鍘婚噸閫昏緫
+  const uniqueArr = removeDuplicateAreas(remainingAreas);
+
+  // 4. 鑾峰彇褰撳墠宸插瓨鍦ㄧ殑浣欐枡鐭╁舰锛堥渶瑕佷繚鐣欏紩鐢ㄤ互渚挎洿鏂帮級
   const currentGrayRects = glassDetails.filter(r => r.isRemain);
-  //寰幆浣欐枡鏁版嵁璺熷叏閮ㄧ殑瀵规瘮
-  currentGrayRects.forEach((_, index) => {
-    if (index >= remainingAreas.length) {
-      glassDetails.splice(index, 1);
-    }
+
+  // 5. 娓呴櫎鎵�鏈夌幇鏈夌殑浣欐枡鐭╁舰
+  // 鍏堟敹闆嗛潪浣欐枡鐭╁舰
+  const nonRemainRects = glassDetails.filter(r => !r.isRemain);
+
+  // 6. 閲嶆柊鏋勫缓鐜荤拑璇︽儏鏁扮粍
+  // 淇濈暀闈炰綑鏂欑煩褰�
+  const newGlassDetails = [...nonRemainRects];
+
+  // 娣诲姞鏂扮殑浣欐枡鐭╁舰
+  uniqueArr.forEach((area) => {
+    newGlassDetails.push({
+      x: area.x,
+      y: area.y,
+      width: area.width,
+      height: area.height,
+      isRemain: true
+    });
   });
 
-  uniqueArr.forEach((area, index) => {
-    if (index < currentGrayRects.length) {
-      currentGrayRects[index].x = Math.round(area.x);
-      currentGrayRects[index].y = Math.round(area.y);
-      currentGrayRects[index].width = Math.round(area.width);
-      currentGrayRects[index].height = Math.round(area.height);
-    } else {
-      glassDetails.push({
-        x: Math.round(area.x),
-        y: Math.round(area.y),
-        width: Math.round(area.width),
-        height: Math.round(area.height),
-        isRemain: true
-      });
-    }
-  });
+  // 7. 鏇存柊甯冨眬鐨勭幓鐠冭鎯�
+  layout.glassDetails = newGlassDetails;
 
-  mergeAdjacentGrayRects(glassDetails,layout.width, layout.height);
+  // 8. 鍚堝苟鐩搁偦鐨勪綑鏂欑煩褰�
+  mergeAdjacentGrayRects(layout.glassDetails, layout.width, layout.height);
 };
+
+
+const removeDuplicateAreas = (areas) => {
+  const result = [];
+
+  areas.forEach(area => {
+    // 妫�鏌ユ槸鍚︿笌宸插瓨鍦ㄧ殑鍖哄煙閲嶅彔鎴栫浉绛�
+    const isDuplicate = result.some(existingArea => {
+      return (
+          existingArea.x === area.x &&
+          existingArea.y === area.y &&
+          existingArea.width === area.width &&
+          existingArea.height === area.height
+      );
+    });
+
+    if (!isDuplicate) {
+      result.push(area);
+    }
+  });
+
+  return result;
+};
+
+
 
 //鏃嬭浆鏂规硶
 const rotateRect = (layoutIndex, rectIndex) => {
@@ -764,6 +968,25 @@
   }
 
   if (isValidRotation) {
+    // 鏇存柊glassPoint鍧愭爣锛堝鏋滃瓨鍦級
+    if (glassDetail.glassPoint && Array.isArray(glassDetail.glassPoint)) {
+      // 淇濆瓨鍘熷鐐瑰潗鏍�
+      const originalPoints = JSON.parse(JSON.stringify(glassDetail.glassPoint));
+
+      // 鏃嬭浆鐐瑰潗鏍囷紙浠ョ煩褰㈠乏涓婅涓哄師鐐圭殑鏃嬭浆锛�
+      glassDetail.glassPoint.forEach((point, index) => {
+        // 璁$畻鐩稿浜庣煩褰㈠乏涓婅鐨勫潗鏍�
+        const relX = originalPoints[index].X - originalState.x;
+        const relY = originalPoints[index].Y - originalState.y;
+
+        // 鏃嬭浆90搴﹀悗鐨勫潗鏍囷紙椤烘椂閽堬級
+        point.X = originalState.x + relY;
+        point.Y = originalState.y + (originalState.width - relX);
+        // 娣诲姞绮惧害鎺у埗
+        point.X = parseFloat(point.X.toFixed(2));
+        point.Y = parseFloat(point.Y.toFixed(2));
+      });
+    }
     adjustGrayRectangles(layoutIndex);
   } else {
     glassDetail.width = originalState.width;
@@ -827,6 +1050,11 @@
     return;
   }
 
+
+  // 淇濆瓨鍘熷鍧愭爣
+  const originalX = glassDetail.x;
+  const originalY = glassDetail.y;
+
   switch (direction) {
     case 'up':
       glassDetail.y += maxStep;
@@ -858,6 +1086,19 @@
   }
 
   if (isValidMove) {
+    // 鏇存柊glassPoint鍧愭爣
+    if (glassDetail.glassPoint && Array.isArray(glassDetail.glassPoint)) {
+      const offsetX = glassDetail.x - originalX;
+      const offsetY = glassDetail.y - originalY;
+
+      glassDetail.glassPoint.forEach(point => {
+        point.X += offsetX;
+        point.Y += offsetY;
+        // 娣诲姞绮惧害鎺у埗
+        point.X = parseFloat(point.X.toFixed(2));
+        point.Y = parseFloat(point.Y.toFixed(2));
+      });
+    }
     adjustGrayRectangles(layoutIndex);
   } else {
     glassDetail.x = originalState.x;
@@ -882,56 +1123,78 @@
 };
 
 //閲嶆柊璁$畻浣欐枡鍧愭爣浠ュ強灏哄1
-const calculateRemainingAreas = (totalWidth, totalHeight, obstacles) => {
-  let remaining = [{ x: 0, y: 0, width: totalWidth, height: totalHeight }];
-  obstacles.forEach(glassDetail => {
-    remaining = cutRemainingAreas(remaining, glassDetail,totalWidth,totalHeight);
-  });
-  return remaining;
-};
+// const calculateRemainingAreas = (totalWidth, totalHeight, obstacles) => {
+//   let remaining = [{ x: 0, y: 0, width: totalWidth, height: totalHeight }];
+//   obstacles.forEach(glassDetail => {
+//     remaining = cutRemainingAreas(remaining, glassDetail,totalWidth,totalHeight);
+//   });
+//   return remaining;
+// };
 
 //閲嶆柊璁$畻浣欐枡鍧愭爣浠ュ強灏哄2
-const cutRemainingAreas = (remainingAreas, obstacle,totalWidth,totalHeight) => {
+const cutRemainingAreas = (remainingAreas, obstacle, totalWidth, totalHeight) => {
   const newRemaining = [];
-  remainingAreas.forEach(area => {
-    if (checkOverlap(area, obstacle)) {
-      if (obstacle.x > area.x) {
-        newRemaining.push({
-          x: area.x,
-          y: area.y,
-          width: obstacle.x - area.x,
-          height: area.height
-        });
-      }
-      if (obstacle.x + obstacle.width < area.x + area.width) {
-        newRemaining.push({
-          x: obstacle.x + obstacle.width,
-          y: area.y,
-          width: area.width - (obstacle.x + obstacle.width - area.x),
-          height: area.height
-        });
-      }
-      if (obstacle.y > area.y) {
-        newRemaining.push({
-          x: area.x,
-          y: area.y,
-          width: area.width,
-          height: obstacle.y - area.y
-        });
-      }
-      if (obstacle.y + obstacle.height < area.y + area.height ) {
-          newRemaining.push({
-            x: area.x,
-            y: obstacle.y + obstacle.height,
-            width: area.width,
-            height: area.height - (obstacle.y + obstacle.height - area.y)
-          });
 
-      }
-    } else {
+  remainingAreas.forEach(area => {
+    // 濡傛灉闅滅鐗╀笌褰撳墠鍖哄煙娌℃湁閲嶅彔锛屼繚鐣欏師鍖哄煙
+    if (!checkOverlap(area, obstacle)) {
       newRemaining.push(area);
+      return;
+    }
+
+    // 璁$畻閲嶅彔鍖哄煙鐨勮竟鐣�
+    const overlapLeft = Math.max(area.x, obstacle.x);
+    const overlapRight = Math.min(area.x + area.width, obstacle.x + obstacle.width);
+    const overlapTop = Math.max(area.y, obstacle.y);
+    const overlapBottom = Math.min(area.y + area.height, obstacle.y + obstacle.height);
+
+    // 鐢熸垚鍥涗釜鍙兘鐨勬柊鍖哄煙锛堜笂銆佷笅銆佸乏銆佸彸锛�
+
+    // 涓婃柟鍖哄煙
+    if (overlapTop > area.y) {
+      newRemaining.push({
+        x: area.x,
+        y: area.y,
+        width: area.width,
+        height: overlapTop - area.y
+      });
+    }
+
+    // 涓嬫柟鍖哄煙
+    if (overlapBottom < area.y + area.height) {
+      newRemaining.push({
+        x: area.x,
+        y: overlapBottom,
+        width: area.width,
+        height: area.y + area.height - overlapBottom
+      });
+    }
+
+    // 宸︽柟鍖哄煙锛堜粎鍦ㄩ噸鍙犲尯鍩熺殑鍨傜洿鑼冨洿鍐咃級
+    if (overlapLeft > area.x) {
+      const regionTop = overlapTop;
+      const regionBottom = overlapBottom;
+      newRemaining.push({
+        x: area.x,
+        y: regionTop,
+        width: overlapLeft - area.x,
+        height: regionBottom - regionTop
+      });
+    }
+
+    // 鍙虫柟鍖哄煙锛堜粎鍦ㄩ噸鍙犲尯鍩熺殑鍨傜洿鑼冨洿鍐咃級
+    if (overlapRight < area.x + area.width) {
+      const regionTop = overlapTop;
+      const regionBottom = overlapBottom;
+      newRemaining.push({
+        x: overlapRight,
+        y: regionTop,
+        width: area.x + area.width - overlapRight,
+        height: regionBottom - regionTop
+      });
     }
   });
+
   return newRemaining;
 };
 
@@ -1084,6 +1347,15 @@
     // 鏇存柊鐭╁舰浣嶇疆
     glassDetail.x = newX;
     glassDetail.y = newY;
+
+    // 鏇存柊glassPoint鍧愭爣
+    if (glassDetail.glassPoint && Array.isArray(glassDetail.glassPoint)) {
+      glassDetail.glassPoint.forEach(point => {
+        point.X = width - point.X;
+        point.X = parseFloat(point.X.toFixed(2));
+        point.Y = parseFloat(point.Y.toFixed(2));
+      });
+    }
   });
 
   // 鏇存柊甯冨眬
@@ -1104,6 +1376,16 @@
 
     // 鏇存柊鐭╁舰浣嶇疆
     glassDetail.y = newY;
+
+    // 鏇存柊glassPoint鍧愭爣
+    if (glassDetail.glassPoint && Array.isArray(glassDetail.glassPoint)) {
+      glassDetail.glassPoint.forEach(point => {
+        point.Y = height - point.Y;
+        // 娣诲姞绮惧害鎺у埗
+        point.X = parseFloat(point.X.toFixed(2));
+        point.Y = parseFloat(point.Y.toFixed(2));
+      });
+    }
   });
 
   // 鏇存柊甯冨眬
@@ -1215,4 +1497,17 @@
 .context-menu div:hover {
   background-color: #f0f0f0;
 }
+
+.folder-header {
+  font-weight: bold;
+}
+
+.folder-header:hover {
+  background-color: #d0d0d0 !important;
+}
+
+.folder-content {
+  border-left: 2px solid #ccc;
+  margin-left: 5px;
+}
 </style>

--
Gitblit v1.8.0