From 804b677174a88da09ff6da6f8756cd3aa51d54ef Mon Sep 17 00:00:00 2001 From: gyq <875626088@qq.com> Date: Thu, 1 Aug 2024 15:53:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9php=20https?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 2 +- .env.production | 2 +- .env.test | 2 +- dist-electron/main.js | 116 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 118 insertions(+), 4 deletions(-) diff --git a/.env.development b/.env.development index 18a046a..9ec5310 100644 --- a/.env.development +++ b/.env.development @@ -12,7 +12,7 @@ VITE_API_WSS = 'wss://cashier.sxczgkj.cn/client' # VITE_API_WSS = 'ws://192.168.2.17:9998/client' # 正式 php -VITE_API_PHP_URL = 'http://czgdoumei.sxczgkj.com/index.php/api' +VITE_API_PHP_URL = 'https://czgdoumei.sxczgkj.com/index.php/api' # 测试 php 开票 # VITE_API_KP_URL = 'http://192.168.1.13:8888/api' diff --git a/.env.production b/.env.production index 9ec4f03..615938a 100644 --- a/.env.production +++ b/.env.production @@ -5,7 +5,7 @@ ENV = production VITE_API_WSS = 'wss://cashier.sxczgkj.cn/client' # 正式 php -VITE_API_PHP_URL = 'http://czgdoumei.sxczgkj.com/index.php/api' +VITE_API_PHP_URL = 'https://czgdoumei.sxczgkj.com/index.php/api' # 正式 php 开票 VITE_API_KP_URL = 'https://invoice.sxczgkj.cn/api' diff --git a/.env.test b/.env.test index 48c66f1..2fe3b2a 100644 --- a/.env.test +++ b/.env.test @@ -8,7 +8,7 @@ ENV = test VITE_API_WSS = 'wss://cashier.sxczgkj.cn/client' # 正式 php -VITE_API_PHP_URL = 'http://czgdoumei.sxczgkj.com/index.php/api' +VITE_API_PHP_URL = 'https://czgdoumei.sxczgkj.com/index.php/api' # 测试 php 开票 # VITE_API_KP_URL = 'http://192.168.1.13:8888/api' diff --git a/dist-electron/main.js b/dist-electron/main.js index 05cae54..eda7f33 100644 --- a/dist-electron/main.js +++ b/dist-electron/main.js @@ -1 +1,115 @@ -"use strict";const s=require("path"),e=require("electron"),a=require("os");let n;e.app.whenReady().then(()=>{n=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?n.loadURL(process.env.VITE_DEV_SERVER_URL):n.loadFile(s.resolve(__dirname,"../dist/index.html")),e.app.on("activate",()=>{e.BrowserWindow.getAllWindows().length===0&&createWindow()}),e.ipcMain.on("quitHandler",(t,o)=>{n=null,e.app.exit()}),e.ipcMain.on("getPrintList",()=>{n.webContents.getPrintersAsync().then(t=>{n.webContents.send("printList",t)})}),e.ipcMain.on("getOSmacSync",()=>{let t="";a.networkInterfaces().WLAN?(t=a.networkInterfaces().WLAN[0].mac,console.log("wlan.mac===",t)):(t=a.networkInterfaces().以太网[0].mac,console.log("以太网.mac===",t)),n.webContents.send("getOSmacRes",t)});const i=new e.BrowserWindow({show:!1,width:360,height:240,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?i.loadFile(s.join(__dirname,"../public/tag_print.html")):i.loadFile(s.resolve(__dirname,"../dist/tag_print.html")),e.ipcMain.on("printerTagSync",(t,o)=>{console.log(o),i.webContents.send("getParams",o)}),e.ipcMain.on("printTagStart",(t,o)=>{let l=JSON.parse(o).deviceName;i.webContents.print({silent:!0,deviceName:l,pageSize:{width:45e3,height:3e4},scaleFactor:80,landscape:!1,margins:{marginType:"none",top:0,bottom:0,left:0,right:0},dpi:{horizontal:203,vertical:203}})}),e.app.requestSingleInstanceLock()?e.app.on("second-instance",(t,o,r)=>{n&&(n.isMinimized()&&n.restore(),n.focus(),n.show())}):e.app.quit(),n.on("close",t=>{t.preventDefault(),n.webContents.send("showCloseDialog")})});e.app.on("window-all-closed",()=>{process.platform!=="darwin"&&e.app.quit()}); +"use strict"; +const path = require("path"); +const electron = require("electron"); +const os = require("os"); +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) => { + win = null; + electron.app.exit(); + }); + electron.ipcMain.on("getPrintList", () => { + win.webContents.getPrintersAsync().then((res) => { + win.webContents.send("printList", res); + }); + }); + electron.ipcMain.on("getOSmacSync", () => { + let mac = ""; + if (os.networkInterfaces().WLAN) { + mac = os.networkInterfaces().WLAN[0].mac; + console.log("wlan.mac===", mac); + } else { + mac = os.networkInterfaces()["以太网"][0].mac; + console.log("以太网.mac===", mac); + } + win.webContents.send("getOSmacRes", mac); + }); + const tagPrintWin = new electron.BrowserWindow({ + show: false, + width: 360, + 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: 45e3, + height: 3e4 + }, + scaleFactor: 80, + landscape: false, + margins: { + marginType: "none", + top: 0, + bottom: 0, + left: 0, + right: 0 + }, + dpi: { + horizontal: 203, + vertical: 203 + } + }); + }); + const gotTheLock = electron.app.requestSingleInstanceLock(); + if (!gotTheLock) { + electron.app.quit(); + } else { + electron.app.on("second-instance", (event, commandLine, workingDirectory) => { + if (win) { + if (win.isMinimized()) + win.restore(); + win.focus(); + win.show(); + } + }); + } + win.on("close", (e) => { + e.preventDefault(); + win.webContents.send("showCloseDialog"); + }); +}); +electron.app.on("window-all-closed", () => { + if (process.platform !== "darwin") + electron.app.quit(); +});