| | |
| | | <div class="treeMain"> |
| | | <el-tabs tab-position="left" class="demo-tabs" v-model="menuActiveName" @tab-click="(tab,event)=>menuHandleClick(tab,event,'0')"> |
| | | <el-tab-pane v-for="(item,index) in menuGrantList" :label="item.title" :name="item.title"> |
| | | <el-tree ref="tree0" v-if="showtree" :data="treeData" :props="{ label: 'title',children: 'children'}" node-key="id" show-checkbox @check-change="(item,isCheck)=>treeHandleCheckChange(item,isCheck,index)" :default-checked-keys="treeCheck" default-expand-all /> |
| | | <el-tree ref="tree0" v-if="showtree" :data="treeData" :props="{ label: 'title',children: 'children'}" node-key="id" show-checkbox @check-change="(item,isCheck)=>treeHandleCheckChange(item,isCheck,index)" :default-checked-keys="treeCheck" default-expand-all :check-strictly="true"/> |
| | | </el-tab-pane> |
| | | </el-tabs> |
| | | </div> |
| | |
| | | <div class="treeMain"> |
| | | <el-tabs tab-position="left" class="demo-tabs" v-model="menuActiveName" @tab-click="(tab,event)=>menuHandleClick(tab,event,'1')"> |
| | | <el-tab-pane v-for="(item,index) in menuGrantList" :label="item.title" :name="item.title"> |
| | | <el-tree ref="tree1" v-if="showtree" :data="treeData1" :props="{ label: 'title',children: 'children'}" node-key="id" show-checkbox @check-change="(item,isCheck)=>treeHandleCheckChange(item,isCheck,index)" :default-checked-keys="treeCheck" default-expand-all /> |
| | | <el-tree ref="tree1" v-if="showtree" :data="treeData1" :props="{ label: 'title',children: 'children'}" node-key="id" show-checkbox @check-change="(item,isCheck)=>treeHandleCheckChange(item,isCheck,index)" :default-checked-keys="treeCheck" default-expand-all :check-strictly="true"/> |
| | | </el-tab-pane> |
| | | </el-tabs> |
| | | </div> |
| | |
| | | this.menuHandleText = event.target.innerText; |
| | | }, |
| | | treeHandleCheckChange(item,isCheck,index) { |
| | | var that = this; |
| | | if(isCheck) { |
| | | console.log(item.id,111) |
| | | if(!this.treeCheck.includes(item.id)) { |
| | | this.treeCheck.push(item.id); |
| | | function checkoutId(val){ |
| | | if(!that.treeCheck.includes(val.id)) { |
| | | that.treeCheck.push(val.id); |
| | | } |
| | | if(val.children) { |
| | | val.children.forEach(item1=> { |
| | | checkoutId(item1); |
| | | }) |
| | | } |
| | | } |
| | | }else { |
| | | if(this.treeCheck.length != 0) { |
| | | this.treeCheck.forEach((val,valIndex)=> { |
| | | if(val == item.id) { |
| | | this.treeCheck.splice(valIndex,1); |
| | | checkoutId(item); |
| | | that.$refs.tree0[index].setCheckedKeys(this.treeCheck,false); |
| | | }else { //取消选中 |
| | | if(item.children) { //有children |
| | | function delCheckoutId(val){ |
| | | that.treeCheck.forEach((val1,valIndex)=> { |
| | | if(val1 == val.id) { |
| | | that.treeCheck.splice(valIndex,1); |
| | | } |
| | | }) |
| | | if(val.children) { |
| | | val.children.forEach(item1=> { |
| | | delCheckoutId(item1); |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | delCheckoutId(item); |
| | | that.$refs.tree0[index].setCheckedKeys(this.treeCheck,false); |
| | | }else { //没有children |
| | | if(this.treeCheck.length != 0) { |
| | | this.treeCheck.forEach((val,valIndex)=> { |
| | | if(val == item.id) { |
| | | this.treeCheck.splice(valIndex,1); |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | setTreeList(arr,name,index=0) { |
| | |
| | | this.treeData1 = []; |
| | | arr.forEach(item=> { |
| | | if(item.title == name) { |
| | | //this.treeData = item.children; |
| | | if(index == '0') { |
| | | this.treeData = item.children; |
| | | } |
| | |
| | | this.tableData.forEach(item=> { |
| | | item.active = false; |
| | | }) |
| | | this.tableData[index].active = true; //选中 |
| | | this.tableData[index].active = true; //左侧切换角色选中 |
| | | this.showtree = false; |
| | | this.tableLiId = id; //角色id |
| | | this.$nextTick(()=> { |
| | | this.showtree = true; |
| | | //菜单 |
| | | this.menuGrantList = res.data.menu.filter(item=> { //过滤掉没有children的 |
| | | this.menuGrantList = res.data.menu.filter(item=> { //过滤掉没有children的,这里是res,不是resp,是菜单tree左侧的选项 |
| | | return item.children; |
| | | }); |
| | | //卡片 |
| | | this.menuGrantList1 = []; |
| | | this.menuGrantList1 = []; //card的tree左侧的选项 |
| | | res.data.card.forEach(item=> { |
| | | this.menuGrantList.forEach(item1=> { |
| | | if(item.id == item1.id) { |
| | |
| | | }) |
| | | this.menuActiveName = this.menuGrantList[0].title;//默认第一个菜单 |
| | | this.setTreeList(this.menuGrantList,this.menuActiveName);//展示树(左侧菜单list,左侧菜单名字) |
| | | var lastId = []; |
| | | var lastId = this.extractLastLevelIds(this.menuGrantList); //获取最后一级id |
| | | var idarr = this.findOverlap(lastId,resp.data.menu); //找出两个数组重合的部分 |
| | | |
| | | var lastId1 = []; |
| | | var lastId1 = this.extractLastLevelIds(this.menuGrantList1); //获取最后一级id |
| | | var idarr1 = this.findOverlap(lastId1,resp.data.card); //找出两个数组重合的部分 |
| | | var idarr = resp.data.menu.concat(resp.data.card); |
| | | this.treeCheck = [...new Set(idarr)]; //获取选中数据 |
| | | // var lastId = []; |
| | | // var lastId = this.extractLastLevelIds(this.menuGrantList); //获取最后一级id |
| | | // var idarr = this.findOverlap(lastId,resp.data.menu); //找出两个数组重合的部分 |
| | | |
| | | this.treeCheck = [...idarr,...idarr1]; //获取选中数据 |
| | | // var lastId1 = []; |
| | | // var lastId1 = this.extractLastLevelIds(this.menuGrantList1); //获取最后一级id |
| | | // var idarr1 = this.findOverlap(lastId1,resp.data.card); //找出两个数组重合的部分 |
| | | |
| | | // this.treeCheck = [...idarr,...idarr1]; //获取选中数据 |
| | | }) |
| | | } |
| | | }) |