链路状态

This commit is contained in:
郁万成 2024-12-12 11:15:40 +08:00
parent 0d233b2c69
commit 61397c739b
2 changed files with 44 additions and 20 deletions

View File

@ -46,12 +46,7 @@
<el-table-column prop="status" :label="LinkMonitorFieldsEnums['status']" align="center" width="80"> <el-table-column prop="status" :label="LinkMonitorFieldsEnums['status']" align="center" width="80">
<template #default="scope"> <template #default="scope">
<div class="status-container"> <div class="status-container">
<span <span :class="scope.row.status == 0 ? 'status-dot-online' : 'status-dot-offline'"></span>
:class="{
'status-dot-online': !scope.row.status,
'status-dot-offline': scope.row.status,
}"
></span>
</div> </div>
</template> </template>
</el-table-column> </el-table-column>
@ -102,13 +97,13 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { reactive, ref, nextTick } from 'vue' import { reactive, ref, nextTick, onUnmounted } from 'vue'
import { ElContainer, ElAside, ElHeader, ElMain, ElTree, ElInput, ElMessage, ElButton, ElTable, TreeInstance } from 'element-plus' import { ElContainer, ElAside, ElHeader, ElMain, ElTree, ElInput, ElMessage, ElButton, ElTable, TreeInstance } from 'element-plus'
import { Search } from '@element-plus/icons-vue' import { Search } from '@element-plus/icons-vue'
import { LinkMonitorFieldsEnums, LinkMonitorTreeType, LinkMonitorTableType } from './type' import { LinkMonitorFieldsEnums, LinkMonitorTreeType, LinkMonitorTableType } from './type'
import { getNodeListReq, getLinkListReq } from '/@/api/backend/linkMonitor/request' import { getNodeListReq, getLinkListReq } from '/@/api/backend/linkMonitor/request'
import { debounce, cloneDeep } from 'lodash' import { debounce, cloneDeep } from 'lodash'
import { protocolList } from '/@/views/backend/node/utils'
const LinkTreePropReplace = { const LinkTreePropReplace = {
label: 'nodeName', label: 'nodeName',
children: 'children', children: 'children',
@ -184,7 +179,8 @@ const getlinkTreeList = () => {
getlinkTreeList().then((res) => { getlinkTreeList().then((res) => {
curContextMenuTreeData.value = cloneDeep(res as LinkMonitorTreeType) curContextMenuTreeData.value = cloneDeep(res as LinkMonitorTreeType)
linkTreeRef.value?.setCurrentKey(curContextMenuTreeData.value!.id!) linkTreeRef.value?.setCurrentKey(curContextMenuTreeData.value!.id!)
getlinkMonitorList(curContextMenuTreeData.value!.id!, linkMonitorInputValue.value) createTimer()
// getlinkMonitorList(curContextMenuTreeData.value!.id!, linkMonitorInputValue.value)
}) })
const searchLinkTree = () => { const searchLinkTree = () => {
@ -249,7 +245,8 @@ const linkTreeNodeCollapse = (node: any) => {
} }
const linkTreeNodeClick = (target: LinkMonitorTreeType) => { const linkTreeNodeClick = (target: LinkMonitorTreeType) => {
curContextMenuTreeData.value = cloneDeep(target) curContextMenuTreeData.value = cloneDeep(target)
getlinkMonitorList(curContextMenuTreeData.value!.id!, linkMonitorInputValue.value) createTimer()
// getlinkMonitorList(curContextMenuTreeData.value!.id!, linkMonitorInputValue.value)
} }
const renderContent = (h: any, { node, data }: any) => { const renderContent = (h: any, { node, data }: any) => {
const label = node.label || '' const label = node.label || ''
@ -266,10 +263,12 @@ const renderContent = (h: any, { node, data }: any) => {
const linkMonitorInputValue = ref('') const linkMonitorInputValue = ref('')
const searchLinkMonitor = () => { const searchLinkMonitor = () => {
if (linkMonitorInputValue.value === '') { if (linkMonitorInputValue.value === '') {
getlinkMonitorList(curContextMenuTreeData.value!.id!) // getlinkMonitorList(curContextMenuTreeData.value!.id!)
createTimer()
return return
} }
getlinkMonitorList(curContextMenuTreeData.value!.id!, linkMonitorInputValue.value) createTimer()
// getlinkMonitorList(curContextMenuTreeData.value!.id!, linkMonitorInputValue.value)
} }
const linkMonitorTableData = ref<LinkMonitorTableType[]>([]) const linkMonitorTableData = ref<LinkMonitorTableType[]>([])
@ -282,17 +281,23 @@ const paginationOptions = reactive({
pageSizes: [20, 50, 100], pageSizes: [20, 50, 100],
}) })
const getcurrentPage = () => { const getcurrentPage = () => {
getlinkMonitorList(curContextMenuTreeData.value!.id!, linkMonitorInputValue.value) // getlinkMonitorList(curContextMenuTreeData.value!.id!, linkMonitorInputValue.value)
createTimer()
} }
const protocolList = [
{ label: 'IEC104主 *', value: 8 }, // const protocolList = [
{ label: 'IEC104从 *', value: 9 }, // // *
{ label: 'MODBUSRTU主 *', value: 12 }, // { label: 'IEC104 *', value: 9 },
{ label: 'MODBUSTCP主 *', value: 16 }, // { label: 'MODBUSTCP *', value: 17 },
] // { label: 'MODBUS', value: 80 },
// { label: 'ADS', value: 81 },
// ]
const getlinkMonitorList = (nodeId: string, linkName?: string) => { const getlinkMonitorList = (nodeId: string, linkName?: string) => {
getLinkListReq({ nodeId, linkName, pageNum: paginationOptions.current, pageSize: paginationOptions.pageSize }) getLinkListReq({ nodeId, linkName, pageNum: paginationOptions.current, pageSize: paginationOptions.pageSize, withStatus: 1 })
.then((res) => { .then((res) => {
if (!res.rows.length) {
clearTimer()
}
if (res.rows) { if (res.rows) {
linkMonitorTableData.value = res.rows.map((item) => { linkMonitorTableData.value = res.rows.map((item) => {
return { return {
@ -303,10 +308,12 @@ const getlinkMonitorList = (nodeId: string, linkName?: string) => {
paginationOptions.total = res.total paginationOptions.total = res.total
} else { } else {
ElMessage.error(res.msg ?? '查询失败') ElMessage.error(res.msg ?? '查询失败')
clearTimer()
} }
}) })
.catch((err) => { .catch((err) => {
ElMessage.error(err?.response?.data?.msg ?? '查询失败') ElMessage.error(err?.response?.data?.msg ?? '查询失败')
clearTimer()
}) })
} }
@ -323,6 +330,22 @@ const startLink = (val: LinkMonitorTableType) => {
const stopLink = (val: LinkMonitorTableType) => { const stopLink = (val: LinkMonitorTableType) => {
console.log('stopLink') console.log('stopLink')
} }
let timer: any = null
const createTimer = () => {
getlinkMonitorList(curContextMenuTreeData.value!.id!, linkMonitorInputValue.value)
timer && clearInterval(timer)
timer = null
timer = setInterval(() => {
getlinkMonitorList(curContextMenuTreeData.value!.id!, linkMonitorInputValue.value)
}, 5000)
}
const clearTimer = () => {
timer && clearInterval(timer)
timer = null
}
onUnmounted(() => {
clearTimer()
})
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -35,6 +35,7 @@ export type GetLinkMonitorTableParam = {
linkName?: string linkName?: string
pageNum: number pageNum: number
pageSize: number pageSize: number
withStatus?: number
} }
export enum LinkMonitorFieldsEnums { export enum LinkMonitorFieldsEnums {