Browse Source

修改校对拼音高亮问题

natasha 3 days ago
parent
commit
8e3d685871

+ 12 - 3
src/components/PinyinText.vue

@@ -8,18 +8,27 @@
         :style="{ 'align-items': pinyinPosition === 'top' ? 'flex-end' : 'flex-start' }"
       >
         <div v-for="(item, k) in sentence" :key="k" class="pinyin-text">
-          <span v-if="pinyinPosition === 'top'" class="pinyin" :class="{ active: visible && word_index == k }">
+          <span
+            v-if="pinyinPosition === 'top'"
+            class="pinyin"
+            :class="{ active: visible && word_index == k && paragraph_index === i && sentence_index === j }"
+          >
             {{ item.pinyin.replace(/\s+/g, '') }}
           </span>
           <span
-            :class="{ active: visible && word_index == k }"
+            :class="{ active: visible && word_index == k && paragraph_index === i && sentence_index === j }"
             :title="isPreview ? '' : '点击校对'"
             :style="{ ...item.activeTextStyle, cursor: isPreview ? '' : 'pointer' }"
             @click="correctPinyin(item, i, j, k)"
           >
             {{ item.text }}
           </span>
-          <span v-if="pinyinPosition === 'bottom'" class="pinyin">{{ item.pinyin.replace(/\s+/g, '') }}</span>
+          <span
+            v-if="pinyinPosition === 'bottom'"
+            class="pinyin"
+            :class="{ active: visible && word_index == k && paragraph_index === i && sentence_index === j }"
+            >{{ item.pinyin.replace(/\s+/g, '') }}</span
+          >
         </div>
       </div>
     </div>

+ 41 - 6
src/views/book/courseware/create/components/question/table/Table.vue

@@ -199,7 +199,23 @@ export default {
         if (isEnable(val) && text) {
           this.data.paragraph_list_parameter.text = text;
           this.data.paragraph_list_parameter.is_first_sentence_first_hz_pinyin_first_char_upper_case =
-            val.is_first_sentence_first_hz_pinyin_first_char_upper_case;
+            this.data.property.is_first_sentence_first_hz_pinyin_first_char_upper_case;
+          this.crateParsedTextInfoPinyin(text);
+        }
+      },
+      deep: true,
+    },
+    'data.property.is_first_sentence_first_hz_pinyin_first_char_upper_case': {
+      handler(val) {
+        let text = '';
+        this.data.option_list.forEach((item) => {
+          item.forEach((items) => {
+            text += items.content.replace(/<[^>]+>/g, '') + '\n';
+          });
+        });
+        if (text) {
+          this.data.paragraph_list_parameter.text = text;
+          this.data.paragraph_list_parameter.is_first_sentence_first_hz_pinyin_first_char_upper_case = val;
           this.crateParsedTextInfoPinyin(text);
         }
       },
@@ -295,20 +311,39 @@ export default {
         this.data.property.is_first_sentence_first_hz_pinyin_first_char_upper_case;
       CrateParsedTextInfo_Pinyin(this.data.paragraph_list_parameter).then((res) => {
         if (res.parsed_text) {
-          this.data.paragraph_list = res.parsed_text.paragraph_list;
+          const mergedData = res.parsed_text.paragraph_list.map((outerArr, i) =>
+            outerArr.map((innerArr, j) =>
+              innerArr.map((newItem, k) => {
+                // 从 originalData 中找到对应的项
+                const originalItem = this.data.paragraph_list[i]?.[j]?.[k];
+
+                // 如果 originalItem 有 activeTextStyle,就合并到 newItem
+                if (originalItem?.activeTextStyle) {
+                  return {
+                    ...newItem,
+                    activeTextStyle: originalItem.activeTextStyle,
+                  };
+                }
+                // 否则直接返回 newItem
+                return newItem;
+              }),
+            ),
+          );
+          this.data.paragraph_list = mergedData;
         }
       });
     },
     // 填充校对后的拼音
-    fillCorrectPinyin(selectContent, tonePinyin, i, j, k) {
+    fillCorrectPinyin(selectContent, i, j, k) {
       this.data.paragraph_list_parameter.pinyin_proofread_word_list.push({
         paragraph_index: i,
         sentence_index: j,
         word_index: k,
-        word: selectContent,
-        pinyin: tonePinyin,
+        word: selectContent.text,
+        pinyin: selectContent.pinyin,
       });
-      this.data.paragraph_list[i][j][k].pinyin = tonePinyin;
+      if (selectContent.pinyin) this.data.paragraph_list[i][j][k].pinyin = selectContent.pinyin;
+      this.data.paragraph_list[i][j][k].activeTextStyle = selectContent.activeTextStyle;
     },
     // 思维导图数据
     handleMindMap() {