You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
699 B

6 years ago
/**
* el-tree展开折叠控制
6 years ago
* @param ref el-tree实例
* @param action 'expand' | 'collapse'
* @param level 展开的节点最大深度为0时匹配全部节点
* @param func 自定义展开的函数传入一个node返回boolean优先使用
6 years ago
*/
export function expandControl(ref, action = 'expand', level = 1, func) {
const handler = function () {
if (typeof func === 'function') {
return node => func(node)
}
const expand = action === 'expand'
const forAll = level === 0
return node => node.expanded = forAll || node.level <= level ? expand : !expand
}()
ref.store._getAllNodes().forEach(handler)
}