update 菜单完善
This commit is contained in:
@@ -59,11 +59,18 @@ export default {
|
||||
renderCheckbox(data) {
|
||||
return (
|
||||
<div class="yo-authority-view--checkbox">
|
||||
{data.visibleParent && data.type == 2 &&
|
||||
<a-tooltip placement="top" title="选中此项才会显示父节点">
|
||||
<a-icon type="eye" style={{ color: '#1890ff' }} class="mr-xxs" />
|
||||
</a-tooltip>
|
||||
}
|
||||
<a-checkbox
|
||||
value={data.id}
|
||||
checked={data.checked}
|
||||
onChange={(e) => this.onChange(e, data)}
|
||||
>{data.title}</a-checkbox>
|
||||
>
|
||||
{data.title}
|
||||
</a-checkbox>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
@@ -100,7 +107,16 @@ export default {
|
||||
|
||||
this.onSelect(e.target.checked, item)
|
||||
|
||||
this.$emit('select', this.list.filter(p => p.checked).map(p => p.id), this.list.filter(p => p.checked || p.indeterminate).map(p => p.id))
|
||||
const visible = this.getVisible()
|
||||
|
||||
this.$emit('select',
|
||||
// 返回所有选中
|
||||
this.list.filter(p => p.checked).map(p => p.id),
|
||||
// 返回所有选中和半选
|
||||
this.list.filter(p => p.checked || p.indeterminate).map(p => p.id),
|
||||
// 返回所有选中和半选,但是不返回没有子级选中visibleParent的半选
|
||||
visible
|
||||
)
|
||||
},
|
||||
|
||||
onSelect(check, item) {
|
||||
@@ -167,6 +183,42 @@ export default {
|
||||
})
|
||||
},
|
||||
|
||||
getVisible() {
|
||||
const checked = this.list.filter(p => p.checked)
|
||||
const caseChildren = checked.filter(p => p.visibleParent || p.type != 2)
|
||||
const visibleParents = []
|
||||
// 递归寻找父级
|
||||
const findVisibleParents = (children) => {
|
||||
const parents = []
|
||||
children.forEach(item => {
|
||||
if (item.parentId) {
|
||||
const parent = this.list.find(p => p.id === item.parentId)
|
||||
if (parent) {
|
||||
parents.push(parent)
|
||||
visibleParents.push(parent)
|
||||
}
|
||||
}
|
||||
})
|
||||
if (parents.length) {
|
||||
findVisibleParents(parents)
|
||||
}
|
||||
}
|
||||
|
||||
findVisibleParents(caseChildren)
|
||||
|
||||
const checkedIds = checked.map(p => p.id)
|
||||
const visibleParentsIds = visibleParents.map(p => p.id)
|
||||
|
||||
const result = checkedIds
|
||||
visibleParentsIds.forEach(p => {
|
||||
if (result.indexOf(p) === -1) {
|
||||
result.push(p)
|
||||
}
|
||||
})
|
||||
|
||||
return result
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
render() {
|
||||
|
||||
Reference in New Issue
Block a user