From 36838c910b2e80cc048ababc171a9e8fdbee20d2 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 31 Mar 2025 16:53:51 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E8=A7=92=E8=89=B2=20role=20?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90=2080%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/api/system/permission/index.ts | 57 +++++++++++++ apps/web-antd/src/views/system/dept/data.ts | 4 +- apps/web-antd/src/views/system/post/data.ts | 3 + apps/web-antd/src/views/system/role/data.ts | 34 ++++---- .../modules/assign-data-permission-form.vue | 83 ++++++------------- 5 files changed, 105 insertions(+), 76 deletions(-) create mode 100644 apps/web-antd/src/api/system/permission/index.ts diff --git a/apps/web-antd/src/api/system/permission/index.ts b/apps/web-antd/src/api/system/permission/index.ts new file mode 100644 index 000000000..9039d9a05 --- /dev/null +++ b/apps/web-antd/src/api/system/permission/index.ts @@ -0,0 +1,57 @@ +import { requestClient } from '#/api/request'; + +export namespace SystemPermissionApi { + /** 分配用户角色请求 */ + export interface AssignUserRoleReqVO { + userId: number; + roleIds: number[]; + } + + /** 分配角色菜单请求 */ + export interface AssignRoleMenuReqVO { + roleId: number; + menuIds: number[]; + } + + /** 分配角色数据权限请求 */ + export interface AssignRoleDataScopeReqVO { + roleId: number; + dataScope: number; + dataScopeDeptIds: number[]; + } +} + +/** 查询角色拥有的菜单权限 */ +export async function getRoleMenuList(roleId: number) { + return requestClient.get( + `/system/permission/list-role-menus?roleId=${roleId}`, + ); +} + +/** 赋予角色菜单权限 */ +export async function assignRoleMenu( + data: SystemPermissionApi.AssignRoleMenuReqVO, +) { + return requestClient.post('/system/permission/assign-role-menu', data); +} + +/** 赋予角色数据权限 */ +export async function assignRoleDataScope( + data: SystemPermissionApi.AssignRoleDataScopeReqVO, +) { + return requestClient.post('/system/permission/assign-role-data-scope', data); +} + +/** 查询用户拥有的角色数组 */ +export async function getUserRoleList(userId: number) { + return requestClient.get( + `/system/permission/list-user-roles?userId=${userId}`, + ); +} + +/** 赋予用户角色 */ +export async function assignUserRole( + data: SystemPermissionApi.AssignUserRoleReqVO, +) { + return requestClient.post('/system/permission/assign-user-role', data); +} diff --git a/apps/web-antd/src/views/system/dept/data.ts b/apps/web-antd/src/views/system/dept/data.ts index 2947e9f0f..876185542 100644 --- a/apps/web-antd/src/views/system/dept/data.ts +++ b/apps/web-antd/src/views/system/dept/data.ts @@ -11,7 +11,7 @@ import { DICT_TYPE, getDictOptions } from '#/utils/dict'; import { CommonStatusEnum } from '#/utils/constants'; import { handleTree } from '#/utils/tree'; -/** 获取编辑表单的字段配置 */ +/** 新增/修改的表单 */ export function useFormSchema(): VbenFormSchema[] { return [ { @@ -123,7 +123,7 @@ export function useFormSchema(): VbenFormSchema[] { ]; } -/** 获取表格列配置 */ +/** 列表的字段 */ const userList = await getSimpleUserList(); export function useGridColumns( onActionClick?: OnActionClickFn, diff --git a/apps/web-antd/src/views/system/post/data.ts b/apps/web-antd/src/views/system/post/data.ts index 1f6ac3dde..4c0803865 100644 --- a/apps/web-antd/src/views/system/post/data.ts +++ b/apps/web-antd/src/views/system/post/data.ts @@ -5,6 +5,7 @@ import type { SystemPostApi } from '#/api/system/post'; import { DICT_TYPE, getDictOptions } from '#/utils/dict'; import { CommonStatusEnum } from '#/utils/constants'; +/** 新增/修改的表单 */ export function useFormSchema(): VbenFormSchema[] { return [ { @@ -59,6 +60,7 @@ export function useFormSchema(): VbenFormSchema[] { ]; } +/** 列表的搜索表单 */ export function useGridFormSchema(): VbenFormSchema[] { return [ { @@ -83,6 +85,7 @@ export function useGridFormSchema(): VbenFormSchema[] { ]; } +/** 列表的字段 */ export function useGridColumns( onActionClick: OnActionClickFn, ): VxeTableGridOptions['columns'] { diff --git a/apps/web-antd/src/views/system/role/data.ts b/apps/web-antd/src/views/system/role/data.ts index 32ca1e264..058ac74d5 100644 --- a/apps/web-antd/src/views/system/role/data.ts +++ b/apps/web-antd/src/views/system/role/data.ts @@ -1,7 +1,8 @@ -import {type VbenFormSchema, z} from '#/adapter/form'; +import type { VbenFormSchema } from '#/adapter/form'; import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; import type { SystemRoleApi } from '#/api/system/role'; +import { z } from '#/adapter/form'; import { DICT_TYPE, getDictOptions } from '#/utils/dict'; import { CommonStatusEnum, SystemDataScopeEnum } from '#/utils/constants'; @@ -27,7 +28,7 @@ export function useFormSchema(): VbenFormSchema[] { component: 'Input', fieldName: 'code', label: '角色标识', - rules:'required', + rules: 'required', }, { component: 'InputNumber', @@ -56,7 +57,7 @@ export function useFormSchema(): VbenFormSchema[] { component: 'Textarea', fieldName: 'remark', label: '角色备注', - } + }, ]; } @@ -78,7 +79,7 @@ export function useAssignDataPermissionFormSchema(): VbenFormSchema[] { label: '角色名称', componentProps: { disabled: true, - } + }, }, { component: 'Input', @@ -86,7 +87,7 @@ export function useAssignDataPermissionFormSchema(): VbenFormSchema[] { label: '角色标识', componentProps: { disabled: true, - } + }, }, { component: 'Select', @@ -95,22 +96,22 @@ export function useAssignDataPermissionFormSchema(): VbenFormSchema[] { componentProps: { class: 'w-full', options: getDictOptions(DICT_TYPE.SYSTEM_DATA_SCOPE, 'number'), - } + }, }, { component: 'Input', fieldName: 'dataScopeDeptIds', label: '部门范围', - // dependencies: { - // triggerFields: ['dataScope'], - // show: (values) => { - // return values.dataScope === SystemDataScopeEnum.DEPT_CUSTOM; - // } - // }, - formItemClass: 'items-start', // TODO @芋艿: - modelPropName: 'modelValue', // TODO @芋艿: - } - ] + dependencies: { + triggerFields: ['dataScope'], + show: (values) => { + return values.dataScope === SystemDataScopeEnum.DEPT_CUSTOM; + }, + }, + formItemClass: 'items-start', + modelPropName: 'modelValue', // TODO @芋艿:这个是不是可以去掉哈 + }, + ]; } /** 列表的搜索表单 */ @@ -224,4 +225,3 @@ export function useGridColumns( } // TODO @芋艿:角色分配 -// TODO @芋艿:数据权限 \ No newline at end of file diff --git a/apps/web-antd/src/views/system/role/modules/assign-data-permission-form.vue b/apps/web-antd/src/views/system/role/modules/assign-data-permission-form.vue index e7f00b935..9809685ca 100644 --- a/apps/web-antd/src/views/system/role/modules/assign-data-permission-form.vue +++ b/apps/web-antd/src/views/system/role/modules/assign-data-permission-form.vue @@ -1,24 +1,27 @@ - - \ No newline at end of file