feat: 定时更新生成状态和支持全部下载
This commit is contained in:
@@ -30,5 +30,6 @@
|
||||
"addNe": "Add Network Elements",
|
||||
"enterCode": "Please enter Activation Code",
|
||||
"selectNe": "Please select Network Element",
|
||||
"detail": "detail"
|
||||
"detail": "detail",
|
||||
"downloadAll": "Download All"
|
||||
}
|
||||
|
||||
@@ -30,5 +30,6 @@
|
||||
"addNe": "添加网元",
|
||||
"enterCode": "请输入激活码",
|
||||
"selectNe": "请选择网元",
|
||||
"detail": "详情"
|
||||
"detail": "详情",
|
||||
"downloadAll": "全部下载"
|
||||
}
|
||||
|
||||
@@ -43,15 +43,18 @@ const columns = [
|
||||
},
|
||||
{
|
||||
title: 'License文件',
|
||||
dataIndex: 'fileUrl',
|
||||
key: 'fileUrl',
|
||||
dataIndex: 'fileUrlList',
|
||||
key: 'fileUrlList',
|
||||
customRender: (data: any) => {
|
||||
if (!data.value) {
|
||||
return;
|
||||
}
|
||||
const fileName = `${data.value?.slice(
|
||||
Math.max(0, data.value.lastIndexOf('/') + 1),
|
||||
data.value.lastIndexOf('_'),
|
||||
if (!data.value[0]) {
|
||||
return;
|
||||
}
|
||||
const fileName = `${data.value[0]?.slice(
|
||||
Math.max(0, data.value[0].lastIndexOf('/') + 1),
|
||||
data.value[0].lastIndexOf('_'),
|
||||
)}.ini`;
|
||||
// 创建下载链接
|
||||
const link = h(
|
||||
@@ -69,7 +72,7 @@ const columns = [
|
||||
Button,
|
||||
{
|
||||
onClick: async () => {
|
||||
const res = await fetch(data.value);
|
||||
const res = await fetch(data.value[0]);
|
||||
if (!res.ok) {
|
||||
message.error($t('license.downloadFailed'));
|
||||
return;
|
||||
@@ -83,8 +86,7 @@ const columns = [
|
||||
$t('license.download'),
|
||||
);
|
||||
|
||||
// 包裹容器
|
||||
return h(
|
||||
const file = h(
|
||||
'div',
|
||||
{
|
||||
style: {
|
||||
@@ -94,6 +96,64 @@ const columns = [
|
||||
},
|
||||
[link, button],
|
||||
);
|
||||
|
||||
let file1;
|
||||
if (data.value[1]) {
|
||||
const fileName1 = `${data.value[1]?.slice(
|
||||
Math.max(0, data.value[1].lastIndexOf('/') + 1),
|
||||
data.value[1].lastIndexOf('_'),
|
||||
)}.ini`;
|
||||
// 创建下载链接
|
||||
const link1 = h(
|
||||
'span',
|
||||
{
|
||||
style: {
|
||||
marginRight: '15px',
|
||||
},
|
||||
},
|
||||
fileName1,
|
||||
);
|
||||
|
||||
// 创建下载按钮
|
||||
const button1 = h(
|
||||
Button,
|
||||
{
|
||||
onClick: async () => {
|
||||
const res = await fetch(data.value[1]);
|
||||
if (!res.ok) {
|
||||
message.error($t('license.downloadFailed'));
|
||||
return;
|
||||
}
|
||||
const blob1 = await res.blob();
|
||||
|
||||
downloadFileFromBlobPart({ fileName: fileName1, source: blob1 });
|
||||
},
|
||||
type: 'primary',
|
||||
},
|
||||
$t('license.download'),
|
||||
);
|
||||
|
||||
file1 = h(
|
||||
'div',
|
||||
{
|
||||
style: {
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
margin: '8px 0 0 0',
|
||||
},
|
||||
},
|
||||
[link1, button1],
|
||||
);
|
||||
}
|
||||
|
||||
// 包裹容器
|
||||
return h(
|
||||
'div',
|
||||
{
|
||||
style: {},
|
||||
},
|
||||
[file, file1],
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -60,7 +60,7 @@ defineExpose({
|
||||
mode="multiple"
|
||||
allow-clear
|
||||
show-search
|
||||
style="width: 220px"
|
||||
style="width: 100px"
|
||||
:options="props.availableOptions(index)"
|
||||
:filter-option="filterOption"
|
||||
:placeholder="$t('license.selectNe')"
|
||||
|
||||
@@ -143,7 +143,7 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||
fieldName: 'neCodeList',
|
||||
label: $t('license.neList'),
|
||||
component: '',
|
||||
formItemClass: 'col-span-2',
|
||||
formItemClass: 'col-span-2 items-baseline',
|
||||
modelPropName: 'modelValue',
|
||||
rules: z.array(z.object({})),
|
||||
},
|
||||
@@ -533,7 +533,7 @@ export function useGridColumns(
|
||||
code: 'download',
|
||||
text: $t('license.download'),
|
||||
show: (values: LicenseApi.License) => {
|
||||
return values.status === 2;
|
||||
return values.status === 3;
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
<script lang="ts" setup>
|
||||
import type { LicenseApi } from '#/api/license/license';
|
||||
|
||||
import { ref } from 'vue';
|
||||
import { onBeforeUnmount, ref } from 'vue';
|
||||
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';
|
||||
|
||||
@@ -22,6 +23,10 @@ const router = useRouter();
|
||||
const loading = ref(false);
|
||||
const formData = ref<LicenseApi.License>();
|
||||
|
||||
// 定时器引用
|
||||
let checkInterval: null | number = null;
|
||||
let timeoutTimer: null | number = null;
|
||||
|
||||
/** 获取详情数据 */
|
||||
async function getDetail(id: any) {
|
||||
if (!id) {
|
||||
@@ -34,6 +39,7 @@ async function getDetail(id: any) {
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
return formData.value;
|
||||
}
|
||||
|
||||
const tabs = useTabs();
|
||||
@@ -53,33 +59,70 @@ async function onGenerate() {
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await generateLicense(formData.value.id);
|
||||
hideLoading();
|
||||
await getDetail(formData.value.id);
|
||||
|
||||
// 确认是否下载该文件
|
||||
// confirm({
|
||||
// title: $t('license.generateSuccess'),
|
||||
// content: $t('license.isDownload', [fileName]),
|
||||
// confirmText: $t('license.download'),
|
||||
// cancelText: $t('common.cancel'),
|
||||
// }).then(async () => {
|
||||
// const res = await fetch(response);
|
||||
// if (!res.ok) {
|
||||
// message.error($t('license.downloadFailed'));
|
||||
// return;
|
||||
// }
|
||||
// const blob = await res.blob();
|
||||
await generateLicense(formData.value.id);
|
||||
|
||||
// downloadFileFromBlobPart({ fileName, source: blob });
|
||||
// });
|
||||
message.success($t('license.generateSuccess'));
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
// 设置超时(3分钟)
|
||||
timeoutTimer = window.setTimeout(() => {
|
||||
stopProcess(hideLoading);
|
||||
}, 180_000);
|
||||
|
||||
// 首次立即检查
|
||||
await checkStatus(hideLoading);
|
||||
// 设置定期检查(每5秒)
|
||||
checkInterval = window.setInterval(async () => {
|
||||
await checkStatus(hideLoading);
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
const checkStatus = async (hideLoading: () => void) => {
|
||||
if (!formData.value?.id) {
|
||||
return;
|
||||
}
|
||||
const result = await getDetail(formData.value.id);
|
||||
if (result?.status === 3) {
|
||||
message.success($t('license.generateSuccess'));
|
||||
stopProcess(hideLoading);
|
||||
}
|
||||
};
|
||||
|
||||
// 停止处理流程
|
||||
const stopProcess = (hideLoading: () => void): void => {
|
||||
if (checkInterval) clearInterval(checkInterval);
|
||||
if (timeoutTimer) clearTimeout(timeoutTimer);
|
||||
|
||||
hideLoading();
|
||||
|
||||
// 重置定时器引用
|
||||
checkInterval = null;
|
||||
timeoutTimer = null;
|
||||
};
|
||||
|
||||
/** 下载License */
|
||||
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('_'),
|
||||
)}.zip`;
|
||||
const res = await fetch(formData.value.fileUrl);
|
||||
if (!res.ok) {
|
||||
message.error($t('license.downloadFailed'));
|
||||
return;
|
||||
}
|
||||
const blob = await res.blob();
|
||||
|
||||
downloadFileFromBlobPart({ fileName, source: blob });
|
||||
}
|
||||
|
||||
// 组件卸载前清理
|
||||
onBeforeUnmount(() => {
|
||||
if (checkInterval) clearInterval(checkInterval);
|
||||
if (timeoutTimer) clearTimeout(timeoutTimer);
|
||||
});
|
||||
|
||||
// 初始化
|
||||
getDetail(route.query.id);
|
||||
</script>
|
||||
@@ -101,6 +144,14 @@ getDetail(route.query.id);
|
||||
>
|
||||
{{ $t('license.generate') }}
|
||||
</Button>
|
||||
<Button
|
||||
v-if="formData?.status === 3"
|
||||
type="primary"
|
||||
:loading="loading"
|
||||
@click="onDownload"
|
||||
>
|
||||
{{ $t('license.downloadAll') }}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Page>
|
||||
|
||||
@@ -66,7 +66,7 @@ async function onDownload(row: LicenseApi.License) {
|
||||
const fileName = `${row.fileUrl?.slice(
|
||||
Math.max(0, row.fileUrl.lastIndexOf('/') + 1),
|
||||
row.fileUrl.lastIndexOf('_'),
|
||||
)}.ini`;
|
||||
)}.zip`;
|
||||
const res = await fetch(row.fileUrl);
|
||||
if (!res.ok) {
|
||||
message.error($t('license.downloadFailed'));
|
||||
|
||||
Reference in New Issue
Block a user