+ {data.visibleParent && data.type == 2 &&
+
+
+
+ }
this.onChange(e, data)}
- >{data.title}
+ >
+ {data.title}
+
)
},
@@ -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() {
diff --git a/Web/src/pages/system/menu/form.vue b/Web/src/pages/system/menu/form.vue
index dbe65fa..7ce629a 100644
--- a/Web/src/pages/system/menu/form.vue
+++ b/Web/src/pages/system/menu/form.vue
@@ -94,8 +94,11 @@