1.手机扫码下单打印标签

2.PC桌面端下单打印标签
3.无需打开叫号窗口扫码叫号取餐
This commit is contained in:
gyq
2024-06-22 17:29:34 +08:00
parent 44495c3ee7
commit 328b512411
13 changed files with 212 additions and 50 deletions

View File

@@ -2,7 +2,7 @@
<el-config-provider size="large">
<div class="container">
<div class="left" v-if="!hideLeftMenu">
<left-menu />
<left-menu ref="leftMenuRef" />
</div>
<div :class="{ view: !hideLeftMenu }">
<!-- <div class="wrapper">
@@ -31,6 +31,12 @@ import { useUser } from "@/store/user.js";
import { bySubType } from "@/api/device";
import { dayjs, ElMessage } from "element-plus";
import { ipcRenderer } from 'electron'
import { scanSendMessage } from '@/api/order/index'
import { useGlobal } from '@/store/global.js'
const global = useGlobal()
const leftMenuRef = ref(null)
const uuid = ref('')
@@ -182,8 +188,10 @@ function checkLabelPrint(props) {
let sum = 0
props.carts.map(item => {
for (let i = 0; i < item.number; i++) {
sum++
if (pids.some(el => el == item.categoryId)) {
for (let i = 0; i < item.number; i++) {
sum++
}
}
})
@@ -215,9 +223,11 @@ function printLabel(list) {
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
} else {
list.map(item => {
ipcRenderer.send('printerTagSync', JSON.stringify(item))
})
for (let i = 0; i <= list.length - 1; i++) {
setTimeout(() => {
ipcRenderer.send('printerTagSync', JSON.stringify(list[i]))
}, i * 1000)
}
}
}
@@ -319,8 +329,103 @@ function reConnect(wsUrl) {
}, 5000)
}
const nextCodeRef = ref('')
const lastTimeRef = ref('')
const codeRef = ref('')
// 通过扫码枪获取条形码
async function getBarCode(e) {
let nextCode = ''
let nextTime = ''
const lastTime = lastTimeRef.value
let code = codeRef.value
if (window.event) {
// IE
nextCode = e.keyCode
} else if (e.which) {
// Netscape/Firefox/Opera
nextCode = e.which
}
nextTime = new Date().getTime()
// 字母上方 数字键0-9 对应键码值 48-57; 数字键盘 数字键0-9 对应键码值 96-105
if (
(nextCode >= 48 && nextCode <= 57) ||
(nextCode >= 96 && nextCode <= 105)
) {
const codes = {
'48': 48,
'49': 49,
'50': 50,
'51': 51,
'52': 52,
'53': 53,
'54': 54,
'55': 55,
'56': 56,
'57': 57,
'96': 48,
'97': 49,
'98': 50,
'99': 51,
'100': 52,
'101': 53,
'102': 54,
'103': 55,
'104': 56,
'105': 57
}
nextCode = codes[nextCode]
nextTime = new Date().getTime()
}
// 第二次输入延迟两秒,删除之前的数据重新计算
if (nextTime && lastTime && nextTime - lastTime > 2000) {
code = String.fromCharCode(nextCode)
} else {
code += String.fromCharCode(nextCode)
}
// 保存数据
nextCodeRef.value = nextCode
lastTimeRef.value = nextTime
codeRef.value = code
// 键入Enter
if (e.which === 13) {
// 判断 code 长度(这里就获取到条码值了,以下业务自由发挥)
code = code.trim()
if (code.length == 13) {
console.log('A类条码:' + code);
} else if (code.length == 23) {
console.log('B类条码:' + code);
} else if (code.length == 0) {
console.log('请输入条码');
} else {
console.log('条码不合法:' + code);
try {
if (!global.isCallNumber) return
await scanSendMessage({
outNumber: code,
shopId: store.userInfo.shopId,
// shopId: 4
})
ElMessage.success('叫号成功')
leftMenuRef.value.updateCallNumber()
} catch (error) {
console.log(error);
}
}
console.log('code', code);
// 键入回车务必清空code值
codeRef.value = ''
return false
}
}
onMounted(() => {
getPrintList()
document.addEventListener('keydown', (e) => {
getBarCode(e)
})
})
</script>