From d07a33a89803b8b511445aa0b5517dfe44315fb1 Mon Sep 17 00:00:00 2001 From: caiyuchao Date: Tue, 2 Sep 2025 19:30:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E4=B8=8B=E8=BD=BDtar?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web-antd/src/api/license/license/index.ts | 5 +++ .../src/views/license/customer/data.ts | 6 ++-- .../views/license/license/generate/index.vue | 32 +++++++++++++------ .../src/views/license/license/index.vue | 26 ++++++++++----- .../src/views/license/project/data.ts | 2 +- 5 files changed, 49 insertions(+), 22 deletions(-) diff --git a/apps/web-antd/src/api/license/license/index.ts b/apps/web-antd/src/api/license/license/index.ts index 1158465..c00605e 100644 --- a/apps/web-antd/src/api/license/license/index.ts +++ b/apps/web-antd/src/api/license/license/index.ts @@ -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); diff --git a/apps/web-antd/src/views/license/customer/data.ts b/apps/web-antd/src/views/license/customer/data.ts index b583095..ea3779b 100644 --- a/apps/web-antd/src/views/license/customer/data.ts +++ b/apps/web-antd/src/views/license/customer/data.ts @@ -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) => { diff --git a/apps/web-antd/src/views/license/license/generate/index.vue b/apps/web-antd/src/views/license/license/generate/index.vue index 287543e..4a2d4a2 100644 --- a/apps/web-antd/src/views/license/license/generate/index.vue +++ b/apps/web-antd/src/views/license/license/generate/index.vue @@ -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(); + } } // 组件卸载前清理 diff --git a/apps/web-antd/src/views/license/license/index.vue b/apps/web-antd/src/views/license/license/index.vue index 475567b..e4b556a 100644 --- a/apps/web-antd/src/views/license/license/index.vue +++ b/apps/web-antd/src/views/license/license/index.vue @@ -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 */ diff --git a/apps/web-antd/src/views/license/project/data.ts b/apps/web-antd/src/views/license/project/data.ts index 11cb285..8a4a2bd 100644 --- a/apps/web-antd/src/views/license/project/data.ts +++ b/apps/web-antd/src/views/license/project/data.ts @@ -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);