添加节点后保持文件夹打开状态
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<el-container>
|
<el-container>
|
||||||
<el-aside>
|
<el-aside v-loading="loading" :visible.sync="loading">
|
||||||
<el-input placeholder="输入关键字进行过滤" v-model="filterText" size="small" style="margin-bottom: 10px" clearable/>
|
<el-input placeholder="输入关键字进行过滤" v-model="filterText" size="small" style="margin-bottom: 10px" clearable/>
|
||||||
<el-tree class="filter-tree" :data="groupList" @node-click="nodeClick" node-key="id" highlight-current :expand-on-click-node="false" :filter-node-method="filterNode" ref="tree" :default-expanded-keys="[0]">
|
<el-tree class="filter-tree" :data="groupList" @node-click="nodeClick" node-key="id" highlight-current :expand-on-click-node="false" :filter-node-method="filterNode" ref="tree" :default-expanded-keys="[0]">
|
||||||
<span class="custom-tree-node" slot-scope="{ node, data }" v-if="groupState !== 'list' && editId === data.id">
|
<span class="custom-tree-node" slot-scope="{ node, data }" v-if="groupState !== 'list' && editId === data.id">
|
||||||
@@ -51,6 +51,7 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
loading: true,
|
||||||
filterText: "",
|
filterText: "",
|
||||||
groupList: [],
|
groupList: [],
|
||||||
groupState: "list",
|
groupState: "list",
|
||||||
@@ -75,7 +76,8 @@ export default {
|
|||||||
this.getGroup();
|
this.getGroup();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getGroup() {
|
getGroup(openList) {
|
||||||
|
this.loading = true;
|
||||||
this.groupList = [{
|
this.groupList = [{
|
||||||
id: 0,
|
id: 0,
|
||||||
label: "",
|
label: "",
|
||||||
@@ -104,9 +106,16 @@ export default {
|
|||||||
this.groupId = res.data[0].id;
|
this.groupId = res.data[0].id;
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.$refs.tree.setCurrentKey(this.groupId);
|
this.$refs.tree.setCurrentKey(this.groupId);
|
||||||
this.$emit('click', this.groupId);
|
if (openList){
|
||||||
|
openList.forEach(item => {
|
||||||
|
this.$refs.tree.store.nodesMap[item].expanded = true;
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.$emit('click', this.groupId);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
this.loading = false;
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getChild(data, parentId) {
|
getChild(data, parentId) {
|
||||||
@@ -172,7 +181,13 @@ export default {
|
|||||||
}).then(res => {
|
}).then(res => {
|
||||||
this.$modal.msgSuccess("新增成功");
|
this.$modal.msgSuccess("新增成功");
|
||||||
this.cancelNode();
|
this.cancelNode();
|
||||||
this.getGroup();
|
let openList = [];
|
||||||
|
Object.entries(this.$refs.tree.store.nodesMap).forEach(([key, node]) => {
|
||||||
|
if (node.expanded) {
|
||||||
|
openList.push(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.getGroup(openList);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
updateGroup({
|
updateGroup({
|
||||||
|
|||||||
Reference in New Issue
Block a user