From 36e0f739f354244d0e49ebfa457104ca710c4aff Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期四, 30 五月 2024 19:07:48 +0800
Subject: [PATCH] Merge branch 'master' of http://182.92.203.7:2001/r/testbookLayout

---
 src/books/lifeCare/index.vue |  143 ++++++++++++++++++++++++++++++++---------------
 1 files changed, 96 insertions(+), 47 deletions(-)

diff --git a/src/books/lifeCare/index.vue b/src/books/lifeCare/index.vue
index aebcdad..5571fec 100644
--- a/src/books/lifeCare/index.vue
+++ b/src/books/lifeCare/index.vue
@@ -47,6 +47,7 @@
         v-if="showCatalogList.indexOf(8) > -1"
         :showPageList="loadPageList"
         :questionData="questionData"
+        @eventSwdt="swdtChange"
       />
       <chapterEight
         v-if="showCatalogList.indexOf(9) > -1"
@@ -122,6 +123,10 @@
 import _ from "lodash";
 import getQuestionList from "@/assets/methods/examination";
 import testData from "./js/examinationList";
+import Swiper from "swiper/bundle";
+import "swiper/swiper-bundle.css";
+import Viewer from "viewerjs";
+import "viewerjs/dist/viewer.css";
 export default {
   data() {
     return {
@@ -135,6 +140,7 @@
       loadPageObserver: null,
       loadPageList: [],
       questionData: {},
+      renderSignMap: {},
     };
   },
   computed: {
@@ -167,7 +173,7 @@
           this.initObservation();
           this.initThemeColor();
         }, 500);
-      }
+      },
     },
     loadPageList: {
       handler(newVal, oldVal) {
@@ -176,12 +182,12 @@
           this.initSwiper();
           this.initViewer();
         }, 200);
-      }
-    }
+      },
+    },
   },
   mounted() {
     // 榛樿鍔犺浇绔犺妭
-    this.showCatalogList = [1];
+    this.showCatalogList = [8];
     // 婊氬姩鐩戝惉鑺傛祦
     this.throttledScrollHandler = _.throttle(
       this.scrollFun,
@@ -228,21 +234,21 @@
 
     // 娴嬭瘯椤甸潰璺宠浆
     // setTimeout(() => {
-      // this.gotoPage(1, 15);
-      //   setTimeout(() => {
-      //     this.renderSign("Note", {
-      //       id: "2ACA9359",
-      //       txt: "钀ュ吇绱犲拰鐑噺锛屾墠鑳�",
-      //       page: "100",
-      //       type: "Highlight",
-      //       color: "#F5E12A"
-      //     });
-      //     setTimeout(() => {
-      //       this.delSign({
-      //         ids: ["2ACA9359"]
-      //       });
-      //     }, 2000);
-      //   }, 1000);
+    // this.gotoPage(1, 15);
+    //   setTimeout(() => {
+    //     this.renderSign("Note", {
+    //       id: "2ACA9359",
+    //       txt: "钀ュ吇绱犲拰鐑噺锛屾墠鑳�",
+    //       page: "100",
+    //       type: "Highlight",
+    //       color: "#F5E12A"
+    //     });
+    //     setTimeout(() => {
+    //       this.delSign({
+    //         ids: ["2ACA9359"]
+    //       });
+    //     }, 2000);
+    //   }, 1000);
     // }, 1000);
   },
   methods: {
@@ -322,6 +328,14 @@
       }
     },
 
