feat(@vben/web-antd): vxe-table)新增表单验证功能

- 在 vxe-table.ts 中添加 createRequiredValidation函数
- 在 data.ts 中使用 createRequiredValidation 替代原有的 className 函数
- 在 vxe-table 插件中添加 validation 相关的工具函数
- 优化表格列的验证逻辑,提高代码复用性和可维护性
This commit is contained in:
nehc
2025-08-02 23:28:59 +08:00
parent 5f56b14733
commit c64be886b4
4 changed files with 69 additions and 17 deletions

View File

@@ -7,6 +7,7 @@ import { IconifyIcon } from '@vben/icons';
import { $te } from '@vben/locales';
import {
AsyncComponents,
createRequiredValidation,
setupVbenVxeTable,
useVbenVxeGrid,
} from '@vben/plugins/vxe-table';
@@ -354,7 +355,7 @@ setupVbenVxeTable({
useVbenForm,
});
export { useVbenVxeGrid };
export { createRequiredValidation, useVbenVxeGrid };
const [VxeTable, VxeColumn, VxeToolbar] = AsyncComponents;
export { VxeColumn, VxeTable, VxeToolbar };

View File

@@ -1,6 +1,7 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { createRequiredValidation } from '#/adapter/vxe-table';
import { getSupplierSimpleList } from '#/api/erp/purchase/supplier';
import { getSimpleUserList } from '#/api/system/user';
import { DICT_TYPE, getDictOptions } from '#/utils';
@@ -108,22 +109,14 @@ export function useStockInItemTableColumns(
title: '仓库名称',
minWidth: 150,
slots: { default: 'warehouseId' },
className: ({ row }: { row: any }) => {
return isValidating?.value && !row.warehouseId
? 'required-field-error'
: '';
},
className: createRequiredValidation(isValidating, 'warehouseId'),
},
{
field: 'productId',
title: '产品名称',
minWidth: 200,
slots: { default: 'productId' },
className: ({ row }: { row: any }) => {
return isValidating?.value && !row.productId
? 'required-field-error'
: '';
},
className: createRequiredValidation(isValidating, 'productId'),
},
{
field: 'stockCount',
@@ -145,11 +138,7 @@ export function useStockInItemTableColumns(
title: '数量',
minWidth: 120,
slots: { default: 'count' },
className: ({ row }: { row: any }) => {
return isValidating?.value && (!row.count || row.count <= 0)
? 'required-field-error'
: '';
},
className: createRequiredValidation(isValidating, 'count'),
},
{
field: 'productPrice',