Browse Source

提交代码

tangning 1 day ago
parent
commit
b2861e7091
1 changed files with 40 additions and 20 deletions
  1. 40 20
      src/view/case/photos/canvas-photo-editor.js

+ 40 - 20
src/view/case/photos/canvas-photo-editor.js

@@ -504,6 +504,7 @@ export class CanvasPhotoEditor {
 
     let endIindexing1 = {//默认同页面
       x: this.indexingStartX,
+      index: PhotoIndex.pageIndex,
       y: startInfo.itemIndex > PhotoIndex.itemIndex ? (coordinate.y + coordinate.height + 3) : coordinate.y - 3,
     }
     let ceY = PhotoIndex.itemIndex == 0 ? (mouseY - coordinate.y) : (coordinate.y + coordinate.height - mouseY)
@@ -526,17 +527,18 @@ export class CanvasPhotoEditor {
     }
     let points = [{
       x: this.indexingStartX,
+      index: oldPhotoIndex.pageIndex,
       y: this.indexingStartY,
     }, endIindexing1]
     if (PhotoIndex.pageIndex != oldPhotoIndex.pageIndex && (startInfo.count != PhotoIndex.count || startInfo.itemIndex != PhotoIndex.itemIndex)) {//需要折现换行
       let addPage = PhotoIndex.pageIndex > oldPhotoIndex.pageIndex ? PhotoIndex.pageIndex : oldPhotoIndex.pageIndex
       let newX = addPage * (this.pageWidth + this.pageMargin)
-      points.splice(1, 0, { x: newX, y: this.indexingStartY }, { x: newX, y: endIindexing1.y })
+      points.splice(1, 0, { x: newX, y: this.indexingStartY, index: oldPhotoIndex.pageIndex, }, { x: newX, y: endIindexing1.y, index: PhotoIndex.pageIndex, })
     }
     if (startInfo.count == 2 && startInfo.count == PhotoIndex.count && startInfo.itemIndex == PhotoIndex.itemIndex && (mouseX - coordinate.x) > ceY) {//同数量 同item
       console.log(startInfo, endIindexing1, coordinate, '坐标', mouseX, mouseY)
       let newY = PhotoIndex.itemIndex == 0 ? (coordinate.y - 30) : (coordinate.y + coordinate.height + 80)
-      points.splice(1, 0, { x: this.indexingStartX, y: newY }, { x: mouseX, y: newY })
+      points.splice(1, 0, { x: this.indexingStartX, y: newY, index: oldPhotoIndex.pageIndex, }, { x: mouseX, y: newY, index: PhotoIndex.pageIndex, })
     }
     this.tempArrow.start = null
     this.tempArrow.end = null
@@ -1575,6 +1577,7 @@ resizePageAndReflow(pages, pageIndex, itemValue) {
       })
       let fileName = name || "完整导出_" + Date.now();
       pdf.save(fileName + `.pdf`);
+      // this.drawAllPages();
       ElMessage.success("PDF导出成功!");
       return true
     } catch (err) {
@@ -1590,7 +1593,7 @@ resizePageAndReflow(pages, pageIndex, itemValue) {
       return false
     } finally {
       Object.assign(this, originalState);
-      // this.drawAllPages();
+      this.drawAllPages();
       loading.close();
     }
   }
@@ -1752,6 +1755,7 @@ resizePageAndReflow(pages, pageIndex, itemValue) {
 
           ctx.restore();
         });
+        ctx.save();
         this.renderIndexList(ctx, groupIndex, pageWidth, perSheet)
         ctx.restore();
         // 转图片并加入 ZIP
