guanchunjie 3 years ago
parent
commit
3d25a3b91a
3 changed files with 46 additions and 2 deletions
  1. 1 1
      package.json
  2. 44 1
      src/components/inputModules/common/TreeView.vue
  3. 1 0
      src/views/courseView.vue

+ 1 - 1
package.json

@@ -85,4 +85,4 @@
     "npm": ">= 3.0.0"
   },
   "license": "MIT"
-}
+}

+ 44 - 1
src/components/inputModules/common/TreeView.vue

@@ -77,7 +77,14 @@ export default {
   components: {
     Tree: Tree.mixPlugins([Fold, Draggable]),
   },
-  props: ["changeId", "emptyQustion", "bookId", "tryFree", "changeTreeData"],
+  props: [
+    "changeId",
+    "emptyQustion",
+    "bookId",
+    "tryFree",
+    "changeTreeData",
+    "currentTreeID",
+  ],
   data() {
     return {
       treeData: [],
@@ -102,9 +109,45 @@ export default {
       activeIndex: "", // 高亮节点
       nodeLevel: "", // 高亮节点的level
       nodeName: "",
+      pidList:[],
     };
   },
+  watch: {
+    // 监听预览页面翻页的变化 树组件做出相同的操作
+    async currentTreeID(newval, oldval) {
+      if (newval) {
+        this.activeIndex = newval;
+        await this.unfoldData(this.activeIndex, this.treeData);
+        await this.unfoldFather(this.treeData);
+      }
+    },
+  },
   methods: {
+    // 递归找到当前节点的所有父节点
+    unfoldData(activeIndex, data, index, child) {
+      data.forEach((item, i) => {
+        if (item.id == activeIndex) {
+          this.pidList.push(item.pid);
+          if (Object.prototype.toString.call(index).indexOf("Number") != -1) {
+            this.pidList.push(child.pid);
+          }
+        } else if (item.children) {
+          this.unfoldData(activeIndex, item.children, i, item);
+        }
+      });
+    },
+    // 展示父节点
+    unfoldFather(data) {
+      data.forEach((item, i) => {
+        this.pidList.forEach((p) => {
+          if (item.id == p) {
+            item.$folded = false;
+          } else if (item.children) {
+            this.unfoldFather(item.children);
+          }
+        });
+      });
+    },
     foldAll() {
       if (this.$refs.tree !== undefined) {
         this.$refs.tree.foldAll();

+ 1 - 0
src/views/courseView.vue

@@ -9,6 +9,7 @@
           :book-id="bookId"
           :change-id="changeId"
           :changeTreeData="changeTreeData"
+          :currentTreeID="chapterId"
         />
       </div>
       <div id="data-screen" class="inner">