+    // 澶勭悊鏍囪鏁版嵁
+    handelSignData(type, data) {
+      if (!this.renderSignMap[type]) this.renderSignMap[type] = {};
+      if (!this.renderSignMap[type][data.page])
+        this.renderSignMap[type][data.page] = [];
+      this.renderSignMap[type][data.page].push(data);
+    },
+
     // 娓叉煋鏍囪
     renderSign(type, data) {
       const existence = (
@@ -332,29 +346,48 @@
         const pageDom = (
           this.container ? this.container : document
         ).querySelector(`[page="${data.page}"]`);
-        let reg = new RegExp(`${data.txt}`, "ig");
-        switch (type) {
-          case "Highlight":
-            // 楂樹寒
-            pageDom.innerHTML = pageDom.innerHTML.replace(
-              reg,
-              `<span datatype="Highlight" dataid="${data.id}" style="background: ${data.color};" class="highLight" onclick="signClick('Highlight','${data.id}','${data.chapterNum}')">${data.txt}</span>`
-            );
-            break;
-          case "Dashing":
-            // 鍒掔嚎
-            pageDom.innerHTML = pageDom.innerHTML.replace(
-              reg,
-              `<span datatype="Dashing" dataid="${data.id}" style="text-decoration-color:${data.color};" class="underline" onclick="signClick('Dashing','${data.id}','${data.chapterNum}')">${data.txt}</span>`
-            );
-            break;
-          case "Note":
-            // 绗旇
-            pageDom.innerHTML = pageDom.innerHTML.replace(
-              reg,
-              `<span datatype="Note" dataid="${data.id}" style="border-bottom-color:${data.color}" class="notesline" onclick="signClick('Note','${data.id}','${data.chapterNum}')" onmouseover="noteHover('Note','${data.id}','${data.chapterNum}')" onmouseout="noteOut('Note')">${data.txt}<img src="${NoteIcon}"/></span>`
-            );
-            break;
+        // 鍒涘缓 createTreeWalker 杩唬鍣紝鐢ㄤ簬閬嶅巻鏂囨湰鑺傜偣锛屼繚瀛樺埌涓�涓暟缁�
+        const treeWalker = document.createTreeWalker(
+          pageDom,
+          NodeFilter.SHOW_TEXT
+        );
+        const allTextNodes = [];
+        let currentNode = treeWalker.nextNode();
+        while (currentNode) {
+          allTextNodes.push(currentNode);
+          currentNode = treeWalker.nextNode();
+        }
+        for (let i = 0; i < allTextNodes.length; i++) {
+          const textDom = allTextNodes[i];
+          if (textDom.textContent.indexOf(data.txt) > -1) {
+            let reg = new RegExp(`${data.txt}`, "ig");
+            switch (type) {
+              case "Highlight":
+                // 楂樹寒
+                textDom.parentNode.innerHTML =
+                  textDom.parentNode.innerHTML.replace(
+                    reg,
+                    `<span datatype="Highlight" dataid="${data.id}" style="background: ${data.color};" class="highLight" onclick="signClick('Highlight','${data.id}','${data.chapterNum}')">${data.txt}</span>`
+                  );
+                break;
+              case "Dashing":
+                // 鍒掔嚎
+                textDom.parentNode.innerHTML =
+                  textDom.parentNode.innerHTML.replace(
+                    reg,
+                    `<span datatype="Dashing" dataid="${data.id}" style="text-decoration-color:${data.color};" class="underline" onclick="signClick('Dashing','${data.id}','${data.chapterNum}')">${data.txt}</span>`
+                  );
+                break;
+              case "Note":
+                // 绗旇
+                textDom.parentNode.innerHTML =
+                  textDom.parentNode.innerHTML.replace(
+                    reg,
+                    `<span datatype="Note" dataid="${data.id}" style="border-bottom-color:${data.color}" class="notesline" onclick="signClick('Note','${data.id}','${data.chapterNum}')" onmouseover="noteHover('Note','${data.id}','${data.chapterNum}')" onmouseout="noteOut('Note')">${data.txt}<img src="${NoteIcon}"/></span>`
+                  );
+                break;
+            }
+          }
         }
       }
     },
@@ -522,7 +555,7 @@
             this.$store.state.qiankun.pageChange({
               page: page,
               catalog: catalog,
-              text
+              text,
             });
           // const sections = Array.from(document.querySelectorAll(".section"));
           //sections锛氳幏鍙栨墍鏈夊叿鏈� .section 绫诲悕鐨勫厓绱狅紝骞惰浆鎹负鏁扮粍銆�
@@ -536,7 +569,7 @@
         if (entry.isIntersecting) {
           const target = entry.target;
           const page = target.getAttribute("page");
-          if (this.loadPageList.indexOf(page) == -1) {
+          if (this.loadPageList.indexOf(Number(page)) == -1) {
             const catalogDom = this.tool.getParentNodeByClassName(
               target,
               "chapter"
@@ -565,7 +598,16 @@
                 }
               }
             }
+            // 娣诲姞椤电爜
             this.loadPageList.push(Number(page));
+            // 娓叉煋杩欎竴椤电殑鏍囪
+            for (const key in this.renderSignMap) {
+              if (this.renderSignMap[key][page]) {
+                this.renderSignMap[key][page].forEach((item) => {
+                  this.renderSign(key, item);
+                });
+              }
+            }
             if (this.loadPageList.length > 5) {
               // 瓒呰繃5椤�
               this.loadPageList.shift();
@@ -585,7 +627,7 @@
           autoplay: {
             //鑷姩寮�濮�
             delay: 3000, //鏃堕棿闂撮殧
-            disableOnInteraction: false //*鎵嬪姩鎿嶄綔杞挱鍥惧悗涓嶄細鏆傚仠*
+            disableOnInteraction: false, //*鎵嬪姩鎿嶄綔杞挱鍥惧悗涓嶄細鏆傚仠*
           },
           paginationClickable: true,
           slidesPerView: 1, // 涓�缁勪笁涓�
@@ -593,7 +635,7 @@
           // 濡傛灉闇�瑕佸墠杩涘悗閫�鎸夐挳
           navigation: {
             nextEl: ".swiper-button-next",
-            prevEl: ".swiper-button-prev"
+            prevEl: ".swiper-button-prev",
           },
           // 绐楀彛鍙樺寲,閲嶆柊init,閽堝F11鍏ㄥ睆鍜屾斁澶х缉灏�,蹇呴』鍔�
           observer: true,
@@ -615,7 +657,7 @@
         new Viewer(dom, {
           navbar: true, // 鏄剧ず瀵艰埅鏍�
           toolbar: true, // 鏄剧ず宸ュ叿鏍�
-          title: true // 鏄剧ず鏍囬
+          title: true, // 鏄剧ず鏍囬
         });
       }
     },
@@ -670,6 +712,13 @@
         }
       }
     },
+    swdtChange(data) {
+      if (this.$store.state.qiankun && this.$store.state.qiankun.chooseWords) {
+        this.$store.state.qiankun.chooseWords({
+          type: data,
+        });
+      }
+    },
   },
   components: {
     front001,

--
Gitblit v1.9.1