From cf11f2cdf514a1d3b6e4bc8f4ad3b7bb647f98ad Mon Sep 17 00:00:00 2001 From: Kven <2955163637@qq.com> Date: Thu, 8 May 2025 21:19:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(@vben/web-antd):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E9=83=A8=E9=97=A8=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/dept.ts | 76 ++++++++++ apps/web-antd/src/api/core/index.ts | 1 + apps/web-antd/src/api/core/user.ts | 4 - .../src/router/routes/modules/dept.ts | 18 +++ apps/web-antd/src/views/dept/data.ts | 122 +++++++++++++++ apps/web-antd/src/views/dept/list.vue | 140 ++++++++++++++++++ apps/web-antd/src/views/dept/modules/form.vue | 78 ++++++++++ packages/effects/common-ui/src/ui/index.ts | 1 - packages/icons/src/iconify/index.ts | 1 + 9 files changed, 436 insertions(+), 5 deletions(-) create mode 100644 apps/web-antd/src/api/core/dept.ts create mode 100644 apps/web-antd/src/router/routes/modules/dept.ts create mode 100644 apps/web-antd/src/views/dept/data.ts create mode 100644 apps/web-antd/src/views/dept/list.vue create mode 100644 apps/web-antd/src/views/dept/modules/form.vue diff --git a/apps/web-antd/src/api/core/dept.ts b/apps/web-antd/src/api/core/dept.ts new file mode 100644 index 0000000..d336946 --- /dev/null +++ b/apps/web-antd/src/api/core/dept.ts @@ -0,0 +1,76 @@ +import { requestClient } from '#/api/request'; + +export namespace DeptApi { + export interface Dept { + remark: string; + createTime: string; + name: string; + enabled: string; + id: string; + children?: Dept[]; + } + + export interface DeptRecord extends Dept { + id: string; + } + + export interface DeptTreeData { + id: number; + label: string; + children?: DeptTreeData[]; + } +} + +// 添加区域 +export function createDept(data: DeptApi.Dept) { + return requestClient.post(`/api/rest/dept`, data); +} + +// 更新区域信息 +export function updateDept(data: DeptApi.DeptRecord) { + return requestClient.patch(`/api/rest/dept/${data.id}`, data); +} + +// 删除区域 +export function removeDept(id: string) { + return requestClient.delete(`/api/rest/dept/${id}`); +} + +// 模糊查询获取区域列表 +export function queryDeptList(data: DeptApi.DeptRecord) { + return requestClient.get('/api/rest/dept', { data }); +} + +// 获取区域列表 +export function deptList() { + return requestClient.get(`/api/rest/dept`); +} + +// 启用状态 +export function enabledDept(id: string) { + return requestClient.patch(`/api/rest/dept/toggle/${id}`, id); +} + +export function getAllDeptTree(id?: number | string) { + return requestClient.get('/rest/dept/tree', { params: { id } }); +} + +// export function getDeptTree(params?: Partial) { +// return axios.get(`/api/dept/trees`, { +// params, +// paramsSerializer: (obj) => { +// return qs.stringify(obj); +// }, +// }); +// } +// export function listDepts(params?: ListParams>) { +// return axios.get(`/api/dept`, { +// params, +// paramsSerializer: (obj) => { +// return qs.stringify(obj); +// }, +// }); +// } +// export function queryDepts(params?: ListParams>) { +// return queryList(`/api/dept`, params); +// } diff --git a/apps/web-antd/src/api/core/index.ts b/apps/web-antd/src/api/core/index.ts index f12fdf4..b922f35 100644 --- a/apps/web-antd/src/api/core/index.ts +++ b/apps/web-antd/src/api/core/index.ts @@ -1,5 +1,6 @@ export * from './auth'; export * from './chatflow'; +export * from './dept'; export * from './menu'; export * from './server'; export * from './user'; diff --git a/apps/web-antd/src/api/core/user.ts b/apps/web-antd/src/api/core/user.ts index d04da9d..72abc46 100644 --- a/apps/web-antd/src/api/core/user.ts +++ b/apps/web-antd/src/api/core/user.ts @@ -163,7 +163,3 @@ export function deptAudit(id: string, roleId: string) { export function getUserDetail(id: number) { return requestClient.get(`/user/${id}`); } - -export function getAllDeptTree(id?: number | string) { - return requestClient.get('/rest/dept/tree', { params: { id } }); -} diff --git a/apps/web-antd/src/router/routes/modules/dept.ts b/apps/web-antd/src/router/routes/modules/dept.ts new file mode 100644 index 0000000..0ff9f74 --- /dev/null +++ b/apps/web-antd/src/router/routes/modules/dept.ts @@ -0,0 +1,18 @@ +import type { RouteRecordRaw } from 'vue-router'; + +import { RiDept } from '@vben/icons'; + +const routes: RouteRecordRaw[] = [ + { + name: 'dept', + path: '/dept', + component: () => import('#/views/dept/list.vue'), + meta: { + icon: RiDept, + title: '部门管理', + order: 5, + }, + }, +]; + +export default routes; diff --git a/apps/web-antd/src/views/dept/data.ts b/apps/web-antd/src/views/dept/data.ts new file mode 100644 index 0000000..a6c1d64 --- /dev/null +++ b/apps/web-antd/src/views/dept/data.ts @@ -0,0 +1,122 @@ +import type { VxeTableGridOptions } from '@vben/plugins/vxe-table'; + +import type { VbenFormSchema } from '#/adapter/form'; +import type { OnActionClickFn } from '#/adapter/vxe-table'; +import type { DeptApi } from '#/api'; + +import { z } from '#/adapter/form'; +import { getAllDeptTree } from '#/api'; +import { $t } from '#/locales'; + +/** + * 获取编辑表单的字段配置。如果没有使用多语言,可以直接export一个数组常量 + */ +export function useSchema(): VbenFormSchema[] { + return [ + { + component: 'Input', + fieldName: 'name', + label: '部门名称', + rules: z.string(), + }, + { + component: 'ApiTreeSelect', + componentProps: { + allowClear: true, + api: getAllDeptTree(1), + class: 'w-full', + labelField: 'name', + valueField: 'id', + childrenField: 'children', + }, + fieldName: 'pid', + label: '上级部门', + }, + { + 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', + componentProps: { + maxLength: 50, + rows: 3, + showCount: true, + }, + fieldName: 'remark', + label: '备注', + rules: z.string().optional(), + }, + ]; +} + +/** + * 获取表格列配置 + * @description 使用函数的形式返回列数据而不是直接export一个Array常量,是为了响应语言切换时重新翻译表头 + * @param onActionClick 表格操作按钮点击事件 + */ +export function useColumns( + onActionClick?: OnActionClickFn, +): VxeTableGridOptions['columns'] { + return [ + { + align: 'left', + field: 'name', + fixed: 'left', + title: '部门名称', + treeNode: true, + width: 150, + }, + { + cellRender: { name: 'CellTag' }, + field: 'enable', + title: '状态', + width: 100, + }, + { + field: 'createTime', + title: '创建时间', + width: 180, + }, + { + align: 'right', + cellRender: { + attrs: { + nameField: 'name', + nameTitle: '部门', + onClick: onActionClick, + }, + name: 'CellOperation', + options: [ + { + code: 'append', + text: '新增下级', + }, + 'edit', // 默认的编辑按钮 + { + code: 'delete', // 默认的删除按钮 + disabled: (row: DeptApi.Dept) => { + return !!(row.children && row.children.length > 0); + }, + }, + ], + }, + field: 'operation', + fixed: 'right', + headerAlign: 'center', + showOverflow: false, + title: '操作', + width: 200, + }, + ]; +} diff --git a/apps/web-antd/src/views/dept/list.vue b/apps/web-antd/src/views/dept/list.vue new file mode 100644 index 0000000..0b8486c --- /dev/null +++ b/apps/web-antd/src/views/dept/list.vue @@ -0,0 +1,140 @@ + + diff --git a/apps/web-antd/src/views/dept/modules/form.vue b/apps/web-antd/src/views/dept/modules/form.vue new file mode 100644 index 0000000..8eb6bd4 --- /dev/null +++ b/apps/web-antd/src/views/dept/modules/form.vue @@ -0,0 +1,78 @@ + + + diff --git a/packages/effects/common-ui/src/ui/index.ts b/packages/effects/common-ui/src/ui/index.ts index 50524b2..0e6a909 100644 --- a/packages/effects/common-ui/src/ui/index.ts +++ b/packages/effects/common-ui/src/ui/index.ts @@ -5,5 +5,4 @@ export * from './fallback'; export * from './home'; export * from './ppt'; export * from './spider'; -export * from './user'; export * from './word'; diff --git a/packages/icons/src/iconify/index.ts b/packages/icons/src/iconify/index.ts index 29c5ba2..9a9ad37 100644 --- a/packages/icons/src/iconify/index.ts +++ b/packages/icons/src/iconify/index.ts @@ -13,4 +13,5 @@ export const MdiGoogle = createIconifyIcon('mdi:google'); 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 MdiUser = createIconifyIcon('mdi:user');