|
|
@@ -532,22 +532,27 @@ const channelMonitorCards = computed(() => {
|
|
|
const cards = []
|
|
|
const cardsByChannel = new Map()
|
|
|
const usedCameraCodes = new Set()
|
|
|
+ // 每通道的道闸设备优先取 MQTT 道闸(独立道闸控制器),读卡器继电器设备次之
|
|
|
+ const gatePreference = device => (device.connect_type === 'mqtt' ? 0 : 1) + (device.connected ? 0 : 2)
|
|
|
+ const devicesByChannel = new Map()
|
|
|
gateDevices.value.forEach(device => {
|
|
|
const channelKey = String(device.channel_id || device.channel_code || device.device_code)
|
|
|
- const camera = cameras.value.find(item => String(item.channel_id) === String(device.channel_id)) || null
|
|
|
+ const list = devicesByChannel.get(channelKey) || []
|
|
|
+ list.push(device)
|
|
|
+ devicesByChannel.set(channelKey, list)
|
|
|
+ })
|
|
|
+ devicesByChannel.forEach((list, channelKey) => {
|
|
|
+ const camera = cameras.value.find(item => String(item.channel_id) === String(channelKey)) || null
|
|
|
if (camera) usedCameraCodes.add(camera.device_code)
|
|
|
- const existing = cardsByChannel.get(channelKey)
|
|
|
- if (!existing || (!existing.device?.connected && device.connected)) {
|
|
|
- const card = {
|
|
|
- key: `channel-${channelKey}`,
|
|
|
- channelName: device.channel_name || device.channel_code || `通道 ${device.channel_id || '-'}`,
|
|
|
- device,
|
|
|
- camera
|
|
|
- }
|
|
|
- cardsByChannel.set(channelKey, card)
|
|
|
- if (!existing) cards.push(card)
|
|
|
- else cards[cards.indexOf(existing)] = card
|
|
|
+ const device = [...list].sort((a, b) => gatePreference(a) - gatePreference(b))[0]
|
|
|
+ const card = {
|
|
|
+ key: `channel-${channelKey}`,
|
|
|
+ channelName: device.channel_name || device.channel_code || `通道 ${device.channel_id || '-'}`,
|
|
|
+ device,
|
|
|
+ camera
|
|
|
}
|
|
|
+ cardsByChannel.set(channelKey, card)
|
|
|
+ cards.push(card)
|
|
|
})
|
|
|
cameras.value.filter(camera => !usedCameraCodes.has(camera.device_code)).forEach(camera => {
|
|
|
cards.push({
|
|
|
@@ -794,7 +799,8 @@ function assignGateDevice(action = contextAction.value) {
|
|
|
const matches = device => device.connected && (!direction || device.direction === direction || device.direction === 'inout') &&
|
|
|
(action !== 'entry' || !entryForm.parking_lot_id || !device.parking_lot_id || device.parking_lot_id === entryForm.parking_lot_id)
|
|
|
if (current && matches(current)) return
|
|
|
- const next = gateDevices.value.find(matches)
|
|
|
+ // 通道上同时有读卡器(继电器接线开闸)与独立 MQTT 道闸时,道闸控制优先选 MQTT 设备
|
|
|
+ const next = gateDevices.value.find(d => matches(d) && d.connect_type === 'mqtt') || gateDevices.value.find(matches)
|
|
|
selectedGateDeviceCode.value = next?.device_code || ''
|
|
|
if (action === 'entry' && next?.parking_lot_id) {
|
|
|
entryForm.parking_lot_id = next.parking_lot_id
|