|
@@ -33,7 +33,8 @@ export default {
|
|
|
defaultCheckedKeys:[],
|
|
|
treeLoading:false,
|
|
|
checkAll:false,
|
|
|
- isIndeterminate:false
|
|
|
+ isIndeterminate:false,
|
|
|
+ checkList:[],
|
|
|
};
|
|
|
},
|
|
|
watch:{
|
|
@@ -61,10 +62,49 @@ export default {
|
|
|
if(!res.Data) return
|
|
|
const {List,ChoiceList=[],HalfChoiceList=[]} = res.Data
|
|
|
this.authList = List||[]
|
|
|
- this.defaultCheckedKeys = ChoiceList.filter((item)=>!HalfChoiceList.some((halfItem)=>item===halfItem))
|
|
|
- this.handleCheckChange(this.defaultCheckedKeys,HalfChoiceList)
|
|
|
+ this.checkList = ChoiceList
|
|
|
+ this.authList.forEach(item=>{
|
|
|
+ this.checkTree(item)
|
|
|
+ })
|
|
|
+ //this.defaultCheckedKeys = ChoiceList.filter((item)=>!HalfChoiceList.some((halfItem)=>item===halfItem))
|
|
|
+ this.$nextTick(()=>{
|
|
|
+ this.defaultCheckedKeys = this.checkList
|
|
|
+ this.handleCheckChange(this.defaultCheckedKeys,HalfChoiceList)
|
|
|
+ })
|
|
|
+
|
|
|
})
|
|
|
},
|
|
|
+ checkTree(data){
|
|
|
+ //非叶子节点递归
|
|
|
+ if(data.Children && data.Children.length){
|
|
|
+ data.Children = data.Children.map(i=>{
|
|
|
+ return this.checkTree(i)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ //叶子节点向上检查MenuId
|
|
|
+ if(!data.Children||data.Children&&data.Children.length===0){
|
|
|
+ this.checkDataList(data)
|
|
|
+ }
|
|
|
+ return data
|
|
|
+ },
|
|
|
+ //根据MenuId找到对应节点
|
|
|
+ findTreeNode(MenuId){
|
|
|
+ return this.$refs.checkboxTree.getNode(MenuId)
|
|
|
+ },
|
|
|
+ checkDataList(data){
|
|
|
+ //获取data的MenuId 和 checkList对比
|
|
|
+ //如果MenuId不在checkList里,检查data.ParentId在不在checkList里,若在,则从checkList里去除
|
|
|
+ if(!this.checkList.includes(data.MenuId)&&this.checkList.includes(data.ParentId)){
|
|
|
+ const index = this.checkList.indexOf(data.ParentId)
|
|
|
+ index!==-1&&this.checkList.splice(index,1)
|
|
|
+ console.log('应该去除的节点',data.ParentId)
|
|
|
+ }
|
|
|
+ //向上检查MenuId
|
|
|
+ const parentNode = this.findTreeNode(data.ParentId)
|
|
|
+ if(parentNode){
|
|
|
+ this.checkDataList(parentNode.data)
|
|
|
+ }
|
|
|
+ },
|
|
|
async handleBtnClik(type){
|
|
|
if(type==='save'){
|
|
|
//获取树形列表选择的项 getCheckedKeys getHalfCheckedKeys
|