2
0

4 Коммиты c4672e0c48 ... b9361665df

Автор SHA1 Сообщение Дата
  natasha b9361665df Merge branch 'lhd' 1 неделя назад
  dsy 7f2bf3f0dd 修复位置调整页中图片组件的序号显示在上方或下方时,序号那一行的高度没有被预留。手动拖拽高度,图片才恢复正常大小 1 неделя назад
  dsy 16eaa08bf1 Merge branch 'master' of http://60.205.254.193:3000/GCLS/eep_page 1 неделя назад
  dsy 4fd8ce096b 填空题弹窗的正确答案,显示拼音模式下,底部对齐文本与正确答案文本 1 неделя назад

+ 1 - 1
.env

@@ -11,4 +11,4 @@ VUE_APP_BookWebSI = '/GCLSBookWebSI/ServiceInterface'
 VUE_APP_EepServer = '/EEPServer/SI'
 
 #version
-VUE_APP_VERSION = '2026.11.25'
+VUE_APP_VERSION = '2026.11.26'

+ 43 - 9
src/views/book/courseware/preview/components/fill/FillPreview.vue

@@ -9,7 +9,7 @@
         :color="data.unified_attrib?.topic_color"
         :file-id="data.audio_file_id"
       />
-      <div class="fill-wrapper">
+      <div class="fill-wrapper" :class="{ 'without-pinyin': !isEnable(data.property.view_pinyin) }">
         <div class="fill-content">
           <template v-for="(group, gi) in groupedModelEssay">
             <span :key="`group-${gi}`" :style="groupStyle(group)">
@@ -148,6 +148,7 @@
         v-if="isShowJudgeCorrect"
         slot="right-answer"
         class="fill-wrapper"
+        :class="{ 'without-pinyin': !isEnable(data.property.view_pinyin) }"
         :style="{ '--fill-font-family': data.property.fill_font }"
       >
         <div class="fill-content">
