From 07d7df0416be37c74b26ca3e2a672380f1a64f30 Mon Sep 17 00:00:00 2001 From: gyq <875626088@qq.com> Date: Wed, 3 Apr 2024 15:57:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A2=9E=E5=8A=A0=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist-electron/main.js | 2 +- electron/main.js | 151 ++---- package.json | 2 +- public/print.css | 79 +++ public/print.html | 108 ++-- public/print.scss | 71 +++ src/App.vue | 11 +- src/api/device.js | 52 ++ src/assets/icon_dev1.png | Bin 0 -> 174060 bytes src/assets/icon_dev2.png | Bin 0 -> 223619 bytes src/assets/icon_dev3.png | Bin 0 -> 264038 bytes src/components/leftMenu.vue | 2 - src/components/more.vue | 17 +- src/router/index.js | 10 + src/views/device/add.vue | 364 +++++++++++++ src/views/device/icons.js | 8 + src/views/device/index.vue | 344 ++++++++++++ src/views/home/components/settleAccount.vue | 572 +++++++++++--------- src/views/home/index.vue | 309 ++++++----- 19 files changed, 1562 insertions(+), 540 deletions(-) create mode 100644 public/print.css create mode 100644 public/print.scss create mode 100644 src/api/device.js create mode 100644 src/assets/icon_dev1.png create mode 100644 src/assets/icon_dev2.png create mode 100644 src/assets/icon_dev3.png create mode 100644 src/views/device/add.vue create mode 100644 src/views/device/icons.js create mode 100644 src/views/device/index.vue diff --git a/dist-electron/main.js b/dist-electron/main.js index f5b57fa..7d21254 100644 --- a/dist-electron/main.js +++ b/dist-electron/main.js @@ -1 +1 @@ -"use strict";const p=require("path"),e=require("electron"),{PosPrinter:r}=require("electron-pos-printer-vue");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(p.resolve(__dirname,"../dist/index.html")),e.app.on("activate",()=>{e.BrowserWindow.getAllWindows().length===0&&createWindow()}),e.ipcMain.on("quitHandler",(i,n)=>{e.app.quit()}),e.ipcMain.on("printStart",(i,n)=>{console.log("开始打印",n);const s={silent:!0,preview:!1,margin:"0 0 0 0",copies:1,printerName:"Xprinter XP-365B",pageSize:{height:22860,width:30480}},o=[{type:"text",value:"#B5 B6",style:{"font-weight":"700","font-size":"18px"}},{type:"text",value:"#B5 B6",style:{"font-weight":"700","font-size":"18px"}},{type:"text",value:"#B5 B6",style:{"font-weight":"700","font-size":"18px"}},{type:"text",value:"#B5 B6",style:{"font-weight":"700","font-size":"18px"}},{type:"text",value:"#B5 B6",style:{"font-weight":"700","font-size":"18px"}},{type:"text",value:"#B5 B6",style:{"font-weight":"700","font-size":"18px"}},{type:"text",value:"#B5 B6",style:{"font-weight":"700","font-size":"18px"}},{type:"text",value:"#B5 B6",style:{"font-weight":"700","font-size":"18px"}},{type:"text",value:"#B5 B6",style:{"font-weight":"700","font-size":"18px"}},{type:"text",value:"喔喔奶茶 x100",style:{"font-size":"18px"}},{type:"text",value:"麻辣味",style:{"font-size":"18px"}},{type:"text",value:"03-08 16:32 ¥123.00",style:{"font-size":"18px"}}];r.print(o,s).then(()=>{}).catch(l=>{console.error(l)})})});e.app.on("window-all-closed",()=>{process.platform!=="darwin"&&e.app.quit()}); +"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",(i,r)=>{e.app.quit()}),e.ipcMain.on("getPrintList",()=>{t.webContents.getPrintersAsync().then(i=>{t.webContents.send("printList",i)})});const n=new e.BrowserWindow({show:!0,width:464,height:2206,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?n.loadFile(s.join(__dirname,"../public/print.html")):n.loadFile(s.resolve(__dirname,"../dist/print.html")),e.ipcMain.on("printerInfoSync",(i,r)=>{n.webContents.send("getParams",r)}),n.on("printStart",(i,r)=>{let o=JSON.parse(r).deviceName;n.webContents.print({silent:!0,deviceName:o,pageSize:{width:58e3,height:276e3},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 6861e20..5cfd09f 100644 --- a/electron/main.js +++ b/electron/main.js @@ -1,6 +1,5 @@ import path from "path"; import { app, BrowserWindow, ipcMain } from "electron"; -const { PosPrinter } = require("electron-pos-printer-vue"); let win; app.whenReady().then(() => { @@ -40,118 +39,62 @@ app.whenReady().then(() => { app.quit(); }); + // 给渲染进程返回打印机列表 + ipcMain.on('getPrintList', () => { + win.webContents.getPrintersAsync().then(res => { + win.webContents.send('printList', res) + }) + }) + // 创建打印小票子窗口 - // const printWin = new BrowserWindow({ - // show: true, - // webPreferences: { - // // 集成网页和 Node.js,也就是在渲染进程中,可以调用 Node.js 方法 - // nodeIntegration: true, - // contextIsolation: false, - // }, - // }); + const printWin = new BrowserWindow({ + show: true, + width: 464, + height: 2206, + webPreferences: { + // 集成网页和 Node.js,也就是在渲染进程中,可以调用 Node.js 方法 + nodeIntegration: true, + contextIsolation: false, + }, + }); - // if (process.env.VITE_DEV_SERVER_URL) { - // // 加载打印的html文件 - // printWin.loadFile(path.join(__dirname, "../public/print.html")); - // } else { - // printWin.loadFile(path.resolve(__dirname, "../dist/print.html")); // 打包后使用文件路径访问应用 - // } + if (process.env.VITE_DEV_SERVER_URL) { + // 加载打印的html文件 + printWin.loadFile(path.join(__dirname, "../public/print.html")); + } else { + printWin.loadFile(path.resolve(__dirname, "../dist/print.html")); // 打包后使用文件路径访问应用 + } - // win.webContents.getPrintersAsync().then(res => { - // // console.log('list', res) - // }) - - // ipcMain.on("printerInfoSync", (event, params) => { - // // console.log(JSON.parse(params)) - // printWin.webContents.send("getParams", params); - // }); + // 接收订单页面发过来的参数发送给打印页 + ipcMain.on('printerInfoSync', (event, arg) => { + printWin.webContents.send('getParams', arg) + }) // 执行打印操作 - ipcMain.on('printStart', (event, arg) => { - console.log('开始打印', arg) - - let name = 'Xprinter XP-365B' - // let name = 'Generic / Text Only' - - const options = { + printWin.on('printStart', (event, arg) => { + const _parmas = JSON.parse(arg) + let name = _parmas.deviceName + printWin.webContents.print({ silent: true, - preview: false, // width of content body - margin: '0 0 0 0', // margin of content body - copies: 1, // Number of copies to print - printerName: name, // printerName: string, check with webContent.getPrinters() - // timeOutPerLine: 400, - pageSize: { height: 22860, width: 30480 } // page size - } - - const data = [ - { - type: 'text', // 'text' | 'barCode' | 'qrCode' | 'image' | 'table - value: '#B5 B6', - style: { "font-weight": "700", "font-size": "18px" } - }, { - type: 'text', // 'text' | 'barCode' | 'qrCode' | 'image' | 'table - value: '#B5 B6', - style: { "font-weight": "700", "font-size": "18px" } - }, { - type: 'text', // 'text' | 'barCode' | 'qrCode' | 'image' | 'table - value: '#B5 B6', - style: { "font-weight": "700", "font-size": "18px" } - }, { - type: 'text', // 'text' | 'barCode' | 'qrCode' | 'image' | 'table - value: '#B5 B6', - style: { "font-weight": "700", "font-size": "18px" } - }, { - type: 'text', // 'text' | 'barCode' | 'qrCode' | 'image' | 'table - value: '#B5 B6', - style: { "font-weight": "700", "font-size": "18px" } - }, { - type: 'text', // 'text' | 'barCode' | 'qrCode' | 'image' | 'table - value: '#B5 B6', - style: { "font-weight": "700", "font-size": "18px" } - }, { - type: 'text', // 'text' | 'barCode' | 'qrCode' | 'image' | 'table - value: '#B5 B6', - style: { "font-weight": "700", "font-size": "18px" } - }, { - type: 'text', // 'text' | 'barCode' | 'qrCode' | 'image' | 'table - value: '#B5 B6', - style: { "font-weight": "700", "font-size": "18px" } - }, { - type: 'text', // 'text' | 'barCode' | 'qrCode' | 'image' | 'table - value: '#B5 B6', - style: { "font-weight": "700", "font-size": "18px" } + deviceName: name, + pageSize: { + width: 58000, + height: 276000 }, - { - type: 'text', // 'text' | 'barCode' | 'qrCode' | 'image' | 'table' - value: '喔喔奶茶 x100', - style: { "font-size": "18px" }, + scaleFactor: 80, + landscape: false, + margins: { + marginType: "none", + top: 0, + bottom: 0, + left: 0, + right: 0 }, - { - type: 'text', // 'text' | 'barCode' | 'qrCode' | 'image' | 'table' - value: '麻辣味', - style: { "font-size": "18px" }, - }, - { - type: 'text', // 'text' | 'barCode' | 'qrCode' | 'image' | 'table' - value: '03-08 16:32 ¥123.00', - style: { "font-size": "18px" }, + dpi: { + horizontal: 203, + vertical: 203 } - ] - - PosPrinter.print(data, options) - .then(() => { }) - .catch((error) => { - console.error(error); - }); - - // printWin.webContents.print({ - // silent: true, - // deviceName: name, - // pageSize: { - // width: 30480, - // height: 22860 - // } - // }) + }) }) }); diff --git a/package.json b/package.json index 5b1cc8f..0717fdf 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vite-electron", "private": true, - "version": "1.0.12", + "version": "1.0.14", "main": "dist-electron/main.js", "scripts": { "dev": "chcp 65001 && vite", diff --git a/public/print.css b/public/print.css new file mode 100644 index 0000000..5eabcd6 --- /dev/null +++ b/public/print.css @@ -0,0 +1,79 @@ +* { + padding: 0; + margin: 0; + -webkit-box-sizing: border-box; + box-sizing: border-box; +} + +body { + padding: 0 8mm; +} + +.print_view { + padding: 20px 0; +} +.print_view .title { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + margin-bottom: 4px; +} +.print_view .title.t1 { + font-size: 24px; +} +.print_view .title.t2 { + margin-bottom: 15px; +} +.print_view .row { + margin-top: 2px; + font-size: 12px; +} +.print_view .row.between { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; +} +.print_view .line { + margin: 10px 0; + border-bottom: 1px solid #000; +} +.print_view .table { + width: 100%; +} +.print_view .table tr { + width: 100%; + display: -webkit-box; + display: -ms-flexbox; + display: flex; +} +.print_view .table tr:not(:last-child) { + margin-bottom: 10px; +} +.print_view .table tr td { + -webkit-box-flex: 1; + -ms-flex: 1; + flex: 1; + font-size: 12px; +} +.print_view .table tr td:nth-child(1) { + -webkit-box-flex: 2; + -ms-flex: 2; + flex: 2; +} +.print_view .table tr td:not(:first-child) { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: end; + -ms-flex-pack: end; + justify-content: flex-end; +} +.print_view .table tr td .sku { + font-size: 10px; +} \ No newline at end of file diff --git a/public/print.html b/public/print.html index b8104a7..750a8a2 100644 --- a/public/print.html +++ b/public/print.html @@ -6,54 +6,88 @@
| 品名 | +单价 | +数量 | +小计 | +
|
+ {{item.name}}
+ {{item.skuName}}
+ |
+ {{item.salePrice}} | +{{item.number}} | +{{item.totalAmount}} | +