Files
fe.ems.vue3/src/views/system/quick-start/components/NeInfoConfig.vue

811 lines
22 KiB
Vue

<script setup lang="ts">
import { Modal, message } from 'ant-design-vue/lib';
import { onMounted, reactive, ref, toRaw } from 'vue';
import {
addNeInfo,
delNeInfo,
listAllNeInfo,
getNeInfo,
updateNeInfo,
} from '@/api/ne/neInfo';
import { neHostAuthorizedRSA, testNeHost } from '@/api/ne/neHost';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import { NE_TYPE_LIST } from '@/constants/ne-constants';
import { regExpIPv4, regExpIPv6 } from '@/utils/regular-utils';
import { fnToStepName } from '../hooks/useStep';
import useI18n from '@/hooks/useI18n';
import useDictStore from '@/store/modules/dict';
const { getDict } = useDictStore();
const { t } = useI18n();
/**字典数据 */
let dict: {
/**主机类型 */
neHostType: DictType[];
/**分组 */
neHostGroupId: DictType[];
/**认证模式 */
neHostAuthMode: DictType[];
} = reactive({
neHostType: [],
neHostGroupId: [],
neHostAuthMode: [],
});
/**标签对象信息状态类型 */
type TabStateType = {
/**激活选中 */
activeKey: string;
/**页签数据 */
panes: Record<string, any>[];
/**等待loading */
confirmLoading: boolean;
};
/**标签对象信息状态 */
const tabState: TabStateType = reactive({
activeKey: 'neType@neId',
panes: [],
confirmLoading: false,
});
/**对话框对象信息状态类型 */
type ModalStateType = {
/**新增框或修改框是否显示 */
visibleByEdit: boolean;
/**标题 */
title: string;
/**表单数据 */
from: Record<string, any>;
/**确定按钮 loading */
confirmLoading: boolean;
/**更新加载数据按钮 loading */
loadDataLoading: boolean;
};
/**对话框对象信息状态 */
let modalState: ModalStateType = reactive({
visibleByEdit: false,
title: '网元配置',
from: {
id: undefined,
neType: '',
neId: '',
neName: '',
ip: '',
port: 33030,
pvFlag: 'PNF',
rmUid: '',
neAddress: '',
dn: '-',
vendorName: '-',
province: '-',
hosts: [],
},
confirmLoading: false,
loadDataLoading: false,
});
/**表格状态 */
let tableState: any = reactive({
loading: false,
size: 'small',
seached: true,
data: [],
selectedRowKeys: [],
});
/**表格字段列 */
let tableColumns: any = [
{
title: t('common.operate'),
dataIndex: 'operation',
key: 'operation',
align: 'left',
width: 100,
},
{
title: t('views.ne.common.neType'),
dataIndex: 'neType',
align: 'left',
width: 100,
},
{
title: t('views.ne.common.neId'),
dataIndex: 'neId',
align: 'left',
width: 150,
},
{
title: t('views.ne.common.ipAddr'),
dataIndex: 'ip',
align: 'left',
width: 150,
},
{
title: t('views.ne.neHost.user'),
dataIndex: 'hosts',
customRender(opt: any) {
const hosts = opt.value;
return hosts[0].user;
},
align: 'left',
width: 100,
},
];
/**
* 测试主机连接
*/
function fnHostTest(row: Record<string, any>) {
if (tabState.confirmLoading || !row.addr) return;
tabState.confirmLoading = true;
const hide = message.loading(t('common.loading'), 0);
testNeHost(row)
.then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success({
content: `${row.addr}:${row.port} ${t('views.ne.neHost.testOk')}`,
duration: 2,
});
} else {
message.error({
content: `${row.addr}:${row.port} ${res.msg}`,
duration: 2,
});
}
})
.finally(() => {
hide();
tabState.confirmLoading = false;
});
}
/**测试主机连接-免密直连 */
function fnHostAuthorized(row: Record<string, any>) {
if (tabState.confirmLoading || !row.addr) return;
Modal.confirm({
title: t('common.tipTitle'),
content: t('views.ne.neHost.authRSATip'),
onOk: () => {
tabState.confirmLoading = true;
neHostAuthorizedRSA(row).then(res => {
tabState.confirmLoading = false;
if (res.code === RESULT_CODE_SUCCESS) {
message.success(t('common.operateOk'), 3);
} else {
message.error(t('common.operateErr'), 3);
}
});
},
});
}
/**
* 表单修改网元类型
*/
function fnNeTypeChange(v: any, data: any) {
const hostsLen = data.hosts.length;
// 网元默认只含22和4100
if (hostsLen === 3 && v !== 'UPF') {
data.hosts.pop();
}
// UPF标准版本可支持5002
if (hostsLen === 2 && v === 'UPF') {
data.hosts.push({
hostId: undefined,
hostType: 'telnet',
groupId: '1',
title: 'Telnet_NE_5002',
addr: '',
port: 5002,
user: 'admin',
authMode: '0',
password: 'admin',
remark: '',
});
}
}
//打开新增或修改界面
function fnModalVisibleByEdit(record?: any) {
if (!record) {
//modalStateFrom.resetFields();
modalState.title = t('views.configManage.neManage.addNe');
const neId = `${new Date().getMilliseconds()}`.padStart(3, '0');
modalState.from = {
id: undefined,
neId: neId,
neType: '',
neName: `New_${neId}`,
ip: '',
port: 33030,
pvFlag: 'PNF',
rmUid: `4400HXNew${neId}`,
neAddress: '',
dn: '-',
vendorName: '-',
province: '-',
// 主机
hosts: [
{
hostId: undefined,
hostType: 'ssh',
groupId: '1',
title: 'SSH_NE_22',
addr: '',
port: 22,
user: 'omcuser',
authMode: '2',
password: '',
privateKey: '',
passPhrase: '',
remark: '',
},
{
hostId: undefined,
hostType: 'telnet',
groupId: '1',
title: 'Telnet_NE_4100',
addr: '',
port: 4100,
user: 'admin',
authMode: '0',
password: 'admin',
remark: '',
},
],
};
modalState.visibleByEdit = true;
} else {
//获取单个网元信息 当修改时
if (modalState.confirmLoading) return;
const hide = message.loading(t('common.loading'), 0);
modalState.confirmLoading = true;
getNeInfo(record.id).then(res => {
modalState.confirmLoading = false;
hide();
if (res.code === RESULT_CODE_SUCCESS) {
Object.assign(modalState.from, res.data);
modalState.title = t('views.configManage.neManage.editNe');
modalState.visibleByEdit = true;
} else {
message.error(t('common.getInfoFail'), 2);
}
});
}
}
/**新增或修改网元 */
function fnModalOk() {
modalState.confirmLoading = true;
const from = toRaw(modalState.from);
from.rmUid = `4400HX${from.neType}${from.neId}`; // 4400HX1AMF001
from.neName = `${from.neType}_${from.neId}`; // AMF_001
const result = from.id ? updateNeInfo(from) : addNeInfo(from);
const hide = message.loading(t('common.loading'), 0);
result
.then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success({
content: t('common.operateOk'),
duration: 3,
});
fnGetList();
} else {
message.error({
content: `${res.msg}`,
duration: 3,
});
}
})
.finally(() => {
hide();
fnModalCancel();
});
}
/**
* 删除网元
* @param data 当前选项的data
*/
function fnDelete(data: any) {
Modal.confirm({
title: t('common.tipTitle'),
content: `${data.neName} ${t('views.ne.neInfo.delTip')}`,
onOk() {
tableState.loading = true;
const hide = message.loading(t('common.loading'), 0);
delNeInfo(data.id)
.then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success(t('common.operateOk'), 3);
tableState.loading = false;
fnGetList();
} else {
message.error({
content: `${res.msg}`,
duration: 3,
});
}
})
.finally(() => {
hide();
tableState.loading = false;
});
},
});
}
/**
* 对话框弹出关闭执行函数
* 进行表达规则校验
*/
function fnModalCancel() {
modalState.visibleByEdit = false;
modalState.confirmLoading = false;
tabState.confirmLoading = false;
}
/**
* 表单修改网元IP
*/
function fnNeIPChange(e: any, data: any) {
const v = e.target.value;
if (v.length < 7) return; //IP地址长度
//主机host数组addr都置成e.target.value
for (const host of data.hosts) {
host.addr = v;
}
}
/**表单验证IP地址是否有效 */
function modalStateFromEqualIPV4AndIPV6(
rule: Record<string, any>,
value: string,
callback: (error?: string) => void
) {
if (!value) {
return Promise.reject(t('views.ne.common.ipAddrPlease'));
}
if (value.indexOf('.') === -1 && value.indexOf(':') === -1) {
return Promise.reject(t('valid.ipPlease'));
}
if (value.indexOf('.') !== -1 && !regExpIPv4.test(value)) {
return Promise.reject(t('valid.ipv4Reg'));
}
if (value.indexOf(':') !== -1 && !regExpIPv6.test(value)) {
return Promise.reject(t('valid.ipv6Reg'));
}
return Promise.resolve();
}
/**返回上一步 */
function fnStepPrev() {
Modal.confirm({
title: t('common.tipTitle'),
content: t('views.system.quickStart.stepNeInfoStepPrev'),
onOk() {
fnToStepName('SystemConfig');
},
});
}
/**下一步操作 先全部集体发过去请求新增 */
function fnStepNext(stepName: 'NeInfoConfigPara5G') {
if (stepName === 'NeInfoConfigPara5G') {
Modal.confirm({
title: t('common.tipTitle'),
content: t('views.system.quickStart.stepNeInfoStepNext'),
okButtonProps: {
loading: tabState.confirmLoading,
},
onOk() {
tabState.confirmLoading = true;
// 使用 Promise.allSettled 等待所有 Promise 完成
Promise.allSettled(
tabState.panes.map((item: any) =>
item.id ? updateNeInfo(item) : addNeInfo(item)
)
).finally(() => {
tabState.confirmLoading = false;
fnToStepName('NeInfoConfigPara5G');
});
},
});
}
}
/**获取列表 */
function fnGetList() {
listAllNeInfo({
bandHost: true,
}).then(res => {
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
tabState.panes = [];
for (const item of res.data) {
if (item.neType === 'OMC' || !Array.isArray(item.hosts)) continue;
tabState.panes.push(item);
}
}
});
}
//
onMounted(() => {
// 初始字典数据
Promise.allSettled([
getDict('ne_host_type'),
getDict('ne_host_groupId'),
getDict('ne_host_authMode'),
])
.then(resArr => {
if (resArr[0].status === 'fulfilled') {
dict.neHostType = resArr[0].value;
}
if (resArr[1].status === 'fulfilled') {
dict.neHostGroupId = resArr[1].value;
}
if (resArr[2].status === 'fulfilled') {
dict.neHostAuthMode = resArr[2].value;
}
})
.finally(() => {
fnGetList();
});
});
</script>
<template>
<div class="ne">
<a-table
class="table"
row-key="imsi"
:columns="tableColumns"
:loading="tableState.loading"
:data-source="tabState.panes"
:size="tableState.size"
:pagination="false"
:scroll="{ y: 'calc(100vh - 480px)' }"
@resizeColumn="(w:number, col:any) => (col.width = w)"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'operation'">
<a-space :size="8" align="center">
<a-tooltip>
<template #title>{{ t('common.editText') }}</template>
<a-button
type="link"
@click.prevent="fnModalVisibleByEdit(record)"
>
<template #icon>
<FormOutlined />
</template>
</a-button>
</a-tooltip>
<a-tooltip>
<template #title> {{ t('common.deleteText') }}</template>
<a-button type="link" @click.prevent="fnDelete(record)">
<template #icon>
<delete-outlined />
</template>
</a-button>
</a-tooltip>
</a-space>
</template>
</template>
</a-table>
<!-- 新增框或修改框 -->
<ProModal
:drag="true"
:width="800"
:destroyOnClose="true"
:keyboard="false"
:mask-closable="false"
:visible="modalState.visibleByEdit"
:title="modalState.title"
:confirm-loading="modalState.confirmLoading"
@ok="fnModalOk"
@cancel="fnModalCancel"
>
<a-form
name="modalStateFrom"
layout="horizontal"
:label-col="{ span: 6 }"
:labelWrap="true"
:model="modalState.from"
autocomplete="off"
>
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.ne.common.neType')"
name="neType"
:rules="{
required: true,
message: t('views.ne.common.neTypePlease'),
}"
>
<a-auto-complete
v-model:value="modalState.from.neType"
:options="
NE_TYPE_LIST.filter(s => s !== 'OMC').map(v => ({
value: v,
}))
"
@change="(v:any) => fnNeTypeChange(v, modalState.from)"
>
<a-input
allow-clear
:placeholder="t('views.ne.common.neTypePlease')"
:maxlength="32"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
{{ t('views.ne.common.neTypeTip') }}
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-auto-complete>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.ne.common.neId')"
name="neId"
:rules="{
required: true,
message: t('views.ne.common.neIdPlease'),
}"
>
<a-input
v-model:value="modalState.from.neId"
allow-clear
:placeholder="t('views.ne.common.neIdPlease')"
:maxlength="24"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
{{ t('views.ne.common.neIdTip') }}
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.ne.common.ipAddr')"
name="ip"
:rules="[
{
required: true,
},
{
validator: modalStateFromEqualIPV4AndIPV6,
},
]"
>
<a-input
v-model:value="modalState.from.ip"
allow-clear
:placeholder="t('views.ne.common.ipAddrPlease')"
:maxlength="128"
@change="(e:any) => fnNeIPChange(e, modalState.from)"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>
{{ t('views.ne.common.ipAddrTip') }}
</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24"> </a-col>
</a-row>
<template v-if="modalState.from.hosts.length > 0">
<a-divider orientation="left">
{{ t('views.ne.neInfo.hostConfig') }}
</a-divider>
<!-- 主机连接配置 -->
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item :label="t('views.ne.neHost.addr')">
<a-input
v-model:value="modalState.from.hosts[0].addr"
allow-clear
:maxlength="128"
:placeholder="t('common.inputPlease')"
>
</a-input>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item :label="t('views.ne.neHost.port')" name="port">
<a-input-number
v-model:value="modalState.from.hosts[0].port"
:min="10"
:max="65535"
:step="1"
:maxlength="5"
:placeholder="t('common.inputPlease')"
style="width: 100%"
></a-input-number>
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item :label="t('views.ne.neHost.user')">
<a-input
v-model:value="modalState.from.hosts[0].user"
allow-clear
:maxlength="32"
:placeholder="t('common.inputPlease')"
>
</a-input>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item :label="t('views.ne.neHost.authMode')">
<a-select
v-model:value="modalState.from.hosts[0].authMode"
default-value="0"
:options="dict.neHostAuthMode"
>
</a-select>
</a-form-item>
</a-col>
</a-row>
<a-form-item
v-if="modalState.from.hosts[0].authMode === '0'"
:label="t('views.ne.neHost.password')"
:label-col="{ span: 3 }"
:label-wrap="true"
>
<a-input-password
v-model:value="modalState.from.hosts[0].password"
:maxlength="128"
:placeholder="t('common.inputPlease')"
>
</a-input-password>
</a-form-item>
<template v-if="modalState.from.hosts[0].authMode === '1'">
<a-form-item
:label="t('views.ne.neHost.privateKey')"
:label-col="{ span: 3 }"
:label-wrap="true"
>
<a-textarea
v-model:value="modalState.from.hosts[0].privateKey"
:auto-size="{ minRows: 4, maxRows: 6 }"
:maxlength="3000"
:show-count="true"
:placeholder="t('views.ne.neHost.privateKeyPlease')"
/>
</a-form-item>
<a-form-item
:label="t('views.ne.neHost.passPhrase')"
:label-col="{ span: 3 }"
:label-wrap="true"
>
<a-input-password
v-model:value="modalState.from.hosts[0].passPhrase"
:maxlength="128"
:placeholder="t('common.inputPlease')"
>
</a-input-password>
</a-form-item>
</template>
<a-form-item
:label="t('views.ne.neHost.test')"
name="test"
:label-col="{ span: 3 }"
:label-wrap="true"
>
<a-button
type="dashed"
shape="round"
@click="fnHostTest(modalState.from.hosts[0])"
:disabled="tabState.confirmLoading"
>
<template #icon><LinkOutlined /></template>
</a-button>
<a-button
type="link"
@click="fnHostAuthorized(modalState.from.hosts[0])"
:disabled="tabState.confirmLoading"
v-if="
modalState.from.hosts[0].hostType === 'ssh' &&
modalState.from.hosts[0].authMode !== '2'
"
>
{{ t('views.ne.neHost.authRSA') }}
</a-button>
</a-form-item>
</template>
<!-- <a-form-item :wrapper-col="{ offset: 10, span: 4 }">
<a-button
type="primary"
ghost
html-type="submit"
:disabled="tabState.confirmLoading"
>
{{ t('views.system.quickStart.save') }}
</a-button>
</a-form-item> -->
</a-form>
</ProModal>
<div class="ne-oper">
<a-space direction="horizontal" :size="18">
<!-- 添加网元 -->
<a-button type="primary" @click.prevent="fnModalVisibleByEdit()">
<template #icon><PlusOutlined /></template>
{{ t('common.addText') }}
</a-button>
<a-button @click="fnStepPrev()" :disabled="tabState.confirmLoading">
{{ t('views.system.quickStart.exit') }}
</a-button>
<a-button
type="primary"
@click="fnStepNext('NeInfoConfigPara5G')"
:loading="tabState.confirmLoading"
>
{{ t('views.system.quickStart.stepNext') }}
</a-button>
</a-space>
</div>
</div>
</template>
<style lang="less" scoped>
.neinfo-tabs :deep(.ant-tabs-tabpane) {
padding: 24px;
height: 60vh;
overflow-y: auto;
overflow-x: hidden;
// margin-bottom: 24px;
// margin-top: 24px;
}
.ne {
padding-top: 12px;
// height: 78vh;
overflow-x: hidden;
overflow-y: auto;
&-oper {
padding-top: 24px;
text-align: end;
}
}
</style>