【更新】修复错误

This commit is contained in:
小诺 2021-04-16 13:26:44 +08:00 committed by 小诺
parent d42dfbc806
commit daa75e6594
2 changed files with 148 additions and 176 deletions

View File

@ -36,149 +36,149 @@
</template> </template>
<script> <script>
import {SysMenuTreeForGrant} from '@/api/modular/system/menuManage' import { SysMenuTreeForGrant } from '@/api/modular/system/menuManage'
import {sysRoleOwnMenu, sysRoleGrantMenu} from '@/api/modular/system/roleManage' import { sysRoleOwnMenu, sysRoleGrantMenu } from '@/api/modular/system/roleManage'
export default { export default {
data() { data() {
return { return {
labelCol: { labelCol: {
style: {'padding-right': '20px'}, style: { 'padding-right': '20px' },
xs: {span: 24}, xs: { span: 24 },
sm: {span: 5} sm: { span: 5 }
}, },
wrapperCol: { wrapperCol: {
xs: {span: 24}, xs: { span: 24 },
sm: {span: 15} sm: { span: 15 }
}, },
menuTreeData: [], menuTreeData: [],
expandedKeys: [], expandedKeys: [],
checkedKeys: [], checkedKeys: [],
visible: false, visible: false,
confirmLoading: false, confirmLoading: false,
formLoading: true, formLoading: true,
autoExpandParent: true, autoExpandParent: true,
selectedKeys: [], selectedKeys: [],
subValues: [], subValues: [],
roleEntity: [], roleEntity: [],
replaceFields: { replaceFields: {
key: 'id' key: 'id'
}, },
form: this.$form.createForm(this), form: this.$form.createForm(this),
commitKeys: [], commitKeys: [],
leastChilds: [] leastChilds: []
}
},
methods: {
//
roleMenu(record) {
this.formLoading = true
this.roleEntity = record
this.visible = true
this.getMenuTree()
},
/**
* 获取菜单列表
*/
getMenuTree() {
const _this = this
SysMenuTreeForGrant().then((res) => {
if (res.success) {
_this.menuTreeData = res.data
_this.getLeastChilds(res.data)
//
_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])
} }
}, },
methods: {
//
roleMenu(record) {
this.formLoading = true
this.roleEntity = record
this.visible = true
this.getMenuTree()
},
pushLeastChilds(e) { /**
if (e.children.length > 0) { * 获取菜单列表
this.getLeastChilds(e.children) */
return getMenuTree() {
} const _this = this
this.leastChilds.push(e.id) SysMenuTreeForGrant().then((res) => {
}, if (res.success) {
_this.menuTreeData = res.data
_this.getLeastChilds(res.data)
//
_this.menuTreeData.forEach(item => {
_this.expandedKeys.push(item.id)
})
/** _this.expandedMenuKeys(_this.roleEntity)
* 此角色已有菜单权限 }
*/ })
expandedMenuKeys(record) { },
const _this = this
sysRoleOwnMenu({id: record.id}).then((res) => { getLeastChilds(data) {
if (res.success) { for (let i = 0; i < data.length; i++) {
_this.pickCheckedKeys(res.data) this.pushLeastChilds(data[i])
_this.commitKeys = res.data
} }
_this.formLoading = false },
})
},
pickCheckedKeys(data){ pushLeastChilds(e) {
for (let i = 0; i < data.length; i++) { if (e.children.length > 0) {
if (this.leastChilds.includes(data[i])) { this.getLeastChilds(e.children)
this.checkedKeys.push(data[i]) return
} }
} this.leastChilds.push(e.id)
}, },
onExpand(expandedKeys) { /**
this.expandedKeys = expandedKeys * 此角色已有菜单权限
this.autoExpandParent = false */
}, expandedMenuKeys(record) {
const _this = this
sysRoleOwnMenu({ id: record.id }).then((res) => {
if (res.success) {
_this.pickCheckedKeys(res.data)
_this.commitKeys = res.data
}
_this.formLoading = false
})
},
onCheck(checkedKeys, info) { pickCheckedKeys(data) {
this.checkedKeys = checkedKeys for (let i = 0; i < data.length; i++) {
this.commitKeys = checkedKeys.concat(info.halfCheckedKeys); if (this.leastChilds.includes(data[i])) {
}, this.checkedKeys.push(data[i])
}
}
},
onSelect(selectedKeys, info) { onExpand(expandedKeys) {
console.log(selectedKeys) this.expandedKeys = expandedKeys
console.log(info) this.autoExpandParent = false
this.selectedKeys = selectedKeys },
},
handleSubmit() { onCheck(checkedKeys, info) {
const _this = this; this.checkedKeys = checkedKeys
const {form: {validateFields}} = this this.commitKeys = checkedKeys.concat(info.halfCheckedKeys)
this.confirmLoading = true },
validateFields((errors, values) => {
if (!errors) { onSelect(selectedKeys, info) {
sysRoleGrantMenu({id: _this.roleEntity.id, grantMenuIdList: _this.commitKeys}).then((res) => { console.log(selectedKeys)
if (res.success) { console.log(info)
_this.$message.success('授权成功') 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.commitKeys }).then((res) => {
if (res.success) {
_this.$message.success('授权成功')
_this.confirmLoading = false
_this.$emit('ok', values)
_this.handleCancel()
} else {
_this.$message.error('授权失败:' + res.message)
}
}).finally((res) => {
_this.confirmLoading = false _this.confirmLoading = false
_this.$emit('ok', values) })
_this.handleCancel() } else {
} else {
_this.$message.error('授权失败:' + res.message)
}
}).finally((res) => {
_this.confirmLoading = false _this.confirmLoading = false
}) }
} else { })
_this.confirmLoading = false },
} handleCancel() {
}) //
}, this.checkedKeys = []
handleCancel() { //
// this.expandedKeys = []
this.checkedKeys = [] this.visible = false
// }
this.expandedKeys = []
this.visible = false
} }
} }
}
</script> </script>

View File

@ -28,13 +28,14 @@
<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"
@check="onCheck" @select="onSelect"
/> />
</a-form-item> </a-form-item>
</div> </div>
@ -75,9 +76,7 @@
replaceFields: { replaceFields: {
key: 'id' key: 'id'
}, },
form: this.$form.createForm(this), form: this.$form.createForm(this)
commitKeys: [],
leastChilds: []
} }
}, },
@ -111,6 +110,8 @@
this.orgTreeShow = true this.orgTreeShow = true
// //
this.getOrgTree() this.getOrgTree()
//
this.sysRoleOwnData(this.roleEntity)
} else { } else {
this.orgTreeShow = false this.orgTreeShow = false
// //
@ -122,20 +123,14 @@
* 获取机构树 * 获取机构树
*/ */
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.expandedKeys.push(item.id)
this.orgTreeData.forEach(item => { })
this.expandedKeys.push(item.id) }
})
//
this.sysRoleOwnData(_this.roleEntity)
}
}) })
}, },
@ -143,57 +138,34 @@
* 此角色已有数据列表 * 此角色已有数据列表
*/ */
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) {
_this.pickCheckedKeys(res.data) console.log(JSON.stringify(res.data))
_this.commitKeys = res.data this.checkedKeys = 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, info) { onCheck (checkedKeys) {
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) {
sysRoleGrantData({ id: this.roleEntity.id, grantOrgIdList: _this.commitKeys, dataScopeType: values.dataScopeType }).then((res) => { const checkedKeys = this.checkedKeys.checked === undefined ? this.checkedKeys : this.checkedKeys.checked
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('授权成功')