fix: 获取网元状态定时轮询修复

This commit is contained in:
TsMask
2024-11-21 18:19:07 +08:00
parent 78f963fbea
commit fb855fd74e
3 changed files with 29 additions and 15 deletions

View File

@@ -162,6 +162,7 @@ function loadData() {
clearInterval(interval10s.value); clearInterval(interval10s.value);
interval10s.value = setInterval(() => { interval10s.value = setInterval(() => {
if (!interval10s.value) return
if (upfTFActive.value === '0') { if (upfTFActive.value === '0') {
upfTFSend('7'); upfTFSend('7');
upfTFActive.value = '7'; upfTFActive.value = '7';
@@ -176,6 +177,7 @@ function loadData() {
clearInterval(interval5s.value); clearInterval(interval5s.value);
interval5s.value = setInterval(() => { interval5s.value = setInterval(() => {
if (!interval5s.value) return
fnGetSkim(); // 获取概览信息 fnGetSkim(); // 获取概览信息
fnGetNeState(); // 获取网元状态 fnGetNeState(); // 获取网元状态
}, 5_000); }, 5_000);

View File

@@ -30,11 +30,12 @@ function fnRanderData() {
} }
/**网元状态调度器 */ /**网元状态调度器 */
const interval10s = ref<any>(null); const interval = ref<boolean>(true);
/**查询网元状态 */ /**查询网元状态 */
async function fnGetState() { async function fnGetState() {
for (const node of graphG6Data.nodes) { for (const node of graphG6Data.nodes) {
if (!interval.value) return;
const ne = node.info; const ne = node.info;
// if (ne.neType === 'OMC') continue; // if (ne.neType === 'OMC') continue;
const result = await stateNeInfo(ne.neType, ne.neId); const result = await stateNeInfo(ne.neType, ne.neId);
@@ -151,11 +152,21 @@ function fnGetList(refresh: boolean = false) {
}) })
.then(randerGroph => { .then(randerGroph => {
if (!randerGroph) return; if (!randerGroph) return;
fnGetState().finally(() => { repeatFn();
interval10s.value = setInterval(() => { });
fnGetState(); // 获取网元状态 }
}, 10_000);
}); /**递归刷新网元状态 */
function repeatFn() {
if (!interval.value) {
return;
}
fnGetState()
.finally(() => {
repeatFn(); // 递归调用自己
})
.catch(error => {
console.error(error);
}); });
} }
@@ -165,7 +176,7 @@ onMounted(() => {
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {
clearInterval(interval10s.value); interval.value = false;
}); });
</script> </script>

View File

@@ -166,7 +166,7 @@ const graphNodeTooltip = new Tooltip({
</span></div> </span></div>
<div><strong>${t('views.monitor.topology.expiryDate')}</strong><span> <div><strong>${t('views.monitor.topology.expiryDate')}</strong><span>
${neState.expire ?? '--'} ${neState.expire ?? '--'}
</span></div> </span></div>
</div> </div>
`; `;
}, },
@@ -294,7 +294,8 @@ function fnGraphDataLoad(reload: boolean = false) {
Reflect.set(node, 'neState', { online: false }); Reflect.set(node, 'neState', { online: false });
// 图片路径处理 // 图片路径处理
if (node.img) node.img = parseBasePath(node.img); if (node.img) node.img = parseBasePath(node.img);
if (node.icon.show && node.icon?.img) node.icon.img = parseBasePath(node.icon.img); if (node.icon.show && node.icon?.img)
node.icon.img = parseBasePath(node.icon.img);
// 遍历是否有网元数据 // 遍历是否有网元数据
const nodeID: string = node.id; const nodeID: string = node.id;
const hasNe = res.neList.some(ne => { const hasNe = res.neList.some(ne => {
@@ -352,11 +353,11 @@ function fnGraphDataLoad(reload: boolean = false) {
} }
clearInterval(interval10s.value); clearInterval(interval10s.value);
interval10s.value = null; interval10s.value = null;
fnGetState().finally(() => { fnGetState();
interval10s.value = setInterval(() => { interval10s.value = setInterval(async () => {
fnGetState(); // 获取网元状态 if (!interval10s.value) return;
}, 10_000); fnGetState(); // 获取网元状态
}); }, 20_000);
}); });
} }
@@ -364,7 +365,7 @@ function fnGraphDataLoad(reload: boolean = false) {
const interval10s = ref<any>(null); const interval10s = ref<any>(null);
/**查询网元状态 */ /**查询网元状态 */
async function fnGetState() { function fnGetState() {
// 获取节点状态 // 获取节点状态
for (const node of graphState.data.nodes) { for (const node of graphState.data.nodes) {
if (notNeNodes.includes(node.id)) continue; if (notNeNodes.includes(node.id)) continue;