diff --git a/dist-electron/main.js b/dist-electron/main.js index 205ac11..3b14b44 100644 --- a/dist-electron/main.js +++ b/dist-electron/main.js @@ -1 +1,86 @@ -"use strict";const r=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(r.resolve(__dirname,"../dist/index.html")),e.app.on("activate",()=>{e.BrowserWindow.getAllWindows().length===0&&createWindow()}),e.ipcMain.on("quitHandler",(o,n)=>{e.app.quit()}),e.ipcMain.on("getPrintList",()=>{t.webContents.getPrintersAsync().then(o=>{t.webContents.send("printList",o)})});const i=new e.BrowserWindow({show:!1,width:464,height:2206,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?i.loadFile(r.join(__dirname,"../public/print.html")):i.loadFile(r.resolve(__dirname,"../dist/print.html")),e.ipcMain.on("printerInfoSync",(o,n)=>{i.webContents.send("getParams",n)}),e.ipcMain.on("printStart",(o,n)=>{console.log(n);const s=JSON.parse(n);console.log(s);let a=s.deviceName;i.webContents.print({silent:!0,deviceName:a,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()}); +"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 + } + }); + }); +}); +electron.app.on("window-all-closed", () => { + if (process.platform !== "darwin") + electron.app.quit(); +}); diff --git a/electron/main.js b/electron/main.js index 2c9df85..7ff6091 100644 --- a/electron/main.js +++ b/electron/main.js @@ -50,7 +50,7 @@ app.whenReady().then(() => { const printWin = new BrowserWindow({ show: false, width: 464, - height: 2206, + height: 1726, webPreferences: { // 集成网页和 Node.js,也就是在渲染进程中,可以调用 Node.js 方法 nodeIntegration: true, @@ -74,14 +74,14 @@ app.whenReady().then(() => { ipcMain.on('printStart', (event, arg) => { console.log(arg); const _parmas = JSON.parse(arg) - console.log(_parmas) + // console.log(_parmas) let name = _parmas.deviceName printWin.webContents.print({ silent: true, deviceName: name, pageSize: { width: 58000, - height: 276000 + height: 216000 }, scaleFactor: 80, landscape: false, diff --git a/package.json b/package.json index e97f591..f514572 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vite-electron", "private": true, - "version": "1.0.20", + "version": "1.0.25", "main": "dist-electron/main.js", "scripts": { "dev": "chcp 65001 && vite", diff --git a/src/App.vue b/src/App.vue index 32882a4..dabbe07 100644 --- a/src/App.vue +++ b/src/App.vue @@ -23,22 +23,22 @@ + + diff --git a/src/router/index.js b/src/router/index.js index e65f45c..0734e71 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -73,6 +73,11 @@ const routes = [ path: "/add_device", name: "add_device", component: () => import("@/views/device/add.vue"), + }, + { + path: "/add_label", + name: "add_label", + component: () => import("@/views/device/add_label.vue"), } ]; diff --git a/src/views/device/add_label.vue b/src/views/device/add_label.vue new file mode 100644 index 0000000..2347bcf --- /dev/null +++ b/src/views/device/add_label.vue @@ -0,0 +1,344 @@ + + + + + + + {{ form.id ? "编辑便签打印机" : "添加便签打印机" }} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{ item.name }}, + + + 请选择分类 + + + + + + + + + #A9 #A9 + + 甜橙马黛茶 + 1 + + 加奶、加珍珠 + + 03-08 16:58 + ¥28 + + + + + 打印测试小票 + + + + + 保存 + + + + + + + + (form.config.categoryList = e)" + /> + + + + + diff --git a/src/views/device/index.vue b/src/views/device/index.vue index 40c0620..bd4a21e 100644 --- a/src/views/device/index.vue +++ b/src/views/device/index.vue @@ -43,7 +43,10 @@ 编辑 @@ -84,10 +87,7 @@ --> - + 用来打印客户(收银)小票的打印机。 - + path.replace(/^\/api/, '') }