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

---
 package-lock.json                            |    8 ++--
 src/main.js                                  |    1 
 src/App.vue                                  |    2 
 src/books/childHealth/view/content/index.vue |   96 ++++++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 98 insertions(+), 9 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index d962b1e..b23307d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
 {
-  "name": "temp-book",
-  "version": "0.1.0",
+  "name": "testbook",
+  "version": "1.0.0",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
-      "name": "temp-book",
-      "version": "0.1.0",
+      "name": "testbook",
+      "version": "1.0.0",
       "dependencies": {
         "axios": "^1.6.8",
         "core-js": "^3.8.3",
diff --git a/src/App.vue b/src/App.vue
index 8d95a78..e0274e7 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -27,7 +27,7 @@
     };
   },
   async created() {
-    this.activeBook = await this.config.getBookConfig();
+    this.activeBook = this.thisBookConfig;
     console.log('鍥句功',this.activeBook);
     if (this.$store.state.qiankun,this.$store.state.qiankun.getBookConfig) {
       this.$store.state.qiankun.getBookConfig({
diff --git a/src/books/childHealth/view/content/index.vue b/src/books/childHealth/view/content/index.vue
index cd70098..702c809 100644
--- a/src/books/childHealth/view/content/index.vue
+++ b/src/books/childHealth/view/content/index.vue
@@ -1,8 +1,6 @@
 <template>
   <div class="page-main" @scroll="throttledScrollHandler">
-    <div
-      class="page-content"
-    >
+    <div class="page-content">
       <pageHeader v-if="showCatalogList.indexOf(0) > -1"></pageHeader>
       <chapterOne v-if="showCatalogList.indexOf(1) > -1"></chapterOne>
       <chapterTwo v-if="showCatalogList.indexOf(2) > -1"></chapterTwo>
@@ -67,6 +65,7 @@
         // 鍚姩椤电爜瑙傚療
         setTimeout(() => {
           this.initObservation();
+          this.initThemeColor();
         }, 500);
       }
     }
@@ -109,6 +108,7 @@
     // 鍚姩椤电爜瑙傚療
     setTimeout(() => {
       this.initObservation();
+      this.initThemeColor();
     }, 500);
 
     // 娴嬭瘯椤甸潰璺宠浆
@@ -206,6 +206,7 @@
         console.log("绔犺妭閿欒锛�");
       }
     },
