添加节点后保持文件夹打开状态
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="app-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-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">
|
||||
@@ -51,6 +51,7 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
loading: true,
|
||||
filterText: "",
|
||||
groupList: [],
|
||||
groupState: "list",
|
||||
@@ -75,7 +76,8 @@ export default {
|
||||
this.getGroup();
|
||||
},
|
||||
methods: {
|
||||
getGroup() {
|
||||
getGroup(openList) {
|
||||
this.loading = true;
|
||||
this.groupList = [{
|
||||
id: 0,
|
||||
label: "",
|
||||
@@ -104,9 +106,16 @@ export default {
|
||||
this.groupId = res.data[0].id;
|
||||
this.$nextTick(() => {
|
||||
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) {
|
||||
@@ -172,7 +181,13 @@ export default {
|
||||
}).then(res => {
|
||||
this.$modal.msgSuccess("新增成功");
|
||||
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 {
|
||||
updateGroup({
|
||||
|
||||
Reference in New Issue
Block a user