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