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

@ -1 +1 @@
"use strict";const i=require("path"),e=require("electron");let a;e.app.whenReady().then(()=>{a=new e.BrowserWindow({title:"银收客",width:1024,height:768,fullscreenable:!0,fullscreen:!process.env.VITE_DEV_SERVER_URL,simpleFullscreen:!0,frame:!!process.env.VITE_DEV_SERVER_URL,webPreferences:{nodeIntegration:!0,contextIsolation:!1}}),process.env.VITE_DEV_SERVER_URL?a.loadURL(process.env.VITE_DEV_SERVER_URL):a.loadFile(i.resolve(__dirname,"../dist/index.html")),e.app.on("activate",()=>{e.BrowserWindow.getAllWindows().length===0&&createWindow()}),e.ipcMain.on("quitHandler",(t,n)=>{e.app.quit()}),e.ipcMain.on("getPrintList",()=>{a.webContents.getPrintersAsync().then(t=>{a.webContents.send("printList",t)})});const o=new e.BrowserWindow({show:!1,width:464,height:1726,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?o.loadFile(i.join(__dirname,"../public/print.html")):o.loadFile(i.resolve(__dirname,"../dist/print.html")),e.ipcMain.on("printerInfoSync",(t,n)=>{o.webContents.send("getParams",n)}),e.ipcMain.on("printStart",(t,n)=>{console.log(n);let r=JSON.parse(n).deviceName;o.webContents.print({silent:!0,deviceName:r,pageSize:{width:58e3,height:216e3},scaleFactor:80,landscape:!1,margins:{marginType:"none",top:0,bottom:0,left:0,right:0},dpi:{horizontal:203,vertical:203}})});const s=new e.BrowserWindow({show:!1,width:464,height:1726,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?s.loadFile(i.join(__dirname,"../public/work_print.html")):s.loadFile(i.resolve(__dirname,"../dist/work_print.html")),e.ipcMain.on("printerWorkSync",(t,n)=>{s.webContents.send("getParams",n)}),e.ipcMain.on("printWorkStart",(t,n)=>{let r=JSON.parse(n).deviceName;s.webContents.print({silent:!0,deviceName:r,pageSize:{width:58e3,height:216e3},scaleFactor:80,landscape:!1,margins:{marginType:"none",top:0,bottom:0,left:0,right:0},dpi:{horizontal:203,vertical:203}})});const l=new e.BrowserWindow({show:!0,width:320,height:240,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?l.loadFile(i.join(__dirname,"../public/tag_print.html")):l.loadFile(i.resolve(__dirname,"../dist/tag_print.html")),e.ipcMain.on("printerTagSync",(t,n)=>{console.log(n),l.webContents.send("getParams",n)}),e.ipcMain.on("printTagStart",(t,n)=>{let r=JSON.parse(n).deviceName;l.webContents.print({silent:!0,deviceName:r,pageSize:{width:4e4,height:3e4},scaleFactor:80,landscape:!1,margins:{marginType:"none",top:0,bottom:0,left:0,right:0},dpi:{horizontal:203,vertical:203}})})});e.app.on("window-all-closed",()=>{process.platform!=="darwin"&&e.app.quit()});
"use strict";const i=require("path"),e=require("electron");let a;e.app.whenReady().then(()=>{a=new e.BrowserWindow({title:"银收客",width:1024,height:768,fullscreenable:!0,fullscreen:!process.env.VITE_DEV_SERVER_URL,simpleFullscreen:!0,frame:!!process.env.VITE_DEV_SERVER_URL,webPreferences:{nodeIntegration:!0,contextIsolation:!1}}),process.env.VITE_DEV_SERVER_URL?a.loadURL(process.env.VITE_DEV_SERVER_URL):a.loadFile(i.resolve(__dirname,"../dist/index.html")),e.app.on("activate",()=>{e.BrowserWindow.getAllWindows().length===0&&createWindow()}),e.ipcMain.on("quitHandler",(t,n)=>{e.app.quit()}),e.ipcMain.on("getPrintList",()=>{a.webContents.getPrintersAsync().then(t=>{a.webContents.send("printList",t)})});const o=new e.BrowserWindow({show:!1,width:464,height:1726,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?o.loadFile(i.join(__dirname,"../public/print.html")):o.loadFile(i.resolve(__dirname,"../dist/print.html")),e.ipcMain.on("printerInfoSync",(t,n)=>{o.webContents.send("getParams",n)}),e.ipcMain.on("printStart",(t,n)=>{console.log(n);let r=JSON.parse(n).deviceName;o.webContents.print({silent:!0,deviceName:r,pageSize:{width:58e3,height:216e3},scaleFactor:80,landscape:!1,margins:{marginType:"none",top:0,bottom:0,left:0,right:0},dpi:{horizontal:203,vertical:203}})});const s=new e.BrowserWindow({show:!1,width:464,height:1726,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?s.loadFile(i.join(__dirname,"../public/work_print.html")):s.loadFile(i.resolve(__dirname,"../dist/work_print.html")),e.ipcMain.on("printerWorkSync",(t,n)=>{s.webContents.send("getParams",n)}),e.ipcMain.on("printWorkStart",(t,n)=>{let r=JSON.parse(n).deviceName;s.webContents.print({silent:!0,deviceName:r,pageSize:{width:58e3,height:216e3},scaleFactor:80,landscape:!1,margins:{marginType:"none",top:0,bottom:0,left:0,right:0},dpi:{horizontal:203,vertical:203}})});const l=new e.BrowserWindow({show:!1,width:320,height:240,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?l.loadFile(i.join(__dirname,"../public/tag_print.html")):l.loadFile(i.resolve(__dirname,"../dist/tag_print.html")),e.ipcMain.on("printerTagSync",(t,n)=>{console.log(n),l.webContents.send("getParams",n)}),e.ipcMain.on("printTagStart",(t,n)=>{let r=JSON.parse(n).deviceName;l.webContents.print({silent:!0,deviceName:r,pageSize:{width:4e4,height:3e4},scaleFactor:80,landscape:!1,margins:{marginType:"none",top:0,bottom:0,left:0,right:0},dpi:{horizontal:203,vertical:203}})})});e.app.on("window-all-closed",()=>{process.platform!=="darwin"&&e.app.quit()});

View File

@ -164,7 +164,7 @@ app.whenReady().then(() => {
// 标签小票的窗口
const tagPrintWin = new BrowserWindow({
show: true,
show: false,
width: 320,
height: 240,
webPreferences: {

View File

@ -1,7 +1,7 @@
{
"name": "vite-electron",
"private": true,
"version": "1.3.6",
"version": "1.3.12",
"main": "dist-electron/main.js",
"scripts": {
"dev": "chcp 65001 && vite",

View File

@ -46,7 +46,7 @@
onMounted(() => {
ipcRenderer.on("getParams", (event, arg) => {
data.value = JSON.parse(arg);
console.log(data.value);
// console.log(data.value);
let size = 46;
let qrcode = new QRCode(document.getElementById("ewm"), {
@ -56,17 +56,17 @@
correctLevel: QRCode.CorrectLevel.H,
});
// ipcRenderer.send(
// "printTagStart",
// JSON.stringify({ deviceName: data.value.deviceName })
// );
ipcRenderer.send(
"printTagStart",
JSON.stringify({ deviceName: data.value.deviceName })
);
setTimeout(() => {
ipcRenderer.send(
"printTagStart",
JSON.stringify({ deviceName: data.value.deviceName })
);
}, 100);
// setTimeout(() => {
// ipcRenderer.send(
// "printTagStart",
// JSON.stringify({ deviceName: data.value.deviceName })
// );
// }, 100);
});
});

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>

View File

@ -2,9 +2,9 @@
<template>
<el-dialog :title="props.title" width="600" v-model="dialogVisible" @open="opne">
<!-- <el-input v-model="number" :placeholder="props.placeholder" readonly></el-input> -->
<el-input ref="inputRef" v-model="number" :placeholder="props.placeholder" :readonly="loading" clearable
@change="inputChange"></el-input>
<div class="tips">注意扫码请确保输入口获得焦点</div>
<!-- <el-input ref="inputRef" v-model="number" :placeholder="props.placeholder" :readonly="loading" clearable
@change="inputChange"></el-input> -->
<div class="tips">注意描标签二维</div>
<!-- <div class="keybord_wrap">
<div v-for="item in 9" :key="item">
<el-button plain type="info" style="width: 100%;" @click="inputHandle(item)">{{ item }}</el-button>
@ -46,9 +46,9 @@
<el-pagination v-model:current-page="tableData.page" v-model:page-size="tableData.pageSize" background
layout="total, prev, pager, next" :total="tableData.total" @current-change="handleCurrentChange" />
</div>
<div class="footer">
<!-- <div class="footer">
<el-button type="primary" style="width: 100%;" :loading="loading" @click="confirmHandle">确认</el-button>
</div>
</div> -->
</el-dialog>
</template>
@ -59,12 +59,14 @@ import { ElMessage } from 'element-plus'
import { onMounted, reactive, ref } from 'vue';
import { useUser } from "@/store/user.js";
import { scanSendMessage, getsendMessage } from '@/api/order/index'
import { useGlobal } from '@/store/global.js'
const global = useGlobal()
const store = useUser();
const props = defineProps({
title: {
type: String,
default: '叫号取餐'
default: '叫号取餐记录'
},
placeholder: {
type: String,
@ -96,13 +98,14 @@ function filterCode(t, c = '#') {
function show() {
dialogVisible.value = true
getsendMessageAjax()
setTimeout(() => {
inputRef.value.focus();
}, 500);
// setTimeout(() => {
// inputRef.value.focus();
// }, 500);
}
function opne() {
number.value = ''
global.updateData(true)
}
//
@ -177,7 +180,8 @@ const confirmHandle = _.throttle(async function () {
}, 800, { leading: true, trailing: false })
defineExpose({
show
show,
getsendMessageAjax
})
</script>

View File

@ -120,6 +120,10 @@ async function confirmOrder() {
if (payLoading.value) return
try {
if (payList.value[payActive.value].payType == "scanCode") {
if (money.value <= 0) {
ElMessage.error("请输入大于0的金额");
return;
}
scanModalRef.value.show();
} else {
if (money.value <= 0) {

View File

@ -73,9 +73,18 @@ const menus = ref([
}
])
//
function updateCallNumber() {
callNumberRef.value.getsendMessageAjax()
}
function openCall() {
callNumberRef.value.show()
}
defineExpose({
updateCallNumber
})
</script>
<style scoped lang="scss">

View File

@ -56,7 +56,9 @@ import { ref } from "vue";
import icon from "@/assets/icon_scan.png";
import { scanpay, queryOrder, quickPay, queryQuickPayStatus, accountPay, queryScanPay } from "@/api/pay";
import { useUser } from "@/store/user.js";
import { useGlobal } from '@/store/global.js'
const store = useUser();
const global = useGlobal()
import {
queryMembermember,
createMembermember,
@ -167,6 +169,8 @@ function autoCheckOrder() {
function clearAutoCheckOrder() {
clearInterval(timer.value)
timer.value = null
//
global.updateData(true)
}
//
@ -296,6 +300,8 @@ function close() {
function reset() {
loading.value = false;
scanCode.value = "";
//
global.updateData(false)
}
defineExpose({

15
src/store/global.js Normal file
View File

@ -0,0 +1,15 @@
import { defineStore } from "pinia";
export const useGlobal = defineStore({
id: "global",
state: () => ({
// 是否监听叫号
isCallNumber: true,
}),
actions: {
// 更新状态
updateData(state) {
this.isCallNumber = state;
},
},
});

View File

@ -27,9 +27,9 @@
</div>
<div class="search_wrap">
<div class="input">
<el-input placeholder="请输入商品名称查询" prefix-icon="Search" v-model="commdityName" clearable
@input="inputChange"></el-input>
<el-input placeholder="请输入商品名称查询" v-model="commdityName" clearable @input="inputChange"></el-input>
</div>
<el-button :loading="searchLoading" :icon="Search" @click="searchHandle">搜索</el-button>
<!-- <el-button :icon="shopListType == 'text' ? 'PictureRounded' : 'PriceTag'"
@click="changeShopListType"></el-button> -->
</div>
@ -41,7 +41,8 @@
<div class="item">
<div class="dot" v-if="item.orderCount">{{ item.orderCount }}</div>
<div class="cover" v-if="shopListType == 'img'">
<el-image :src="`${item.coverImg}?x-oss-process=image/resize,m_lfit,w_150,h_150`" class="el_img" fit="cover"></el-image>
<el-image :src="`${item.coverImg}?x-oss-process=image/resize,m_lfit,w_150,h_150`"
class="el_img" fit="cover"></el-image>
</div>
<div class="name"><el-text line-clamp="1">{{ item.name }}</el-text></div>
<div class="item_empty" v-if="shopListType == 'text'"></div>
@ -61,6 +62,7 @@
</template>
<script setup>
import { Search } from '@element-plus/icons-vue'
import { ref } from 'vue'
import _ from 'lodash'
import useStorage from "@/utils/useStorage";
@ -106,6 +108,13 @@ const loopTimer = ref(null)
const showPopover = ref(false)
const inputChange = _.debounce(function () {
searchHandle()
}, 500)
//
const searchLoading = ref(false)
function searchHandle() {
searchLoading.value = true
goodsList.value = []
goodsPage.value = 1
finish.value = false
@ -114,7 +123,7 @@ const inputChange = _.debounce(function () {
loopTimer.value = null
updataGoods()
}, 500)
}
//
function skuConfirm(params) {
@ -279,9 +288,11 @@ async function updataGoods() {
const res2 = await productqueryCommodityInfoAjax()
goodsList.value.push(res2)
}
searchLoading.value = false
} else {
goodsPage.value = currentGoodsIndex.value + 1
goodsList.value[currentGoodsIndex.value] = await productqueryCommodityInfoAjax()
searchLoading.value = false
}
}

View File

@ -179,8 +179,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++
}
}
})
@ -212,9 +214,11 @@ const 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)
}
}
}
@ -236,11 +240,11 @@ async function printHandle() {
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
};
checkLabelPrint(data)
if (!checkLocalPrint(printList.value[0].config.deviceName)) {
ElMessage.error("本地打印机无法使用请检查打印机是否正确连接3");
} else {
ipcRenderer.send("printerInfoSync", JSON.stringify(data));
}
// if (!checkLocalPrint(printList.value[0].config.deviceName)) {
// ElMessage.error("使3");
// } else {
// ipcRenderer.send("printerInfoSync", JSON.stringify(data));
// }
} else {
// ElMessage.error("使");
try {

View File

@ -318,8 +318,10 @@ function checkLabelPrint(props) {
let sum = 0
props.skuInfos.map(item => {
for (let i = 0; i < item.num; i++) {
sum++
if (pids.some(el => el == item.categoryId)) {
for (let i = 0; i < item.num; i++) {
sum++
}
}
})
@ -350,9 +352,11 @@ const printLabel = lodash.throttle(function (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)
}
}
}, 1500, { leading: true, trailing: false })