This commit is contained in:
@@ -21,5 +21,6 @@
|
|||||||
@import './lib/select.less';
|
@import './lib/select.less';
|
||||||
@import './lib/dropdown.less';
|
@import './lib/dropdown.less';
|
||||||
@import './lib/tree-layout.less';
|
@import './lib/tree-layout.less';
|
||||||
|
@import './lib/authority-view.less';
|
||||||
@import './theme/primary.less';
|
@import './theme/primary.less';
|
||||||
// @import './lib/font-weight.less';
|
// @import './lib/font-weight.less';
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
@import (reference) '~@/assets/style/extend.less';
|
||||||
|
.yo-authority-view {
|
||||||
|
.ant-descriptions-item-label {
|
||||||
|
width: 150px;
|
||||||
|
}
|
||||||
|
.ant-descriptions {
|
||||||
|
margin-bottom: @padding-sm;
|
||||||
|
&:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.ant-descriptions-item-content {
|
||||||
|
padding: @padding-sm @padding-md;
|
||||||
|
>.yo-authority-view--checkbox {
|
||||||
|
display: inline-block;
|
||||||
|
|
||||||
|
width: 150px;
|
||||||
|
margin: @padding-xxs 0;
|
||||||
|
.ant-checkbox-wrapper {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,10 +28,7 @@ const initInstance = () => {
|
|||||||
|
|
||||||
instance.interceptors.response.use((res) => {
|
instance.interceptors.response.use((res) => {
|
||||||
if (res.data.status === status.Unauthorized) {
|
if (res.data.status === status.Unauthorized) {
|
||||||
token.value = ''
|
handlerUnauthorized()
|
||||||
app.$router.replace({
|
|
||||||
path: '/login'
|
|
||||||
}).catch(() => { })
|
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
@@ -40,6 +37,8 @@ const initInstance = () => {
|
|||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const errerCodes = [status.BadRequest, status.InternalServerError]
|
||||||
|
|
||||||
const errorNotification = ({ code, message }) => {
|
const errorNotification = ({ code, message }) => {
|
||||||
switch (message.constructor) {
|
switch (message.constructor) {
|
||||||
case Array:
|
case Array:
|
||||||
@@ -61,6 +60,13 @@ const errorNotification = ({ code, message }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handlerUnauthorized = () => {
|
||||||
|
token.value = ''
|
||||||
|
app.$router.replace({
|
||||||
|
path: '/login'
|
||||||
|
}).catch(() => { })
|
||||||
|
}
|
||||||
|
|
||||||
const api = {}
|
const api = {}
|
||||||
|
|
||||||
for (let key in urls) {
|
for (let key in urls) {
|
||||||
@@ -96,21 +102,26 @@ for (let key in urls) {
|
|||||||
return new Promise((reslove, reject) => {
|
return new Promise((reslove, reject) => {
|
||||||
api[`${key}Wait`](params)
|
api[`${key}Wait`](params)
|
||||||
.then(({ data }) => {
|
.then(({ data }) => {
|
||||||
if ([status.BadRequest].indexOf(data.code) >= 0) {
|
if (errerCodes.indexOf(data.code) >= 0) {
|
||||||
errorNotification(data)
|
errorNotification(data)
|
||||||
reject(data)
|
reject(data)
|
||||||
|
} else if (data.code === status.Unauthorized) {
|
||||||
|
handlerUnauthorized()
|
||||||
} else {
|
} else {
|
||||||
reslove(data)
|
reslove(data)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(({ response: { data } }) => {
|
.catch(({ response: { data } }) => {
|
||||||
if (process.env.VUE_APP_NODE_ENV === 'development') {
|
if (process.env.VUE_APP_NODE_ENV === 'development') {
|
||||||
|
errorNotification(data)
|
||||||
|
reject(data)
|
||||||
|
if (data.code === status.Unauthorized) {
|
||||||
|
handlerUnauthorized()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
errorNotification({
|
errorNotification({
|
||||||
message: '发生错误,请联系管理员'
|
message: '发生错误,请联系管理员'
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
errorNotification(data)
|
|
||||||
reject(data)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,202 @@
|
|||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
loadData: {
|
||||||
|
type: Function,
|
||||||
|
require: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
autoLoad: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
|
||||||
|
defaultSelectedKeys: {
|
||||||
|
type: Array,
|
||||||
|
default: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
loading: false,
|
||||||
|
|
||||||
|
data: [],
|
||||||
|
list: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
created() {
|
||||||
|
if (this.autoLoad) {
|
||||||
|
this.onLoadData()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
|
||||||
|
renderDescriptions(data) {
|
||||||
|
return data.map(p => {
|
||||||
|
return p.children && p.children.length ? this.renderItem(p) : this.renderCheckbox(p)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
renderItem(data) {
|
||||||
|
return (
|
||||||
|
<a-descriptions bordered column={1}>
|
||||||
|
<a-descriptions-item>
|
||||||
|
<a-checkbox
|
||||||
|
slot="label"
|
||||||
|
value={data.id}
|
||||||
|
checked={data.checked}
|
||||||
|
indeterminate={data.indeterminate}
|
||||||
|
onChange={(e) => this.onChange(e, data)}
|
||||||
|
>{data.title}</a-checkbox>
|
||||||
|
{this.renderDescriptions(data.children)}
|
||||||
|
</a-descriptions-item>
|
||||||
|
</a-descriptions>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
|
renderCheckbox(data) {
|
||||||
|
return (
|
||||||
|
<div class="yo-authority-view--checkbox">
|
||||||
|
<a-checkbox
|
||||||
|
value={data.id}
|
||||||
|
checked={data.checked}
|
||||||
|
onChange={(e) => this.onChange(e, data)}
|
||||||
|
>{data.title}</a-checkbox>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoadData() {
|
||||||
|
this.loading = true
|
||||||
|
|
||||||
|
this.loadData().then((res) => {
|
||||||
|
this.data = this.generateCheck(res)
|
||||||
|
|
||||||
|
this.list = []
|
||||||
|
this.generateList(this.data)
|
||||||
|
|
||||||
|
if (this.defaultSelectedKeys.length) {
|
||||||
|
this.list.map(p => {
|
||||||
|
if (this.defaultSelectedKeys.indexOf(p.id) > -1 && (!p.children || !p.children.length)) {
|
||||||
|
this.onSelect(true, p)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
this.loading = false
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
onReloadData() {
|
||||||
|
|
||||||
|
this.data = []
|
||||||
|
this.onLoadData()
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
onChange(e, item) {
|
||||||
|
|
||||||
|
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))
|
||||||
|
},
|
||||||
|
|
||||||
|
onSelect(check, item) {
|
||||||
|
item.checked = check
|
||||||
|
item.indeterminate = false
|
||||||
|
if (item.children && item.children.length) {
|
||||||
|
this.onChangeChildren(item.checked, item.children)
|
||||||
|
}
|
||||||
|
if (item.parentId) {
|
||||||
|
this.onChangeParent(item.checked, item.parentId)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onChangeParent(checked, parentId) {
|
||||||
|
const parent = this.list.find(p => p.id === parentId)
|
||||||
|
if (parent) {
|
||||||
|
const checkedCount = parent.children.filter(p => p.checked).length
|
||||||
|
const indeterminateCount = parent.children.filter(p => p.indeterminate).length
|
||||||
|
if (checkedCount === parent.children.length) {
|
||||||
|
// 全选
|
||||||
|
parent.checked = true
|
||||||
|
parent.indeterminate = false
|
||||||
|
} else if (!checkedCount && !indeterminateCount) {
|
||||||
|
// 全不选
|
||||||
|
parent.checked = false
|
||||||
|
parent.indeterminate = false
|
||||||
|
} else {
|
||||||
|
// 半选
|
||||||
|
parent.checked = false
|
||||||
|
parent.indeterminate = true
|
||||||
|
}
|
||||||
|
this.onChangeParent(checked, parent.parentId)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onChangeChildren(checked, children) {
|
||||||
|
children.forEach(p => {
|
||||||
|
p.checked = checked
|
||||||
|
p.indeterminate = false
|
||||||
|
if (p.children && p.children.length) {
|
||||||
|
this.onChangeChildren(checked, p.children)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
generateCheck(data) {
|
||||||
|
data.forEach(p => {
|
||||||
|
if (p.children && p.children.length) {
|
||||||
|
p.children = this.generateCheck(p.children)
|
||||||
|
}
|
||||||
|
p.checked = false
|
||||||
|
p.indeterminate = false
|
||||||
|
})
|
||||||
|
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
|
||||||
|
generateList(data) {
|
||||||
|
data.forEach(p => {
|
||||||
|
if (p.children && p.children.length) {
|
||||||
|
this.generateList(p.children)
|
||||||
|
}
|
||||||
|
this.list.push(p)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div class="yo-authority-view">
|
||||||
|
<a-spin style={{ width: '100%' }} spinning={this.loading}>
|
||||||
|
<a-icon slot="indicator" type="loading" spin />
|
||||||
|
{
|
||||||
|
!this.loading &&
|
||||||
|
<a-descriptions bordered column={1}>
|
||||||
|
{
|
||||||
|
this.data.map(p => {
|
||||||
|
return (
|
||||||
|
<a-descriptions-item>
|
||||||
|
<a-checkbox
|
||||||
|
slot="label"
|
||||||
|
value={p.id}
|
||||||
|
checked={p.checked}
|
||||||
|
indeterminate={p.indeterminate}
|
||||||
|
onChange={(e) => this.onChange(e, p)}
|
||||||
|
>{p.title}</a-checkbox>
|
||||||
|
{this.renderDescriptions(p.children)}
|
||||||
|
</a-descriptions-item>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</a-descriptions>
|
||||||
|
}
|
||||||
|
</a-spin>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
import { template } from "lodash"
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
loadData: {
|
loadData: {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
@cancel="onCancel"
|
@cancel="onCancel"
|
||||||
@ok="onOk"
|
@ok="onOk"
|
||||||
class="yo-modal-form"
|
class="yo-modal-form"
|
||||||
title="新增应用"
|
title="新增角色"
|
||||||
>
|
>
|
||||||
<FormBody ref="form-body" />
|
<FormBody ref="form-body" />
|
||||||
</a-modal>
|
</a-modal>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
@cancel="onCancel"
|
@cancel="onCancel"
|
||||||
@ok="onOk"
|
@ok="onOk"
|
||||||
class="yo-modal-form"
|
class="yo-modal-form"
|
||||||
title="角色编辑"
|
title="编辑角色"
|
||||||
>
|
>
|
||||||
<FormBody ref="form-body" />
|
<FormBody ref="form-body" />
|
||||||
</a-modal>
|
</a-modal>
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
</a-popconfirm>
|
</a-popconfirm>
|
||||||
</Auth>
|
</Auth>
|
||||||
<Auth :auth="{ sysRole: [['grantMenu'], ['grantData']] }">
|
<Auth :auth="{ sysRole: [['grantMenu'], ['grantData']] }">
|
||||||
<a-dropdown>
|
<a-dropdown placement="bottomRight">
|
||||||
<a class="ant-dropdown-link">
|
<a class="ant-dropdown-link">
|
||||||
授权
|
授权
|
||||||
<a-icon type="down" />
|
<a-icon type="down" />
|
||||||
@@ -45,12 +45,12 @@
|
|||||||
<a-menu slot="overlay">
|
<a-menu slot="overlay">
|
||||||
<Auth auth="sysRole:grantMenu">
|
<Auth auth="sysRole:grantMenu">
|
||||||
<a-menu-item>
|
<a-menu-item>
|
||||||
<a @click="$refs.roleMenuForm.roleMenu(record)">授权菜单</a>
|
<a @click="onOpen('menu-form', record)">授权菜单</a>
|
||||||
</a-menu-item>
|
</a-menu-item>
|
||||||
</Auth>
|
</Auth>
|
||||||
<Auth auth="sysRole:grantData">
|
<Auth auth="sysRole:grantData">
|
||||||
<a-menu-item>
|
<a-menu-item>
|
||||||
<a @click="$refs.roleOrgForm.roleOrg(record)">授权数据</a>
|
<a @click="onOpen('org-form', record)">授权数据</a>
|
||||||
</a-menu-item>
|
</a-menu-item>
|
||||||
</Auth>
|
</Auth>
|
||||||
</a-menu>
|
</a-menu>
|
||||||
@@ -63,21 +63,21 @@
|
|||||||
<br />
|
<br />
|
||||||
<add-form @ok="onReloadData" ref="add-form" />
|
<add-form @ok="onReloadData" ref="add-form" />
|
||||||
<edit-form @ok="onReloadData" ref="edit-form" />
|
<edit-form @ok="onReloadData" ref="edit-form" />
|
||||||
<role-menu-form @ok="onReloadData" ref="roleMenuForm" />
|
<menu-form @ok="onReloadData" ref="menu-form" />
|
||||||
<role-org-form @ok="onReloadData" ref="roleOrgForm" />
|
<org-form @ok="onReloadData" ref="org-form" />
|
||||||
</container>
|
</container>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import AddForm from './addForm';
|
import AddForm from './addForm';
|
||||||
import editForm from './editForm';
|
import editForm from './editForm';
|
||||||
import roleMenuForm from './roleMenuForm';
|
import menuForm from './menuForm';
|
||||||
import roleOrgForm from './roleOrgForm';
|
import orgForm from './orgForm';
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
AddForm,
|
AddForm,
|
||||||
editForm,
|
editForm,
|
||||||
roleMenuForm,
|
menuForm,
|
||||||
roleOrgForm,
|
orgForm,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -95,18 +95,23 @@ export default {
|
|||||||
title: '排序',
|
title: '排序',
|
||||||
dataIndex: 'sort',
|
dataIndex: 'sort',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: '操作',
|
|
||||||
width: '200px',
|
|
||||||
dataIndex: 'action',
|
|
||||||
scopedSlots: {
|
|
||||||
customRender: 'action',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {},
|
created() {
|
||||||
|
const flag = this.$auth({
|
||||||
|
sysRole: [['edit'], ['delete'], ['grantMenu'], ['grantData']],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
this.columns.push({
|
||||||
|
title: '操作',
|
||||||
|
width: '200px',
|
||||||
|
dataIndex: 'action',
|
||||||
|
scopedSlots: { customRender: 'action' },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
/**
|
/**
|
||||||
* 必要的方法
|
* 必要的方法
|
||||||
@@ -157,7 +162,7 @@ export default {
|
|||||||
|
|
||||||
onDelete(record) {
|
onDelete(record) {
|
||||||
this.$refs.table.onLoading();
|
this.$refs.table.onLoading();
|
||||||
this.$api.sysRoleDel(record).then(({ success, message }) => {
|
this.$api.sysRoleDel(record).then(({ success }) => {
|
||||||
this.onResult(success, '删除成功');
|
this.onResult(success, '删除成功');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,168 +1,101 @@
|
|||||||
<template>
|
<template>
|
||||||
<a-modal
|
<a-modal
|
||||||
title="授权菜单"
|
|
||||||
:width="600"
|
|
||||||
:visible="visible"
|
|
||||||
:confirmLoading="confirmLoading"
|
:confirmLoading="confirmLoading"
|
||||||
@ok="handleSubmit"
|
:visible="visible"
|
||||||
@cancel="handleCancel"
|
:width="1200"
|
||||||
|
@cancel="onCancel"
|
||||||
|
@ok="onOk"
|
||||||
|
title="授权菜单"
|
||||||
>
|
>
|
||||||
<a-spin :spinning="formLoading">
|
<yo-authority-view
|
||||||
<a-form :form="form">
|
:auto-load="false"
|
||||||
|
:default-selected-keys="selectedKeys"
|
||||||
<a-form-item
|
:load-data="loadData"
|
||||||
label="菜单权限"
|
@select="onSelect"
|
||||||
:labelCol="labelCol"
|
ref="authority-view"
|
||||||
:wrapperCol="wrapperCol">
|
/>
|
||||||
|
|
||||||
<a-tree
|
|
||||||
v-model="checkedKeys"
|
|
||||||
multiple
|
|
||||||
checkable
|
|
||||||
:auto-expand-parent="autoExpandParent"
|
|
||||||
:expanded-keys="expandedKeys"
|
|
||||||
:tree-data="menuTreeData"
|
|
||||||
:selected-keys="selectedKeys"
|
|
||||||
:replaceFields="replaceFields"
|
|
||||||
@expand="onExpand"
|
|
||||||
@select="onSelect"
|
|
||||||
@check="treeCheck"
|
|
||||||
/>
|
|
||||||
</a-tree></a-form-item>
|
|
||||||
|
|
||||||
</a-form>
|
|
||||||
|
|
||||||
</a-spin>
|
|
||||||
</a-modal>
|
</a-modal>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// import { sysRoleOwnMenu, sysRoleGrantMenu } from '@/api/modular/system/roleManage'
|
import YoAuthorityView from '@/components/yoAuthorityView';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data () {
|
components: {
|
||||||
return {
|
YoAuthorityView,
|
||||||
labelCol: {
|
},
|
||||||
style: { 'padding-right': '20px' },
|
|
||||||
xs: { span: 24 },
|
data() {
|
||||||
sm: { span: 5 }
|
return {
|
||||||
},
|
visible: false,
|
||||||
wrapperCol: {
|
|
||||||
xs: { span: 24 },
|
record: {},
|
||||||
sm: { span: 15 }
|
selectedKeys: [],
|
||||||
},
|
|
||||||
menuTreeData: [],
|
confirmLoading: false,
|
||||||
expandedKeys: [],
|
};
|
||||||
checkedKeys: [],
|
},
|
||||||
halfCheckedKeys: [],
|
|
||||||
visible: false,
|
methods: {
|
||||||
confirmLoading: false,
|
/**
|
||||||
formLoading: true,
|
* 必要的方法
|
||||||
autoExpandParent: true,
|
* 从外部调用打开本窗口
|
||||||
selectedKeys: [],
|
*/
|
||||||
subValues: [],
|
onOpen(record) {
|
||||||
roleEntity: [],
|
this.visible = true;
|
||||||
replaceFields: {
|
this.record = record;
|
||||||
key: 'id'
|
|
||||||
},
|
this.$nextTick(async () => {
|
||||||
form: this.$form.createForm(this)
|
const view = this.$refs['authority-view'];
|
||||||
}
|
view.loading = true;
|
||||||
|
view.data = [];
|
||||||
|
this.selectedKeys = await this.onLoadRoleOwnMenu();
|
||||||
|
view.onReloadData();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
loadData() {
|
||||||
// 初始化方法
|
return this.$api.SysMenuTreeForGrant().then((res) => {
|
||||||
onOpen (record) {
|
return res.data;
|
||||||
this.formLoading = true
|
});
|
||||||
this.roleEntity = record
|
},
|
||||||
this.visible = true
|
|
||||||
this.getMenuTree()
|
|
||||||
this.expandedMenuKeys(record)
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取菜单列表
|
* 此角色已有菜单权限
|
||||||
*/
|
*/
|
||||||
getMenuTree () {
|
onLoadRoleOwnMenu() {
|
||||||
this.$api.SysMenuTreeForGrant().then((res) => {
|
return this.$api.sysRoleOwnMenu({ id: this.record.id }).then(({ data }) => {
|
||||||
if (res.success) {
|
return data;
|
||||||
this.menuTreeData = res.data
|
});
|
||||||
// 默认展开目录级
|
},
|
||||||
this.menuTreeData.forEach(item => {
|
|
||||||
this.expandedKeys.push(item.id)
|
onSelect(a1, a2) {
|
||||||
})
|
this.selectedKeys = a2;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
onOk() {
|
||||||
|
this.confirmLoading = true;
|
||||||
|
|
||||||
|
this.$api
|
||||||
|
.sysRoleGrantMenu({
|
||||||
|
id: this.record.id,
|
||||||
|
grantMenuIdList: this.selectedKeys,
|
||||||
})
|
})
|
||||||
},
|
.then(({ success }) => {
|
||||||
|
if (success) {
|
||||||
/**
|
this.$message.success('授权成功');
|
||||||
* 此角色已有菜单权限
|
this.$emit('ok');
|
||||||
*/
|
this.onCancel();
|
||||||
expandedMenuKeys (record) {
|
|
||||||
this.$api.sysRoleOwnMenu({ id: record.id }).then((res) => {
|
|
||||||
if (res.success) {
|
|
||||||
this.checkedKeys = res.data
|
|
||||||
this.findAllChildren(this.menuTreeData)
|
|
||||||
}
|
|
||||||
this.formLoading = false
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
treeCheck (checkKeys, event) {
|
|
||||||
this.halfCheckedKeys = event.halfCheckedKeys
|
|
||||||
},
|
|
||||||
onExpand (expandedKeys) {
|
|
||||||
this.expandedKeys = expandedKeys
|
|
||||||
this.autoExpandParent = false
|
|
||||||
},
|
|
||||||
onCheck (checkedKeys) {
|
|
||||||
this.checkedKeys = checkedKeys
|
|
||||||
},
|
|
||||||
onSelect (selectedKeys, info) {
|
|
||||||
this.selectedKeys = selectedKeys
|
|
||||||
},
|
|
||||||
|
|
||||||
handleSubmit () {
|
|
||||||
const { form: { validateFields } } = this
|
|
||||||
this.confirmLoading = true
|
|
||||||
validateFields((errors, values) => {
|
|
||||||
if (!errors) {
|
|
||||||
this.$api.sysRoleGrantMenu({ id: this.roleEntity.id, grantMenuIdList: this.checkedKeys.concat(this.halfCheckedKeys) }).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.confirmLoading = false
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
.finally((res) => {
|
||||||
handleCancel () {
|
this.confirmLoading = false;
|
||||||
// 清空已选择的
|
});
|
||||||
this.checkedKeys = []
|
},
|
||||||
// 清空已展开的
|
|
||||||
this.expandedKeys = []
|
onCancel() {
|
||||||
this.visible = false
|
this.visible = false;
|
||||||
},
|
},
|
||||||
// 遍历树形然后获取到对父节点进行移除,使用子节点,而且将父节点加入到mainMenuList
|
},
|
||||||
findAllChildren(data) {
|
};
|
||||||
data.forEach((item, index) => {
|
|
||||||
if (item.children.length !== 0) {
|
|
||||||
for (let i = 0; i < this.checkedKeys.length; i++) {
|
|
||||||
if (item.id === this.checkedKeys[i]) {
|
|
||||||
this.checkedKeys.splice(i, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.findAllChildren(item.children)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,195 +1,170 @@
|
|||||||
<template>
|
<template>
|
||||||
<a-modal
|
<a-modal
|
||||||
title="授权数据"
|
|
||||||
:width="600"
|
|
||||||
:visible="visible"
|
|
||||||
:confirmLoading="confirmLoading"
|
:confirmLoading="confirmLoading"
|
||||||
@ok="handleSubmit"
|
:visible="visible"
|
||||||
@cancel="handleCancel"
|
:width="600"
|
||||||
|
@cancel="onCancel"
|
||||||
|
@ok="onOk"
|
||||||
|
title="授权数据"
|
||||||
>
|
>
|
||||||
<a-spin :spinning="formLoading">
|
<a-spin :spinning="loading">
|
||||||
<a-form :form="form">
|
<a-icon slot="indicator" spin type="loading" />
|
||||||
<a-form-item
|
<a-form-model :model="form" :rules="rules" class="yo-form" ref="form">
|
||||||
label="授权范围"
|
<div class="yo-form-group">
|
||||||
:labelCol="labelCol"
|
<a-form-model-item has-feedback label="授权范围" prop="dataScopeType">
|
||||||
:wrapperCol="wrapperCol"
|
<a-select placeholder="请选择授权范围" v-model="form.dataScopeType">
|
||||||
has-feedback
|
<a-select-option
|
||||||
>
|
:key="item.code"
|
||||||
<a-select style="width: 100%" placeholder="请选择授权范围" v-decorator="['dataScopeType', {rules: [{ required: true, message: '请选择授权范围!' }]}]" >
|
:value="item.code"
|
||||||
<a-select-option v-for="(item,index) in dataScopeTypeData" :key="index" :value="item.code" @click="handleChange(item.code)">{{ item.value }}</a-select-option>
|
@click="onChange(item.code)"
|
||||||
</a-select>
|
v-for="item in dataScopeTypeData"
|
||||||
</a-form-item>
|
>{{ item.value }}</a-select-option>
|
||||||
<div v-show="orgTreeShow">
|
</a-select>
|
||||||
<a-form-item
|
</a-form-model-item>
|
||||||
label="选择机构"
|
<a-form-model-item label="选择机构" v-show="orgTreeShow">
|
||||||
:labelCol="labelCol"
|
<a-tree-select
|
||||||
:wrapperCol="wrapperCol"
|
:show-checked-strategy="SHOW_PARENT"
|
||||||
>
|
|
||||||
<a-tree
|
|
||||||
v-model="checkedKeys"
|
|
||||||
checkable
|
|
||||||
checkStrictly
|
|
||||||
:auto-expand-parent="autoExpandParent"
|
|
||||||
:expanded-keys="expandedKeys"
|
|
||||||
:tree-data="orgTreeData"
|
:tree-data="orgTreeData"
|
||||||
:selected-keys="selectedKeys"
|
placeholder="请选择机构"
|
||||||
:replaceFields="replaceFields"
|
tree-checkable
|
||||||
@expand="onExpand"
|
v-model="checkedKeys"
|
||||||
@select="onSelect"
|
|
||||||
/>
|
/>
|
||||||
</a-form-item>
|
</a-form-model-item>
|
||||||
</div>
|
</div>
|
||||||
</a-form>
|
</a-form-model>
|
||||||
</a-spin>
|
</a-spin>
|
||||||
</a-modal>
|
</a-modal>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { TreeSelect } from 'ant-design-vue';
|
||||||
|
const SHOW_PARENT = TreeSelect.SHOW_PARENT;
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
visible: false,
|
||||||
|
confirmLoading: false,
|
||||||
|
loading: true,
|
||||||
|
|
||||||
export default {
|
record: {},
|
||||||
data () {
|
|
||||||
return {
|
form: {
|
||||||
labelCol: {
|
dataScopeType: '',
|
||||||
style: { 'padding-right': '20px' },
|
},
|
||||||
xs: { span: 24 },
|
rules: {
|
||||||
sm: { span: 5 }
|
dataScopeType: [{ required: true, message: '请选择授权范围' }],
|
||||||
},
|
},
|
||||||
wrapperCol: {
|
|
||||||
xs: { span: 24 },
|
SHOW_PARENT,
|
||||||
sm: { span: 15 }
|
orgTreeData: [],
|
||||||
},
|
|
||||||
orgTreeData: [],
|
checkedKeys: [],
|
||||||
expandedKeys: [],
|
dataScopeTypeData: [],
|
||||||
checkedKeys: [],
|
orgTreeShow: false,
|
||||||
visible: false,
|
replaceFields: {
|
||||||
confirmLoading: false,
|
key: 'id',
|
||||||
formLoading: true,
|
},
|
||||||
autoExpandParent: true,
|
};
|
||||||
selectedKeys: [],
|
},
|
||||||
subValues: [],
|
|
||||||
roleEntity: [],
|
methods: {
|
||||||
dataScopeTypeData: [],
|
async onOpen(record) {
|
||||||
orgTreeShow: false,
|
this.visible = true;
|
||||||
replaceFields: {
|
this.record = record;
|
||||||
key: 'id'
|
|
||||||
},
|
this.loading = true;
|
||||||
form: this.$form.createForm(this)
|
|
||||||
|
await this.onLoadCodes();
|
||||||
|
this.form.dataScopeType = record.dataScopeType.toString();
|
||||||
|
|
||||||
|
await this.onChange(record.dataScopeType);
|
||||||
|
|
||||||
|
this.loading = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载字典数据时的必要方法
|
||||||
|
*/
|
||||||
|
onLoadCodes() {
|
||||||
|
return this.$api
|
||||||
|
.$queue([this.$api.sysDictTypeDropDownWait({ code: 'data_scope_type' })])
|
||||||
|
.then(([dataScopeType]) => {
|
||||||
|
this.dataScopeTypeData = dataScopeType.data;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
async onChange(value) {
|
||||||
|
if (value == '5') {
|
||||||
|
this.loading = true;
|
||||||
|
this.orgTreeShow = true;
|
||||||
|
// 获取机构树
|
||||||
|
this.orgTreeData = await this.onLoadTreeData();
|
||||||
|
// 已关联数据
|
||||||
|
this.checkedKeys = await this.onLoadRoleOwn();
|
||||||
|
|
||||||
|
this.loading = false;
|
||||||
|
} else {
|
||||||
|
this.orgTreeShow = false;
|
||||||
|
// 清理已选中机构
|
||||||
|
this.checkedKeys = [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
/**
|
||||||
// 初始化方法
|
* 获取机构树
|
||||||
onOpen (record) {
|
*/
|
||||||
this.roleEntity = record
|
onLoadTreeData() {
|
||||||
this.visible = true
|
return this.$api.getOrgTree().then(({ data }) => {
|
||||||
this.formLoading = true
|
return data;
|
||||||
this.sysDictTypeDropDown()
|
});
|
||||||
this.form.getFieldDecorator('dataScopeType', { initialValue: record.dataScopeType.toString() })
|
},
|
||||||
this.handleChange(record.dataScopeType)
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取字典数据
|
* 此角色已有数据列表
|
||||||
*/
|
*/
|
||||||
sysDictTypeDropDown () {
|
onLoadRoleOwn() {
|
||||||
// 数据范围
|
return this.$api.sysRoleOwnData({ id: this.record.id }).then(({ data }) => {
|
||||||
this.$api.sysDictTypeDropDown({ code: 'data_scope_type' }).then((res) => {
|
return data;
|
||||||
this.dataScopeTypeData = res.data
|
});
|
||||||
this.formLoading = false
|
},
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
// 范围下拉框事件
|
onOk() {
|
||||||
handleChange (value) {
|
this.$refs.form.validate((valid) => {
|
||||||
// eslint-disable-next-line eqeqeq
|
if (valid) {
|
||||||
if (value == '5') {
|
this.confirmLoading = true;
|
||||||
this.formLoading = true
|
this.$api
|
||||||
this.orgTreeShow = true
|
.sysRoleGrantData({
|
||||||
// 获取机构树
|
id: this.record.id,
|
||||||
this.getOrgTree()
|
grantOrgIdList: this.checkedKeys,
|
||||||
// 已关联数据
|
dataScopeType: this.form.dataScopeType,
|
||||||
this.sysRoleOwnData(this.roleEntity)
|
|
||||||
} else {
|
|
||||||
this.orgTreeShow = false
|
|
||||||
// 清理已选中机构
|
|
||||||
this.checkedKeys = []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取机构树
|
|
||||||
*/
|
|
||||||
getOrgTree () {
|
|
||||||
this.$api.getOrgTree().then((res) => {
|
|
||||||
if (res.success) {
|
|
||||||
this.orgTreeData = res.data
|
|
||||||
// 默认展开
|
|
||||||
this.orgTreeData.forEach(item => {
|
|
||||||
this.expandedKeys.push(item.id)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 此角色已有数据列表
|
|
||||||
*/
|
|
||||||
sysRoleOwnData (record) {
|
|
||||||
this.$api.sysRoleOwnData({ id: record.id }).then((res) => {
|
|
||||||
if (res.success) {
|
|
||||||
//console.log(JSON.stringify(res.data))
|
|
||||||
this.checkedKeys = res.data
|
|
||||||
}
|
|
||||||
this.formLoading = false
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
onExpand (expandedKeys) {
|
|
||||||
this.expandedKeys = expandedKeys
|
|
||||||
this.autoExpandParent = false
|
|
||||||
},
|
|
||||||
onCheck (checkedKeys) {
|
|
||||||
//console.log(JSON.stringify(checkedKeys))
|
|
||||||
this.checkedKeys = checkedKeys
|
|
||||||
},
|
|
||||||
onSelect (selectedKeys, info) {
|
|
||||||
this.selectedKeys = selectedKeys
|
|
||||||
},
|
|
||||||
|
|
||||||
handleSubmit () {
|
|
||||||
const { form: { validateFields } } = this
|
|
||||||
this.confirmLoading = true
|
|
||||||
validateFields((errors, values) => {
|
|
||||||
if (!errors) {
|
|
||||||
const checkedKeys = this.checkedKeys.checked === undefined ? this.checkedKeys : this.checkedKeys.checked
|
|
||||||
this.$api.sysRoleGrantData({ id: this.roleEntity.id, grantOrgIdList: checkedKeys, dataScopeType: values.dataScopeType }).then((res) => {
|
|
||||||
this.confirmLoading = false
|
|
||||||
if (res.success) {
|
|
||||||
this.$message.success('授权成功')
|
|
||||||
this.$emit('ok', values)
|
|
||||||
this.handleCancel()
|
|
||||||
} else {
|
|
||||||
this.$message.error('授权失败:' + res.message)
|
|
||||||
}
|
|
||||||
}).finally((res) => {
|
|
||||||
this.confirmLoading = false
|
|
||||||
})
|
})
|
||||||
} else {
|
.then(({ success }) => {
|
||||||
this.confirmLoading = false
|
if (success) {
|
||||||
}
|
this.$message.success('授权成功');
|
||||||
})
|
this.$emit('ok');
|
||||||
},
|
this.onCancel();
|
||||||
handleCancel () {
|
}
|
||||||
this.form.resetFields()
|
})
|
||||||
// 清空已选择的
|
.finally(() => {
|
||||||
this.checkedKeys = []
|
this.confirmLoading = false;
|
||||||
// 清空已展开的
|
});
|
||||||
this.expandedKeys = []
|
}
|
||||||
this.visible = false
|
});
|
||||||
// 隐藏机构树
|
},
|
||||||
this.orgTreeShow = false
|
onCancel() {
|
||||||
}
|
this.visible = false;
|
||||||
}
|
|
||||||
}
|
setTimeout(() => {
|
||||||
|
this.record = {};
|
||||||
|
this.checkedKeys = [];
|
||||||
|
this.dataScopeTypeData = [];
|
||||||
|
this.orgTreeShow = false;
|
||||||
|
this.form = {};
|
||||||
|
|
||||||
|
this.$refs.form.resetFields();
|
||||||
|
}, 300);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user