Bladeren bron

表格不显示拼音时的调整 把前后标点包在一起

natasha 3 dagen geleden
bovenliggende
commit
1b43009b66

+ 0 - 1
src/views/book/courseware/preview/components/new_word/NewWordPreview.vue

@@ -2582,7 +2582,6 @@ export default {
           this.$set(this.multilingualTextList, item.type, chunkedArr);
         });
       }
-      console.log(this.data);
     },
     handleChangeTab() {
       this.wordShow = !this.wordShow;

+ 326 - 5
src/views/book/courseware/preview/components/table/TablePreview.vue

@@ -243,7 +243,252 @@
                       </template>
                     </template>
                     <template v-else>
-                      <template v-if="col.rich_text_list && col.rich_text_list.length !== 0">
+                      <template v-if="col.new_rich_text_list && col.new_rich_text_list.length !== 0">
+                        <div
+                          v-for="(item, index) in col.new_rich_text_list"
+                          :key="index"
+                          class="pinyin-text pinyin-text-sentence"
+                          :class="[
+                            index === 0 ? 'pinyin-text-left' : '',
+                            item.type === 'audio' ? 'pinyin-text-audio' : '',
+                            item.type === 'newline' ? 'pinyin-text-br' : '',
+                          ]"
+                        >
+                          <!-- 文字块:包含 word_list -->
+                          <span
+                            v-if="item.type === 'text'"
+                            :key="'text-' + index"
+                            class="pinyin-sentence"
+                            :style="[
+                              { 'align-items': data.property.pinyin_position === 'top' ? 'flex-end' : 'flex-start' },
+                            ]"
+                          >
+                            <span v-for="(word, wIndex) in item.new_text_list" :key="wIndex" class="pinyin-text">
+                              <span v-if="word.isShow" class="table-words-box">
+                                <span
+                                  v-if="
+                                    item.new_text_list[wIndex - 1] &&
+                                    item.new_text_list[wIndex - 1].text &&
+                                    firstFhlist.indexOf(item.new_text_list[wIndex - 1].text) > -1 &&
+                                    item.new_text_list[wIndex - 2] &&
+                                    item.new_text_list[wIndex - 2].text &&
+                                    firstFhlist.indexOf(item.new_text_list[wIndex - 2].text) > -1
+                                  "
+                                  :style="{
+                                    flexDirection:
+                                      data.property.pinyin_position === 'top' ? 'column' : 'column-reverse',
+                                    'align-items': getWordAlignItems(item.new_text_list[wIndex - 2], item),
+                                    ...item.new_text_list[wIndex - 2].last_styleObj,
+                                  }"
+                                >
+                                  <span class="py-char" :style="getCharStyle(item.new_text_list[wIndex - 2], item)">{{
+                                    convertText(item.new_text_list[wIndex - 2].text).trim()
+                                      ? convertText(item.new_text_list[wIndex - 2].text)
+                                      : '&nbsp;'
+                                  }}</span>
+                                </span>
+                                <span
+                                  v-if="
+                                    item.new_text_list[wIndex - 1] &&
+                                    item.new_text_list[wIndex - 1].text &&
+                                    firstFhlist.indexOf(item.new_text_list[wIndex - 1].text) > -1
+                                  "
+                                >
+                                  <span
+                                    :style="{
+                                      flexDirection:
+                                        data.property.pinyin_position === 'top' ? 'column' : 'column-reverse',
+                                      'align-items': getWordAlignItems(item.new_text_list[wIndex - 1], item),
+                                      ...item.new_text_list[wIndex - 1].last_styleObj,
+                                    }"
+                                  >
+                                    <span class="py-char" :style="getCharStyle(item.new_text_list[wIndex - 1], item)">{{
+                                      convertText(item.new_text_list[wIndex - 1].text).trim()
+                                        ? convertText(item.new_text_list[wIndex - 1].text)
+                                        : '&nbsp;'
+                                    }}</span>
+                                  </span>
+                                </span>
+                                <span v-if="word.type === 'text'">
+                                  <span
+                                    :style="{
+                                      flexDirection:
+                                        data.property.pinyin_position === 'top' ? 'column' : 'column-reverse',
+                                      'align-items': getWordAlignItems(word, item),
+                                      ...word.last_styleObj,
+                                    }"
+                                  >
+                                    <span class="py-char" :style="getCharStyle(word, item)">{{
+                                      convertText(word.text).trim() ? convertText(word.text) : '&nbsp;'
+                                    }}</span>
+                                  </span>
+                                </span>
+                                <template v-else-if="word.type === 'input'">
+                                  <template v-if="data.property.fill_type === fillTypeList[0].value">
+                                    <el-input
+                                      :key="index"
+                                      v-model="word.value"
+                                      :disabled="disabled"
+                                      :class="[...computedAnswerClass(word, i, j)]"
+                                      :style="getInputStyle(item.styleObj, word)"
+                                    />
+                                  </template>
+                                  <template v-else-if="data.property.fill_type === fillTypeList[1].value">
+                                    <el-popover :key="index" placement="top" trigger="click">
+                                      <div class="word-list">
+                                        <span
+                                          v-for="{ content, mark } in data.word_list"
+                                          :key="mark"
+                                          class="word-item"
+                                          @click="handleSelectWord(content, mark, word)"
+                                        >
+                                          {{ convertText(content) }}
+                                        </span>
+                                      </div>
+
+                                      <el-input
+                                        slot="reference"
+                                        v-model="word.value"
+                                        :readonly="true"
+                                        :class="[...computedAnswerClass(word, i, j)]"
+                                        :style="getInputStyle(item.styleObj, word)"
+                                      />
+                                    </el-popover>
+                                  </template>
+
+                                  <template v-else-if="data.property.fill_type === fillTypeList[2].value">
+                                    <span :key="j" class="write-click" @click="handleWriteClick(word)">
+                                      <img
+                                        v-show="word.write_base64"
+                                        style="background-color: #f4f4f4"
+                                        :src="word.write_base64"
+                                        alt="write-show"
+                                      />
+                                    </span>
+                                  </template>
+
+                                  <template v-else-if="data.property.fill_type === fillTypeList[3].value">
+                                    <SoundRecordBox
+                                      ref="record"
+                                      :key="j"
+                                      type="mini"
+                                      :many-times="false"
+                                      class="record-box"
+                                      :answer-record-list="data.audio_answer_list"
+                                      :task-model="isJudgingRightWrong ? 'ANSWER' : ''"
+                                      :attrib="data.unified_attrib"
+                                      @handleWav="handleMiniWav($event, word)"
+                                    />
+                                  </template>
+                                </template>
+                                <template
+                                  v-if="
+                                    item.new_text_list[wIndex + 1] &&
+                                    item.new_text_list[wIndex + 1].text &&
+                                    chsFhList.indexOf(item.new_text_list[wIndex + 1].text) > -1
+                                  "
+                                >
+                                  <span>
+                                    <span
+                                      :style="{
+                                        flexDirection:
+                                          data.property.pinyin_position === 'top' ? 'column' : 'column-reverse',
+                                        'align-items': getWordAlignItems(item.new_text_list[wIndex + 1], item),
+                                        ...item.new_text_list[wIndex + 1].last_styleObj,
+                                      }"
+                                    >
+                                      <span
+                                        class="py-char"
+                                        :style="getCharStyle(item.new_text_list[wIndex + 1], item)"
+                                        >{{
+                                          convertText(item.new_text_list[wIndex + 1].text).trim()
+                                            ? convertText(item.new_text_list[wIndex + 1].text)
+                                            : '&nbsp;'
+                                        }}</span
+                                      >
+                                    </span>
+                                  </span>
+                                  <span
+                                    v-if="
+                                      item.new_text_list[wIndex + 2] &&
+                                      item.new_text_list[wIndex + 2].text &&
+                                      chsFhList.indexOf(item.new_text_list[wIndex + 2].text) > -1
+                                    "
+                                  >
+                                    <span
+                                      :style="{
+                                        flexDirection:
+                                          data.property.pinyin_position === 'top' ? 'column' : 'column-reverse',
+                                        'align-items': getWordAlignItems(item.new_text_list[wIndex + 2], item),
+                                        ...item.new_text_list[wIndex + 2].last_styleObj,
+                                      }"
+                                    >
+                                      <span
+                                        class="py-char"
+                                        :style="getCharStyle(item.new_text_list[wIndex + 2], item)"
+                                        >{{
+                                          convertText(item.new_text_list[wIndex + 2].text).trim()
+                                            ? convertText(item.new_text_list[wIndex + 2].text)
+                                            : '&nbsp;'
+                                        }}</span
+                                      >
+                                    </span>
+                                  </span>
+                                </template>
+                              </span>
+                            </span>
+                          </span>
+                          <!-- 图片块 -->
+                          <div
+                            v-else-if="item.type === 'image'"
+                            :key="'image-' + index"
+                            :style="item.containerStyle"
+                            class="image-container"
+                          >
+                            <img
+                              :src="item.src"
+                              :alt="item.alt"
+                              :width="item.width"
+                              :height="item.height"
+                              :style="item.imageStyle"
+                              class="inline-image"
+                            />
+                          </div>
+                          <!-- 视频块 -->
+                          <div
+                            v-else-if="item.type === 'video'"
+                            :key="'video-' + index"
+                            :style="item.containerStyle"
+                            class="video-container"
+                          >
+                            <video
+                              :poster="item.poster"
+                              :width="item.width"
+                              :height="item.height"
+                              :style="item.mediaStyle"
+                              controls
+                              class="inline-video"
+                            >
+                              <source :src="item.src" :type="item.videoType" />
+                              您的浏览器不支持视频播放
+                            </video>
+                          </div>
+                          <!-- 音频块 -->
+                          <div
+                            v-else-if="item.type === 'audio'"
+                            :key="'audio-' + index"
+                            :style="item.containerStyle"
+                            class="audio-container"
+                          >
+                            <audio :src="item.src" :style="item.mediaStyle" controls class="inline-audio">
+                              您的浏览器不支持音频播放
+                            </audio>
+                          </div>
+                          <!-- 换行符 -->
+                          <br v-else-if="item.type === 'newline'" :key="'newline-' + index" />
+                        </div>
+                      </template>
+                      <template v-else-if="col.rich_text_list && col.rich_text_list.length !== 0">
                         <div
                           v-for="(item, index) in col.rich_text_list"
                           :key="index"
