update _web/src/views/system/role/roleMenuForm.vue.

This commit is contained in:
yuanbp 2021-04-12 13:11:05 +08:00 committed by Gitee
parent 45542a878f
commit f830480d7d

View File

@ -19,15 +19,13 @@
v-model="checkedKeys"
multiple
checkable
checkStrictly
:auto-expand-parent="autoExpandParent"
:expanded-keys="expandedKeys"
:tree-data="menuTreeData"
:selected-keys="selectedKeys"
:replaceFields="replaceFields"
@expand="onExpand"
@select="onSelect"
@check="treeCheck"
@check="onCheck"
/>
</a-form-item>
@ -66,10 +64,11 @@
replaceFields: {
key: 'id'
},
form: this.$form.createForm(this)
form: this.$form.createForm(this),
commitKeys: [],
leastChilds: []
}
},
methods: {
//
roleMenu(record) {
@ -77,68 +76,99 @@
this.roleEntity = record
this.visible = true
this.getMenuTree()
this.expandedMenuKeys(record)
},
/**
* 获取菜单列表
*/
getMenuTree() {
const _this = this
SysMenuTreeForGrant().then((res) => {
if (res.success) {
this.menuTreeData = res.data
_this.menuTreeData = res.data
_this.getLeastChilds(res.data)
//
this.menuTreeData.forEach(item => {
this.expandedKeys.push(item.id)
_this.menuTreeData.forEach(item => {
_this.expandedKeys.push(item.id)
})
_this.expandedMenuKeys(_this.roleEntity)
}
})
},
getLeastChilds(data){
for (let i = 0; i < data.length; i++) {
this.pushLeastChilds(data[i])
}
},
pushLeastChilds(e) {
if (e.children.length > 0) {
this.getLeastChilds(e.children)
return
}
this.leastChilds.push(e.id)
},
/**
* 此角色已有菜单权限
*/
expandedMenuKeys(record) {
const _this = this
sysRoleOwnMenu({id: record.id}).then((res) => {
if (res.success) {
this.checkedKeys = res.data
_this.pickCheckedKeys(res.data)
_this.commitKeys = res.data
}
this.formLoading = false
_this.formLoading = false
})
},
treeCheck (checkKeys) {
pickCheckedKeys(data){
for (let i = 0; i < data.length; i++) {
if (this.leastChilds.includes(data[i])) {
this.checkedKeys.push(data[i])
}
}
},
onExpand(expandedKeys) {
this.expandedKeys = expandedKeys
this.autoExpandParent = false
},
onCheck (checkedKeys) {
onCheck(checkedKeys, info) {
this.checkedKeys = checkedKeys
this.commitKeys = checkedKeys.concat(info.halfCheckedKeys);
},
onSelect(selectedKeys, info) {
console.log(selectedKeys)
console.log(info)
this.selectedKeys = selectedKeys
},
handleSubmit() {
const _this = this;
const {form: {validateFields}} = this
this.confirmLoading = true
validateFields((errors, values) => {
if (!errors) {
sysRoleGrantMenu({ id: this.roleEntity.id, grantMenuIdList: this.checkedKeys.checked }).then((res) => {
sysRoleGrantMenu({id: _this.roleEntity.id, grantMenuIdList: _this.commitKeys}).then((res) => {
if (res.success) {
this.$message.success('授权成功')
this.confirmLoading = false
this.$emit('ok', values)
this.handleCancel()
_this.$message.success('授权成功')
_this.confirmLoading = false
_this.$emit('ok', values)
_this.handleCancel()
} else {
this.$message.error('授权失败:' + res.message)
_this.$message.error('授权失败:' + res.message)
}
}).finally((res) => {
this.confirmLoading = false
_this.confirmLoading = false
})
} else {
this.confirmLoading = false
_this.confirmLoading = false
}
})
},