From 588709c58957a7c86e97e7ec4491907f87d5c1d3 Mon Sep 17 00:00:00 2001 From: caiyuchao Date: Sat, 24 May 2025 16:12:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=A2=E6=88=B7=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/api/license/customer/index.ts | 12 ++++++++++ .../src/views/license/customer/data.ts | 24 ++++++++++++++++++- .../views/license/customer/modules/form.vue | 5 ++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/apps/web-antd/src/api/license/customer/index.ts b/apps/web-antd/src/api/license/customer/index.ts index fe8a042..fa3319c 100644 --- a/apps/web-antd/src/api/license/customer/index.ts +++ b/apps/web-antd/src/api/license/customer/index.ts @@ -52,3 +52,15 @@ export function deleteCustomer(id: number) { export function exportCustomer(params: any) { return requestClient.download('/license/customer/export-excel', params); } + +/** 客户名称是否存在 */ +async function isCustomerNameExists( + name: string, + id?: CustomerApi.Customer['id'], +) { + return requestClient.get('/license/customer/name-exists', { + params: { id, name }, + }); +} + +export { isCustomerNameExists }; diff --git a/apps/web-antd/src/views/license/customer/data.ts b/apps/web-antd/src/views/license/customer/data.ts index 93f1436..f9a61a0 100644 --- a/apps/web-antd/src/views/license/customer/data.ts +++ b/apps/web-antd/src/views/license/customer/data.ts @@ -2,14 +2,19 @@ import type { VbenFormSchema } from '#/adapter/form'; import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; import type { CustomerApi } from '#/api/license/customer'; +import { ref } from 'vue'; + import { useAccess } from '@vben/access'; +import { z } from '#/adapter/form'; +import { isCustomerNameExists } from '#/api/license/customer'; import { getAreaTree } from '#/api/system/area'; import { $t } from '#/locales'; import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils'; const { hasAccessByCodes } = useAccess(); +export const formData = ref(); /** 新增/修改的表单 */ export function useFormSchema(): VbenFormSchema[] { return [ @@ -24,8 +29,25 @@ export function useFormSchema(): VbenFormSchema[] { { fieldName: 'name', label: $t('customer.customerName'), - rules: 'required', component: 'Input', + rules: z + .string() + .min(1, $t('ui.formRules.required', [$t('customer.customerName')])) + .max( + 60, + $t('ui.formRules.maxLength', [$t('customer.customerName'), 60]), + ) + .refine( + async (value: string) => { + return !(await isCustomerNameExists(value, formData.value?.id)); + }, + (value) => ({ + message: $t('ui.formRules.alreadyExists', [ + $t('customer.customerName'), + value, + ]), + }), + ), }, { fieldName: 'code', diff --git a/apps/web-antd/src/views/license/customer/modules/form.vue b/apps/web-antd/src/views/license/customer/modules/form.vue index 7aad623..c94c51f 100644 --- a/apps/web-antd/src/views/license/customer/modules/form.vue +++ b/apps/web-antd/src/views/license/customer/modules/form.vue @@ -1,7 +1,7 @@