@@ -1000,7 +1245,31 @@ export default {
       writeMark: '',
       isHasInput: false,
       statusList: ['normal', 'tick', 'cross'],
-      chsFhList: [',', '。', '”', ':', '》', '?', '!', ';', '#', '、', '’', ')', '〕', '〕〕', '〉'],
+      chsFhList: [
+        ',',
+        '。',
+        '”',
+        ':',
+        '》',
+        '?',
+        '!',
+        ';',
+        '#',
+        '、',
+        '’',
+        ')',
+        '〕',
+        '〕〕',
+        '〉',
+        ',',
+        '.',
+        ';',
+        '?',
+        '!',
+        ':',
+        '>',
+      ],
+      firstFhlist: ['(', '“', '‘', '〔', '〔〔', '〈', '《', "'", '<'],
     };
   },
   computed: {
@@ -1316,8 +1585,8 @@ export default {
       }
 
       // 如果该文字块有着重点标记,应用到字符上
-      if (block.hasEmphasisDot) {
-        const letterSpacing = block.styleObj?.letterSpacing || '0';
+      if (block.hasEmphasisDot || word.last_hasEmphasisDot) {
+        const letterSpacing = word.last_hasEmphasisDot ? word.last_styleObj : block.styleObj?.letterSpacing || '0';
         const letterSpacingValue = parseFloat(letterSpacing) || 0;
 
         baseStyle['border-bottom'] = 'none';
@@ -1343,7 +1612,10 @@ export default {
     },
     // 如果汉字有字间距,拼音与汉字左对齐,如果没有则居中对齐
     getWordAlignItems(word, block) {
-      const letterSpacing = block.styleObj?.letterSpacing;
+      const letterSpacing =
+        word.last_styleObj && word.last_styleObj.letterSpacing
+          ? word.last_styleObj.letterSpacing
+          : block.styleObj?.letterSpacing;
       if (letterSpacing && letterSpacing !== '0' && letterSpacing !== '0px') {
         return 'flex-start';
       }
@@ -1545,8 +1817,57 @@ export default {
           if (items.cell && items.cell.isCross && this.data.answer_lists[index][indexs].crossAnswer !== 'normal') {
             this.isHasInput = true;
           }
+          // 将rich_text_list的内容连续word_list组合到一起
+          if (items.rich_text_list) {
+            let new_arr = [];
+            let new_text_list = [];
+            items.rich_text_list.forEach((li, index) => {
+              if (li.type === 'text') {
+                if (li.word_list) {
+                  li.word_list.forEach((lis) => {
+                    lis.last_hasEmphasisDot = li.hasEmphasisDot;
+                    lis.last_index = li.index;
+                    lis.last_oldIndex = li.oldIndex;
+                    lis.last_paragraphIndex = li.paragraphIndex;
+                    lis.last_styleObj = li.styleObj;
+                    lis.last_type = li.type;
+                    lis.isShow = this.mergeWordSymbol(lis.text);
+                    new_text_list.push(lis);
+                  });
+                }
+                // 如果循环到最后把上一段的文字框存进去
+                if (index === items.rich_text_list.length - 1) {
+                  new_arr.push({
+                    type: 'text',
+                    new_text_list,
+                  });
+                  new_text_list = [];
+                }
+              } else {
+                // 如果循环到最后把上一段的文字框存进去或者new_text_obj有值的时候存进去
+                if (index === items.rich_text_list.length - 1 || new_text_list.length !== 0) {
+                  new_arr.push({
+                    type: 'text',
+                    new_text_list,
+                  });
+                  new_text_list = [];
+                }
+                new_arr.push(li);
+              }
+            });
+            this.$set(items, 'new_rich_text_list', new_arr);
+          }
         });
       });
+      // console.log(this.data);
+    },
+    // 计算标点符号是否显示
+    mergeWordSymbol(text) {
+      if (this.chsFhList.indexOf(text) > -1 || this.firstFhlist.indexOf(text) > -1) {
+        return false;
+      } else {
+        return true;
+      }
     },
     // 计算单元格是否显示
     computedTableCellShow() {