人员管理增加修改

This commit is contained in:
2026-06-02 09:15:38 +08:00
parent 92165c914a
commit 05a72ac7dd
6 changed files with 212 additions and 87 deletions
+44 -9
View File
@@ -38,7 +38,7 @@ const enqueueTask = (task) => {
// 规则1: 去重 - 已存在相同cmd的任务则丢弃
const isDuplicate = rs485Queue.some(t => t.cmd === task.cmd)
if (isDuplicate) {
console.warn('[RS485队列] 丢弃重复任务:', task.cmd)
// console.warn('[RS485队列] 丢弃重复任务:', task.cmd)
return false
}
@@ -54,16 +54,16 @@ const enqueueTask = (task) => {
}
}
if (lastLowIndex !== -1) {
console.warn('[RS485队列] 高优挤掉低优:', rs485Queue[lastLowIndex].cmd)
// console.warn('[RS485队列] 高优挤掉低优:', rs485Queue[lastLowIndex].cmd)
rs485Queue.splice(lastLowIndex, 1)
} else {
// 没有低优先级可挤,踢掉队首最老的
console.warn('[RS485队列] 满,踢掉队首:', rs485Queue[0].cmd)
// console.warn('[RS485队列] 满,踢掉队首:', rs485Queue[0].cmd)
rs485Queue.shift()
}
} else {
// 低优先级:直接踢掉队首最老的
console.warn('[RS485队列] 满,踢掉队首:', rs485Queue[0].cmd)
// console.warn('[RS485队列] 满,踢掉队首:', rs485Queue[0].cmd)
rs485Queue.shift()
}
}
@@ -80,10 +80,41 @@ const enqueueTask = (task) => {
rs485Queue.push(task)
}
console.log(`[RS485队列] 入队成功, 长度:${rs485Queue.length}, cmd:${task.cmd}`)
// console.log(`[RS485队列] 入队成功, 长度:${rs485Queue.length}, cmd:${task.cmd}`)
return true
}
// ========== RS485 发送超时保护 ==========
const RS485_SEND_TIMEOUT = 2000 // 发送超时2秒
/**
* 带超时的RS485发送封装
* 防止底层串口驱动卡死导致Promise永久pending,造成队列死锁
*/
const sendWithTimeout = (rs485Instance, cmd) => {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
console.warn(`[RS485] 发送超时(${RS485_SEND_TIMEOUT}ms), cmd: ${cmd}`)
reject(new Error('RS485发送超时'))
}, RS485_SEND_TIMEOUT)
const result = rs485Instance.sendDataString(cmd)
if (result && typeof result.then === 'function') {
result.then(res => {
clearTimeout(timer)
resolve(res)
}).catch(err => {
clearTimeout(timer)
reject(err)
})
} else {
clearTimeout(timer)
resolve(result)
}
})
}
// ========== RS485 发送超时保护 END ==========
const processRS485Queue = async () => {
if (isRS485Sending || rs485Queue.length === 0) {
return
@@ -95,10 +126,8 @@ const processRS485Queue = async () => {
if (!RS485) {
throw new Error('RS485 not initialized')
}
const result = RS485.sendDataString(task.cmd)
if (result && typeof result.then === 'function') {
await result
}
// 使用带超时的发送封装,防止Promise永久pending导致队列死锁
await sendWithTimeout(RS485, task.cmd)
// 发送后延迟,确保总线空闲再发下一条
await new Promise(r => setTimeout(r, RS485_SEND_DELAY))
task.resolve()
@@ -132,6 +161,7 @@ const clearRS485Queue = () => {
const task = rs485Queue.shift()
task.reject(new Error('RS485队列已清空(重连中)'))
}
isRS485Sending = false // 强制释放发送锁,防止队列死锁
}
/**
@@ -223,6 +253,11 @@ export default {
clearRS485Queue,
getRS485QueueSize,
// 重置RS485队列锁(供外部重连时调用)
resetRS485Lock() {
clearRS485Queue() // 内部已包含清队列 + 释放锁
},
// 解析门卡数据,返回卡号
parse232dData: (hexString) => {
// IC卡 20 01 00 08 04 00 00 00 0e 26 fe ab 8f 03