From 1439f12ee5bb4b0de0784619326c8adf8b55a9df Mon Sep 17 00:00:00 2001 From: gyq <875626088@qq.com> Date: Fri, 14 Jun 2024 11:41:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=B0=E5=A2=9E=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E6=89=93=E5=8D=B0=E4=BA=A4=E7=8F=AD=E5=B0=8F=E7=A5=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist-electron/main.js | 130 ++++++++++++++++++++++++++++- electron/main.js | 102 ++++++++++++----------- package.json | 143 ++++++++++++++++---------------- public/work_print.css | 4 + public/work_print.html | 165 +++++++++++++++++-------------------- public/work_print.scss | 3 + src/api/work/index.js | 61 ++++++++------ src/views/member/index.vue | 2 +- src/views/work/index.vue | 127 ++++++++++++++++++++++------ 9 files changed, 473 insertions(+), 264 deletions(-) diff --git a/dist-electron/main.js b/dist-electron/main.js index a9d897e..6a09f94 100644 --- a/dist-electron/main.js +++ b/dist-electron/main.js @@ -1 +1,129 @@ -"use strict";const s=require("path"),e=require("electron");let t;e.app.whenReady().then(()=>{t=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?t.loadURL(process.env.VITE_DEV_SERVER_URL):t.loadFile(s.resolve(__dirname,"../dist/index.html")),e.app.on("activate",()=>{e.BrowserWindow.getAllWindows().length===0&&createWindow()}),e.ipcMain.on("quitHandler",(r,n)=>{e.app.quit()}),e.ipcMain.on("getPrintList",()=>{t.webContents.getPrintersAsync().then(r=>{t.webContents.send("printList",r)})});const i=new e.BrowserWindow({show:!1,width:464,height:1726,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?i.loadFile(s.join(__dirname,"../public/print.html")):i.loadFile(s.resolve(__dirname,"../dist/print.html")),e.ipcMain.on("printerInfoSync",(r,n)=>{i.webContents.send("getParams",n)}),e.ipcMain.on("printStart",(r,n)=>{console.log(n);let o=JSON.parse(n).deviceName;i.webContents.print({silent:!0,deviceName:o,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}})})});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) => { + console.log(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 + } + }); + }); +}); +electron.app.on("window-all-closed", () => { + if (process.platform !== "darwin") + electron.app.quit(); +}); diff --git a/electron/main.js b/electron/main.js index 72c2115..0682313 100644 --- a/electron/main.js +++ b/electron/main.js @@ -1,5 +1,11 @@ import path from "path"; import { app, BrowserWindow, ipcMain } from "electron"; +// import SerialPort from "serialport"; + +// SerialPort.list().then( +// (ports) => ports.forEach(console.log), +// (err) => console.error(err) +// ); let win; app.whenReady().then(() => { @@ -100,58 +106,56 @@ app.whenReady().then(() => { }); // 交班小票的窗口 - // const workPrintWin = new BrowserWindow({ - // show: true, - // width: 464, - // height: 1726, - // webPreferences: { - // nodeIntegration: true, - // contextIsolation: false, - // }, - // }); + const workPrintWin = new BrowserWindow({ + show: false, + width: 464, + height: 1726, + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + }, + }); - // if (process.env.VITE_DEV_SERVER_URL) { - // // 加载打印的html文件 - // workPrintWin.loadFile(path.join(__dirname, "../public/work_print.html")); - // } else { - // workPrintWin.loadFile(path.resolve(__dirname, "../dist/work_print.html")); // 打包后使用文件路径访问应用 - // } - - // // 接收渲染进程发送的数据 - // ipcMain.on("printerWorkSync", (event, arg) => { - // workPrintWin.webContents.send("getParams", arg); - // }); - - // // 执行交班小票的打印操作 - // ipcMain.on("printWorkStart", (event, arg) => { - // console.log(arg); - // const _parmas = JSON.parse(arg); - // // console.log(_parmas) - // let name = _parmas.deviceName; - // printWin.webContents.print({ - // silent: true, - // deviceName: name, - // pageSize: { - // width: 58000, - // height: 216000, - // }, - // scaleFactor: 80, - // landscape: false, - // margins: { - // marginType: "none", - // top: 0, - // bottom: 0, - // left: 0, - // right: 0, - // }, - // dpi: { - // horizontal: 203, - // vertical: 203, - // }, - // }); - // }); + if (process.env.VITE_DEV_SERVER_URL) { + // 加载打印的html文件 + workPrintWin.loadFile(path.join(__dirname, "../public/work_print.html")); + } else { + workPrintWin.loadFile(path.resolve(__dirname, "../dist/work_print.html")); // 打包后使用文件路径访问应用 + } + // 接收渲染进程发送的数据 + ipcMain.on("printerWorkSync", (event, arg) => { + workPrintWin.webContents.send("getParams", arg); + }); + // 执行交班小票的打印操作 + ipcMain.on("printWorkStart", (event, arg) => { + console.log(arg); + const _parmas = JSON.parse(arg); + // console.log(_parmas) + let name = _parmas.deviceName; + workPrintWin.webContents.print({ + silent: true, + deviceName: name, + pageSize: { + width: 58000, + height: 216000, + }, + scaleFactor: 80, + landscape: false, + margins: { + marginType: "none", + top: 0, + bottom: 0, + left: 0, + right: 0, + }, + dpi: { + horizontal: 203, + vertical: 203, + }, + }); + }); }); app.on("window-all-closed", () => { diff --git a/package.json b/package.json index 81997ea..9c0b110 100644 --- a/package.json +++ b/package.json @@ -1,72 +1,73 @@ { - "name": "vite-electron", - "private": true, - "version": "1.2.16", - "main": "dist-electron/main.js", - "scripts": { - "dev": "chcp 65001 && vite", - "build": "node ./addVersion.js && vite build && electron-builder", - "preview": "vite preview", - "build:win": "node ./addVersion.js && vite build && electron-builder --w" - }, - "dependencies": { - "@element-plus/icons-vue": "^2.3.1", - "axios": "^1.6.2", - "dayjs": "^1.11.10", - "electron-pos-printer": "^1.3.6", - "electron-pos-printer-vue": "^1.0.9", - "element-plus": "^2.4.3", - "lodash": "^4.17.21", - "pinia": "^2.1.7", - "swiper": "^11.1.1", - "vue": "^3.3.8", - "vue-router": "^4.2.5" - }, - "devDependencies": { - "@vitejs/plugin-vue": "^4.5.0", - "electron": "^28.2.3", - "electron-builder": "^24.13.3", - "electron-rebuild": "^3.2.9", - "path": "^0.12.7", - "sass": "^1.69.5", - "sass-loader": "^13.3.2", - "tree-kill": "^1.2.2", - "vite": "^5.0.0", - "vite-plugin-electron": "^0.15.4", - "vite-plugin-electron-renderer": "^0.14.5" - }, - "build": { - "appId": "com.cashierdesktop.app", - "productName": "银收客", - "asar": true, - "files": [ - "./dist/**/*", - "./dist-electron/**/*" - ], - "directories": { - "buildResources": "build", - "output": "release" - }, - "win": { - "icon": "./public/logo.ico", - "target": [ - { - "target": "nsis", - "arch": [ - "ia32" - ] - } - ] - }, - "nsis": { - "oneClick": false, - "allowElevation": true, - "allowToChangeInstallationDirectory": true, - "installerIcon": "./public/logo.ico", - "uninstallerIcon": "./public/logo.ico", - "installerHeaderIcon": "./public/logo.ico", - "createDesktopShortcut": true, - "createStartMenuShortcut": true - } - } -} \ No newline at end of file + "name": "vite-electron", + "private": true, + "version": "1.2.16", + "main": "dist-electron/main.js", + "scripts": { + "dev": "chcp 65001 && vite", + "build": "node ./addVersion.js && vite build && electron-builder", + "preview": "vite preview", + "build:win": "node ./addVersion.js && vite build && electron-builder --w" + }, + "dependencies": { + "@element-plus/icons-vue": "^2.3.1", + "axios": "^1.6.2", + "dayjs": "^1.11.10", + "electron-pos-printer": "^1.3.6", + "electron-pos-printer-vue": "^1.0.9", + "element-plus": "^2.4.3", + "lodash": "^4.17.21", + "pinia": "^2.1.7", + "serialport": "^12.0.0", + "swiper": "^11.1.1", + "vue": "^3.3.8", + "vue-router": "^4.2.5" + }, + "devDependencies": { + "@vitejs/plugin-vue": "^4.5.0", + "electron": "^28.2.3", + "electron-builder": "^24.13.3", + "electron-rebuild": "^3.2.9", + "path": "^0.12.7", + "sass": "^1.69.5", + "sass-loader": "^13.3.2", + "tree-kill": "^1.2.2", + "vite": "^5.0.0", + "vite-plugin-electron": "^0.15.4", + "vite-plugin-electron-renderer": "^0.14.5" + }, + "build": { + "appId": "com.cashierdesktop.app", + "productName": "银收客", + "asar": true, + "files": [ + "./dist/**/*", + "./dist-electron/**/*" + ], + "directories": { + "buildResources": "build", + "output": "release" + }, + "win": { + "icon": "./public/logo.ico", + "target": [ + { + "target": "nsis", + "arch": [ + "ia32" + ] + } + ] + }, + "nsis": { + "oneClick": false, + "allowElevation": true, + "allowToChangeInstallationDirectory": true, + "installerIcon": "./public/logo.ico", + "uninstallerIcon": "./public/logo.ico", + "installerHeaderIcon": "./public/logo.ico", + "createDesktopShortcut": true, + "createStartMenuShortcut": true + } + } +} diff --git a/public/work_print.css b/public/work_print.css index 5eabcd6..a22964e 100644 --- a/public/work_print.css +++ b/public/work_print.css @@ -9,6 +9,10 @@ body { padding: 0 8mm; } +.empty { + height: 20px; +} + .print_view { padding: 20px 0; } diff --git a/public/work_print.html b/public/work_print.html index 06644b7..51accd9 100644 --- a/public/work_print.html +++ b/public/work_print.html @@ -1,97 +1,80 @@ - - - - - Print preview - - - - -
-