|
|
|
@ -205,7 +205,7 @@ import { FetchWaitBorrower } from '@/api/archivesManage/lendManage' |
|
|
|
import alarmApi from '@/api/home/alarm' |
|
|
|
// import { allDeviceData, mockIpData } from '@/views/environmentalScreen/index.js' |
|
|
|
|
|
|
|
// // 同步mock方法 |
|
|
|
// 同步mock方法 |
|
|
|
// const mockFetchDataForIP = (params) => { |
|
|
|
// return new Promise((resolve) => { |
|
|
|
// setTimeout(() => { |
|
|
|
@ -310,7 +310,8 @@ export default { |
|
|
|
ipToNameMap: {}, // IP到设备名称映射 |
|
|
|
currentDeviceName: '', // 当前显示设备名称 |
|
|
|
currentIpIndex: 0, // IP轮询索引 |
|
|
|
excludeIpList: ['192.168.99.101:6003'] // 排除IP列表 |
|
|
|
excludeIpList: ['192.168.99.101:6003'], // 排除IP列表 |
|
|
|
dataTimer: null // 数据轮询定时器 |
|
|
|
} |
|
|
|
}, |
|
|
|
computed: { |
|
|
|
@ -318,12 +319,16 @@ export default { |
|
|
|
'roles' |
|
|
|
]) |
|
|
|
}, |
|
|
|
beforeDestroy() { |
|
|
|
if (this.dataTimer) { |
|
|
|
clearInterval(this.dataTimer) |
|
|
|
this.dataTimer = null |
|
|
|
console.log('轮询定时器已清除') |
|
|
|
} |
|
|
|
}, |
|
|
|
async created() { |
|
|
|
this.getWaitBorrower() |
|
|
|
|
|
|
|
// console.log('allDeviceData:', allDeviceData) |
|
|
|
// this.allDisplayConfigData = allDeviceData |
|
|
|
// this.handleDeviceIpList() |
|
|
|
// 真实请求请替换: |
|
|
|
await alarmApi.FetchYpGetSite().then((data) => { |
|
|
|
if (data && data.length > 0) { |
|
|
|
@ -333,28 +338,37 @@ export default { |
|
|
|
} else { |
|
|
|
this.allDisplayConfigData = [] |
|
|
|
} |
|
|
|
// this.allDisplayConfigData = allDeviceData |
|
|
|
// this.handleDeviceIpList() |
|
|
|
}) |
|
|
|
|
|
|
|
// 初始加载数据 |
|
|
|
// 初始加载+创建定时器 |
|
|
|
if (this.allDeviceIds.length > 0) { |
|
|
|
this.currentDeviceName = this.ipToNameMap[this.allDeviceIds[0]] || '' |
|
|
|
await this.getRealTimeData(this.allDeviceIds[0]) |
|
|
|
console.log('初始加载IP数据:', this.allDeviceIds[0]) |
|
|
|
} else { |
|
|
|
console.warn('无有效设备IP,停止轮询') |
|
|
|
this.newAlarm = [] |
|
|
|
} |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
if (this.allDeviceIds.length > 0) { |
|
|
|
|
|
|
|
// 移到这里创建定时器 |
|
|
|
this.dataTimer = setInterval(async() => { |
|
|
|
const currentIp = this.getNextIp() |
|
|
|
this.currentDeviceName = this.ipToNameMap[currentIp] || '' |
|
|
|
await this.getRealTimeData(currentIp) |
|
|
|
}, 10000) |
|
|
|
console.log(`启动IP轮询,共${this.allDeviceIds.length}个有效IP:`, this.allDeviceIds) |
|
|
|
} else { |
|
|
|
console.warn('无有效设备IP,停止轮询') |
|
|
|
this.newAlarm = [] |
|
|
|
} |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
// if (this.allDeviceIds.length > 0) { |
|
|
|
// this.dataTimer = setInterval(async() => { |
|
|
|
// const currentIp = this.getNextIp() |
|
|
|
// this.currentDeviceName = this.ipToNameMap[currentIp] || '' |
|
|
|
// await this.getRealTimeData(currentIp) |
|
|
|
// }, 10000) |
|
|
|
// console.log(`启动IP轮询,共${this.allDeviceIds.length}个有效IP:`, this.allDeviceIds) |
|
|
|
// } |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
/** |
|
|
|
* 处理设备IP列表(去重+排除+名称映射) |
|
|
|
@ -383,6 +397,8 @@ export default { |
|
|
|
*/ |
|
|
|
getNextIp() { |
|
|
|
if (this.allDeviceIds.length === 0) return '' |
|
|
|
// 先重置索引(防止数组长度变化导致越界) |
|
|
|
this.currentIpIndex = this.currentIpIndex % this.allDeviceIds.length |
|
|
|
const ip = this.allDeviceIds[this.currentIpIndex] |
|
|
|
this.currentIpIndex = (this.currentIpIndex + 1) % this.allDeviceIds.length |
|
|
|
console.log(`轮询切换 - 当前IP:${ip},下一个索引:${this.currentIpIndex}`) |
|
|
|
|