From 007ae3ba140cf6577324a8efa220373d7ace37db Mon Sep 17 00:00:00 2001 From: "luoJunYong.123" Date: Fri, 25 Feb 2022 15:23:35 +0800 Subject: [PATCH] store_tree_data --- src/views/Transaction.vue | 69 ++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/src/views/Transaction.vue b/src/views/Transaction.vue index 827aa50..33f652a 100644 --- a/src/views/Transaction.vue +++ b/src/views/Transaction.vue @@ -353,6 +353,7 @@ import quill from "@/components/quill"; import MyTree from "@/components/myTree/src/tree"; import {deepCopy} from "@/utils/deepCopy"; +import { mapState } from 'vuex' export default { components: {quill, MyTree}, @@ -401,6 +402,11 @@ export default { loading:true, }; }, + computed: { + ...mapState({ + treeDataStore: state => state.treeDataStore + }) + }, mounted() { this.$route.query.token && this.$store.commit("setParam", { token: atob(decodeURI(this.$route.query.token)) @@ -671,23 +677,51 @@ export default { } }, getTreeData() { // 获取树结构数据 - this.$get(this.api.getLcRecord).then(res => { - if (res.status == 200 && res.list.length>0) { - if (res.list.length>0) { - this.treeData = this.toTreeId(res.list, res.list[0].parentId); - if (this.$route.query.lcId) { - this.lcId = this.$route.query.lcId; - this.getInfoData(this.$route.query.lcId); - } else { - this.loading = false + + if(this.treeDataStore.length) { + const tmp = [...this.treeDataStore] + this.treeData = this.toTreeId(tmp, this.treeDataStore[0].parentId); + if (this.$route.query.lcId) { + this.lcId = this.$route.query.lcId; + this.getInfoData(this.$route.query.lcId); + } + }else { + this.$get(this.api.getLcRecord).then(res => { + if (res.status == 200 && res.list.length>0) { + if (res.list.length>0) { + this.$store.commit('setTreeDataStore', { treeDataStore: res.list}) + this.treeData = this.toTreeId(res.list, res.list[0].parentId); + if (this.$route.query.lcId) { + this.lcId = this.$route.query.lcId; + this.getInfoData(this.$route.query.lcId); + } } + } else { + this.$message.warning(res.message); } - } else { - this.$message.warning(res.message); - } - }).catch(err => { - // console.log(err); - }); + }).catch(err => { + // console.log(err); + }); + } + + + // this.$get(this.api.getLcRecord).then(res => { + // if (res.status == 200 && res.list.length>0) { + // if (res.list.length>0) { + // this.treeData = this.toTreeId(res.list, res.list[0].parentId); + // if (this.$route.query.lcId) { + // this.lcId = this.$route.query.lcId; + // this.getInfoData(this.$route.query.lcId); + // } else { + // this.loading = false + // } + // } + // } else { + // this.$message.warning(res.message); + // } + // }).catch(err => { + // // console.log(err); + // }); }, toTreeId(data, parentId) { // id重新串连成(父+子+孙),已便达到树节点需要的key唯一性,且后面提交数据,需要传这个id串到后台 let result = []; @@ -840,7 +874,10 @@ export default { }) } addSuffix(treeData) - this.$refs.tree.setCheckedKeys([]) + this.$nextTick(() => { + this.$refs.tree.setCheckedKeys([]) + }) + }, addRule() { // 新增规则 this.changeArr.splice(0, this.changeArr.length)