@@ -373,9 +374,8 @@ export default {
     /**
      * 计算填空控件需要补偿的 margin-bottom。
      * 显示拼音时,拼音词块在底部补了 (line-height - 1)em 的行间留白,汉字底部相应上移;
-     * 不显示拼音时汉字按段落行高居中,只需补偿半行留白。
-     * 输入框需要使用相同补偿,才能与词级文本处于同一视觉基线。
-     * 预览页再按实际渲染微调:开启拼音 +6px,未开启拼音 +1px。
+     * 不显示拼音时使用 CSS 基线对齐,不需要行高补偿。
+     * 显示拼音时预览页在原有补偿基础上再微调 +6px。
      * 返回值默认用 em(随控件字号缩放);答案解析里的答案文字字号与输入框的 em 基准不同,
      * 同一个 calc 会算出不同的 px,此时传 toPixel 按输入框基准换算成 px,保证两处横线偏移一致。
      * @param {Object} li 填空块对象
@@ -383,6 +383,8 @@ export default {
      * @returns {String} 与拼音词块行间距一致的补偿值
      */
     resolveFillControlMargin(li, toPixel = false) {
+      if (!this.isEnable(this.data?.property?.view_pinyin)) return '0px';
+
       let lineHeight = '';
       (li?.rich_text_list || []).forEach((item) => {
         const match = String(item?.text || '').match(/line-height\s*:\s*([^;"']+)/i);
@@ -392,8 +394,8 @@ export default {
       if (!/^\d*\.?\d+$/.test(lineHeight)) lineHeight = '1.5';
 
       const ratio = Number(lineHeight);
-      const isShowPinyin = this.isEnable(this.data?.property?.view_pinyin);
-      const spacing = isShowPinyin ? ratio - 1 : (ratio - 1) / 2;
+      const spacing = ratio - 1;
+      // 根据行高计算基础偏移量,后续会在此基础上进行微调
       const lineHeightOffsets = [
         { ratio: 1, offset: -6 },
         { ratio: 1.2, offset: -3 },
@@ -413,7 +415,7 @@ export default {
         offset = lower.offset + ((ratio - lower.ratio) / (upper.ratio - lower.ratio)) * (upper.offset - lower.offset);
       }
       // 预览页在原有补偿基础上追加微调量
-      const totalOffset = offset + (isShowPinyin ? 6 : 1);
+      const totalOffset = offset + 6;
       // 按输入框的 em 基准(见样式里 .el-input 的 font-size)换算成 px,
       // 避免不同字号的元素用同一 em 算式却得到不同偏移
       if (toPixel) return `${Number((spacing * FILL_CONTROL_EM_BASIS_PX + totalOffset).toFixed(2))}px`;
@@ -718,8 +720,7 @@ export default {
       margin: 0 10px;
       margin-bottom: -2px;
 
-      // 显式固定 em 补偿的基准(element-ui 默认值):
-      // 模板传入的 marginBottom 是 em 单位,基准需与 resolveFillControlMargin 中的换算保持一致
+      // 显示拼音时,em 补偿的基准需与 resolveFillControlMargin 中的换算保持一致
       font-size: 14px;
       vertical-align: bottom;
 
@@ -776,6 +777,39 @@ export default {
       vertical-align: bottom;
       border-bottom: 1px solid $font-color;
     }
+
+    &.without-pinyin {
+      :deep .pinyin-area .pinyin-text,
+      .el-input,
+      .right-answer {
+        vertical-align: baseline;
+      }
+
+      .el-input {
+        align-items: flex-end;
+        font-family: var(--fill-font-family, 'arial'), sans-serif;
+        font-size: 16pt;
+        line-height: 1em;
+
+        // 输入框本身的基线位于边框,使用零宽字符提供文字基线。
+        &::before {
+          content: '\200b';
+        }
+      }
+
+      // 选词框与输入框共用一套盒模型:1em 高的盒子 + 文字贴底,
+      // 下边框即填空横线,文字底部与正文齐平;
+      // 零宽字符保证未选词时也有文字基线,选词前后行盒高度一致。
+      .select-content {
+        height: 1em;
+        line-height: 1em;
+        vertical-align: baseline;
+
+        &::before {
+          content: '\200b';
+        }
+      }
+    }
   }
 
   .record-box {

+ 45 - 70
src/views/book/courseware/preview/components/picture/PicturePreview.vue

@@ -104,24 +104,9 @@ export default {
       handler(val) {
         this.fileLen = val.file_list.length;
         if (this.fileLen === 0) return;
-        if (this.data.property.view_method === 'list') {
-          const ele = this.$refs.pictureAreaBox;
-          const sn_position = this.data.property.sn_position;
-          const viewMemo = this.isEnable(this.data.property.view_memo);
-          // 序号在左和右补齐序号高度,去掉padding(8*2)
-          if (sn_position.includes('left') || sn_position.includes('right')) {
-            this.elementWidth = viewMemo ? (ele.clientWidth - 16) * 0.8 : ele.clientWidth - 16;
-            this.elementHeight = ele.clientHeight;
-          } else {
-            this.elementWidth = viewMemo ? ele.clientWidth * 0.8 : ele.clientWidth;
-            this.elementHeight = ele.clientHeight;
-          }
-          // 统一图片播放模式位置调整和预览初始高度
-          // if (ele.clientHeight <= 0) {
-          //    this.elementHeight = this.data.min_height - 60;
-          // }
-
-          const mainEle = this.$refs.pictureArea;
+
+        const mainEle = this.$refs.pictureArea;
+        if (mainEle) {
           // 检查元素是否包含已知的类名
           mainEle.classList.forEach((className) => {
             // 排除已知的类名
@@ -132,25 +117,12 @@ export default {
           });
         }
 
-        if (this.data.property.view_method === 'independent') {
-          const ele = this.$refs.pictureAreaBox;
-          const sn_position = this.data.property.sn_position;
-          // 序号在左和右补齐序号高度,去掉padding(8*2)
-          if (sn_position.includes('left') || sn_position.includes('right')) {
-            this.elementWidth = ele.clientWidth - 16;
-            this.elementHeight = ele.clientHeight;
-          } else {
-            this.elementWidth = ele.clientWidth;
-            this.elementHeight = ele.clientHeight;
-          }
-          // 统一图片播放模式位置调整和预览初始高度
-          // if (ele.clientHeight <= 0) {
-          //    this.elementHeight = this.data.min_height - 60;
-          // }
-        }
-
-        this.elementHeight = Math.max(this.elementHeight, this.data.min_height);
-        this.$emit('handleHeightChange', this.id, `${this.elementHeight}px`);
+        // 序号位置/显示方式变化会改变组件内部布局,等 DOM 更新后再测量,否则量到的是切换前的布局
+        this.$nextTick(() => {
+          this.updateElementSize();
+          // 上报组件整体高度(含序号占用高度),否则图片会挤占序号的位置
+          this.$emit('handleHeightChange', this.id, `${this.elementHeight + this.getSerialNumberHeight()}px`);
+        });
       },
       deep: true,
     },
@@ -163,45 +135,17 @@ export default {
   },
   mounted() {
     this.$nextTick(() => {
-      const ele = this.$refs.pictureAreaBox;
-      if (!ele) return;
-      const sn_position = this.data.property.sn_position;
-      const viewMemo = this.isEnable(this.data.property.view_memo);
-      // 序号在左和右补齐序号高度,去掉padding(8*2)
-      if (sn_position.includes('left') || sn_position.includes('right')) {
-        this.elementWidth = viewMemo ? (ele.clientWidth - 16) * 0.8 : ele.clientWidth - 16;
-        this.elementHeight = ele.clientHeight;
-      } else {
-        this.elementWidth = viewMemo ? ele.clientWidth * 0.8 : ele.clientWidth;
-        this.elementHeight = ele.clientHeight;
-      }
       this.fileLen = this.data.file_list.length;
+      this.updateElementSize();
 
-      this.resizeObserver = new ResizeObserver((entries) => {
+      this.resizeObserver = new ResizeObserver(() => {
         if (!this.getDragStatus()) return;
         this.isResizing = true; // 标记为调整中
 
-        for (let entry of entries) {
-          window.requestAnimationFrame(() => {
-            const sn_position = this.data.property.sn_position;
-            const viewMemo = this.isEnable(this.data.property.view_memo);
-            // 序号在上方和下方减去序号高度,在左右去掉padding(8*2)
-            let w = viewMemo ? (entry.contentRect.width - 16) * 0.8 : entry.contentRect.width - 16;
-            let h = entry.contentRect.height;
-            if (sn_position.includes('top') || sn_position.includes('bottom')) {
-              w = viewMemo ? entry.contentRect.width * 0.8 : entry.contentRect.width;
-              h = entry.contentRect.height - 30;
-            }
-            if (this.elementWidth === w) {
-              this.elementHeight = h;
-            } else {
-              this.elementWidth = w;
-            }
-            this.elementHeight = Math.max(this.elementHeight, this.data.min_height);
-          });
-        }
+        // 拖拽调整期间按组件实际尺寸重新计算显示区域
+        window.requestAnimationFrame(() => this.updateElementSize());
 
-        // 防抖:100ms 后恢复监听
+        // 防抖:500ms 后恢复监听
         setTimeout(() => {
           this.isResizing = false;
         }, 500);
@@ -215,6 +159,34 @@ export default {
     }
   },
   methods: {
+    /**
+     * 序号占用的高度:序号高度 24 + 网格间距 6(序号在左右时不占用高度)
+     */
+    getSerialNumberHeight() {
+      const { sn_display_mode: snDisplayMode, sn_position: snPosition = '' } = this.data.property;
+      if (!this.isEnable(snDisplayMode)) return 0;
+      return snPosition.includes('top') || snPosition.includes('bottom') ? 30 : 0;
+    },
+    /**
+     * 按组件实际尺寸计算图片显示区域尺寸(高度不含序号占用的高度)
+     */
+    updateElementSize() {
+      const root = this.$refs.pictureArea;
+      const box = this.$refs.pictureAreaBox;
+      if (!root || !box) return;
+
+      const { view_method: viewMethod, view_memo: viewMemo, sn_position: snPosition = '' } = this.data.property;
+      const isSidePosition = snPosition.includes('left') || snPosition.includes('right');
+      const viewMemoEnable = viewMethod === 'list' && this.isEnable(viewMemo);
+      // 序号在左右时去掉 padding(8*2)
+      const boxWidth = isSidePosition ? box.clientWidth - 16 : box.clientWidth;
+
+      this.elementWidth = viewMemoEnable ? boxWidth * 0.8 : boxWidth;
+      this.elementHeight = Math.max(
+        root.clientHeight - this.getSerialNumberHeight(),
+        Number(this.data.min_height) || 0,
+      );
+    },
     getVideoItemStyle() {
       if (this.data.property.view_method !== 'independent') {
         return {};
@@ -301,6 +273,9 @@ export default {
 
   .main {
     position: relative;
+
+    // 保证图片内容不会撑高 1fr 行、挤占序号所占的行
+    min-height: 0;
     overflow: auto hidden !important;
 
     // Firefox 滚动条样式