From 996a8972fff761db04f96cc0a93cdc89f5776371 Mon Sep 17 00:00:00 2001 From: Kven <2955163637@qq.com> Date: Sat, 10 May 2025 21:47:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(@vben/web-antd):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/api/core/user.ts | 21 +- apps/web-antd/src/views/user/data.ts | 197 ++++++++++++++++++ apps/web-antd/src/views/user/list.vue | 168 +++++++++++++++ apps/web-antd/src/views/user/modules/form.vue | 138 ++++++++++++ 4 files changed, 514 insertions(+), 10 deletions(-) create mode 100644 apps/web-antd/src/views/user/data.ts create mode 100644 apps/web-antd/src/views/user/list.vue create mode 100644 apps/web-antd/src/views/user/modules/form.vue diff --git a/apps/web-antd/src/api/core/user.ts b/apps/web-antd/src/api/core/user.ts index 72abc46..09debbc 100644 --- a/apps/web-antd/src/api/core/user.ts +++ b/apps/web-antd/src/api/core/user.ts @@ -76,9 +76,10 @@ export namespace UserApi { createAt?: string; } - export interface UserState { + export interface User { username?: string; nickName?: string; + name: string; avatar?: string; email?: string; phone?: string; @@ -112,7 +113,7 @@ export function register(data: UserApi.CreateRecord) { } // 新建用户 -export function create(data: UserApi.CreateRecord) { +export function createUser(data: UserApi.CreateRecord) { return requestClient.post('/rest/user', data); } @@ -127,32 +128,32 @@ export function queryUserList(params: any) { } // 根据id查询用户信息 -export function userDetail(id: string) { +export function userDetail(id: any) { return requestClient.get(`/rest/user/${id}`); } // 是否启用 -export function enabled(id: string) { +export function enabledUser(id: any) { return requestClient.patch(`/rest/user/${id}/toggle`); } // 删除用户 -export function remove(id: string) { +export function removeUser(id: string) { return requestClient.delete(`/rest/user/${id}`); } // 更新用户信息 -export function update(data: UserApi.UserRecord) { - return requestClient.patch(`/rest/user/${data.id}`, data); +export function updateUser(id: any, data: UserApi.UserRecord) { + return requestClient.patch(`/rest/user/${id}`, data); } -export function selfUpdate(data: UserApi.UserState) { +export function selfUpdate(data: UserApi.User) { return requestClient.patch(`/rest/user/self`, data); } // 获取个人用户信息 export function getUserInfo() { - return requestClient.get('/rest/user/self'); + return requestClient.get('/rest/user/self'); } // 部门的审核员 @@ -161,5 +162,5 @@ export function deptAudit(id: string, roleId: string) { } export function getUserDetail(id: number) { - return requestClient.get(`/user/${id}`); + return requestClient.get(`/user/${id}`); } diff --git a/apps/web-antd/src/views/user/data.ts b/apps/web-antd/src/views/user/data.ts new file mode 100644 index 0000000..d7869df --- /dev/null +++ b/apps/web-antd/src/views/user/data.ts @@ -0,0 +1,197 @@ +import type { VbenFormSchema } from '#/adapter/form'; +import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; +import type { UserApi } from '#/api'; + +import { ref } from 'vue'; + +import { getAllDeptTree, queryRoleList } from '#/api'; +import { $t } from '#/locales'; + +const treeData = ref([]); +const optionsRoleData = ref([]); + +queryRoleList('').then((res) => { + optionsRoleData.value = res.records.map((item) => ({ + label: item.name, + value: item.id, + })); +}); + +function transformToTreeData(data: any) { + return data.map((item) => ({ + value: item.id, + label: item.name, + ...(item.children && { children: transformToTreeData(item.children) }), + })); +} + +// 使用示例 +getAllDeptTree(1).then((res) => { + treeData.value = transformToTreeData(res); +}); +export function useFormSchema(): VbenFormSchema[] { + return [ + { + component: 'Input', + fieldName: 'username', + label: '用户名称', + rules: 'required', + }, + { + component: 'Input', + fieldName: 'name', + label: '昵称', + rules: 'required', + }, + { + component: 'Input', + fieldName: 'email', + label: 'Email', + rules: 'required', + }, + { + component: 'Input', + fieldName: 'phone', + label: '电话', + rules: 'required', + }, + { + component: 'Input', + fieldName: 'password', + label: '密码', + rules: 'required', + }, + { + component: 'Input', + fieldName: 'address', + label: '地址', + }, + { + component: 'RadioGroup', + componentProps: { + buttonStyle: 'solid', + options: [ + { label: $t('common.enabled'), value: true }, + { label: $t('common.disabled'), value: false }, + ], + optionType: 'button', + }, + defaultValue: true, + fieldName: 'enable', + label: '状态', + }, + { + component: 'Textarea', + fieldName: 'remark', + label: '备注', + }, + { + component: 'Select', + componentProps: { + allowClear: true, + mode: 'multiple', + // api: queryRoleList(''), + options: optionsRoleData, + class: 'w-full', + labelField: 'name', + valueField: 'id', + }, + fieldName: 'roleIds', + label: '所属角色', + }, + { + component: 'TreeSelect', + componentProps: { + allowClear: true, + // api: getAllDeptTree(1), + treeData, + class: 'w-full', + labelField: 'name', + valueField: 'id', + childrenField: 'children', + }, + fieldName: 'deptId', + label: '所属部门', + }, + ]; +} + +export function useGridFormSchema(): VbenFormSchema[] { + return [ + { + component: 'Input', + fieldName: 'username', + label: '用户名称', + }, + { + component: 'Select', + componentProps: { + allowClear: true, + options: [ + { label: $t('common.enabled'), value: true }, + { label: $t('common.disabled'), value: false }, + ], + }, + fieldName: 'enableState', + 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: 'username', + title: '用户名称', + width: 200, + }, + { + cellRender: { + attrs: { beforeChange: onStatusChange }, + name: onStatusChange ? 'CellSwitch' : 'CellTag', + }, + field: 'enableState', + title: '用户状态', + width: 100, + }, + { + field: 'remark', + minWidth: 100, + title: '备注', + }, + { + field: 'createTime', + slots: { default: 'createTime' }, + title: '创建时间', + width: 200, + }, + { + align: 'center', + cellRender: { + attrs: { + nameField: 'name', + nameTitle: '用户', + onClick: onActionClick, + }, + name: 'CellOperation', + }, + field: 'operation', + fixed: 'right', + title: '操作', + width: 130, + }, + ]; +} diff --git a/apps/web-antd/src/views/user/list.vue b/apps/web-antd/src/views/user/list.vue new file mode 100644 index 0000000..94f220d --- /dev/null +++ b/apps/web-antd/src/views/user/list.vue @@ -0,0 +1,168 @@ + + diff --git a/apps/web-antd/src/views/user/modules/form.vue b/apps/web-antd/src/views/user/modules/form.vue new file mode 100644 index 0000000..b6aa7c3 --- /dev/null +++ b/apps/web-antd/src/views/user/modules/form.vue @@ -0,0 +1,138 @@ + + +