廖井涛
2025-12-03 54d3fc3ec46edab0f39c91608a15497ec5103e4e
Merge branch 'master' of http://10.153.19.25:10105/r/ERP_override
1个文件已修改
244 ■■■■ 已修改文件
north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue 244 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue
@@ -53,10 +53,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">
@@ -108,9 +104,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);
@@ -344,9 +340,9 @@
//点击小片
const handleRectClick = (layoutIndex, rectIndex) => {
  if (dragging.value) {
    return;
  }
  // if (dragging.value) {
  //   return;
  // }
  focusIndex.value = { layoutIndex, rectIndex };
  emit('rectClicked', layoutIndex, rectIndex);
@@ -535,122 +531,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
//   };
// };
  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 (!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 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 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];