@@ -1777,20 +1781,22 @@ resizePageAndReflow(pages, pageIndex, itemValue) {
       return base64List;
   }
   renderIndexList(ctx, pageIndex, pageWith, perSheet = 1) {
+    const pageOffsetX = pageIndex * (this.pageWidth + this.pageMargin) * perSheet;
     this.indexingLineList.forEach(line => {
-      let { points, coordinate, indexingList } = line;
+      ctx.save();
+      const { points, coordinate, indexingList } = line;
       const startInfo = indexingList[0];
       const endInfo = indexingList[1];
 
       // 当前正在导出的是哪一页
-      // const currentIsStart = startInfo.pageIndex === pageIndex;
+      const currentEnd = Math.max(endInfo.pageIndex,startInfo.pageIndex)
+      const currentStart = Math.min(endInfo.pageIndex,startInfo.pageIndex)
       // const currentIsEnd = endInfo.pageIndex === pageIndex || startInfo.pageIndex === pageIndex;
       // if (isPdf && !currentIsStart && !currentIsEnd) return;
       // if (!isPdf && !currentIsEnd) return;
-      if((pageIndex*perSheet > endInfo.pageIndex || (pageIndex+1)*perSheet < endInfo.pageIndex) && (pageIndex*perSheet > startInfo.pageIndex || (pageIndex+1)*perSheet < startInfo.pageIndex)){
-        return;
-      }
-      ctx.save();
+      // if(currentStart<pageIndex*perSheet && currentEnd<pageIndex*perSheet || currentEnd>(pageIndex+1)*perSheet && currentStart>(pageIndex+1)*perSheet){
+      if(pageIndex*perSheet <= currentStart< (pageIndex + 1)*perSheet || pageIndex*perSheet < currentEnd<= (pageIndex + 1)*perSheet){
+        // return;
       ctx.strokeStyle = '#ff0000';
       ctx.fillStyle = '#ff0000';
       ctx.lineWidth = 2;
@@ -1798,34 +1804,47 @@ resizePageAndReflow(pages, pageIndex, itemValue) {
       ctx.lineJoin = 'round';
 
       // 页面全局偏移(核心修正)
-      const pageOffsetX = pageIndex * ((pageWith + 30) * perSheet);
-      // const pageOffsetX = pageIndex * (this.pageWidth + this.pageMargin) * perSheet;
+      // const pageOffsetX = pageIndex * ((pageWith + 30) * perSheet); + this.pageMargin
+      console.log(pageOffsetX, pageIndex, perSheet, this.pageWidth, 'pageOffsetX')
       // 绘制连线
       ctx.beginPath();
-      coordinate.x = coordinate.x - (Math.round(coordinate.x / this.pageWidth)*this.pageMargin);
+      let last = points[points.length - 1];
+      const newcoorindex = (Math.round(coordinate.x / this.pageWidth)) - (pageIndex*perSheet);
+      const newcoordinateX = coordinate.x - (newcoorindex*this.pageMargin) - pageOffsetX;
       points.forEach((p, i) => {
-        p.x = p.x - (Math.round(p.x / this.pageWidth)*this.pageMargin);
-        const x = p.x;
+        const newindex = (Math.round(p.x / this.pageWidth)) - (pageIndex*perSheet);
+        console.log(newindex, 'newindex')
+        const itemOffsetX = newindex>0?newindex*this.pageMargin:0;
+        // p.x = p.x  - pageOffsetX;
+        const x = p.x  - pageOffsetX - itemOffsetX;
         const y = p.y;
+        if(i == points.length - 1){
+          last = {
+            ...last,
+            x,
+          }
+        }
         i === 0 ? ctx.moveTo(x, y) : ctx.lineTo(x, y);
       });
+      console.log(...points, 'pageOffsetX1', pageOffsetX)
       ctx.stroke();
       // T型端线(只在终点页画)
       // if (currentIsEnd) {
-        const last = points[points.length - 1];
         ctx.beginPath();
         if (startInfo.count == endInfo.count && startInfo.count == 2 && startInfo.itemIndex == endInfo.itemIndex && points.length == 4) {
-          ctx.moveTo(coordinate.x, last.y);
-          ctx.lineTo((coordinate.x + coordinate.width), last.y);
+          ctx.moveTo(newcoordinateX, last.y);
+          ctx.lineTo((newcoordinateX + coordinate.width), last.y);
         } else if (startInfo.pageIndex === endInfo.pageIndex) {
-          ctx.moveTo(coordinate.x, last.y);
-          ctx.lineTo(coordinate.x + coordinate.width, last.y);
+          ctx.moveTo(newcoordinateX, last.y);
+          ctx.lineTo(newcoordinateX + coordinate.width, last.y);
         } else {
           ctx.moveTo(last.x, coordinate.y);
           ctx.lineTo(last.x, coordinate.y + coordinate.height);
         }
         ctx.stroke();
-      // }
+      }else{
+      console.log(currentEnd, currentStart,'pageIndex', pageIndex, 'perSheet', perSheet)
+      }
 
       ctx.restore();
     });
@@ -1863,6 +1882,7 @@ resizePageAndReflow(pages, pageIndex, itemValue) {
     } else {
       this.exportPagesAsImages(paperType, name);
     }
+    // this.drawAllPages();
     console.log('正在导出1');
   }
   async checkIndexing(mes = '此操作将会清除所有标引是否继续?', type = false) {