From 843ec6554154159c595d3f9d524eb62e41cb6091 Mon Sep 17 00:00:00 2001 From: caiyuchao Date: Fri, 4 Jul 2025 14:10:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20SN=E5=94=AF=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/api/license/license/index.ts | 10 ++++++++++ apps/web-antd/src/views/license/license/data.ts | 13 +++++++++++++ .../src/views/license/license/modules/form.vue | 5 ++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/apps/web-antd/src/api/license/license/index.ts b/apps/web-antd/src/api/license/license/index.ts index 0129f3c..1c1a266 100644 --- a/apps/web-antd/src/api/license/license/index.ts +++ b/apps/web-antd/src/api/license/license/index.ts @@ -56,3 +56,13 @@ export function deleteLicense(id: number) { export function exportLicense(params: any) { return requestClient.download('/license/license/export-excel', params); } + +/** License SN是否唯一 */ +export async function isLicenseSnUnique( + sn: string, + id?: LicenseApi.License['id'], +) { + return requestClient.get('/license/license/sn-unique', { + params: { id, sn }, + }); +} diff --git a/apps/web-antd/src/views/license/license/data.ts b/apps/web-antd/src/views/license/license/data.ts index 3897dca..7fa3a90 100644 --- a/apps/web-antd/src/views/license/license/data.ts +++ b/apps/web-antd/src/views/license/license/data.ts @@ -2,9 +2,13 @@ import type { VbenFormSchema } from '#/adapter/form'; import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; import type { LicenseApi } from '#/api/license/license'; +import { ref } from 'vue'; + import { useAccess } from '@vben/access'; +import { z } from '#/adapter/form'; import { getCustomerList } from '#/api/license/customer'; +import { isLicenseSnUnique } from '#/api/license/license'; import { getProjectList } from '#/api/license/project'; import { getLicenseAdminList, getSimpleUserList } from '#/api/system/user'; import { $t } from '#/locales'; @@ -13,6 +17,7 @@ import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils'; const { hasAccessByCodes } = useAccess(); let projectList = await getProjectList({}); const customerList = await getCustomerList(); +export const formData = ref(); /** 新增/修改的表单 */ export function useFormSchema(): VbenFormSchema[] { @@ -88,6 +93,14 @@ export function useFormSchema(): VbenFormSchema[] { // 只有指定的字段改变时,才会触发 triggerFields: ['customerId', 'projectId'], }, + rules: z.string().refine( + async (value: string) => { + return await isLicenseSnUnique(value, formData.value?.id); + }, + (value) => ({ + message: $t('ui.formRules.alreadyExists', ['SN', value]), + }), + ), }, { fieldName: 'expirationTime', diff --git a/apps/web-antd/src/views/license/license/modules/form.vue b/apps/web-antd/src/views/license/license/modules/form.vue index 26e4a67..f734a98 100644 --- a/apps/web-antd/src/views/license/license/modules/form.vue +++ b/apps/web-antd/src/views/license/license/modules/form.vue @@ -1,7 +1,7 @@