Przeglądaj źródła

图片导出线条偏移

tangning 8 godzin temu
rodzic
commit
eb970bb164

+ 10 - 4
src/view/case/photos/canvas-photo-editor.js

@@ -1251,6 +1251,7 @@ export class CanvasPhotoEditor {
         }
       })
     }
+    // this.saveHistory()
     this.pages = newPages
     this.selectedPageIndex = Math.min(this.selectedPageIndex, this.pages.length - 1)
     if(this.selectedPageItem.index == -1){
@@ -1396,6 +1397,7 @@ export class CanvasPhotoEditor {
       indexingLineList: [...this.indexingLineList], // 保存标引线信息,以便恢复时使用
     });
     this.currentIndex++;
+    console.log("saveHistory", this.history, this.currentIndex);
     if (this.history.length > 5) {
       this.history.shift(); // 删除最早的一条
       // this.currentIndex--;
@@ -1679,7 +1681,7 @@ exportPagesAsImages(paperType = "a4", name, fileType = 'pdf') {
       const pageCanvas = document.createElement("canvas");
       let pageWidth = this.pageWidth
       if(paperType === "four"){
-        pageWidth = pageWidth / (724/840)
+        pageWidth = pageWidth * (724/840)
       }
       pageCanvas.width = pageWidth * DPR * (paperType === "a3" ? 2 : paperType === "a4" ? 1 : 4);
       pageCanvas.height = this.pageHeight * DPR * 1;
@@ -1733,10 +1735,14 @@ exportPagesAsImages(paperType = "a4", name, fileType = 'pdf') {
               ctx.clip();
 
               const s = Math.min(coord.width / img.width, coord.height / img.height);
-              const w = img.width * s;
+                let w = img.width * s;
               const h = img.height * s;
-              const x = coord.x + (coord.width - w) / 2;
+                let x = coord.x + (coord.width - w) / 2;
               const y = coord.y + (coord.height - h) / 2;
+              if(paperType == 'four'){
+                  w = w / (724/840)
+                  x = x * (724/840)
+                }
               ctx.drawImage(img, x, y, w, h);
               ctx.restore();
             }
@@ -1786,7 +1792,7 @@ exportPagesAsImages(paperType = "a4", name, fileType = 'pdf') {
             ctx.lineJoin = 'round';
 
             // 页面全局偏移(核心修正)
-            const pageOffsetX = pageIndex * (pageWidth + this.pageMargin);
+            const pageOffsetX = pageIndex * (this.pageWidth + this.pageMargin);
 
             // 绘制连线
             ctx.beginPath();

+ 1 - 5
src/view/case/photos/index.vue

@@ -631,18 +631,14 @@ const handleDrop = async (e) => {
   // 获取拖拽到的页面和位置
   const position = editor.value.getPhotoPositionInPage(e);
   const { pageIndex, itemIndex } = position;
-  console.log("getPhotoPositionInPage", position, );
 
   if (pageIndex === -1 || itemIndex === -1) return;
   
-  console.log("handleDrop", pages);
   // 更新页面数据
   const newPages = [...pages.value];
   // 确保页面数组存在
-  console.log("handleDrop", newPages);
   if (!newPages[pageIndex]) newPages[pageIndex] = [];
   // 确保位置足够
-  console.log("handleDrop", newPages[pageIndex], itemIndex);
   while (newPages[pageIndex].list.length <= itemIndex) {
     newPages[pageIndex].list.push("");
   }
@@ -652,7 +648,6 @@ const handleDrop = async (e) => {
   // 放入照片ID
   newPages[pageIndex].list[itemIndex] = draggedPhoto.value.id;
   newPages[pageIndex].item[itemIndex] = draggedPhoto.value;
-  console.log("handleDrop", position, newPages[pageIndex], draggedPhoto.value);
 
   // 同步数据
   pages.value = newPages;
@@ -661,6 +656,7 @@ const handleDrop = async (e) => {
 
   // 重新绘制
   editor.value.pages = pages.value;
+  editor.value.saveHistory();
   editor.value.drawAllPages(photos.value);
   e.preventDefault();
 };