feat: 支持修改license申请

This commit is contained in:
caiyuchao
2025-09-04 17:16:48 +08:00
parent f21bd1764e
commit 6ca7fb0a69
5 changed files with 71 additions and 41 deletions

View File

@@ -7,6 +7,7 @@ import type { DescriptionItemSchema } from '#/components/description';
import { h, ref } from 'vue';
import { useAccess } from '@vben/access';
import { formatDate, formatDateTime } from '@vben/utils';
import dayjs, { Dayjs } from 'dayjs';
@@ -20,6 +21,7 @@ import { DictTag } from '#/components/dict-tag';
import { $t } from '#/locales';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
const { hasAccessByRoles } = useAccess();
const customerList = ref<CustomerApi.Customer[]>([]);
const projectList = ref<ProjectApi.Project[]>([]);
export const formData = ref<LicenseApi.License>();
@@ -105,7 +107,7 @@ export function useFormSchema(): VbenFormSchema[] {
label: 'SN',
component: 'Input',
componentProps: {
disabled: true,
// disabled: true,
},
dependencies: {
trigger(values, form) {
@@ -125,15 +127,19 @@ export function useFormSchema(): VbenFormSchema[] {
},
// 只有指定的字段改变时,才会触发
triggerFields: ['customerId', 'projectId', 'id'],
disabled: () => !hasAccessByRoles(['license_admin']),
},
rules: z.string().refine(
async (value: string) => {
return await isLicenseSnUnique(value, formData.value?.id);
},
(value) => ({
message: $t('ui.formRules.alreadyExists', ['SN', value]),
}),
),
rules: z
.string()
.max(8, $t('ui.formRules.maxLength', ['SN', 8]))
.refine(
async (value: string) => {
return await isLicenseSnUnique(value, formData.value?.id);
},
(value) => ({
message: $t('ui.formRules.alreadyExists', ['SN', value]),
}),
),
},
{
fieldName: 'expiryDate',

View File

@@ -106,10 +106,6 @@ async function onDownload() {
if (!formData.value?.fileUrl) {
return;
}
const fileName = `${formData.value.fileUrl?.slice(
Math.max(0, formData.value.fileUrl.lastIndexOf('/') + 1),
formData.value.fileUrl.lastIndexOf('_'),
)}.tar.gz`;
const hideLoading = message.loading({
content: '下载中...',
@@ -121,7 +117,7 @@ async function onDownload() {
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = fileName;
link.download = formData.value.fileUrl;
link.click();
window.URL.revokeObjectURL(url);
} finally {

View File

@@ -73,11 +73,6 @@ function onHistory(row: LicenseApi.License) {
/** 下载License */
async function onDownload(row: LicenseApi.License) {
const fileName = `${row.fileUrl?.slice(
Math.max(0, row.fileUrl.lastIndexOf('/') + 1),
row.fileUrl.lastIndexOf('_'),
)}.tar.gz`;
const hideLoading = message.loading({
content: '下载中...',
key: 'action_key_msg',
@@ -88,7 +83,7 @@ async function onDownload(row: LicenseApi.License) {
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = fileName;
link.download = row.fileUrl;
link.click();
window.URL.revokeObjectURL(url);
} finally {
@@ -101,6 +96,11 @@ function onReapply(row: LicenseApi.License) {
formModalApi.setData(row).open();
}
/** 修改License */
function onEdit(row: LicenseApi.License) {
formModalApi.setData({ ...row, action: 1 }).open();
}
/** 删除License */
async function onDelete(row: LicenseApi.License) {
const hideLoading = message.loading({
@@ -253,6 +253,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
auth: ['license:license:query'],
onClick: onHistory.bind(null, row),
},
{
label: $t('common.edit'),
type: 'link',
ifShow:
row.status === 4 || row.status === 1 || row.dataType === 1,
auth: ['license:license:update'],
onClick: onEdit.bind(null, row),
},
]"
/>
</template>

View File

@@ -14,6 +14,7 @@ import {
createLicense,
getLicense,
reapplyLicense,
updateLicense,
} from '#/api/license/license';
import { $t } from '#/locales';
import { DICT_TYPE, getDictOptions } from '#/utils';
@@ -34,13 +35,25 @@ const state = reactive({
const neCodeRef = ref();
const getTitle = computed(() => {
return formData.value?.id
? $t('license.reapplyAction', ['License'])
: $t('license.applyAction', ['License']);
if (formData.value?.id) {
if (formData.value?.action === 1) {
return $t('ui.actionTitle.edit', ['License']);
}
return $t('license.reapplyAction', ['License']);
} else {
return $t('license.applyAction', ['License']);
}
});
const getConfirmText = computed(() => {
return formData.value?.id ? $t('license.reapply') : $t('license.apply');
if (formData.value?.id) {
if (formData.value?.action === 1) {
return $t('page.action.confirm');
}
return $t('license.reapply');
} else {
return $t('license.apply');
}
});
const [Form, formApi] = useVbenForm({
@@ -92,12 +105,19 @@ const [Modal, modalApi] = useVbenModal({
const data = (await formApi.getValues()) as LicenseApi.License;
data.neList = state.checkedList;
data.neCodeList = state.neCodeList;
const action = formData.value?.action || 0;
try {
await (formData.value?.id ? reapplyLicense(data) : createLicense(data));
if (formData.value?.id) {
await (action === 1 ? updateLicense(data) : reapplyLicense(data));
} else {
await createLicense(data);
}
// 关闭并提示
await modalApi.close();
emit('success');
message.success($t('license.applySuccess'), 3);
action === 1
? message.success($t('ui.actionMessage.operationSuccess'))
: message.success($t('license.applySuccess'), 3);
} finally {
modalApi.unlock();
}
@@ -114,16 +134,25 @@ const [Modal, modalApi] = useVbenModal({
}
if (data.id) {
modalApi.setState({ loading: true });
const action = data.action || 0; // 确保 action 字段存在
formData.value = { ...data, action };
data = await getLicense(data.id);
data.action = action; // 保留 action 字段
}
// 处理数据
data.expiryDate = data.expiryDate ? data.expiryDate.toString() : '';
// 设置到 values
formData.value = data;
state.checkedList = data.neList || [];
state.neCodeList = data.neCodeList || [
{ neList: [], activationCode: '', id: 1 },
];
if (state.neCodeList.length > 1) {
state.neCodeList = state.neCodeList.filter(
(item) => item.neList && item.neList.length > 0,
);
}
await formApi.setValues(formData.value);
modalApi.setState({ loading: false });
},
@@ -165,21 +194,10 @@ const addNeCode = () => {
neList: [],
activationCode: '',
id: nextId++,
fileUrl: '',
});
};
const availableOptions = (groupIdx: number) => {
// 其他分组已选标签
const otherSelected = new Set(
state.neCodeList
.filter((_, idx) => idx !== groupIdx)
.flatMap((g) => g.neList),
);
const aaaa = options.value?.map((item) => ({
...item,
options: item.options.filter(
(option: any) => !otherSelected.has(option.value),
),
}));
const availableOptions = () => {
return options.value;
};
</script>

View File

@@ -525,12 +525,14 @@ export function useGridColumns(
{
field: 'commentNum',
title: $t('project.commentNum'),
minWidth: 90,
sortable: true,
minWidth: 100,
},
{
field: 'applyCount',
title: $t('license.applyCount'),
minWidth: 120,
sortable: true,
minWidth: 130,
},
{
field: 'updateTime',