|
@@ -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,44 @@ 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();
|