From bfbf97874c796041d72e8f8a026fa999fe8cd718 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 3 Oct 2025 08:50:43 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E3=80=90antd=E3=80=91=E3=80=90erp?= =?UTF-8?q?=20=E7=B3=BB=E7=BB=9F=E3=80=91product=20category=20=E8=BF=81?= =?UTF-8?q?=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/erp/product/category/data.ts | 28 ++++++++- .../src/views/erp/product/category/index.vue | 57 ++++++++++++------- .../erp/product/category/modules/form.vue | 23 ++++---- 3 files changed, 75 insertions(+), 33 deletions(-) diff --git a/apps/web-antd/src/views/erp/product/category/data.ts b/apps/web-antd/src/views/erp/product/category/data.ts index 2c04efb80..b5eb365ce 100644 --- a/apps/web-antd/src/views/erp/product/category/data.ts +++ b/apps/web-antd/src/views/erp/product/category/data.ts @@ -58,7 +58,7 @@ export function useFormSchema(): VbenFormSchema[] { componentProps: { placeholder: '请输入分类编码', }, - rules: z.string().regex(/^[A-Z]+$/, '分类编码必须为大写字母'), + rules: 'required', }, { fieldName: 'sort', @@ -71,7 +71,6 @@ export function useFormSchema(): VbenFormSchema[] { }, rules: 'required', }, - { fieldName: 'status', label: '状态', @@ -86,6 +85,31 @@ export function useFormSchema(): VbenFormSchema[] { ]; } +/** 查询表单 */ +export function useQueryFormSchema(): VbenFormSchema[] { + return [ + { + component: 'Input', + fieldName: 'name', + label: '分类名称', + componentProps: { + placeholder: '请输入分类名称', + allowClear: true, + }, + }, + { + component: 'Select', + fieldName: 'status', + label: '开启状态', + componentProps: { + options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), + placeholder: '请选择开启状态', + allowClear: true, + }, + }, + ]; +} + /** 列表的字段 */ export function useGridColumns(): VxeTableGridOptions['columns'] { return [ diff --git a/apps/web-antd/src/views/erp/product/category/index.vue b/apps/web-antd/src/views/erp/product/category/index.vue index aae932240..cc22cb7a1 100644 --- a/apps/web-antd/src/views/erp/product/category/index.vue +++ b/apps/web-antd/src/views/erp/product/category/index.vue @@ -5,17 +5,19 @@ import type { ErpProductCategoryApi } from '#/api/erp/product/category'; import { ref } from 'vue'; import { DocAlert, Page, useVbenModal } from '@vben/common-ui'; +import { downloadFileFromBlobPart } from '@vben/utils'; import { message } from 'ant-design-vue'; import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; import { deleteProductCategory, + exportProductCategory, getProductCategoryList, } from '#/api/erp/product/category'; import { $t } from '#/locales'; -import { useGridColumns } from './data'; +import { useGridColumns, useQueryFormSchema } from './data'; import Form from './modules/form.vue'; const [FormModal, formModalApi] = useVbenModal({ @@ -25,16 +27,22 @@ const [FormModal, formModalApi] = useVbenModal({ /** 切换树形展开/收缩状态 */ const isExpanded = ref(true); -function toggleExpand() { +function handleExpand() { isExpanded.value = !isExpanded.value; gridApi.grid.setAllTreeExpand(isExpanded.value); } /** 刷新表格 */ -function onRefresh() { +function handleRefresh() { gridApi.query(); } +/** 导出表格 */ +async function handleExport() { + const data = await exportProductCategory(await gridApi.formApi.getValues()); + downloadFileFromBlobPart({ fileName: '产品分类.xls', source: data }); +} + /** 创建分类 */ function handleCreate() { formModalApi.setData(null).open(); @@ -58,29 +66,30 @@ async function handleDelete(row: ErpProductCategoryApi.ProductCategory) { }); try { await deleteProductCategory(row.id as number); - message.success({ - content: $t('ui.actionMessage.deleteSuccess', [row.name]), - }); - onRefresh(); + message.success($t('ui.actionMessage.deleteSuccess', [row.name])); + handleRefresh(); } finally { hideLoading(); } } const [Grid, gridApi] = useVbenVxeGrid({ + formOptions: { + schema: useQueryFormSchema(), + }, gridOptions: { columns: useGridColumns(), height: 'auto', - proxyConfig: { - ajax: { - query: async () => { - return await getProductCategoryList(); - }, - }, - }, pagerConfig: { enabled: false, }, + proxyConfig: { + ajax: { + query: async (_, formValues) => { + return await getProductCategoryList(formValues); + }, + }, + }, rowConfig: { keyField: 'id', isHover: true, @@ -90,11 +99,11 @@ const [Grid, gridApi] = useVbenVxeGrid({ search: true, }, treeConfig: { - transform: true, - rowField: 'id', parentField: 'parentId', + rowField: 'id', + transform: true, expandAll: true, - accordion: false, + reserve: true, }, } as VxeTableGridOptions, }); @@ -108,7 +117,8 @@ const [Grid, gridApi] = useVbenVxeGrid({ url="https://doc.iocoder.cn/erp/product/" /> - + +