From 44495c3ee76bd14c0bf904ac57721b0cad81aebb Mon Sep 17 00:00:00 2001 From: gyq <875626088@qq.com> Date: Sat, 22 Jun 2024 09:15:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=93=E5=8D=B0=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist-electron/main.js | 2 +- electron/main.js | 2 +- package.json | 2 +- public/tag_print.html | 2 +- src/App.vue | 54 +++++++----- src/components/callNumber.vue | 6 +- src/components/payCard/scanModal.vue | 3 +- src/views/home/components/settleAccount.vue | 93 +++++++++++++++++---- src/views/order/index.vue | 34 ++++---- 9 files changed, 136 insertions(+), 62 deletions(-) diff --git a/dist-electron/main.js b/dist-electron/main.js index d617e47..6692179 100644 --- a/dist-electron/main.js +++ b/dist-electron/main.js @@ -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:!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()}); +"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()}); diff --git a/electron/main.js b/electron/main.js index 0816753..5a16fc4 100644 --- a/electron/main.js +++ b/electron/main.js @@ -164,7 +164,7 @@ app.whenReady().then(() => { // 标签小票的窗口 const tagPrintWin = new BrowserWindow({ - show: false, + show: true, width: 320, height: 240, webPreferences: { diff --git a/package.json b/package.json index fe9256a..9aee605 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vite-electron", "private": true, - "version": "1.3.5", + "version": "1.3.6", "main": "dist-electron/main.js", "scripts": { "dev": "chcp 65001 && vite", diff --git a/public/tag_print.html b/public/tag_print.html index e052922..e361471 100644 --- a/public/tag_print.html +++ b/public/tag_print.html @@ -48,7 +48,7 @@ data.value = JSON.parse(arg); console.log(data.value); - let size = 40; + let size = 46; let qrcode = new QRCode(document.getElementById("ewm"), { text: data.value.outNumber, width: size, diff --git a/src/App.vue b/src/App.vue index a48ef8b..7bdf613 100644 --- a/src/App.vue +++ b/src/App.vue @@ -32,8 +32,15 @@ import { bySubType } from "@/api/device"; import { dayjs, ElMessage } from "element-plus"; import { ipcRenderer } from 'electron' -if (!useStorage.get('uuid')) { - useStorage.set('uuid', uuidv4()) +const uuid = ref('') + +function createUUID() { + if (!useStorage.get('uuid')) { + useStorage.set('uuid', uuidv4()) + uuid.value = useStorage.get('uuid') + } else { + uuid.value = useStorage.get('uuid') + } } const store = useUser(); @@ -57,12 +64,14 @@ watch(route, (to) => { if (ws.value != null) { console.log('关闭ws'); ws.value.close() + ws.value = null wsIsClose.value = true } } else { // 打开ws - console.log('打开ws'); openWs() + // setTimeout(() => { + // }, 1000) } }); @@ -168,9 +177,20 @@ function checkLabelPrint(props) { } else { let pids = printLabelList.value[0].config.categoryList.map(item => item.id) let labelList = [] + + let count = 0 + let sum = 0 + + props.carts.map(item => { + for (let i = 0; i < item.number; i++) { + sum++ + } + }) + props.carts.map(item => { if (pids.some(el => el == item.categoryId)) { for (let i = 0; i < item.number; i++) { + count++ labelList.push( { outNumber: props.outNumber, @@ -178,7 +198,8 @@ function checkLabelPrint(props) { skuName: item.skuName, masterId: props.orderInfo.tableName, deviceName: printLabelList.value[0].config.deviceName, - createdAt: dayjs(props.createdAt).format('YYYY-MM-DD HH:mm:ss') + createdAt: dayjs(props.createdAt).format('YYYY-MM-DD HH:mm:ss'), + count: `${count}/${sum}` } ) } @@ -190,24 +211,13 @@ function checkLabelPrint(props) { } // 打印标签 -let labelCount = ref(0) -let labelPrintTimer = ref(null) function printLabel(list) { - console.log(list); if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) { ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接"); } else { - labelPrintTimer.value = setInterval(() => { - // console.log('labelCount', labelCount.value); - list[labelCount.value].count = `${list.length - labelCount.value}/${list.length}` - ipcRenderer.send('printerTagSync', JSON.stringify(list[labelCount.value])) - labelCount.value++ - if (labelCount.value > list.length - 1) { - clearInterval(labelPrintTimer.value) - labelPrintTimer.value = null - labelCount.value = 0 - } - }, 1000) + list.map(item => { + ipcRenderer.send('printerTagSync', JSON.stringify(item)) + }) } } @@ -215,9 +225,11 @@ let ws = ref(null) let wsIsClose = ref(false) // 初始化websocket function initWebSocket(wsUrl = import.meta.env.VITE_API_WSS) { + createUUID() + wsIsClose.value = false ws.value = new WebSocket(wsUrl); - console.log("websocket:", ws.value); + // console.log("websocket:", ws.value); ws.value.onopen = function () { console.log('wss连接成功'); @@ -234,7 +246,7 @@ function initWebSocket(wsUrl = import.meta.env.VITE_API_WSS) { ws.value.send(JSON.stringify({ type: "connect", shopId: store.userInfo.shopId, - clientId: useStorage.get('uuid') + clientId: uuid.value })) }; @@ -308,7 +320,7 @@ function reConnect(wsUrl) { } onMounted(() => { - getPrintList(); + getPrintList() }) diff --git a/src/components/callNumber.vue b/src/components/callNumber.vue index 1fdcbee..49bcccf 100644 --- a/src/components/callNumber.vue +++ b/src/components/callNumber.vue @@ -2,7 +2,7 @@