|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
<template>
|
|
|
|
|
<a-modal
|
|
|
|
|
title="授权数据"
|
|
|
|
|
:width="600"
|
|
|
|
|
:width="800"
|
|
|
|
|
:visible="visible"
|
|
|
|
|
:confirmLoading="confirmLoading"
|
|
|
|
|
@ok="handleSubmit"
|
|
|
|
@ -9,147 +9,324 @@
|
|
|
|
|
>
|
|
|
|
|
<a-spin :spinning="formLoading">
|
|
|
|
|
<a-form :form="form">
|
|
|
|
|
<a-form-item
|
|
|
|
|
label="选择机构"
|
|
|
|
|
:labelCol="labelCol"
|
|
|
|
|
:wrapperCol="wrapperCol"
|
|
|
|
|
class="grantOrgScrollbar"
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
<a-tree
|
|
|
|
|
v-model="checkedKeys"
|
|
|
|
|
checkable
|
|
|
|
|
checkStrictly
|
|
|
|
|
:auto-expand-parent="autoExpandParent"
|
|
|
|
|
:expanded-keys="expandedKeys"
|
|
|
|
|
:tree-data="orgTreeData"
|
|
|
|
|
:selected-keys="selectedKeys"
|
|
|
|
|
:replaceFields="replaceFields"
|
|
|
|
|
@expand="onExpand"
|
|
|
|
|
@select="onSelect"
|
|
|
|
|
/>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
|
|
|
|
<a-row>
|
|
|
|
|
<a-col :span="12">
|
|
|
|
|
<a-form-item label="选择菜单" :labelCol="labelCol" :wrapperCol="wrapperCol" class="grantOrgScrollbar">
|
|
|
|
|
<a-tree
|
|
|
|
|
v-model="checkedMenuKeys"
|
|
|
|
|
checkable
|
|
|
|
|
checkStrictly
|
|
|
|
|
:auto-expand-parent="autoExpandParentMenu"
|
|
|
|
|
:tree-data="menuTreeData"
|
|
|
|
|
:selected-keys="selectedKeys"
|
|
|
|
|
:replaceFields="replaceMenuFields"
|
|
|
|
|
@select="onSelectMenu"
|
|
|
|
|
@check="onCheckMenu"
|
|
|
|
|
/>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :span="12">
|
|
|
|
|
<a-form-item
|
|
|
|
|
v-show="SelectMenu"
|
|
|
|
|
label="授权范围"
|
|
|
|
|
:labelCol="labelCol"
|
|
|
|
|
:wrapperCol="wrapperCol"
|
|
|
|
|
has-feedback
|
|
|
|
|
>
|
|
|
|
|
<a-select
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
placeholder="请选择授权范围"
|
|
|
|
|
v-decorator="['dataScopeType', { rules: [{ required: true, message: '请选择授权范围!' }] }]"
|
|
|
|
|
>
|
|
|
|
|
<a-select-option
|
|
|
|
|
v-for="(item, index) in dataScopeTypeData"
|
|
|
|
|
:key="index"
|
|
|
|
|
:value="item.code"
|
|
|
|
|
@click="handleChange(item.code)"
|
|
|
|
|
>
|
|
|
|
|
{{ item.value }}
|
|
|
|
|
</a-select-option>
|
|
|
|
|
</a-select>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
<div v-show="SelectMenu && orgTreeShow">
|
|
|
|
|
<a-form-item label="选择机构" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
|
|
|
|
<a-tree
|
|
|
|
|
v-model="checkedKeys"
|
|
|
|
|
checkable
|
|
|
|
|
checkStrictly
|
|
|
|
|
:auto-expand-parent="autoExpandParent"
|
|
|
|
|
:expanded-keys="expandedKeys"
|
|
|
|
|
:tree-data="orgTreeData"
|
|
|
|
|
:selected-keys="selectedKeys"
|
|
|
|
|
:replaceFields="replaceFields"
|
|
|
|
|
@expand="onExpand"
|
|
|
|
|
@check="onCheck"
|
|
|
|
|
/>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</div>
|
|
|
|
|
</a-col>
|
|
|
|
|
</a-row>
|
|
|
|
|
</a-form>
|
|
|
|
|
</a-spin>
|
|
|
|
|
</a-modal>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { getOrgTree } from '@/api/modular/system/orgManage'
|
|
|
|
|
import { sysUserOwnData, sysUserGrantData } from '@/api/modular/system/userManage'
|
|
|
|
|
import { getMenuList, getOrgTree } from '@/api/modular/system/orgManage'
|
|
|
|
|
import {
|
|
|
|
|
SysDataUserMenuGrantData,
|
|
|
|
|
SysDataUserMenuGrantRightData,
|
|
|
|
|
SysDataUserMenuGetGrantRightData,
|
|
|
|
|
SysDataUserMenuGetGrantData
|
|
|
|
|
} from '@/api/modular/system/userManage'
|
|
|
|
|
import { sysDictTypeDropDown } from '@/api/modular/system/dictManage'
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
labelCol: {
|
|
|
|
|
style: { 'padding-right': '20px' },
|
|
|
|
|
xs: { span: 24 },
|
|
|
|
|
sm: { span: 5 }
|
|
|
|
|
},
|
|
|
|
|
wrapperCol: {
|
|
|
|
|
xs: { span: 24 },
|
|
|
|
|
sm: { span: 15 }
|
|
|
|
|
},
|
|
|
|
|
orgTreeData: [],
|
|
|
|
|
menuTreeData: [],
|
|
|
|
|
expandedKeys: [],
|
|
|
|
|
expandedMenuKeys: [],
|
|
|
|
|
checkedKeys: [],
|
|
|
|
|
checkedMenuKeys: [],
|
|
|
|
|
visible: false,
|
|
|
|
|
confirmLoading: false,
|
|
|
|
|
formLoading: true,
|
|
|
|
|
autoExpandParent: true,
|
|
|
|
|
autoExpandParentMenu: true,
|
|
|
|
|
selectedKeys: [],
|
|
|
|
|
userEntity: [],
|
|
|
|
|
replaceFields: {
|
|
|
|
|
key: 'id',
|
|
|
|
|
title: 'title'
|
|
|
|
|
},
|
|
|
|
|
replaceMenuFields: {
|
|
|
|
|
key: 'id',
|
|
|
|
|
title: 'name'
|
|
|
|
|
},
|
|
|
|
|
form: this.$form.createForm(this),
|
|
|
|
|
dataScopeTypeData: [],
|
|
|
|
|
orgTreeShow: false,
|
|
|
|
|
GrantData: [],
|
|
|
|
|
SelectMenu: false,
|
|
|
|
|
SelectMenuId: '',
|
|
|
|
|
MeuncheckedKeys: []
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
labelCol: {
|
|
|
|
|
style: { 'padding-right': '20px' },
|
|
|
|
|
xs: { span: 24 },
|
|
|
|
|
sm: { span: 5 }
|
|
|
|
|
},
|
|
|
|
|
wrapperCol: {
|
|
|
|
|
xs: { span: 24 },
|
|
|
|
|
sm: { span: 15 }
|
|
|
|
|
},
|
|
|
|
|
orgTreeData: [],
|
|
|
|
|
expandedKeys: [],
|
|
|
|
|
checkedKeys: [],
|
|
|
|
|
visible: false,
|
|
|
|
|
confirmLoading: false,
|
|
|
|
|
formLoading: true,
|
|
|
|
|
autoExpandParent: true,
|
|
|
|
|
selectedKeys: [],
|
|
|
|
|
userEntity: [],
|
|
|
|
|
replaceFields: {
|
|
|
|
|
key: 'id'
|
|
|
|
|
},
|
|
|
|
|
form: this.$form.createForm(this)
|
|
|
|
|
}
|
|
|
|
|
methods: {
|
|
|
|
|
// 初始化方法
|
|
|
|
|
userOrg(record) {
|
|
|
|
|
this.userEntity = record
|
|
|
|
|
this.visible = true
|
|
|
|
|
// 获取授权范围
|
|
|
|
|
this.sysDictTypeDropDown()
|
|
|
|
|
// 获取菜单树
|
|
|
|
|
this.getMenuList()
|
|
|
|
|
// 获取权限
|
|
|
|
|
this.SysDataUserMenuGetGrantData(record)
|
|
|
|
|
// // 获取自定义权限
|
|
|
|
|
// this.SysDataUserMenuGetGrantRightData(record)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
// 初始化方法
|
|
|
|
|
userOrg (record) {
|
|
|
|
|
this.userEntity = record
|
|
|
|
|
this.visible = true
|
|
|
|
|
// 获取权限
|
|
|
|
|
SysDataUserMenuGetGrantData(record) {
|
|
|
|
|
SysDataUserMenuGetGrantData({ userid: record.id }).then(res => {
|
|
|
|
|
this.GrantData = res.data
|
|
|
|
|
res.data.forEach(item => {
|
|
|
|
|
this.checkedMenuKeys.push(item.sysMenuId)
|
|
|
|
|
})
|
|
|
|
|
// 获取用户自定义权限
|
|
|
|
|
SysDataUserMenuGetGrantRightData({ userid: record.id }).then(res => {
|
|
|
|
|
this.GrantData.forEach(item => {
|
|
|
|
|
item.RightData = []
|
|
|
|
|
res.data.forEach(item2 => {
|
|
|
|
|
if (item.sysMenuId == item2.sysMenuId) {
|
|
|
|
|
item.RightData.push({ menuId: item2.sysMenuId, orgId: item2.sysOrgId })
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
// 获取用户自定义权限
|
|
|
|
|
// SysDataUserMenuGetGrantRightData(record) {},
|
|
|
|
|
// 范围下拉框事件
|
|
|
|
|
handleChange(value) {
|
|
|
|
|
let Type = false
|
|
|
|
|
this.GrantData.forEach(item => {
|
|
|
|
|
if (item.sysMenuId == this.SelectMenuId) {
|
|
|
|
|
// if (value == '5') {
|
|
|
|
|
// this.checkedKeys = []
|
|
|
|
|
// item.RightData.forEach(item => {
|
|
|
|
|
// this.checkedKeys.push(item.orgId)
|
|
|
|
|
// })
|
|
|
|
|
// console.log(this.checkedKeys)
|
|
|
|
|
// } else {
|
|
|
|
|
// item.RightData = []
|
|
|
|
|
// }
|
|
|
|
|
item.dataScopeType = value
|
|
|
|
|
Type = true
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if (!Type) {
|
|
|
|
|
this.GrantData.push({ dataScopeType: value, sysMenuId: this.SelectMenuId, RightData: [] })
|
|
|
|
|
}
|
|
|
|
|
// eslint-disable-next-line eqeqeq
|
|
|
|
|
if (value == '5') {
|
|
|
|
|
this.orgTreeShow = true
|
|
|
|
|
// 获取机构树
|
|
|
|
|
this.getOrgTree()
|
|
|
|
|
// 已关联数据
|
|
|
|
|
this.sysUserOwnData(this.userEntity)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取机构树
|
|
|
|
|
*/
|
|
|
|
|
getOrgTree () {
|
|
|
|
|
this.formLoading = true
|
|
|
|
|
getOrgTree().then((res) => {
|
|
|
|
|
if (res.success) {
|
|
|
|
|
this.orgTreeData = res.data
|
|
|
|
|
// 默认展开
|
|
|
|
|
this.orgTreeData.forEach(item => {
|
|
|
|
|
this.expandedKeys.push(item.id)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
} else {
|
|
|
|
|
this.orgTreeShow = false
|
|
|
|
|
// 清理已选中机构
|
|
|
|
|
this.checkedKeys = []
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 获取机构树
|
|
|
|
|
*/
|
|
|
|
|
getOrgTree() {
|
|
|
|
|
getOrgTree().then(res => {
|
|
|
|
|
if (res.success) {
|
|
|
|
|
this.orgTreeData = res.data
|
|
|
|
|
console.log(this.orgTreeData, 1111111111111111111111111)
|
|
|
|
|
// 默认展开
|
|
|
|
|
this.orgTreeData.forEach(item => {
|
|
|
|
|
this.expandedKeys.push(item.id)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 获取字典数据
|
|
|
|
|
*/
|
|
|
|
|
sysDictTypeDropDown() {
|
|
|
|
|
// 数据范围
|
|
|
|
|
sysDictTypeDropDown({ code: 'data_scope_type' }).then(res => {
|
|
|
|
|
this.dataScopeTypeData = res.data
|
|
|
|
|
this.formLoading = false
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 获取菜单树
|
|
|
|
|
*/
|
|
|
|
|
getMenuList() {
|
|
|
|
|
this.formLoading = true
|
|
|
|
|
getMenuList().then(res => {
|
|
|
|
|
if (res.success) {
|
|
|
|
|
this.menuTreeData = res.data
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 此用户已有数据列表
|
|
|
|
|
*/
|
|
|
|
|
sysUserOwnData (record) {
|
|
|
|
|
sysUserOwnData({ id: record.id }).then((res) => {
|
|
|
|
|
if (res.success) {
|
|
|
|
|
this.checkedKeys = res.data
|
|
|
|
|
}
|
|
|
|
|
this.formLoading = false
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
onExpand(expandedKeys) {
|
|
|
|
|
this.expandedKeys = expandedKeys
|
|
|
|
|
this.autoExpandParent = false
|
|
|
|
|
},
|
|
|
|
|
onCheck(checkedKeys) {
|
|
|
|
|
this.checkedKeys = checkedKeys.checked
|
|
|
|
|
this.GrantData.forEach(item => {
|
|
|
|
|
if (item.sysMenuId == this.SelectMenuId) {
|
|
|
|
|
item.RightData = []
|
|
|
|
|
checkedKeys.checked.forEach(item2 => {
|
|
|
|
|
item.RightData.push({ menuId: this.SelectMenuId, orgId: item2 })
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onExpand (expandedKeys) {
|
|
|
|
|
this.expandedKeys = expandedKeys
|
|
|
|
|
this.autoExpandParent = false
|
|
|
|
|
},
|
|
|
|
|
onCheck (checkedKeys) {
|
|
|
|
|
this.checkedKeys = checkedKeys
|
|
|
|
|
},
|
|
|
|
|
onSelect (selectedKeys, info) {
|
|
|
|
|
this.selectedKeys = selectedKeys
|
|
|
|
|
},
|
|
|
|
|
onSelectMenu(selectedKeys) {
|
|
|
|
|
this.checkedKeys = []
|
|
|
|
|
this.SelectMenu = true
|
|
|
|
|
this.SelectMenuId = selectedKeys[0]
|
|
|
|
|
let type = ''
|
|
|
|
|
this.GrantData.forEach(item => {
|
|
|
|
|
if (item.sysMenuId == selectedKeys[0]) {
|
|
|
|
|
console.log(item.sysMenuId, item.RightData)
|
|
|
|
|
item.RightData.forEach(item2 => {
|
|
|
|
|
this.checkedKeys.push(item2.orgId)
|
|
|
|
|
})
|
|
|
|
|
type = `${item.dataScopeType}`
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
this.handleChange(type)
|
|
|
|
|
this.form.setFieldsValue({
|
|
|
|
|
dataScopeType: type
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
onCheckMenu(checkedKeys, e) {
|
|
|
|
|
this.MeuncheckedKeys = checkedKeys.checked
|
|
|
|
|
},
|
|
|
|
|
handleSubmit() {
|
|
|
|
|
const {
|
|
|
|
|
form: { validateFields }
|
|
|
|
|
} = this
|
|
|
|
|
this.confirmLoading = true
|
|
|
|
|
validateFields((errors, values) => {
|
|
|
|
|
if (!errors) {
|
|
|
|
|
let childrens = []
|
|
|
|
|
this.MeuncheckedKeys.forEach(item => {
|
|
|
|
|
this.GrantData.forEach(item2 => {
|
|
|
|
|
if (item == item2.sysMenuId) {
|
|
|
|
|
childrens.push({ ...item2, menuId: item2.sysMenuId })
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
handleSubmit () {
|
|
|
|
|
const { form: { validateFields } } = this
|
|
|
|
|
this.confirmLoading = true
|
|
|
|
|
validateFields((errors, values) => {
|
|
|
|
|
if (!errors) {
|
|
|
|
|
const checkedKeys = this.checkedKeys.checked === undefined ? this.checkedKeys : this.checkedKeys.checked
|
|
|
|
|
sysUserGrantData({ id: this.userEntity.id, grantOrgIdList: checkedKeys }).then((res) => {
|
|
|
|
|
SysDataUserMenuGrantData({ userId: this.userEntity.id, childrens })
|
|
|
|
|
.then(res => {
|
|
|
|
|
if (res.success) {
|
|
|
|
|
this.$message.success('授权成功')
|
|
|
|
|
this.confirmLoading = false
|
|
|
|
|
this.$emit('ok', values)
|
|
|
|
|
this.handleCancel()
|
|
|
|
|
let childrens2 = []
|
|
|
|
|
childrens.forEach(item => {
|
|
|
|
|
childrens2 = [...childrens2, ...item.RightData]
|
|
|
|
|
})
|
|
|
|
|
SysDataUserMenuGrantRightData({ userId: this.userEntity.id, childrens: childrens2 })
|
|
|
|
|
.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
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error('授权失败:' + res.message)
|
|
|
|
|
}
|
|
|
|
|
}).finally((res) => {
|
|
|
|
|
})
|
|
|
|
|
.finally(res => {
|
|
|
|
|
this.confirmLoading = false
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
this.confirmLoading = false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleCancel () {
|
|
|
|
|
this.form.resetFields()
|
|
|
|
|
// 清空已选择的
|
|
|
|
|
this.checkedKeys = []
|
|
|
|
|
// 清空已展开的
|
|
|
|
|
this.expandedKeys = []
|
|
|
|
|
this.visible = false
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.confirmLoading = false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleCancel() {
|
|
|
|
|
this.form.resetFields()
|
|
|
|
|
// 清空已选择的
|
|
|
|
|
this.checkedKeys = []
|
|
|
|
|
this.checkedMenuKeys = []
|
|
|
|
|
// 清空已展开的
|
|
|
|
|
this.expandedKeys = []
|
|
|
|
|
this.visible = false
|
|
|
|
|
this.SelectMenu = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
@ -157,4 +334,4 @@
|
|
|
|
|
max-height: 60vh;
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
</style>
|
|
|
|
|