feat: SN唯一
This commit is contained in:
@@ -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<boolean>('/license/license/sn-unique', {
|
||||
params: { id, sn },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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<LicenseApi.License>();
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
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',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import type { LicenseApi } from '#/api/license/license';
|
||||
|
||||
import { computed, reactive, ref, watch } from 'vue';
|
||||
import { computed, reactive, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
@@ -16,11 +16,10 @@ import {
|
||||
import { $t } from '#/locales';
|
||||
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import { formData, useFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const neSwitchOptions = getDictOptions(DICT_TYPE.LIC_NE_SWITCH, 'number');
|
||||
const formData = ref<LicenseApi.License>();
|
||||
|
||||
const state = reactive({
|
||||
indeterminate: false,
|
||||
|
||||
Reference in New Issue
Block a user