feat: 导入License功能调整

This commit is contained in:
caiyuchao
2025-08-26 19:03:23 +08:00
parent bd641818d4
commit 70d48f9e0a
3 changed files with 61 additions and 42 deletions

View File

@@ -12,9 +12,12 @@ import { formatDate, formatDateTime } from '@vben/utils';
import dayjs, { Dayjs } from 'dayjs';
import { z } from '#/adapter/form';
import { getLicenseCustomerList } from '#/api/license/customer';
import {
getCustomerList,
getLicenseCustomerList,
} from '#/api/license/customer';
import { isLicenseSnUnique } from '#/api/license/license';
import { getLicenseProjectList } from '#/api/license/project';
import { getLicenseProjectList, getProjectList } from '#/api/license/project';
import { getLicenseAdminList, getSimpleUserList } from '#/api/system/user';
import { DictTag } from '#/components/dict-tag';
import { $t } from '#/locales';
@@ -39,16 +42,22 @@ export function useFormSchema(): VbenFormSchema[] {
fieldName: 'customerId',
label: $t('license.customer'),
rules: 'required',
component: 'ApiSelect',
component: 'Select',
dependencies: {
triggerFields: ['id'],
disabled: (values) => !!values.id,
componentProps: async (values) => {
customerList.value = await (values.id
? getCustomerList()
: getLicenseCustomerList());
return {
options: customerList,
};
},
},
componentProps: {
api: async () => {
customerList.value = await getLicenseCustomerList();
return customerList.value;
},
options: customerList,
allowClear: true,
fieldNames: { label: 'name', value: 'id' },
showSearch: true,
@@ -71,15 +80,23 @@ export function useFormSchema(): VbenFormSchema[] {
},
dependencies: {
componentProps: async (values) => {
projectList.value = await getLicenseProjectList({
customerId: values.customerId,
});
const hasProject = projectList.value.find((project) => {
return project.id === values.projectId;
});
if (!hasProject) {
values.projectId = '';
projectList.value = await (values.id
? getProjectList({
customerId: values.customerId,
})
: getLicenseProjectList({
customerId: values.customerId,
}));
if (!values.id) {
const hasProject = projectList.value.find((project) => {
return project.id === values.projectId;
});
if (!hasProject) {
values.projectId = '';
}
}
return {
options: projectList,
};

View File

@@ -7,7 +7,7 @@ import { useVbenModal } from '@vben/common-ui';
// import { InboxOutlined } from '@vben/icons';
import { downloadFileFromBlobPart } from '@vben/utils';
import { Button, message, UploadDragger } from 'ant-design-vue';
import { Button, notification, UploadDragger } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import { importLicense, importTemplate } from '#/api/license/license';
@@ -41,40 +41,42 @@ const [Modal, modalApi] = useVbenModal({
await modalApi.close();
emit('success');
let failuresMsg: any;
if (result.creates && result.creates.length > 0) {
failuresMsg = h(
'div',
{
style: {
color: 'green',
},
const createsLength = result.creates ? result.creates.length : 0;
const updatesLength = result.updates ? result.updates.length : 0;
const total = result.total || 0;
const failuresLength = total - createsLength - updatesLength;
const resultMsg = `总共${total}条,新增成功${createsLength}条, 更新成功${updatesLength}条, 导入失败${failuresLength}`;
failuresMsg = h(
'div',
{
style: {
color: 'blue',
},
[failuresMsg, `新增成功:${result.creates.join('')}`],
);
}
if (result.updates && result.updates.length > 0) {
failuresMsg = h(
'div',
{
style: {
color: 'blue',
},
},
[failuresMsg, `更新成功:${result.updates.join('')}`],
);
}
for (const key in result.failures) {
},
[failuresMsg, resultMsg],
);
for (const key in result.failureMap) {
failuresMsg = h(
'div',
{
style: {
color: 'red',
overflowY: 'auto',
maxHeight: '600px',
},
},
[failuresMsg, `导入失败${key},失败原因${result.failures[key]}`],
[failuresMsg, `导入失败SN${key}${result.failureMap[key]}`],
);
}
message.info(failuresMsg, 10);
notification.open({
message: '导入结果',
description: failuresMsg,
style: {
color: failuresLength > 0 ? 'red' : 'green',
},
duration: 0,
});
} finally {
modalApi.unlock();
}