feat: 开站网元安装步骤进度的显示

This commit is contained in:
TsMask
2024-04-28 10:23:14 +08:00
parent efb98ac577
commit 957868cc27
10 changed files with 566 additions and 188 deletions

View File

@@ -0,0 +1,296 @@
<script setup lang="ts">
import { Modal, TableColumnsType, message } from 'ant-design-vue/lib';
import { defineAsyncComponent, onMounted, reactive, ref, toRaw } from 'vue';
import { fnToStepName, stepState } from '../hooks/useStep';
import useI18n from '@/hooks/useI18n';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import {
codeNeLicense,
listNeLicense,
stateNeLicense,
} from '@/api/ne/neLicense';
import saveAs from 'file-saver';
const { t } = useI18n();
const UploadLicenseFile = defineAsyncComponent(
() => import('../../../ne/neLicense/components/UploadLicenseFile.vue')
);
/**表格字段列 */
let tableColumns = ref<TableColumnsType>([
{
title: 'neType',
dataIndex: 'neType',
align: 'left',
width: 100,
},
{
title: 'neId',
dataIndex: 'neId',
align: 'left',
width: 100,
},
{
title: 'status',
dataIndex: 'status',
key: 'status',
align: 'left',
width: 100,
},
{
title: 'serialNum',
dataIndex: 'serialNum',
align: 'left',
width: 100,
},
{
title: 'expiryDate',
dataIndex: 'expiryDate',
align: 'left',
width: 100,
},
]);
/**对象信息信息状态类型 */
type StateType = {
/**加载等待 */
loading: boolean;
/**记录数据 */
data: any[];
/**勾选记录 */
selectedRowKeys: (string | number)[];
/**授权文件上传 */
visibleByLicenseFile: boolean;
/**确定按钮 loading */
confirmLoading: boolean;
};
/**对象信息状态 */
let state: StateType = reactive({
loading: false,
data: [],
selectedRowKeys: [],
visibleByLicenseFile: false,
confirmLoading: false,
});
/**表格多选 */
function fnTableSelectedRowKeys(keys: (string | number)[]) {
state.selectedRowKeys = keys;
}
/**对话框弹出确认执行函数*/
function fnModalOk() {
fnGetList();
}
/**对话框弹出关闭执行函数*/
function fnModalCancel() {
state.visibleByLicenseFile = false;
}
/**勾选刷新网元状态 */
function fnRecordState() {
Modal.confirm({
title: t('common.tipTitle'),
content: `check refresh license state?`,
onOk: async () => {
if (state.confirmLoading) return;
state.confirmLoading = true;
const hide = message.loading(t('common.loading'), 0);
// 勾选的网元数据
const selectRows = state.data.filter(item =>
state.selectedRowKeys.includes(item.id)
);
for (const row of selectRows) {
if (row.neType.toUpperCase() === 'OMC') {
continue;
}
const res = await stateNeLicense(row.neType, row.neId);
if (res.code === RESULT_CODE_SUCCESS && res.data) {
row.status = '1';
row.serialNum = res.data.sn;
row.expiryDate = res.data.expire;
}
}
message.success(t('common.operateOk'), 3);
hide();
state.confirmLoading = false;
},
});
}
/**勾选下载网元授权code */
function fnRecordCode() {
Modal.confirm({
title: t('common.tipTitle'),
content: `check download license activation code file?`,
onOk: async () => {
if (state.confirmLoading) return;
state.confirmLoading = true;
const hide = message.loading(t('common.loading'), 0);
// 勾选的网元数据
const selectRows = state.data.filter(item =>
state.selectedRowKeys.includes(item.id)
);
const codeArr: string[] = [];
for (const row of selectRows) {
if (row.neType.toUpperCase() === 'OMC') {
continue;
}
const res = await codeNeLicense(row.neType, row.neId);
if (res.code === RESULT_CODE_SUCCESS) {
const activationRequestCode = res.data;
row.activationRequestCode = activationRequestCode;
codeArr.push(`[${row.neType} ${row.neId}]:${activationRequestCode}`);
}
}
if (codeArr.length > 0) {
const blob = new Blob([codeArr.join('\r\n')], {
type: 'text/plain',
});
saveAs(blob, `CheckRecordActivationCode_${new Date().getTime()}.txt`);
}
hide();
state.confirmLoading = false;
},
});
}
/**获取列表 */
function fnGetList() {
state.loading = true;
listNeLicense({
neType: undefined,
neId: '',
version: '',
pageNum: 1,
pageSize: 20,
}).then(res => {
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.rows)) {
// 取消勾选
if (state.selectedRowKeys.length > 0) {
state.selectedRowKeys = [];
}
state.data = res.rows;
}
state.loading = false;
});
}
/**返回上一步 */
function fnStepPrev() {
Modal.confirm({
title: t('common.tipTitle'),
content: '确认要放弃当前变更返回上一步吗?',
onOk() {
fnToStepName('NeInfoSoftwareInstall');
},
});
}
/**下一步操作 */
function fnStepNext(stepName: 'Done') {
if (stepName === 'Done') {
Modal.confirm({
title: t('common.tipTitle'),
content: '确认要结束网元安装吗?',
onOk() {
stepState.setupNE = true;
fnToStepName('Done');
},
});
}
}
onMounted(() => {
fnGetList();
});
</script>
<template>
<div class="ne">
<!-- 表格列表 -->
<a-table
class="table"
row-key="id"
:columns="tableColumns"
:loading="state.loading"
:data-source="state.data"
size="middle"
:pagination="false"
@resizeColumn="(w:number, col:any) => (col.width = w)"
:scroll="{ y: '65vh' }"
:row-selection="{
type: 'checkbox',
columnWidth: '48px',
selectedRowKeys: state.selectedRowKeys,
onChange: fnTableSelectedRowKeys,
}"
>
</a-table>
<!-- 授权文件上传框 -->
<UploadLicenseFile
v-model:visible="state.visibleByLicenseFile"
@ok="fnModalOk"
@cancel="fnModalCancel"
></UploadLicenseFile>
<div class="ne-oper">
<a-space direction="horizontal" :size="18">
<a-button @click="fnStepPrev()"> 上一步 </a-button>
<a-button
type="primary"
@click.prevent="
() => (state.visibleByLicenseFile = !state.visibleByLicenseFile)
"
>
<template #icon><UploadOutlined /></template>
Upload License
</a-button>
<a-button
type="default"
danger
:disabled="state.selectedRowKeys.length <= 0"
:loading="state.confirmLoading"
@click.prevent="fnRecordState()"
>
<template #icon><ReloadOutlined /></template>
Refresh State
</a-button>
<a-button
type="ghost"
:disabled="state.selectedRowKeys.length <= 0"
:loading="state.confirmLoading"
@click.prevent="fnRecordCode()"
>
<template #icon><DownloadOutlined /></template>
Download Activation Code
</a-button>
<a-button type="dashed" @click="fnStepNext('Done')"> 结束 </a-button>
</a-space>
</div>
</div>
</template>
<style lang="less" scoped>
.ne {
padding-top: 12px;
height: 78vh;
overflow-x: hidden;
overflow-y: auto;
&-oper {
padding-top: 24px;
text-align: end;
}
}
</style>