feat: 快速安装页面

This commit is contained in:
TsMask
2024-04-11 17:35:19 +08:00
parent 3970797d5b
commit dc6f4560d5
9 changed files with 1126 additions and 343 deletions

View File

@@ -1,22 +1,17 @@
<script setup lang="ts">
import { reactive, onMounted, toRaw, ref } from 'vue';
import { reactive, onMounted, toRaw } from 'vue';
import { message, Form, Upload } from 'ant-design-vue/lib';
import useI18n from '@/hooks/useI18n';
import {
RESULT_CODE_ERROR,
RESULT_CODE_SUCCESS,
} from '@/constants/result-constants';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import { NE_TYPE_LIST } from '@/constants/ne-constants';
import TerminalSSH from '@/components/TerminalSSH/index.vue';
import { ColumnsType } from 'ant-design-vue/lib/table';
import { checkInstallNeSoftware, listNeSoftware } from '@/api/ne/neSoftware';
import { installNeSoftware, listNeSoftware } from '@/api/ne/neSoftware';
import { parseDateToStr } from '@/utils/date-utils';
import { FileType } from 'ant-design-vue/lib/upload/interface';
import { UploadRequestOption } from 'ant-design-vue/lib/vc-upload/interface';
import { uploadFileChunk } from '@/api/tool/file';
import { stepState } from '../hooks/useStep';
const { t } = useI18n();
const emit = defineEmits(['next']);
/**表格字段列 */
let tableColumns: ColumnsType = [
@@ -33,9 +28,9 @@ let tableColumns: ColumnsType = [
width: 100,
},
{
title: 'fileName',
dataIndex: 'fileName',
key: 'fileName',
title: 'name',
dataIndex: 'name',
key: 'name',
align: 'left',
width: 300,
},
@@ -46,20 +41,20 @@ let tableColumns: ColumnsType = [
width: 100,
},
{
title: 'comment',
dataIndex: 'comment',
key: 'comment',
title: 'description',
dataIndex: 'description',
key: 'description',
align: 'left',
ellipsis: true,
},
{
title: 'updateTime',
dataIndex: 'updateTime',
title: 'createTime',
dataIndex: 'createTime',
align: 'left',
width: 150,
customRender(opt) {
if (!opt.value) return '';
return parseDateToStr(opt.value);
return parseDateToStr(+opt.value);
},
},
];
@@ -155,9 +150,9 @@ function fnGetList(pageNum?: number) {
/**安装对象信息状态类型 */
type InstallStateType = {
/**步骤 */
setp: 'pkg' | 'preinput' | 'ssh';
/**安装步骤命令 */
setpSSHArr: string[];
setp: 'pkg' | 'preinput' | 'log';
/**步骤日志输出 */
setpLog: string;
/**主机ID */
hostId: string;
/**文件操作类型 上传 or 选择 */
@@ -182,7 +177,7 @@ type InstallStateType = {
/**安装对象信息状态 */
let installState: InstallStateType = reactive({
setp: 'pkg',
setpSSHArr: [],
setpLog: '',
hostId: '',
optionType: 'upload',
from: {
@@ -200,6 +195,7 @@ let installState: InstallStateType = reactive({
mcc: '001',
mnc: '01',
priIP: '172.16.16.51',
pisCSCF: 'true',
},
});
@@ -315,25 +311,14 @@ function fnUploadFile(up: UploadRequestOption) {
});
}
/**软件包运行检查 */
/**软件包检查 */
function fnRunCheck() {
if (installState.confirmLoading) return;
const hide = message.loading(t('common.loading'), 0);
installStateFrom
.validate()
.then(() => {
const form = toRaw(installState.from);
Object.assign(form, { hostId: installState.hostId });
installState.confirmLoading = true;
return checkInstallNeSoftware(form);
})
.then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
installState.setpSSHArr = res.data;
installState.setp = 'preinput';
} else {
message.error(res.msg, 3);
}
installState.setp = 'preinput';
})
.catch(e => {
message.error(t('common.errorFields', { num: e.errorFields.length }), 3);
@@ -344,107 +329,53 @@ function fnRunCheck() {
});
}
/**安装检查预输入 */
function fnInstallPreinput() {
/**开始安装 */
function fnInstall() {
if (installState.confirmLoading) return;
// IMS
if (installState.from.neType === 'IMS') {
const modipplmn = installState.setpSSHArr[1];
if (modipplmn.includes('modipplmn.sh')) {
installState.setpSSHArr[1] = modipplmn
.replace('{PUBIP}', installState.preinput.pubIP)
.replace('{MCC}', installState.preinput.mcc)
.replace('{MNC}', installState.preinput.mnc);
}
const modintraip = installState.setpSSHArr[2];
if (modintraip.includes('modintraip.sh')) {
installState.setpSSHArr[2] = modintraip.replace(
'{PRIIP}',
installState.preinput.priIP
);
}
}
// 其他
//
installState.setp = 'ssh';
installState.confirmLoading = true;
const hide = message.loading(t('common.loading'), 0);
const from = toRaw(installState.from);
const preinput = toRaw(installState.preinput);
Object.assign(from, { hostId: installState.hostId });
installNeSoftware({
software: from,
preinput: preinput,
action: 'install',
})
.then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
installState.setp = 'log';
installState.setpLog = res.data;
message.success('软件安装成功', 3);
// 记录当前步骤状态信息
stepState.states[stepState.current] = {
from: from,
preinput: preinput,
};
stepState.stepNext = true;
} else {
message.error(res.msg, 3);
}
})
.finally(() => {
hide();
installState.confirmLoading = false;
});
}
/**安装终端 */
const installTerminal = ref();
/**
* 终端连接状态
* @param data 主机连接结果
*/
function fnTerminalConnect(data: Record<string, any>) {
console.log('fnTerminalConnect', data);
}
/**
* 终端消息数据
* @param data 主机连接结果
*/
function fnTerminalMessage(res: Record<string, any>) {
const { code, requestId, data } = res;
if (code === RESULT_CODE_ERROR) {
console.warn(res.msg);
return;
}
console.log('fnTerminalMessage', data);
// 安装遇到问题
if (data.includes('Errors were encountered while processing:')) {
installTerminal.value.send('logout');
return;
}
// 安装成功后退出
if (data.includes('software install successful')) {
installTerminal.value.send('logout');
message.success('软件安装成功', 3);
// 记录当前步骤状态信息
stepState.states[stepState.current] = { from: {} };
stepState.stepNext = true;
return;
}
// IMS预输入
if (data.includes('(P/I/S-CSCF Config)? <y/n>')) {
installTerminal.value.send(installState.preinput.pisCSCF);
return;
}
// 命令结束后继续输入命令
if (data.endsWith('$ ')) {
console.log('结束');
const cmdStr = installState.setpSSHArr.shift();
if (cmdStr) {
installTerminal.value.send(cmdStr);
}
return;
}
}
/**
* 终端关闭状态
* @param data 主机连接结果
*/
function fnTerminalClose(data: Record<string, any>) {
console.log('fnTerminalClose', data);
}
/**终端重新安装 */
function fnTerminalReset() {
/**重新安装 */
function fnInstallReset() {
installState.setp = 'pkg';
installState.optionType = 'option';
}
onMounted(() => {
// 读取步骤:网元信息
const stepPrevFrom = stepState.states[1].from;
installState.from.neType = stepPrevFrom.neType;
installState.hostId = stepPrevFrom.hostIds.split(',')[0];
const stepPrevFrom = stepState.states[1];
if (stepPrevFrom && stepPrevFrom.from) {
installState.from.neType = stepPrevFrom.from.neType;
installState.hostId = stepPrevFrom.from.hostIds.split(',')[0];
}
});
</script>
@@ -515,8 +446,8 @@ onMounted(() => {
</a-form-item>
<a-form-item
:label="t('views.configManage.softwareManage.updateComment')"
name="comment"
v-bind="installStateFrom.validateInfos.comment"
name="description"
v-bind="installStateFrom.validateInfos.description"
>
<a-textarea
v-model:value="installState.from.description"
@@ -575,16 +506,16 @@ onMounted(() => {
}"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'fileName'">
<template v-if="column.key === 'name'">
<a-tooltip placement="topLeft">
<template #title>{{ record.path }}</template>
<div style="cursor: pointer">{{ record.fileName }}</div>
<div style="cursor: pointer">{{ record.name }}</div>
</a-tooltip>
</template>
<template v-if="column.key === 'comment'">
<template v-if="column.key === 'description'">
<a-tooltip placement="topLeft">
<template #title>{{ record.comment }}</template>
<div style="cursor: pointer">{{ record.comment }}</div>
<template #title>{{ record.description }}</template>
<div style="cursor: pointer">{{ record.description }}</div>
</a-tooltip>
</template>
</template>
@@ -659,7 +590,7 @@ onMounted(() => {
<a-button
type="primary"
html-type="submit"
@click="fnInstallPreinput()"
@click="fnInstall()"
:loading="installState.confirmLoading"
>
开始安装
@@ -669,7 +600,7 @@ onMounted(() => {
<div>---- 安装进行信息</div>
<template v-if="installState.setp === 'ssh'">
<template v-if="installState.setp === 'log'">
<a-form-item
name="info"
label="安装日志"
@@ -677,23 +608,18 @@ onMounted(() => {
:wrapper-col="{ span: 24 }"
:label-wrap="true"
>
<TerminalSSH
ref="installTerminal"
:id="installState.hostId"
:hostId="installState.hostId"
init-cmd="clear"
@connect="fnTerminalConnect"
@message="fnTerminalMessage"
@close="fnTerminalClose"
>
</TerminalSSH>
<TerminalText
id="installLog"
:rows="28"
:value="installState.setpLog"
></TerminalText>
</a-form-item>
<a-form-item :wrapper-col="{ span: 14, offset: 3 }">
<a-button
type="primary"
html-type="submit"
@click="fnTerminalReset()"
@click="fnInstallReset()"
:loading="installState.confirmLoading"
>
返回重新选择安装