Commit 294fc864 by wusiyi

fix: 尝试修复打印机任务并发导致打印内容错乱问题 #1001679

parent 95e79b9a
......@@ -2864,12 +2864,19 @@ const handleSeedingWall = (type: 'print' | 'sort') => {
podOrderVisible.value = true
}
const printOrder = async (
/** LODOP 单例不可并发,打印串行 */
let printOrderChain: Promise<void> = Promise.resolve()
const printOrder = (
data: OrderData,
callback: (status: boolean) => void,
) => {
const run = async () => {
const lodop = getCLodop(null, null)
if (!lodop) return
if (!lodop) {
callback && callback(false)
return
}
lodop.PRINT_INIT('打印内容')
const printerIndex = lodop.SET_PRINTER_INDEX(sheetPrinter.value)
console.log(
......@@ -2924,11 +2931,9 @@ const printOrder = async (
console.log('PRINT_STATUS_OK:', jobCode, `ok: ${ok}`)
if (ok == 1) {
console.log('打印成功')
// 打印状态:成功
callback && callback(true)
return
}
// 如果打印状态表示未成功或者返回了空,继续获取任务是否存在
const exist = await lodopCall((lodop) =>
lodop.GET_VALUE('PRINT_STATUS_EXIST', jobCode),
)
......@@ -2942,7 +2947,6 @@ const printOrder = async (
)
if (exist == 0) {
console.log('任务不存在了', `exist:${exist}`)
// 任务不存在了
callback && callback(true)
return
}
......@@ -2959,6 +2963,9 @@ const printOrder = async (
lodop.PRINT()
callback && callback(false)
}
}
printOrderChain = printOrderChain.then(run, run)
}
let _lodop: LODOPObject | null = null
let _lodopCallback: { [key: string]: (value: string) => void } = {}
......
......@@ -1442,15 +1442,24 @@ const handlePrinterChange = (value: string) => {
emit('set-printer', value)
}
/** 已自动打印过的订单,避免 WS 回写清掉 printResult 后重复打印 */
const autoPrintedIds = new Set<number>()
const print = (data: OrderData, forcePrint = false, callback?: () => void) => {
const _boxIndex = boxIndex.value
const orderId = data.id
if (!forcePrint && data.printResult) {
if (
!forcePrint &&
(data.printResult || (orderId != null && autoPrintedIds.has(orderId)))
) {
callback && callback()
return
}
if (!forcePrint && orderId != null) autoPrintedIds.add(orderId)
props.printOrder(data, (status: boolean) => {
if (!status && orderId != null) autoPrintedIds.delete(orderId)
callback && callback()
const item = podBoxList.value?.find((item) => item.box === _boxIndex)
if (item && item.data) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment