Commit 5976cb3d by 杨北旺

角色查看处理树的横向

1 parent fe1adbde
......@@ -123,71 +123,75 @@ export default {
history.go(-1)
},
// 递归:处理某个值
traverse(arr = [],count = 0) {
traverse(arr = [], count = 0) {
count++
arr.map(item => {
if (item.children && item.children instanceof Array) {
item.perms = false
this.traverse(item.children,count)
}else if(!item.children&&count>2){
this.traverse(item.children, count)
} else if (!item.children && count > 2) {
item.perms = true
}
item.count = count
return item
})
return arr
},
// 继续处理已经处理完的树
toContiuneTree(arr = [], count = 0, maxLevel = 0) {
count++
arr.map(item => {
if (item.children && item.children instanceof Array) {
item.perms = false
this.toContiuneTree(item.children, count, maxLevel)
} else if (!item.children && count > maxLevel - 1) {
item.perms = true
}
item.count = count
return item
})
return arr
},
// 调用此方法去重构树节点
handlerTreeDom() {
this.newTreeList = this.traverse(this.newTreeList)
// if (this.newTreeList.length) {
// this.newTreeList.map(item => {
// if (item.children) {
// item.children.map(el => {
// if (el.children) {
// el.children.map(ele => {
// if (ele.children) {
// ele.perms = false
// ele.children.map(elel => {
// elel.perms = true
// return elel
// })
// } else {
// ele.perms = true
// }
// return ele
// })
// }
// el.perms = false
// return el
// })
// }
// item.perms = false
// return item
// })
// }
console.log(this.newTreeList, '*******')
let temp = this.flattenDeep(this.newTreeList)
let maxval = Math.max.apply(
Math,
temp.map(item => {
return item.count
})
)
this.newTreeList = this.toContiuneTree(this.newTreeList, 0, maxval)
console.log(this.newTreeList);
this.maxval = maxval-1
this.$nextTick(() => {
this.changeTreeClass()
this.changeTreeClass(maxval)
})
},
// 处理树横向
renderContent(h, { node, data }) {
let className = ''
if (data.perms) {
if (data.perms&&data.count>this.maxval) {
className = 'especially'
}
return <div class={className}>{data.label}</div>
},
// 改变tree节点样式
changeTreeClass() {
changeTreeClass(maxval) {
let piefix = (maxval-1)*20
var classDomList = document.getElementsByClassName('especially')
for (var i = 0; i < classDomList.length; i++) {
classDomList[i].parentNode.style.cssText = 'float:left'
classDomList[i].parentNode.className = 'el-tree-node__content option-wrapper'
classDomList[i].parentNode.parentNode.parentNode.style.marginLeft = '20px'
// classDomList[i].parentNode.className = 'el-tree-node__content option-wrapper'
classDomList[i].parentNode.parentNode.parentNode.style.marginLeft = `${piefix}px`
}
},
flattenDeep(arr = [], childs = 'children', pid = 0) {
return arr.reduce((flat, item) => {
item.pid = pid
return flat.concat(item, item[childs] ? this.flattenDeep(item[childs], childs, item.id) : [])
}, [])
}
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!