+
     // 娓叉煋鏍囪
     renderSign(type, data) {
       const existence = (
@@ -273,8 +274,8 @@
       const sections = (
         this.container ? this.container : document
       ).querySelectorAll(".page-box");
-      //observer 瑙傚療姣忎釜鍏冪礌锛屼互渚垮湪瀹冧滑杩涘叆鎴栫寮�瑙嗙獥鏃惰Е鍙戝洖璋冨嚱鏁般��
       sections.forEach((section) => {
+        //observer 瑙傚療姣忎釜鍏冪礌锛屼互渚垮湪瀹冧滑杩涘叆鎴栫寮�瑙嗙獥鏃惰Е鍙戝洖璋冨嚱鏁般��
         const isObserver = section.getAttribute("observer");
         if (!isObserver) {
           this.observer.observe(section);
@@ -282,6 +283,93 @@
         }
       });
     },
+    initThemeColor() {
+      // 鑾峰彇鍚勭闇�瑕佷富棰樿壊鐨勮妭鐐�
+      const colorDom = (
+        this.container ? this.container : document
+      ).querySelectorAll(".theme-color");
+      const backgroundColorDom = (
+        this.container ? this.container : document
+      ).querySelectorAll(".theme-back");
+      const borderColorDom = (
+        this.container ? this.container : document
+      ).querySelectorAll(".theme-border");
+      // 鑾峰彇閰嶇疆鐨勪富棰樿壊
+      const bookThemeColor =
+        this.thisBookConfig && this.thisBookConfig.bookThemeColor
+          ? this.thisBookConfig.bookThemeColor
+          : null;
+      const chapterThemeColor =
+        this.thisBookConfig && this.thisBookConfig.chapterThemeColor
+          ? this.thisBookConfig.chapterThemeColor
+          : null;
+      const pageThemeColor =
+        this.thisBookConfig && this.thisBookConfig.pageThemeColor
+          ? this.thisBookConfig.pageThemeColor
+          : null;
+      colorDom.forEach((domItem) => {
+        // 鑾峰彇绔犺妭銆侀〉鐮�
+        let pageDom = this.getParentWithClass(domItem, "page-box");
+        let chapterDom = this.getParentWithClass(domItem, "chapter");
+        let page, chapterNum;
+        if (pageDom) page = pageHtml.getAttribute("page");
+        if (chapterDom) chapterNum = chapterDom.getAttribute("num");
+        // 鍚戜笂鍖归厤涓婚鑹�
+        const themeColor =
+          page && pageThemeColor && pageThemeColor[page]
+            ? pageThemeColor[page]
+            : chapterNum && chapterThemeColor && chapterThemeColor[chapterNum]
+            ? chapterThemeColor[chapterNum]
+            : bookThemeColor;
+        if (themeColor) {
+          domItem.style.color = themeColor;
+        }
+      });
+      backgroundColorDom.forEach((domItem) => {
+        // 鑾峰彇绔犺妭銆侀〉鐮�
+        let pageDom = this.getParentWithClass(domItem, "page-box");
+        let chapterDom = this.getParentWithClass(domItem, "chapter");
+        let page, chapterNum;
+        if (pageDom) page = pageHtml.getAttribute("page");
+        if (chapterDom) chapterNum = chapterDom.getAttribute("num");
+        // 鍚戜笂鍖归厤涓婚鑹�
+        const themeColor =
+          page && pageThemeColor && pageThemeColor[page]
+            ? pageThemeColor[page]
+            : chapterNum && chapterThemeColor && chapterThemeColor[chapterNum]
+            ? chapterThemeColor[chapterNum]
+            : bookThemeColor;
+        if (themeColor) {
+          domItem.style.backgroundColor = themeColor;
+        }
+      });
+      borderColorDom.forEach((domItem) => {
+        // 鑾峰彇绔犺妭銆侀〉鐮�
+        let pageDom = this.getParentWithClass(domItem, "page-box");
+        let chapterDom = this.getParentWithClass(domItem, "chapter");
+        let page, chapterNum;
+        if (pageDom) page = pageHtml.getAttribute("page");
+        if (chapterDom) chapterNum = chapterDom.getAttribute("num");
+        // 鍚戜笂鍖归厤涓婚鑹�
+        const themeColor =
+          page && pageThemeColor && pageThemeColor[page]
+            ? pageThemeColor[page]
+            : chapterNum && chapterThemeColor && chapterThemeColor[chapterNum]
+            ? chapterThemeColor[chapterNum]
+            : bookThemeColor;
+        if (themeColor) {
+          domItem.style.borderColor = themeColor;
+        }
+      });
+    },
+    getParentWithClass(element, className) {
+      while (element.parentElement) {
+        element = element.parentElement;
+        if (element.classList.contains(className)) {
+          return element;
+        }
+      }
+    },
     pageChangeCallback(entries, observer) {
       //entries锛氫唬琛ㄨ瀵熷埌鐨勭洰鏍囧厓绱犵殑闆嗗悎銆� observer锛氫唬琛ㄨ瀵熻�呭璞°��
       entries.forEach((entry) => {
diff --git a/src/main.js b/src/main.js
index 0a4b258..f7438ce 100644
--- a/src/main.js
+++ b/src/main.js
@@ -10,6 +10,7 @@
 // 鑷畾涔夐厤缃�
 import config from "@/assets/js/config";
 Vue.prototype.config = config;
+Vue.prototype.thisBookConfig = await config.getBookConfig();
 
 // 璇锋眰澶勭悊
 import MG from "@/assets/js/middleGround/WebMiddleGroundApi";

--
Gitblit v1.9.1