ソースを参照

切换课件时重新计算生词预览的行宽

natasha 2 週間 前
親
コミット
00e85e3d24

+ 40 - 18
src/views/book/courseware/preview/components/new_word/NewWordPreview.vue

@@ -1650,7 +1650,26 @@ export default {
               setTimeout(() => {
                 let totalWidth = document.querySelector('.newWord-preview').clientWidth;
                 this.width = `${totalWidth - (this.data.property.sn_display_mode === 'true' ? 15 : 0) - 1}`;
-              }, 200);
+                this.rowWidth = 0;
+                this.data.col_width.forEach((item, index) => {
+                  if (
+                    this.data.property.pinyin_position &&
+                    (this.data.property.pinyin_position == 'top' || this.data.property.pinyin_position == 'bottom')
+                  ) {
+                    if (index < 2) {
+                      this.rowWidth = this.rowWidth > Number(item.value) ? this.rowWidth : Number(item.value);
+                    } else {
+                      this.rowWidth += this.colHasContent[index] ? Number(item.value) : 0;
+                    }
+                  } else {
+                    this.rowWidth += this.colHasContent[index] ? Number(item.value) : 0;
+                  }
+                });
+                this.rowWidth += 132;
+                if (this.rowWidth < this.width - 2) {
+                  this.rowWidth = this.width - 2;
+                }
+              }, 50);
             });
 
             this.dataHeight = this.$refs.previewContainer ? this.$refs.previewContainer.style.height : 0;
@@ -1684,7 +1703,26 @@ export default {
       setTimeout(() => {
         let totalWidth = document.querySelector('.newWord-preview').clientWidth;
         this.width = `${totalWidth - (this.data.property.sn_display_mode === 'true' ? 15 : 0) - 1}`;
-      }, 200);
+        this.rowWidth = 0;
+        this.data.col_width.forEach((item, index) => {
+          if (
+            this.data.property.pinyin_position &&
+            (this.data.property.pinyin_position == 'top' || this.data.property.pinyin_position == 'bottom')
+          ) {
+            if (index < 2) {
+              this.rowWidth = this.rowWidth > Number(item.value) ? this.rowWidth : Number(item.value);
+            } else {
+              this.rowWidth += this.colHasContent[index] ? Number(item.value) : 0;
+            }
+          } else {
+            this.rowWidth += this.colHasContent[index] ? Number(item.value) : 0;
+          }
+        });
+        this.rowWidth += 132;
+        if (this.rowWidth < this.width - 2) {
+          this.rowWidth = this.width - 2;
+        }
+      }, 50);
     });
 
     this.dataHeight = this.$refs.previewContainer ? this.$refs.previewContainer.style.height : 0;
@@ -1820,7 +1858,6 @@ export default {
         this.is_list = true;
       }
       this.hasVoice = false;
-      this.rowWidth = 0;
       this.colHasContent = [];
       this.showObj = {
         pinyin: true,
@@ -1856,21 +1893,6 @@ export default {
           this.colHasContent.push(Boolean(str_col));
         });
       }
-      this.data.col_width.forEach((item, index) => {
-        if (
-          this.data.property.pinyin_position &&
-          (this.data.property.pinyin_position == 'top' || this.data.property.pinyin_position == 'bottom')
-        ) {
-          if (index < 2) {
-            this.rowWidth = this.rowWidth > Number(item.value) ? this.rowWidth : Number(item.value);
-          } else {
-            this.rowWidth += this.colHasContent[index] ? Number(item.value) : 0;
-          }
-        } else {
-          this.rowWidth += this.colHasContent[index] ? Number(item.value) : 0;
-        }
-      });
-      this.rowWidth += 132;
 
       this.is_change = true;
       setTimeout(() => {