feat: 客户编码校验

This commit is contained in:
caiyuchao
2025-05-26 17:27:01 +08:00
parent 2e08750e4c
commit d49879c2a8
2 changed files with 44 additions and 4 deletions

View File

@@ -63,9 +63,19 @@ async function isCustomerNameUnique(
}); });
} }
/** 客户编号是否唯一 */
async function isCustomerCodeUnique(
code: number,
id?: CustomerApi.Customer['id'],
) {
return requestClient.get<boolean>('/license/customer/code-unique', {
params: { id, code },
});
}
/** 查询当前最大sn */ /** 查询当前最大sn */
async function getMaxSn() { async function getMaxSn() {
return requestClient.get<boolean>('/license/customer/max-sn'); return requestClient.get<boolean>('/license/customer/max-sn');
} }
export { getMaxSn, isCustomerNameUnique }; export { getMaxSn, isCustomerCodeUnique, isCustomerNameUnique };

View File

@@ -7,7 +7,10 @@ import { ref } from 'vue';
import { useAccess } from '@vben/access'; import { useAccess } from '@vben/access';
import { z } from '#/adapter/form'; import { z } from '#/adapter/form';
import { isCustomerNameUnique } from '#/api/license/customer'; import {
isCustomerCodeUnique,
isCustomerNameUnique,
} from '#/api/license/customer';
import { getAreaTree } from '#/api/system/area'; import { getAreaTree } from '#/api/system/area';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils'; import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
@@ -52,8 +55,35 @@ export function useFormSchema(): VbenFormSchema[] {
{ {
fieldName: 'code', fieldName: 'code',
label: $t('customer.customerSn'), label: $t('customer.customerSn'),
rules: 'required', component: 'InputNumber',
component: 'Input', rules: z
.number()
.min(
2000,
$t('ui.formRules.range', [$t('customer.customerSn'), 2000, 9999]),
)
.max(
9999,
$t('ui.formRules.range', [$t('customer.customerSn'), 2000, 9999]),
)
.refine(
async (value: number) => {
return await isCustomerCodeUnique(value, formData.value?.id);
},
(value) => ({
message: $t('ui.formRules.alreadyExists', [
$t('customer.customerSn'),
value,
]),
}),
)
.nullable()
.refine(
(value: null | number) => {
return value;
},
{ message: $t('ui.formRules.required', [$t('customer.customerSn')]) },
),
}, },
{ {
fieldName: 'type', fieldName: 'type',