From 565c2993dd86054c034cd2c3974e768474d809df Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期三, 29 五月 2024 19:19:21 +0800
Subject: [PATCH] Merge branch 'master' of http://182.92.203.7:2001/r/testbookLayout

---
 src/books/childHealth/view/content/index.vue |  137 +++++++++++++++++++++++++++++----------------
 1 files changed, 88 insertions(+), 49 deletions(-)

diff --git a/src/books/childHealth/view/content/index.vue b/src/books/childHealth/view/content/index.vue
index 3c07077..9bc3114 100644
--- a/src/books/childHealth/view/content/index.vue
+++ b/src/books/childHealth/view/content/index.vue
@@ -5,7 +5,7 @@
       :style="{
         fontSize: fontSize ? fontSize + 'px' : '16px',
         transform: `scale(${pageZoom ? pageZoom : 1})`,
-        transformOrigin: 'center top',
+        transformOrigin: 'center top'
       }"
     >
       <pageHeader
@@ -115,6 +115,7 @@
       loadPageObserver: null,
       loadPageList: [],
       questionData: {},
+      renderSignMap: {}
     };
   },
   computed: {
@@ -123,7 +124,7 @@
     },
     pageZoom() {
       return this.$store.state.qiankun.scale / 100;
-    },
+    }
   },
   watch: {
     showCatalogList: {
@@ -134,7 +135,7 @@
         ) {
           // 璋冪敤鐖跺眰鏂规硶
           this.$store.state.qiankun.catalogChange({
-            showCatalogList: newVal,
+            showCatalogList: newVal
           });
         }
         // 鍚姩椤电爜瑙傚療
@@ -172,12 +173,14 @@
         },
         // 娓叉煋绗旇銆侀珮浜�佸垝绾�
         renderSign: (type, data) => {
-          this.renderSign(type, data);
+          // 鍥犱负璋冩暣涓洪〉闈㈡噿鍔犺浇锛屾墍浠ユ覆鏌撴爣璁颁篃闇�瑕佹寜鐓ч〉闈㈣繘琛屽鐞嗭紝鍏堝偍瀛樻暟鎹紝椤甸潰鍔犺浇瀹屾垚鍐嶆覆鏌撳搴旂殑鏍囪锛�
+          this.handelSignData(type, data);
+          // this.renderSign(type, data);
         },
         // 鍒犻櫎绗旇銆侀珮浜�佸垝绾�
         delSign: (data) => {
           this.delSign(data);
-        },
+        }
       });
     }
 
@@ -186,13 +189,13 @@
     this.observer = new IntersectionObserver(this.pageChangeCallback, {
       root: null, // 鎸囧畾鏍瑰厓绱狅紝杩欓噷璁句负 null锛岃〃绀洪�夊彇鏁翠釜瑙嗙獥浣滀负鏍瑰厓绱犮��
       rootMargin: "0px", // 鎸囧畾鏍瑰厓绱犵殑杈圭晫锛岃繖閲岃涓� "0px"锛岃〃绀烘牴鍏冪礌鐨勮竟鐣屽拰瑙嗙獥鐨勮竟鐣岄噸鍚�
-      threshold: 0.5, // 鎸囧畾浜ゅ弶姣斾緥锛岃繖閲岃涓� 0.5锛岃〃绀哄綋鐩爣鍏冪礌涓�鍗婃垨鏇村鏄剧ず鍦ㄨ绐椾腑鏃惰Е鍙戝洖璋冨嚱鏁般��
+      threshold: 0.5 // 鎸囧畾浜ゅ弶姣斾緥锛岃繖閲岃涓� 0.5锛岃〃绀哄綋鐩爣鍏冪礌涓�鍗婃垨鏇村鏄剧ず鍦ㄨ绐椾腑鏃惰Е鍙戝洖璋冨嚱鏁般��
     });
 
     this.loadPageObserver = new IntersectionObserver(this.loadPageCallback, {
       root: null, // 鎸囧畾鏍瑰厓绱狅紝杩欓噷璁句负 null锛岃〃绀洪�夊彇鏁翠釜瑙嗙獥浣滀负鏍瑰厓绱犮��
       rootMargin: "0px", // 鎸囧畾鏍瑰厓绱犵殑杈圭晫锛岃繖閲岃涓� "0px"锛岃〃绀烘牴鍏冪礌鐨勮竟鐣屽拰瑙嗙獥鐨勮竟鐣岄噸鍚�
-      threshold: 0, // 鎸囧畾浜ゅ弶姣斾緥锛岃繖閲岃涓� 0.5锛岃〃绀哄綋鐩爣鍏冪礌涓�鍗婃垨鏇村鏄剧ず鍦ㄨ绐椾腑鏃惰Е鍙戝洖璋冨嚱鏁般��
+      threshold: 0 // 鎸囧畾浜ゅ弶姣斾緥锛岃繖閲岃涓� 0.5锛岃〃绀哄綋鐩爣鍏冪礌涓�鍗婃垨鏇村鏄剧ず鍦ㄨ绐椾腑鏃惰Е鍙戝洖璋冨嚱鏁般��
     });
 
     // 鍚姩椤电爜瑙傚療
@@ -203,21 +206,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, 10);
+    //   setTimeout(() => {
+    //     this.renderSign("Highlight", {
+    //       id: "2ACA9359",
+    //       txt: "棰樹竴瀛︿範涓婚涓� 杩愬姩",
+    //       page: "10",
+    //       type: "Highlight",
+    //       color: "#F5E12A"
+    //     });
+    // setTimeout(() => {
+    //   this.delSign({
+    //     ids: ["2ACA9359"]
+    //   });
+    // }, 2000);
+    //   }, 5000);
     // }, 1000);
   },
   methods: {
@@ -276,7 +279,7 @@
           this.showCatalogList = [
             this.catalogLength - 2,
             this.catalogLength - 1,
-            this.catalogLength,
+            this.catalogLength
           ];
         } else {
           this.showCatalogList = [catalog - 1, catalog, catalog + 1];
@@ -297,6 +300,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 = (
@@ -307,29 +318,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;
+            }
+          }
         }
       }
     },
@@ -511,7 +541,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"
@@ -540,7 +570,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();
@@ -609,8 +648,8 @@
     chapterTen,
     chapterEleven,
     chapterTwelve,
-    chapterThirteen,
-  },
+    chapterThirteen
+  }
 };
 </script>
 

--
Gitblit v1.9.1