From de8c5e20f4eaaebb22bed1c1a9863864ca13483f Mon Sep 17 00:00:00 2001 From: gyq <875626088@qq.com> Date: Sun, 7 Jul 2024 09:11:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist-electron/main.js | 172 +++++++++++++++++++++++++++++++++++++++++- package.json | 2 +- src/App.vue | 12 +-- src/store/print.js | 1 + 4 files changed, 179 insertions(+), 8 deletions(-) diff --git a/dist-electron/main.js b/dist-electron/main.js index d617e47..feb8162 100644 --- a/dist-electron/main.js +++ b/dist-electron/main.js @@ -1 +1,171 @@ -"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 path = require("path"); +const electron = require("electron"); +let win; +electron.app.whenReady().then(() => { + win = new electron.BrowserWindow({ + title: "银收客", + width: 1024, + height: 768, + fullscreenable: true, + fullscreen: process.env.VITE_DEV_SERVER_URL ? false : true, + simpleFullscreen: true, + frame: process.env.VITE_DEV_SERVER_URL ? true : false, + webPreferences: { + // 集成网页和 Node.js,也就是在渲染进程中,可以调用 Node.js 方法 + nodeIntegration: true, + contextIsolation: false + } + }); + if (process.env.VITE_DEV_SERVER_URL) { + win.loadURL(process.env.VITE_DEV_SERVER_URL); + } else { + win.loadFile(path.resolve(__dirname, "../dist/index.html")); + } + electron.app.on("activate", () => { + if (electron.BrowserWindow.getAllWindows().length === 0) { + createWindow(); + } + }); + electron.ipcMain.on("quitHandler", (_, msg) => { + electron.app.quit(); + }); + electron.ipcMain.on("getPrintList", () => { + win.webContents.getPrintersAsync().then((res) => { + win.webContents.send("printList", res); + }); + }); + const printWin = new electron.BrowserWindow({ + show: false, + width: 464, + height: 1726, + webPreferences: { + // 集成网页和 Node.js,也就是在渲染进程中,可以调用 Node.js 方法 + nodeIntegration: true, + contextIsolation: false + } + }); + if (process.env.VITE_DEV_SERVER_URL) { + printWin.loadFile(path.join(__dirname, "../public/print.html")); + } else { + printWin.loadFile(path.resolve(__dirname, "../dist/print.html")); + } + electron.ipcMain.on("printerInfoSync", (event, arg) => { + printWin.webContents.send("getParams", arg); + }); + electron.ipcMain.on("printStart", (event, arg) => { + console.log(arg); + const _parmas = JSON.parse(arg); + let name = _parmas.deviceName; + printWin.webContents.print({ + silent: true, + deviceName: name, + pageSize: { + width: 58e3, + height: 216e3 + }, + scaleFactor: 80, + landscape: false, + margins: { + marginType: "none", + top: 0, + bottom: 0, + left: 0, + right: 0 + }, + dpi: { + horizontal: 203, + vertical: 203 + } + }); + }); + const workPrintWin = new electron.BrowserWindow({ + show: false, + width: 464, + height: 1726, + webPreferences: { + nodeIntegration: true, + contextIsolation: false + } + }); + if (process.env.VITE_DEV_SERVER_URL) { + workPrintWin.loadFile(path.join(__dirname, "../public/work_print.html")); + } else { + workPrintWin.loadFile(path.resolve(__dirname, "../dist/work_print.html")); + } + electron.ipcMain.on("printerWorkSync", (event, arg) => { + workPrintWin.webContents.send("getParams", arg); + }); + electron.ipcMain.on("printWorkStart", (event, arg) => { + const _parmas = JSON.parse(arg); + let name = _parmas.deviceName; + workPrintWin.webContents.print({ + silent: true, + deviceName: name, + pageSize: { + width: 58e3, + height: 216e3 + }, + scaleFactor: 80, + landscape: false, + margins: { + marginType: "none", + top: 0, + bottom: 0, + left: 0, + right: 0 + }, + dpi: { + horizontal: 203, + vertical: 203 + } + }); + }); + const tagPrintWin = new electron.BrowserWindow({ + show: false, + width: 320, + height: 240, + webPreferences: { + nodeIntegration: true, + contextIsolation: false + } + }); + if (process.env.VITE_DEV_SERVER_URL) { + tagPrintWin.loadFile(path.join(__dirname, "../public/tag_print.html")); + } else { + tagPrintWin.loadFile(path.resolve(__dirname, "../dist/tag_print.html")); + } + electron.ipcMain.on("printerTagSync", (event, arg) => { + console.log(arg); + tagPrintWin.webContents.send("getParams", arg); + }); + electron.ipcMain.on("printTagStart", (event, arg) => { + const _parmas = JSON.parse(arg); + let name = _parmas.deviceName; + tagPrintWin.webContents.print({ + silent: true, + deviceName: name, + pageSize: { + width: 4e4, + height: 3e4 + }, + scaleFactor: 80, + landscape: false, + margins: { + marginType: "none", + top: 0, + bottom: 0, + left: 0, + right: 0 + }, + dpi: { + horizontal: 203, + vertical: 203 + } + }); + }); +}); +electron.app.on("window-all-closed", () => { + if (process.platform !== "darwin") + electron.app.quit(); +}); diff --git a/package.json b/package.json index 4ba82c4..8234843 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vite-electron", "private": true, - "version": "1.3.39", + "version": "1.3.41", "main": "dist-electron/main.js", "scripts": { "dev": "chcp 65001 && vite", diff --git a/src/App.vue b/src/App.vue index a55428d..e063a07 100644 --- a/src/App.vue +++ b/src/App.vue @@ -284,7 +284,7 @@ function reConnect(wsUrl) { // reConnectCount.value++ // initWebSocket(wsUrl) ws.value.reconnect(); - }, 1000) + }, 2000) } @@ -412,11 +412,11 @@ onMounted(() => { getBarCode(e) }) // 监听网络在线状态 - window.addEventListener("onLine", updateInfo) - // 监听网络离线 - window.addEventListener("offLine", updateInfo) - // 监听网络信息变化 - navigator.connection.addEventListener('change', updateInfo) + // window.addEventListener("onLine", updateInfo) + // // 监听网络离线 + // window.addEventListener("offLine", updateInfo) + // // 监听网络信息变化 + // navigator.connection.addEventListener('change', updateInfo) }) diff --git a/src/store/print.js b/src/store/print.js index 61ba279..15bef7b 100644 --- a/src/store/print.js +++ b/src/store/print.js @@ -84,6 +84,7 @@ export const usePrint = defineStore({ skuName: item.skuName, masterId: props.orderInfo.tableName, deviceName: this.deviceLableList[0].config.deviceName, + // deviceName: "Xprinter XP-T202UA", createdAt: dayjs(props.createdAt).format("YYYY-MM-DD HH:mm:ss"), isPrint: false, count: `${count}/${sum}`,