1
0
tangning 17 tuntia sitten
vanhempi
commit
c8e70618fe
2 muutettua tiedostoa jossa 14 lisäystä ja 40 poistoa
  1. 13 39
      src/view/case/photos/canvas-photo-editor.js
  2. 1 1
      src/view/case/photos/index.vue

+ 13 - 39
src/view/case/photos/canvas-photo-editor.js

@@ -1008,55 +1008,29 @@ export class CanvasPhotoEditor {
   }
 
   // --- 页面操作 ---
-  autoLayout(selectedPhotos) {
+  autoLayout(selectedPhotos=[]) {
+    let newList = this.pages.flatMap(item => item.list.filter(i => i))
     const layout = this.getItemSize()
-    let newPages = this.pages.map(ele => {
-      ele.layoutMode = this.layoutMode
-      return ele
-    })
+    let newPages = []
     const pageX = this.pages.length * (this.pageWidth + this.pageMargin)
     let currentPage = {
       list: [],
       layoutMode: this.layoutMode, //页码布局类型
       coordinate: this.getCoordinate(pageX, layout), //坐标信息
     }
-    selectedPhotos.forEach((photoId, photoIndex) => {
-      currentPage.list.push(photoId)
-      let newlengt = currentPage.list.length
-      const firstNonEmptyIndex = newPages.findIndex(subArr => {
-        let oldSubArr = subArr.list.filter(i => i) || []
-        return oldSubArr.length < layout.count
-      });
-      if (firstNonEmptyIndex == -1) {//不存在新增页码
-        if (currentPage.list.length == layout.count || (photoIndex + 1) == selectedPhotos.length) {
-          newPages.push(currentPage)
-          currentPage = {
-            list: [],
-            layoutMode: this.layoutMode, //页码布局类型
-            coordinate: [], //坐标信息
-          }
-        } else {
-          // let newList = this.padArrayLength(currentPage.list, layout.count)
-          // newPages.push(currentPage)
-        }
-      } else {
-        let oldList = newPages[firstNonEmptyIndex].list.filter(i => i)
-        if (oldList.length == (layout.count - newlengt)) {
-          newPages[firstNonEmptyIndex] = {
-            ...newPages[firstNonEmptyIndex],
-            list: [...currentPage.list.filter(i => i), ...oldList]
-          }
-          currentPage = {
-            list: [],
-            layoutMode: this.layoutMode, //页码布局类型
-            coordinate: [], //坐标信息
-          }
-        }
+    let list = []
+    const newArr = [...newList, ...selectedPhotos]
+    console.log(newArr, selectedPhotos, 'newArr')
+    newArr.forEach((photoId, photoIndex) => {
+      list.push(photoId)
+      if(list.length == layout.count){
+          newPages.push({...currentPage, list: list, })
+          list = []
+      }else if(photoIndex == newArr.length -1){//最后一条直接写入
+          newPages.push({...currentPage, list: list, })
       }
     })
-    // if (currentPage.list.length > 0) newPages.push(currentPage)
     this.pages = newPages.length > 0 ? newPages : [{ list: [], }]
-    // this.selectedPageIndex = 0
     this.resetPosition()
     return this.pages
   }

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

@@ -141,7 +141,7 @@
           </div>
         </div>
 
-        <div class="auto-layout-bar">
+        <div class="auto-layout-bar" v-if="selectedPhotos.length">
           <div>
             已选 <span>{{ selectedPhotos.length }}</span> 张照片
           </div>