فهرست منبع

重新安装ui 修改上一页和下一页时 同步修改树型组件的节点展开

秦鹏 3 سال پیش
والد
کامیت
6f087d1c86
3فایلهای تغییر یافته به همراه47 افزوده شده و 3 حذف شده
  1. 2 2
      package.json
  2. 44 1
      src/components/inputModules/common/TreeView.vue
  3. 1 0
      src/views/courseView.vue

+ 2 - 2
package.json

@@ -18,7 +18,7 @@
     "@ztree/ztree_v3": "^3.5.46",
     "awe-dnd": "^0.3.4",
     "axios": "0.18.1",
-    "book-ui": "file:../GCLS-Book-question-ui/book-ui-0.1.8.tgz",
+    "book-ui": "file:../book-ui-0.1.11.tgz",
     "cnchar": "^3.0.1",
     "cnchar-all": "^3.0.1",
     "cnchar-order": "^3.0.1",
@@ -84,4 +84,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">