feat: 支持下载tar包

This commit is contained in:
caiyuchao
2025-09-02 19:30:08 +08:00
parent 7d3cf2c5bd
commit d07a33a898
5 changed files with 49 additions and 22 deletions

View File

@@ -95,6 +95,11 @@ export function importLicense(file: File, updateSupport: boolean) {
});
}
/** 下载生成代码 */
export function downloadLicense(id: number) {
return requestClient.download(`/license/license/download?id=${id}`);
}
/** 重新License */
export function reapplyLicense(data: LicenseApi.License) {
return requestClient.put('/license/license/reapply', data);

View File

@@ -61,12 +61,12 @@ export function useFormSchema(): VbenFormSchema[] {
message: $t('ui.formRules.required', [$t('customer.customerSn')]),
})
.min(
2000,
$t('ui.formRules.range', [$t('customer.customerSn'), 2000, 9999]),
1000,
$t('ui.formRules.range', [$t('customer.customerSn'), 1000, 9999]),
)
.max(
9999,
$t('ui.formRules.range', [$t('customer.customerSn'), 2000, 9999]),
$t('ui.formRules.range', [$t('customer.customerSn'), 1000, 9999]),
)
.refine(
async (value: number) => {

View File

@@ -7,11 +7,14 @@ import { useRoute, useRouter } from 'vue-router';
import { useAccess } from '@vben/access';
import { Page } from '@vben/common-ui';
import { useTabs } from '@vben/hooks';
import { downloadFileFromBlobPart } from '@vben/utils';
import { Button, message } from 'ant-design-vue';
import { generateLicense, getLicense } from '#/api/license/license';
import {
downloadLicense,
generateLicense,
getLicense,
} from '#/api/license/license';
import { $t } from '#/locales';
import Detail from '../components/detail.vue';
@@ -106,15 +109,24 @@ async function onDownload() {
const fileName = `${formData.value.fileUrl?.slice(
Math.max(0, formData.value.fileUrl.lastIndexOf('/') + 1),
formData.value.fileUrl.lastIndexOf('_'),
)}.zip`;
const res = await fetch(formData.value.fileUrl);
if (!res.ok) {
message.error($t('license.downloadFailed'));
return;
}
const blob = await res.blob();
)}.tar`;
downloadFileFromBlobPart({ fileName, source: blob });
const hideLoading = message.loading({
content: '下载中...',
key: 'action_key_msg',
});
try {
const res = await downloadLicense(formData.value.id);
const blob = new Blob([res], { type: 'application/tar' });
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = fileName;
link.click();
window.URL.revokeObjectURL(url);
} finally {
hideLoading();
}
}
// 组件卸载前清理

View File

@@ -12,6 +12,7 @@ import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteLicense,
downloadLicense,
exportLicense,
getLicensePage,
} from '#/api/license/license';
@@ -75,15 +76,24 @@ async function onDownload(row: LicenseApi.License) {
const fileName = `${row.fileUrl?.slice(
Math.max(0, row.fileUrl.lastIndexOf('/') + 1),
row.fileUrl.lastIndexOf('_'),
)}.zip`;
const res = await fetch(row.fileUrl);
if (!res.ok) {
message.error($t('license.downloadFailed'));
return;
}
const blob = await res.blob();
)}.tar`;
downloadFileFromBlobPart({ fileName, source: blob });
const hideLoading = message.loading({
content: '下载中...',
key: 'action_key_msg',
});
try {
const res = await downloadLicense(row.id);
const blob = new Blob([res], { type: 'application/tar' });
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = fileName;
link.click();
window.URL.revokeObjectURL(url);
} finally {
hideLoading();
}
}
/** 重新申请License */

View File

@@ -67,7 +67,7 @@ export function useFormSchema(): VbenFormSchema[] {
rules: z
.number({ message: $t('ui.formRules.required', [$t('project.code')]) })
.min(1000, $t('ui.formRules.range', [$t('project.code'), 1000, 9999]))
.max(9999, $t('ui.formRules.range', [$t('project.code'), 2000, 9999]))
.max(9999, $t('ui.formRules.range', [$t('project.code'), 1000, 9999]))
.refine(
async (value: number) => {
return await isProjectCodeUnique(value, formData.value?.id);