natasha преди 1 седмица
родител
ревизия
35ac32a397
променени са 1 файла, в които са добавени 88 реда и са изтрити 8 реда
  1. 88 8
      src/views/dictionary/searchDetail.vue

+ 88 - 8
src/views/dictionary/searchDetail.vue

@@ -66,18 +66,28 @@
         </div>
       </div>
       <div
-        class="definition-list"
-        v-if="searchWordinfo.paraList && searchWordinfo.paraList.length > 0"
+        v-for="(item, index) in searchWordinfo.data"
+        :key="index"
+        class="definition-box"
       >
+        <label v-if="searchWordinfo.data.length > 1">{{
+          item.word_name
+        }}</label>
         <div
-          class="definition-item"
-          v-for="(itemD, indexD) in searchWordinfo.paraList"
-          :key="indexD"
+          class="definition-list"
+          v-if="item.symbols[0].parts && item.symbols[0].parts.length > 0"
         >
-          <label>{{ itemD.part }}</label>
-          <p>{{ itemD.means.join(";") }}</p>
+          <div
+            class="definition-item"
+            v-for="(itemD, indexD) in item.symbols[0].parts"
+            :key="indexD"
+          >
+            <label>{{ itemD.part }}</label>
+            <p>{{ itemD.means.join(";") }}</p>
+          </div>
         </div>
       </div>
+
       <el-divider content-position="left">例句</el-divider>
       <div class="number-list" v-if="sentKwicData">
         <div
@@ -245,6 +255,7 @@ export default {
         pronunciations: [],
         paraList: [],
         hasVoice: false,
+        data: [],
       },
       kwicFlag: false,
       activeIndex: 0, // 高亮索引
@@ -384,6 +395,15 @@ export default {
         if (res.status === 1) {
           this.searchWordinfo.word = this.searchQuery;
           let list = res.data ? res.data : [];
+          list = this.uniqueArray(list, "word_name");
+          // 排序
+          for (let i = 0; i < list.length; i++) {
+            if (list[i].word_name === this.searchWordinfo.word) {
+              list.unshift(list[i]); // 将元素移到数组最前面
+              list.splice(i + 1, 1); // 删除原位置的元素
+              break;
+            }
+          }
           for (let i = 0; i < list.length; i++) {
             if (list[i].word_name === this.searchWordinfo.word) {
               if (list[i].symbols && list[i].symbols.length > 0) {
@@ -395,6 +415,12 @@ export default {
                       : "",
                     sound: list[i].symbols[0].ph_am_mp3,
                   });
+                } else {
+                  this.searchWordinfo.pronunciations.push({
+                    region: "uk",
+                    phonetic: list[i].symbols[0].ph_am,
+                    sound: list[i].symbols[0].ph_am_mp3,
+                  });
                 }
                 if (list[i].symbols[0].ph_en || list[i].symbols[0].ph_en_mp3) {
                   this.searchWordinfo.pronunciations.push({
@@ -404,12 +430,48 @@ export default {
                       : "",
                     sound: list[i].symbols[0].ph_en_mp3,
                   });
+                } else {
+                  this.searchWordinfo.pronunciations.push({
+                    region: "us",
+                    phonetic: list[i].symbols[0].ph_en,
+                    sound: list[i].symbols[0].ph_en_mp3,
+                  });
                 }
 
-                this.searchWordinfo.paraList = list[i].symbols[0].parts;
+                // this.searchWordinfo.paraList = list[i].symbols[0].parts;
+              }
+            } else {
+              if (list[i].symbols && list[i].symbols.length > 0) {
+                this.searchWordinfo.pronunciations[0] = {
+                  region: "uk",
+                  phonetic: this.searchWordinfo.pronunciations[0].phonetic
+                    ? this.searchWordinfo.pronunciations[0].phonetic
+                    : list[i].symbols[0].ph_am
+                    ? "/" + list[i].symbols[0].ph_am + "/"
+                    : "",
+                  sound: this.searchWordinfo.pronunciations[0].sound
+                    ? this.searchWordinfo.pronunciations[0].sound
+                    : list[i].symbols[0].ph_am_mp3
+                    ? list[i].symbols[0].ph_am_mp3
+                    : "",
+                };
+                this.searchWordinfo.pronunciations[1] = {
+                  region: "us",
+                  phonetic: this.searchWordinfo.pronunciations[1].phonetic
+                    ? this.searchWordinfo.pronunciations[1].phonetic
+                    : list[i].symbols[0].ph_en
+                    ? "/" + list[i].symbols[0].ph_en + "/"
+                    : "",
+                  sound: this.searchWordinfo.pronunciations[1].sound
+                    ? this.searchWordinfo.pronunciations[1].sound
+                    : list[i].symbols[0].ph_en_mp3
+                    ? list[i].symbols[0].ph_en_mp3
+                    : "",
+                };
               }
             }
           }
+          this.searchWordinfo.data = list;
         }
       });
     },
@@ -843,6 +905,16 @@ export default {
       newarr.push(arr3);
       return newarr;
     },
+    // 去重
+    uniqueByProperty(arr, key) {
+      return Array.from(new Set(arr.map((item) => item[key])));
+    },
+    uniqueArray(arr, key) {
+      return arr.filter(
+        (value, index, self) =>
+          index === self.findIndex((t) => t[key] === value[key])
+      );
+    },
   },
   //生命周期 - 创建完成(可以访问当前this实例)
   created() {
@@ -1003,6 +1075,14 @@ export default {
         line-height: 24px;
       }
     }
+    .definition-box {
+      display: flex;
+      gap: 10px;
+      label {
+        font-size: 18px;
+        line-height: 24px;
+      }
+    }
     .definition-list {
       padding-bottom: 8px;
       .definition-item {