Merge remote-tracking branch 'origin/master'

pull/22/head
xuyuxiang 2021-04-16 10:14:19 +08:00
commit 0a2cbf3629
2 changed files with 179 additions and 121 deletions

View File

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

View File

@ -28,14 +28,13 @@
<a-tree <a-tree
v-model="checkedKeys" v-model="checkedKeys"
checkable checkable
checkStrictly
:auto-expand-parent="autoExpandParent" :auto-expand-parent="autoExpandParent"
:expanded-keys="expandedKeys" :expanded-keys="expandedKeys"
:tree-data="orgTreeData" :tree-data="orgTreeData"
:selected-keys="selectedKeys" :selected-keys="selectedKeys"
:replaceFields="replaceFields" :replaceFields="replaceFields"
@expand="onExpand" @expand="onExpand"
@select="onSelect" @check="onCheck"
/> />
</a-form-item> </a-form-item>
</div> </div>
@ -76,7 +75,9 @@
replaceFields: { replaceFields: {
key: 'id' key: 'id'
}, },
form: this.$form.createForm(this) form: this.$form.createForm(this),
commitKeys: [],
leastChilds: []
} }
}, },
@ -110,8 +111,6 @@
this.orgTreeShow = true this.orgTreeShow = true
// //
this.getOrgTree() this.getOrgTree()
//
this.sysRoleOwnData(this.roleEntity)
} else { } else {
this.orgTreeShow = false this.orgTreeShow = false
// //
@ -123,13 +122,19 @@
* 获取机构树 * 获取机构树
*/ */
getOrgTree () { getOrgTree () {
const _this = this
getOrgTree().then((res) => { getOrgTree().then((res) => {
if (res.success) { if (res.success) {
this.orgTreeData = res.data this.orgTreeData = res.data
_this.getLeastChilds(res.data)
// //
this.orgTreeData.forEach(item => { this.orgTreeData.forEach(item => {
this.expandedKeys.push(item.id) this.expandedKeys.push(item.id)
}) })
//
this.sysRoleOwnData(_this.roleEntity)
} }
}) })
}, },
@ -138,34 +143,57 @@
* 此角色已有数据列表 * 此角色已有数据列表
*/ */
sysRoleOwnData (record) { sysRoleOwnData (record) {
const _this = this
sysRoleOwnData({ id: record.id }).then((res) => { sysRoleOwnData({ id: record.id }).then((res) => {
if (res.success) { if (res.success) {
console.log(JSON.stringify(res.data)) _this.pickCheckedKeys(res.data)
this.checkedKeys = res.data _this.commitKeys = res.data
} }
this.formLoading = false this.formLoading = false
}) })
}, },
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)
},
pickCheckedKeys(data){
for (let i = 0; i < data.length; i++) {
if (this.leastChilds.includes(data[i])) {
this.checkedKeys.push(data[i])
}
}
},
onExpand (expandedKeys) { onExpand (expandedKeys) {
this.expandedKeys = expandedKeys this.expandedKeys = expandedKeys
this.autoExpandParent = false this.autoExpandParent = false
}, },
onCheck (checkedKeys) { onCheck (checkedKeys, info) {
console.log(JSON.stringify(checkedKeys))
this.checkedKeys = checkedKeys this.checkedKeys = checkedKeys
this.commitKeys = checkedKeys.concat(info.halfCheckedKeys);
}, },
onSelect (selectedKeys, info) { onSelect (selectedKeys, info) {
this.selectedKeys = selectedKeys this.selectedKeys = selectedKeys
}, },
handleSubmit () { handleSubmit () {
const _this = this
const { form: { validateFields } } = this const { form: { validateFields } } = this
this.confirmLoading = true this.confirmLoading = true
validateFields((errors, values) => { validateFields((errors, values) => {
if (!errors) { if (!errors) {
const checkedKeys = this.checkedKeys.checked === undefined ? this.checkedKeys : this.checkedKeys.checked sysRoleGrantData({ id: this.roleEntity.id, grantOrgIdList: _this.commitKeys, dataScopeType: values.dataScopeType }).then((res) => {
sysRoleGrantData({ id: this.roleEntity.id, grantOrgIdList: checkedKeys, dataScopeType: values.dataScopeType }).then((res) => {
this.confirmLoading = false this.confirmLoading = false
if (res.success) { if (res.success) {
this.$message.success('授权成功') this.$message.success('授权成功')