|
@@ -42,6 +42,7 @@ export default {
|
|
|
loading: null, //loading
|
|
|
isLook: false, //是否仅查看
|
|
|
Role:{},//角色
|
|
|
+ checkList:[],//角色应勾选的list
|
|
|
};
|
|
|
},
|
|
|
watch: {
|
|
@@ -84,12 +85,17 @@ export default {
|
|
|
HalfChoiceList = []
|
|
|
} = res.Data
|
|
|
this.authList = List || []
|
|
|
- this.defaultCheckedKeys = ChoiceList.filter((item) => !HalfChoiceList.some((halfItem) =>
|
|
|
- item === halfItem))
|
|
|
+ this.checkList = ChoiceList
|
|
|
+ /* this.defaultCheckedKeys = ChoiceList.filter((item) => !HalfChoiceList.some((halfItem) =>
|
|
|
+ item === halfItem)) */
|
|
|
const type = this.isLook?'all':''
|
|
|
- this.authList.forEach(l=>{
|
|
|
- this.formatTree(l,type)
|
|
|
+ this.$nextTick(()=>{
|
|
|
+ this.authList.forEach(l=>{
|
|
|
+ this.formatTree(l,type)
|
|
|
+ })
|
|
|
+ this.defaultCheckedKeys=this.checkList
|
|
|
})
|
|
|
+
|
|
|
})
|
|
|
},
|
|
|
// 保存
|
|
@@ -113,8 +119,6 @@ export default {
|
|
|
},
|
|
|
formatTree(data,type){
|
|
|
if(/* data.MenuType===2|| */type==='all'){
|
|
|
- //同时存一下ParentId
|
|
|
- //监听check事件,如果是ParentId的check,就把子项从defaultCheckedKeys中删除
|
|
|
data.Disabled = true
|
|
|
}
|
|
|
if(data.Children && data.Children.length){
|
|
@@ -122,8 +126,31 @@ export default {
|
|
|
return this.formatTree(i,type)
|
|
|
})
|
|
|
}
|
|
|
+ if(data.Children&&data.Children.length===0){
|
|
|
+ //叶子节点向上检查MenuId
|
|
|
+ this.checkDataList(data)
|
|
|
+ }
|
|
|
return data
|
|
|
},
|
|
|
+ //根据MenuId找到对应节点
|
|
|
+ findTree(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)
|
|
|
+ }
|
|
|
+ //console.log('data',data.ParentId)
|
|
|
+ const parentNode = this.findTree(data.ParentId)
|
|
|
+ if(parentNode){
|
|
|
+ //console.log('node?',parentNode.data)
|
|
|
+ this.checkDataList(parentNode.data)
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
created() {
|
|
|
if (this.$route.query.id) {
|