1
0
tangning преди 3 дни
родител
ревизия
1cbff8c79f
променени са 2 файла, в които са добавени 19 реда и са изтрити 3 реда
  1. 14 2
      src/view/case/photos/canvas-photo-editor.js
  2. 5 1
      src/view/case/photos/index.vue

+ 14 - 2
src/view/case/photos/canvas-photo-editor.js

@@ -348,10 +348,10 @@ export class CanvasPhotoEditor {
     console.log('pageIndex', this.indexing, this.indexingNum)
   }
   moveItem(arr, fromIndex, toIndex) {
-    let newtoIndex = fromIndex < toIndex ? toIndex : toIndex - 1;
+    let newtoIndex = fromIndex < toIndex ? toIndex-1 : toIndex;
     const newArr = [...arr]
     const item = newArr.splice(fromIndex, 1)[0]
-    newArr.splice(toIndex, 0, item)
+    newArr.splice(newtoIndex, 0, item)
     return newArr
   }
   handleMouseLeave() {
@@ -949,6 +949,15 @@ export class CanvasPhotoEditor {
    * @param {Object} layout - 布局配置,包含宽高和位置信息
    * @param {string} photoId - 图片ID
    */
+  /**
+   * 在指定位置绘制单张照片
+   *
+   * @param {CanvasRenderingContext2D} ctx - Canvas 2D 绘图上下文
+   * @param {number} pageX - 页面起始 X 坐标
+   * @param {number} itemY - 项目起始 Y 坐标
+   * @param {Object} layout - 布局配置对象,包含 x、y、width、height 等属性
+   * @param {string} photoId - 照片的唯一标识 ID
+   */
   renderSinglePhoto(ctx, pageX, itemY, layout, photoId) {
     const photo = this.photos.find(p => p.id === photoId)
     // if (!photo) return
@@ -1060,6 +1069,9 @@ export class CanvasPhotoEditor {
           newPages.push({...currentPage, list: list, })
       }
     })
+    if(newPages.length > 0 && newPages.length != this._pages.length){//需要补位
+      newPages = newPages.concat(Array(4 - newPages.length).fill({...currentPage, list: []}));
+    }
     this.pages = newPages.length > 0 ? newPages : this._pages
     this.resetPosition()
     return this.pages

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

@@ -493,6 +493,10 @@ const autoLayout = () => {
     selectedPhotos.value = []; // 清空已选照片
     selectedPhotosbf.value = []; // 清空已选照片
     editor.value.selectedPageIndex = -1;
+    editor.value.selectedPageItem = {
+      index: -1,
+      pageIndex: -1,
+    };
   }
   // editor.value.drawAllPages()
 };
@@ -576,7 +580,6 @@ const handleDragOver = (e) => {
 
 // 拖拽放下
 const handleDrop = async (e) => {
-  e.preventDefault();
   if (!draggedPhoto.value || !editor.value) return;
   const check = await editor.value.checkIndexing();
 
@@ -606,6 +609,7 @@ const handleDrop = async (e) => {
   // 重新绘制
   editor.value.pages = pages.value;
   editor.value.drawAllPages(photos.value);
+  e.preventDefault();
 };
 
 /**