From 139aa926be44603f2a4612c6964674d4b8c127ab Mon Sep 17 00:00:00 2001 From: Kven <2955163637@qq.com> Date: Thu, 8 May 2025 22:02:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(@vben/web-antd):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/api/core/index.ts | 1 + apps/web-antd/src/api/core/role.ts | 56 ++++++ .../src/router/routes/modules/role.ts | 18 ++ apps/web-antd/src/views/role/data.ts | 127 ++++++++++++++ apps/web-antd/src/views/role/list.vue | 161 ++++++++++++++++++ apps/web-antd/src/views/role/modules/form.vue | 139 +++++++++++++++ packages/icons/src/iconify/index.ts | 1 + 7 files changed, 503 insertions(+) create mode 100644 apps/web-antd/src/api/core/role.ts create mode 100644 apps/web-antd/src/router/routes/modules/role.ts create mode 100644 apps/web-antd/src/views/role/data.ts create mode 100644 apps/web-antd/src/views/role/list.vue create mode 100644 apps/web-antd/src/views/role/modules/form.vue diff --git a/apps/web-antd/src/api/core/index.ts b/apps/web-antd/src/api/core/index.ts index b922f35..8d802e3 100644 --- a/apps/web-antd/src/api/core/index.ts +++ b/apps/web-antd/src/api/core/index.ts @@ -2,6 +2,7 @@ export * from './auth'; export * from './chatflow'; export * from './dept'; export * from './menu'; +export * from './role'; export * from './server'; export * from './user'; export * from './workflow'; diff --git a/apps/web-antd/src/api/core/role.ts b/apps/web-antd/src/api/core/role.ts new file mode 100644 index 0000000..968454d --- /dev/null +++ b/apps/web-antd/src/api/core/role.ts @@ -0,0 +1,56 @@ +import { requestClient } from '#/api/request'; + +export namespace RoleApi { + export interface Role { + name: string; + dataScope: string; + permissionIds: (number | undefined)[]; + remark: string; + authorities: (number | undefined)[]; + id?: string; + } + + // 基础信息 + export interface RoleRecord extends Role { + id: string; + } + + export interface RoleListRecord extends RoleRecord { + name: string; + } +} + +// 查询所有的角色列表、 +export function queryRoleList(data: any) { + // return axios.get('/api/rest/role',data); + return requestClient.get('/api/rest/role', { data }); +} + +// 切换启用状态 +export function enabled(id: string) { + return requestClient.patch(`/api/rest/role/${id}/toggle`); +} + +// 删除 +export function removeRole(id: string) { + return requestClient.delete(`/api/rest/role/${id}`); +} + +// 添加 +export function createRole(data: RoleApi.Role) { + return requestClient.post(`/api/rest/role`, data); +} + +// 更新 +export function updateRole(data: RoleApi.RoleRecord) { + return requestClient.patch(`/api/rest/role/${data.id}`, data); +} + +// 获取详情 +export function getDetail(id: string) { + return requestClient.get(`/api/rest/role/${id}`); +} + +// export function queryRoles(params?: ListParams>) { +// return queryList(`/api/rest/role/query`, params); +// } diff --git a/apps/web-antd/src/router/routes/modules/role.ts b/apps/web-antd/src/router/routes/modules/role.ts new file mode 100644 index 0000000..7916b6e --- /dev/null +++ b/apps/web-antd/src/router/routes/modules/role.ts @@ -0,0 +1,18 @@ +import type { RouteRecordRaw } from 'vue-router'; + +import { EosRole } from '@vben/icons'; + +const routes: RouteRecordRaw[] = [ + { + name: 'role', + path: '/role', + component: () => import('#/views/role/list.vue'), + meta: { + icon: EosRole, + title: '角色管理', + order: 5, + }, + }, +]; + +export default routes; diff --git a/apps/web-antd/src/views/role/data.ts b/apps/web-antd/src/views/role/data.ts new file mode 100644 index 0000000..f2065df --- /dev/null +++ b/apps/web-antd/src/views/role/data.ts @@ -0,0 +1,127 @@ +import type { VbenFormSchema } from '#/adapter/form'; +import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; +import type { RoleApi } from '#/api'; + +import { $t } from '#/locales'; + +export function useFormSchema(): VbenFormSchema[] { + return [ + { + component: 'Input', + fieldName: 'name', + label: '角色名称', + rules: 'required', + }, + { + component: 'RadioGroup', + componentProps: { + buttonStyle: 'solid', + options: [ + { label: $t('common.enabled'), value: 1 }, + { label: $t('common.disabled'), value: 0 }, + ], + optionType: 'button', + }, + defaultValue: 1, + fieldName: 'status', + label: '状态', + }, + { + component: 'Textarea', + fieldName: 'remark', + label: '备注', + }, + { + component: 'Input', + fieldName: 'permissions', + formItemClass: 'items-start', + label: '权限', + modelPropName: 'modelValue', + }, + ]; +} + +export function useGridFormSchema(): VbenFormSchema[] { + return [ + { + component: 'Input', + fieldName: 'name', + label: '角色名称', + }, + { component: 'Input', fieldName: 'id', label: '角色ID' }, + { + component: 'Select', + componentProps: { + allowClear: true, + options: [ + { label: $t('common.enabled'), value: 1 }, + { label: $t('common.disabled'), value: 0 }, + ], + }, + fieldName: 'status', + label: '状态', + }, + { + component: 'Input', + fieldName: 'remark', + label: '备注', + }, + { + component: 'RangePicker', + fieldName: 'createTime', + label: '创建时间', + }, + ]; +} + +export function useColumns( + onActionClick: OnActionClickFn, + onStatusChange?: (newStatus: any, row: T) => PromiseLike, +): VxeTableGridOptions['columns'] { + return [ + { + field: 'name', + title: '角色名称', + width: 200, + }, + { + field: 'id', + title: '角色ID', + width: 200, + }, + { + cellRender: { + attrs: { beforeChange: onStatusChange }, + name: onStatusChange ? 'CellSwitch' : 'CellTag', + }, + field: 'status', + title: '角色状态', + width: 100, + }, + { + field: 'remark', + minWidth: 100, + title: '备注', + }, + { + field: 'createTime', + title: '创建时间', + width: 200, + }, + { + align: 'center', + cellRender: { + attrs: { + nameField: 'name', + nameTitle: $t('system.role.name'), + onClick: onActionClick, + }, + name: 'CellOperation', + }, + field: 'operation', + fixed: 'right', + title: '操作', + width: 130, + }, + ]; +} diff --git a/apps/web-antd/src/views/role/list.vue b/apps/web-antd/src/views/role/list.vue new file mode 100644 index 0000000..fcaecb3 --- /dev/null +++ b/apps/web-antd/src/views/role/list.vue @@ -0,0 +1,161 @@ + + diff --git a/apps/web-antd/src/views/role/modules/form.vue b/apps/web-antd/src/views/role/modules/form.vue new file mode 100644 index 0000000..d90f31c --- /dev/null +++ b/apps/web-antd/src/views/role/modules/form.vue @@ -0,0 +1,139 @@ + + + diff --git a/packages/icons/src/iconify/index.ts b/packages/icons/src/iconify/index.ts index 9a9ad37..e6daf48 100644 --- a/packages/icons/src/iconify/index.ts +++ b/packages/icons/src/iconify/index.ts @@ -14,4 +14,5 @@ export const MdiChevron = createIconifyIcon('tabler:chevron-right'); export const MdiUser = createIconifyIcon('mdi:user'); export const MageRobot = createIconifyIcon('mage:robot'); export const RiDept = createIconifyIcon('ri:door-open-line'); +export const EosRole = createIconifyIcon('eos-icons:role-binding-outlined'); // export const MdiUser = createIconifyIcon('mdi:user');