From 51d63fc7c223f7cbdc056f5820c2d136c29240b2 Mon Sep 17 00:00:00 2001 From: Kven <2955163637@qq.com> Date: Sat, 10 May 2025 13:29:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(@vben/web-antd):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/adapter/vxe-table.ts | 24 +++++++- apps/web-antd/src/api/core/dept.ts | 30 +++++----- apps/web-antd/src/views/dept/data.ts | 18 ++++-- apps/web-antd/src/views/dept/list.vue | 5 +- apps/web-antd/src/views/user/index.vue | 78 -------------------------- 5 files changed, 53 insertions(+), 102 deletions(-) delete mode 100644 apps/web-antd/src/views/user/index.vue diff --git a/apps/web-antd/src/adapter/vxe-table.ts b/apps/web-antd/src/adapter/vxe-table.ts index 870604d..397c04a 100644 --- a/apps/web-antd/src/adapter/vxe-table.ts +++ b/apps/web-antd/src/adapter/vxe-table.ts @@ -5,9 +5,10 @@ import { h } from 'vue'; import { IconifyIcon } from '@vben/icons'; import { $te } from '@vben/locales'; import { setupVbenVxeTable, useVbenVxeGrid } from '@vben/plugins/vxe-table'; -import { isFunction, isString } from '@vben/utils'; +import { get, isFunction, isString } from '@vben/utils'; -import { Button, Image, Popconfirm, Switch } from 'ant-design-vue'; +import { objectOmit } from '@vueuse/core'; +import { Button, Image, Popconfirm, Switch, Tag } from 'ant-design-vue'; import { $t } from '#/locales'; @@ -51,6 +52,25 @@ setupVbenVxeTable({ }, }); + vxeUI.renderer.add('CellTag', { + renderTableDefault({ options, props }, { column, row }) { + const value = get(row, column.field); + const tagOptions = options ?? [ + { color: 'success', label: $t('common.enabled'), value: true }, + { color: 'error', label: $t('common.disabled'), value: false }, + ]; + const tagItem = tagOptions.find((item) => item.value === value); + return h( + Tag, + { + ...props, + ...objectOmit(tagItem ?? {}, ['label']), + }, + { default: () => tagItem?.label ?? value }, + ); + }, + }); + // 表格配置项可以用 cellRender: { name: 'CellLink' }, vxeUI.renderer.add('CellLink', { renderTableDefault(renderOpts) { diff --git a/apps/web-antd/src/api/core/dept.ts b/apps/web-antd/src/api/core/dept.ts index d336946..17b7895 100644 --- a/apps/web-antd/src/api/core/dept.ts +++ b/apps/web-antd/src/api/core/dept.ts @@ -21,34 +21,34 @@ export namespace DeptApi { } } -// 添加区域 +// 添加部门 export function createDept(data: DeptApi.Dept) { - return requestClient.post(`/api/rest/dept`, data); + return requestClient.post(`/rest/dept`, data); } -// 更新区域信息 -export function updateDept(data: DeptApi.DeptRecord) { - return requestClient.patch(`/api/rest/dept/${data.id}`, data); +// 更新部门信息 +export function updateDept(id: string, data: DeptApi.DeptRecord) { + return requestClient.patch(`/rest/dept/${id}`, data); } -// 删除区域 +// 删除部门 export function removeDept(id: string) { - return requestClient.delete(`/api/rest/dept/${id}`); + return requestClient.delete(`/rest/dept/${id}`); } -// 模糊查询获取区域列表 +// 模糊查询获取部门列表 export function queryDeptList(data: DeptApi.DeptRecord) { - return requestClient.get('/api/rest/dept', { data }); + return requestClient.get('/rest/dept', { data }); } -// 获取区域列表 +// 获取部门列表 export function deptList() { - return requestClient.get(`/api/rest/dept`); + return requestClient.get(`/rest/dept`); } // 启用状态 export function enabledDept(id: string) { - return requestClient.patch(`/api/rest/dept/toggle/${id}`, id); + return requestClient.patch(`/rest/dept/toggle/${id}`, id); } export function getAllDeptTree(id?: number | string) { @@ -56,7 +56,7 @@ export function getAllDeptTree(id?: number | string) { } // export function getDeptTree(params?: Partial) { -// return axios.get(`/api/dept/trees`, { +// return axios.get(`/dept/trees`, { // params, // paramsSerializer: (obj) => { // return qs.stringify(obj); @@ -64,7 +64,7 @@ export function getAllDeptTree(id?: number | string) { // }); // } // export function listDepts(params?: ListParams>) { -// return axios.get(`/api/dept`, { +// return axios.get(`/dept`, { // params, // paramsSerializer: (obj) => { // return qs.stringify(obj); @@ -72,5 +72,5 @@ export function getAllDeptTree(id?: number | string) { // }); // } // export function queryDepts(params?: ListParams>) { -// return queryList(`/api/dept`, params); +// return queryList(`/dept`, params); // } diff --git a/apps/web-antd/src/views/dept/data.ts b/apps/web-antd/src/views/dept/data.ts index a6c1d64..c38d5f2 100644 --- a/apps/web-antd/src/views/dept/data.ts +++ b/apps/web-antd/src/views/dept/data.ts @@ -37,13 +37,13 @@ export function useSchema(): VbenFormSchema[] { componentProps: { buttonStyle: 'solid', options: [ - { label: $t('common.enabled'), value: 1 }, - { label: $t('common.disabled'), value: 0 }, + { label: $t('common.enabled'), value: true }, + { label: $t('common.disabled'), value: false }, ], optionType: 'button', }, - defaultValue: 1, - fieldName: 'status', + defaultValue: true, + fieldName: 'enabled', label: '状态', }, { @@ -78,8 +78,10 @@ export function useColumns( width: 150, }, { - cellRender: { name: 'CellTag' }, - field: 'enable', + cellRender: { + name: 'CellTag', + }, + field: 'enabled', title: '状态', width: 100, }, @@ -88,6 +90,10 @@ export function useColumns( title: '创建时间', width: 180, }, + { + field: 'remark', + title: '备注', + }, { align: 'right', cellRender: { diff --git a/apps/web-antd/src/views/dept/list.vue b/apps/web-antd/src/views/dept/list.vue index 0b8486c..b7b8502 100644 --- a/apps/web-antd/src/views/dept/list.vue +++ b/apps/web-antd/src/views/dept/list.vue @@ -100,7 +100,10 @@ const [Grid, gridApi] = useVbenVxeGrid({ proxyConfig: { ajax: { query: async (_params) => { - return await getAllDeptTree(1); + const res = await getAllDeptTree(1); + return { + items: res, + }; }, }, }, diff --git a/apps/web-antd/src/views/user/index.vue b/apps/web-antd/src/views/user/index.vue deleted file mode 100644 index bec1666..0000000 --- a/apps/web-antd/src/views/user/index.vue +++ /dev/null @@ -1,78 +0,0 @@ - - - - -