Commit 9641032f by 胡悦

角色管理添加指定数据权限

1 parent 2dfc20f7
...@@ -30,7 +30,8 @@ const ROLE_API = { ...@@ -30,7 +30,8 @@ const ROLE_API = {
ROLE_EDIT: '/usercenter/role/edit', ROLE_EDIT: '/usercenter/role/edit',
ROLE_DELETE: '/usercenter/role/delete', ROLE_DELETE: '/usercenter/role/delete',
MENU_TREE: '/usercenter/menu/checkedtree', MENU_TREE: '/usercenter/menu/checkedtree',
ROLE_VISIBILITY: '/usercenter/role/visibility' ROLE_VISIBILITY: '/usercenter/role/visibility',
ROLE_PERMISSION: '/usercenter/tenant/rolepermission'
} }
const MENU_API = { const MENU_API = {
MENU_SEARCH: '/usercenter/menu/search', MENU_SEARCH: '/usercenter/menu/search',
......
...@@ -48,4 +48,10 @@ function getVisibility (params) { ...@@ -48,4 +48,10 @@ function getVisibility (params) {
return request(params, url) return request(params, url)
} }
export { getRoleList, roleInfo, getTenantList, addRole, editRole, deleteRole, getMenuTree, getVisibility } // 数据权限租户列表接口
function getPermission (params) {
const url = ROLE_API.ROLE_PERMISSION
return request(params, url)
}
export { getRoleList, roleInfo, getTenantList, addRole, editRole, deleteRole, getMenuTree, getVisibility, getPermission }
...@@ -10,8 +10,35 @@ const Constants = { ...@@ -10,8 +10,35 @@ const Constants = {
'1': '本人及下属', '1': '本人及下属',
'2': '本人部门', '2': '本人部门',
'3': '本部门及下级部门', '3': '本部门及下级部门',
'6': '指定数据权限',
'4': '全部' '4': '全部'
}, },
ROLEAUTH_LIST: [
{
label: '本人',
value: 0
},
{
label: '本人及下属',
value: 1
},
{
label: '本人部门',
value: 2
},
{
label: '本部门及下级部门',
value: 3
},
{
label: '指定数据权限',
value: 6
},
{
label: '全部',
value: 4
}
],
// 租户可见度 // 租户可见度
ROLE_VISIBLE: { ROLE_VISIBLE: {
0: '共享', 0: '共享',
......
...@@ -6,32 +6,33 @@ ...@@ -6,32 +6,33 @@
:formModel="searchForm" :formModel="searchForm"
:formList="roleFormList" :formList="roleFormList"
> >
<span <span class="inline-b" slot="form-slot">
class="inline-b"
slot="form-slot"
>
<el-button <el-button
type="primary" type="primary"
:size="btn_size" :size="btn_size"
icon="el-icon-search" icon="el-icon-search"
:id="tableParams.btnId" :id="tableParams.btnId"
>搜索</el-button> >搜索</el-button
>
<el-button <el-button
type="primary" type="primary"
:size="btn_size" :size="btn_size"
icon="el-icon-refresh" icon="el-icon-refresh"
@click="refresh" @click="refresh"
>重置</el-button> >重置</el-button
>
</span> </span>
</search-form> </search-form>
<h3>角色管理 <h3>
角色管理
<div class="pull-right"> <div class="pull-right">
<el-button <el-button
type="primary" type="primary"
:size="btn_size" :size="btn_size"
icon="el-icon-plus" icon="el-icon-plus"
@click="btnClick('create')" @click="btnClick('create')"
>新增</el-button> >新增</el-button
>
</div> </div>
</h3> </h3>
<basic-table <basic-table
...@@ -41,27 +42,30 @@ ...@@ -41,27 +42,30 @@
:searchForm="searchForm" :searchForm="searchForm"
:hasNum="false" :hasNum="false"
> >
<span <span slot="status" slot-scope="scope">
slot="status"
slot-scope="scope"
>
<span <span
class="dot" class="dot"
:class="scope.scope.enableStatus ? USERSTATUS[scope.scope.enableStatus].split(',')[1] : ''" :class="
scope.scope.enableStatus
? USERSTATUS[scope.scope.enableStatus].split(',')[1]
: ''
"
></span> ></span>
<span class="statusText">{{ scope.scope.enableStatus ? USERSTATUS[scope.scope.enableStatus].split(',')[0] : '--'}}</span> <span class="statusText">{{
scope.scope.enableStatus
? USERSTATUS[scope.scope.enableStatus].split(",")[0]
: "--"
}}</span>
</span> </span>
<span <span slot="table-button" slot-scope="scope">
slot="table-button"
slot-scope="scope"
>
<el-button <el-button
v-for="(j, idx) in tableParams.tableOption.btnList" v-for="(j, idx) in tableParams.tableOption.btnList"
:key="idx" :key="idx"
:type="j.type || 'text'" :type="j.type || 'text'"
:size="btn_size" :size="btn_size"
@click="btnClick(j.pType, scope.scope)" @click="btnClick(j.pType, scope.scope)"
>{{j.name}}</el-button> >{{ j.name }}</el-button
>
</span> </span>
</basic-table> </basic-table>
<basic-dialog <basic-dialog
...@@ -77,7 +81,7 @@ ...@@ -77,7 +81,7 @@
:rules="roleRules" :rules="roleRules"
:ruleData="roleData" :ruleData="roleData"
:labelWidth="'120px'" :labelWidth="'120px'"
ref='roleForm' ref="roleForm"
> >
<div slot="visible-type"> <div slot="visible-type">
<el-radio-group <el-radio-group
...@@ -85,10 +89,11 @@ ...@@ -85,10 +89,11 @@
v-model="roleForm.roleVisibility" v-model="roleForm.roleVisibility"
> >
<el-radio <el-radio
v-for="(child,childIndex) in visibilityList" v-for="(child, childIndex) in visibilityList"
:key="childIndex" :key="childIndex"
:label="child.code" :label="child.code"
>{{child.value}}</el-radio> >{{ child.value }}</el-radio
>
</el-radio-group> </el-radio-group>
<el-select <el-select
v-if="roleForm.roleVisibility == 2" v-if="roleForm.roleVisibility == 2"
...@@ -106,6 +111,34 @@ ...@@ -106,6 +111,34 @@
</el-option> </el-option>
</el-select> </el-select>
</div> </div>
<div slot="data-auth">
<el-radio-group
@change="radioChange(roleForm.roleVisibility)"
v-model="roleForm.rolePermissionType"
>
<el-radio
v-for="(child, childIndex) in $Constants.ROLEAUTH_LIST"
:key="childIndex"
:label="child.value"
>{{ child.label }}</el-radio
>
</el-radio-group>
<el-select
v-if="roleForm.rolePermissionType == 6"
v-model="roleForm.permTenants"
placeholder="请选择"
multiple
filterable
>
<el-option
v-for="i in permissionList"
:key="i.tenantId"
:label="i.tenantName"
:value="i.tenantId"
>
</el-option>
</el-select>
</div>
<el-tree <el-tree
slot="menu-list" slot="menu-list"
:data="treedata" :data="treedata"
...@@ -113,7 +146,7 @@ ...@@ -113,7 +146,7 @@
default-expand-all default-expand-all
node-key="id" node-key="id"
ref="tree" ref="tree"
check-strictly="true" :check-strictly="true"
highlight-current highlight-current
> >
</el-tree> </el-tree>
...@@ -125,244 +158,323 @@ ...@@ -125,244 +158,323 @@
</template> </template>
<script> <script>
import { getRoleList, roleInfo, getTenantList, addRole, editRole, deleteRole, getMenuTree, getVisibility } from 'services/role'; import {
getRoleList,
roleInfo,
getTenantList,
addRole,
editRole,
deleteRole,
getMenuTree,
getVisibility,
getPermission
} from "services/role";
export default { export default {
data() { data() {
var checkMenu = (rule, value, callBack) => { var checkMenu = (rule, value, callBack) => {
if (value && value.length == 0) { if (value && value.length == 0) {
return callBack(new Error('请选择菜单列表')) return callBack(new Error("请选择菜单列表"));
} else { } else {
return callBack() return callBack();
} }
} };
var checkRoleVisibility = (rule, value, callBack) => {
if (value && value == 2) {
return callBack(new Error("请选择指定租户"));
} else {
return callBack();
}
};
var checkRolePermissionType = (rule, value, callBack) => {
if (value && value == 6) {
return callBack(new Error("请选择指定数据权限"));
} else {
return callBack();
}
};
return { return {
USERSTATUS: this.$Constants.USER_STATUS, USERSTATUS: this.$Constants.USER_STATUS,
searchForm: {}, searchForm: {},
roleFormList: [ roleFormList: [
{ {
type: 'input', type: "input",
inputType: 'text', inputType: "text",
prop: 'roleName', prop: "roleName",
placeholder: '请输入角色名称' placeholder: "请输入角色名称"
} }
], ],
tableParams: { tableParams: {
// mutiSelectName: 'role', // mutiSelectName: 'role',
// mutiSelectUniqueKey: 'id', // mutiSelectUniqueKey: 'id',
btnId: new Date().getTime() + parseInt(Math.random() * 1000), btnId: new Date().getTime() + parseInt(Math.random() * 1000),
listName: 'list', listName: "list",
tableColumns: [ tableColumns: [
{ {
label: '角色名称', label: "角色名称",
prop: 'roleName' prop: "roleName"
}, { },
label: '备注', {
prop: 'remark' label: "备注",
}, { prop: "remark"
label: '状态', },
prop: 'enableStatus', {
addHtml: 'status' label: "状态",
}, { prop: "enableStatus",
label: '创建时间', addHtml: "status"
prop: 'createdDate' },
{
label: "创建时间",
prop: "createdDate"
} }
], ],
tableOption: { tableOption: {
width: 300, width: 300,
btnList: [ btnList: [
{ {
name: '编辑', name: "编辑",
pType: 'edit' pType: "edit"
}, },
{ {
name: '删除', name: "删除",
pType: 'delete' pType: "delete"
} }
] ]
} }
}, },
getListApi: getRoleList, getListApi: getRoleList,
// 弹窗数据 // 弹窗数据
roleDialogTitle: '新增角色', roleDialogTitle: "新增角色",
roleVisible: false, roleVisible: false,
roleForm: { roleForm: {
enableStatus: true, enableStatus: true,
menuIdList: [] menuIdList: []
}, },
roleData: [ roleData: [
{ label: '角色名称:', prop: 'roleName', type: 'input', maxlength: 50 }, { label: "角色名称:", prop: "roleName", type: "input", maxlength: 50 },
{ label: '备注:', prop: 'remark', type: 'input', inputText: 'textarea', maxlength: 200, showWordLimit: true }, {
{ label: '状态:', prop: 'enableStatus', type: 'switch' }, label: "备注:",
{ label: '租户可见度:', prop: 'roleVisibility', type: 'customize', slotName: 'visible-type' }, prop: "remark",
{ label: '数据权限:', prop: 'rolePermissionType', type: 'radio', children: this.$Constants.ROLE_AUTH }, type: "input",
{ label: '菜单权限:', prop: 'menuIdList', type: 'customize', slotName: 'menu-list' } inputText: "textarea",
maxlength: 200,
showWordLimit: true
},
{ label: "状态:", prop: "enableStatus", type: "switch" },
{
label: "租户可见度:",
prop: "roleVisibility",
type: "customize",
slotName: "visible-type"
},
{
label: "数据权限:",
prop: "rolePermissionType",
type: "customize",
slotName: "data-auth"
// children: this.$Constants.ROLE_AUTH
},
{
label: "菜单权限:",
prop: "menuIdList",
type: "customize",
slotName: "menu-list"
}
], ],
roleRules: { roleRules: {
roleName: [{ required: true, message: '请输入角色名称', trigger: 'blur' }, roleName: [
{ validator: this.$Common.checkName, trigger: 'blur' }, { required: true, message: "请输入角色名称", trigger: "blur" },
{ min: 5, max: 50, message: '长度在 5 到 50 个字符', trigger: 'blur' }], { validator: this.$Common.checkName, trigger: "blur" },
{ min: 5, max: 50, message: "长度在 5 到 50 个字符", trigger: "blur" }
],
enableStatus: [{ required: true }], enableStatus: [{ required: true }],
roleVisibility: [{ required: true, message: '请选择租户可见度' }], roleVisibility: [
rolePermissionType: [{ required: true, message: '请选择数据权限' }], { required: true, message: "请选择租户可见度" },
menuIdList: [{ required: true, validator: checkMenu, trigger: 'blur' }] { validator: checkRoleVisibility, trigger: "change" }
],
rolePermissionType: [
{ required: true, message: "请选择数据权限" },
{ validator: checkRolePermissionType, trigger: "change" }
],
menuIdList: [{ required: true, validator: checkMenu, trigger: "blur" }]
}, },
treedata: [], treedata: [],
tenantList: [], tenantList: [],
visibilityList: [] visibilityList: [],
} permissionList: []
};
}, },
mounted() { mounted() {
this.getTenantList() this.getTenantList();
this.getVisibility() this.getVisibility();
this.getPermission();
}, },
methods: { methods: {
// 重置搜索条件 // 重置搜索条件
refresh() { refresh() {
this.searchForm = {} this.searchForm = {};
this.$refs.roleTable.refreshTable() this.$refs.roleTable.refreshTable();
}, },
// 确定 // 确定
handleConfirm() { handleConfirm() {
this.getCheckedKeys() this.getCheckedKeys();
console.log(this.roleForm) this.$refs.roleForm.$children[0].validate(valid => {
this.$refs.roleForm.$children[0].validate((valid) => {
if (valid) { if (valid) {
let api = addRole let api = addRole;
let params = { let params = {
remark: this.roleForm.remark, remark: this.roleForm.remark,
roleName: this.roleForm.roleName, roleName: this.roleForm.roleName,
menuIdList: this.roleForm.menuIdList menuIdList: this.roleForm.menuIdList
};
params.enableStatus = this.roleForm.enableStatus ? 1 : 2;
params.roleVisibility = Number(this.roleForm.roleVisibility);
params.rolePermissionType = Number(this.roleForm.rolePermissionType);
if (params.roleVisibility == 2) {
params.roleTenants = this.roleForm.roleTenants.toString();
}
if (params.rolePermissionType == 6) {
params.permTenants = this.roleForm.permTenants.toString();
} }
params.enableStatus = this.roleForm.enableStatus ? 1 : 2
params.roleVisibility = Number(this.roleForm.roleVisibility)
params.rolePermissionType = Number(this.roleForm.rolePermissionType)
if (params.roleVisibility == 2) params.roleTenants = this.roleForm.roleTenants.toString()
if (this.roleForm.id) { if (this.roleForm.id) {
api = editRole api = editRole;
params.roleId = this.roleForm.id params.roleId = this.roleForm.id;
} }
api(params).then(res => { api(params).then(res => {
if (res.code == '200') { if (res.code == "200") {
this.$message({ this.$message({
type: 'success', type: "success",
message: '操作成功!' message: "操作成功!"
}) });
this.handleClose() this.handleClose();
this.$refs.roleTable.refreshTable() this.$refs.roleTable.refreshTable();
} else { } else {
this.$message({ this.$message({
type: 'error', type: "error",
message: res.message message: res.message
}) });
} }
}) });
} }
}) });
}, },
// 取消 // 取消
handleClose() { handleClose() {
if (!this.roleVisible && this.$refs.roleForm) { if (!this.roleVisible && this.$refs.roleForm) {
this.$refs.roleForm.$children[0].resetFields() this.$refs.roleForm.$children[0].resetFields();
} }
this.roleVisible = !this.roleVisible this.roleVisible = !this.roleVisible;
if (!this.roleVisible) this.$refs.tree.setCheckedKeys([]) if (!this.roleVisible) this.$refs.tree.setCheckedKeys([]);
}, },
// 按钮事件 // 按钮事件
btnClick(pType, scope) { btnClick(pType, scope) {
console.log(pType, scope) console.log(pType, scope);
switch (pType) { switch (pType) {
case 'create': case "create":
this.roleDialogTitle = '新增角色' this.roleDialogTitle = "新增角色";
this.roleForm = { this.roleForm = {
enableStatus: true, enableStatus: true,
menuIdList: [] menuIdList: []
} };
this.getMenuTree() this.getMenuTree();
this.handleClose() this.handleClose();
break break;
case 'edit': case "edit":
this.roleDialogTitle = '编辑角色' this.roleDialogTitle = "编辑角色";
this.editEvent(scope) this.editEvent(scope);
break break;
case 'delete': case "delete":
this.deleteEvent(scope.id) this.deleteEvent(scope.id);
break break;
} }
}, },
// 编辑触发事件 // 编辑触发事件
editEvent(row) { editEvent(row) {
const that = this const that = this;
roleInfo({ id: row.id }).then(res => { roleInfo({ id: row.id }).then(res => {
this.roleForm = JSON.parse(JSON.stringify(res.data)) this.roleForm = JSON.parse(JSON.stringify(res.data));
this.roleForm.enableStatus = res.data.enableStatus == 1 ? true : false this.roleForm.enableStatus = res.data.enableStatus == 1 ? true : false;
this.roleForm.roleVisibility = res.data.roleVisibility + '' this.roleForm.roleVisibility = res.data.roleVisibility;
this.roleForm.rolePermissionType = res.data.rolePermissionType + '' this.roleForm.rolePermissionType = res.data.rolePermissionType;
if (res.data.roleTenants) this.roleForm.roleTenants = res.data.roleTenants.split(',').map(Number) if (res.data.roleTenants) {
this.getMenuTree({ roleId: row.id }) this.roleForm.roleTenants = res.data.roleTenants
this.handleClose(res.data) .split(",")
}) .map(Number);
}
if (res.data.permTenants) {
this.roleForm.permTenants = res.data.permTenants
.split(",")
.map(Number);
}
this.getMenuTree({ roleId: row.id });
this.handleClose(res.data);
});
}, },
// 删除触发事件 // 删除触发事件
deleteEvent(id) { deleteEvent(id) {
const that = this const that = this;
const tipData = { const tipData = {
that: that, that: that,
tipText: '是否删除当前记录', tipText: "是否删除当前记录",
tipTitle: '提示', tipTitle: "提示",
type: 'error', type: "error",
callBack: () => { callBack: () => {
deleteRole({ id: id }).then(res => { deleteRole({ id: id }).then(res => {
if (res.code == '200') { if (res.code == "200") {
this.$message({ this.$message({
type: 'success', type: "success",
message: '删除成功!' message: "删除成功!"
}) });
this.$refs.roleTable.refreshTable() this.$refs.roleTable.refreshTable();
} else { } else {
this.$message({ this.$message({
type: 'error', type: "error",
message: res.message message: res.message
}) });
} }
}) });
} }
} };
this.$Common.confirmDialog(tipData) this.$Common.confirmDialog(tipData);
}, },
// 获取菜单权限列表 // 获取菜单权限列表
getMenuTree(params) { getMenuTree(params) {
getMenuTree(params).then(res => { getMenuTree(params).then(res => {
this.treedata = res.data.menuTree this.treedata = res.data.menuTree;
setTimeout(() => { setTimeout(() => {
this.$refs.tree.setCheckedKeys(res.data.checkedIds) this.$refs.tree.setCheckedKeys(res.data.checkedIds);
}, 1000 / 60) }, 1000 / 60);
}) });
}, },
// 获取选中菜单数组 // 获取选中菜单数组
getCheckedKeys() { getCheckedKeys() {
this.roleForm.menuIdList = this.$refs.tree.getCheckedKeys() this.roleForm.menuIdList = this.$refs.tree.getCheckedKeys();
}, },
// 获取角色可见度可选项 // 获取角色可见度可选项
getVisibility() { getVisibility() {
getVisibility().then(res => { getVisibility().then(res => {
console.log(res.data) console.log(res.data);
this.visibilityList = res.data this.visibilityList = res.data;
}) });
},
// 获取数据权限租户列表
getPermission() {
getPermission().then(res => {
this.permissionList = res.data;
});
}, },
// 获取租户列表 // 获取租户列表
getTenantList() { getTenantList() {
getTenantList().then(res => { getTenantList().then(res => {
this.tenantList = res.data this.tenantList = res.data;
}) });
}, },
radioChange(e) { radioChange(e) {
this.$set(this.roleForm, 'roleVisibility', e) this.$set(this.roleForm, "roleVisibility", e);
} }
} }
} };
</script> </script>
<style lang="scss"> <style lang="scss">
.role .el-tree { .role .el-tree {
margin-top: 7px; margin-top: 7px;
} }
</style>
\ No newline at end of file \ No newline at end of file
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!