feat: 客户名称字段校验
This commit is contained in:
@@ -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<boolean>('/license/customer/name-exists', {
|
||||
params: { id, name },
|
||||
});
|
||||
}
|
||||
|
||||
export { isCustomerNameExists };
|
||||
|
||||
@@ -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<CustomerApi.Customer>();
|
||||
/** 新增/修改的表单 */
|
||||
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',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import type { CustomerApi } from '#/api/license/customer';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
@@ -15,10 +15,9 @@ import {
|
||||
} from '#/api/license/customer';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import { formData, useFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<CustomerApi.Customer>();
|
||||
const getTitle = computed(() => {
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', [$t('customer.customer')])
|
||||
|
||||
Reference in New Issue
Block a user