From 8c1e1d3fbc8d349790c22e8c440a8468adef34c5 Mon Sep 17 00:00:00 2001 From: gyq <875626088@qq.com> Date: Fri, 12 Jul 2024 16:36:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 +- .env.production | 8 +- dist-electron/main.js | 29 +++- electron/main.js | 45 +++++- package.json | 152 +++++++++--------- public/tag_print.css | 15 +- public/tag_print.scss | 17 +- src/App.vue | 60 ++++--- src/components/fastPayCard.vue | 9 +- src/components/takeFoodCode.vue | 24 ++- src/store/socket.js | 16 +- src/views/order/index.vue | 267 ++++++++------------------------ 12 files changed, 304 insertions(+), 342 deletions(-) diff --git a/.env.development b/.env.development index 9e06731..cfb0a56 100644 --- a/.env.development +++ b/.env.development @@ -3,10 +3,10 @@ ENV = development # 正式ws -VITE_API_WSS = 'wss://cashier.sxczgkj.cn/client' +# VITE_API_WSS = 'wss://cashier.sxczgkj.cn/client' #测试ws -# VITE_API_WSS = 'wss://wxcashiertest.sxczgkj.cn/client' +VITE_API_WSS = 'wss://wxcashiertest.sxczgkj.cn/client' # 阿伟本地ws # VITE_API_WSS = 'ws://192.168.2.17:9998/client' diff --git a/.env.production b/.env.production index 66fd823..d443f20 100644 --- a/.env.production +++ b/.env.production @@ -2,16 +2,16 @@ ENV = production # 正式ws -VITE_API_WSS = 'wss://cashier.sxczgkj.cn/client' +# VITE_API_WSS = 'wss://cashier.sxczgkj.cn/client' #测试ws -# VITE_API_WSS = 'wss://wxcashiertest.sxczgkj.cn/client' +VITE_API_WSS = 'wss://wxcashiertest.sxczgkj.cn/client' # 测试 php VITE_API_PHP_URL = 'http://192.168.2.33:1666/index.php/api' # 测试 -# VITE_API_URL = 'https://cashier-client.sxczgkj.cn/cashier-client' +VITE_API_URL = 'https://cashier-client.sxczgkj.cn/cashier-client' # 线上环境接口地址 -VITE_API_URL = 'https://cashierclient.sxczgkj.cn/cashier-client/' \ No newline at end of file +# VITE_API_URL = 'https://cashierclient.sxczgkj.cn/cashier-client/' \ No newline at end of file diff --git a/dist-electron/main.js b/dist-electron/main.js index feb8162..70a5210 100644 --- a/dist-electron/main.js +++ b/dist-electron/main.js @@ -1,6 +1,7 @@ "use strict"; const path = require("path"); const electron = require("electron"); +const os = require("os"); let win; electron.app.whenReady().then(() => { win = new electron.BrowserWindow({ @@ -35,6 +36,17 @@ electron.app.whenReady().then(() => { 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 printWin = new electron.BrowserWindow({ show: false, width: 464, @@ -123,7 +135,7 @@ electron.app.whenReady().then(() => { }); const tagPrintWin = new electron.BrowserWindow({ show: false, - width: 320, + width: 360, height: 240, webPreferences: { nodeIntegration: true, @@ -146,7 +158,7 @@ electron.app.whenReady().then(() => { silent: true, deviceName: name, pageSize: { - width: 4e4, + width: 45e3, height: 3e4 }, scaleFactor: 80, @@ -164,6 +176,19 @@ electron.app.whenReady().then(() => { } }); }); + 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(); + } + }); + } }); electron.app.on("window-all-closed", () => { if (process.platform !== "darwin") diff --git a/electron/main.js b/electron/main.js index 0816753..d78ace5 100644 --- a/electron/main.js +++ b/electron/main.js @@ -1,5 +1,6 @@ import path from "path"; -import { app, BrowserWindow, ipcMain } from "electron"; +import { app, BrowserWindow, ipcMain, net } from "electron"; +import os from "os"; // const SerialPort = require("serialport"); let win; @@ -40,6 +41,16 @@ app.whenReady().then(() => { app.quit(); }); + // 监听网络在线事件 + // net.on("online", () => { + // console.log("网络连接恢复"); + // }); + + // // 监听网络离线事件 + // net.on("offline", () => { + // console.log("网络连接断开"); + // }); + // 给渲染进程返回打印机列表 ipcMain.on("getPrintList", () => { win.webContents.getPrintersAsync().then((res) => { @@ -47,6 +58,19 @@ app.whenReady().then(() => { }); }); + // 获取本机mac + 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); + }); + // ipcMain.on("getSerialPort", () => { // SerialPort.SerialPort.list().then( // (ports) => { @@ -165,7 +189,7 @@ app.whenReady().then(() => { // 标签小票的窗口 const tagPrintWin = new BrowserWindow({ show: false, - width: 320, + width: 360, height: 240, webPreferences: { nodeIntegration: true, @@ -196,7 +220,7 @@ app.whenReady().then(() => { silent: true, deviceName: name, pageSize: { - width: 40000, + width: 45000, height: 30000, }, scaleFactor: 80, @@ -214,8 +238,21 @@ app.whenReady().then(() => { }, }); }); -}); + const gotTheLock = app.requestSingleInstanceLock(); + if (!gotTheLock) { + app.quit(); + } else { + app.on("second-instance", (event, commandLine, workingDirectory) => { + // 当运行第二个实例时,将会聚焦到mainWindow这个窗口 + if (win) { + if (win.isMinimized()) win.restore(); + win.focus(); + win.show(); + } + }); + } +}); app.on("window-all-closed", () => { if (process.platform !== "darwin") app.quit(); }); diff --git a/package.json b/package.json index ff43abb..8b08470 100644 --- a/package.json +++ b/package.json @@ -1,77 +1,77 @@ { - "name": "vite-electron", - "private": true, - "version": "1.3.44", - "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", - "js-md5": "^0.8.3", - "lodash": "^4.17.21", - "pinia": "^2.1.7", - "qrcode": "^1.5.3", - "reconnecting-websocket": "^4.4.0", - "serialport": "^12.0.0", - "swiper": "^11.1.1", - "uuid": "^10.0.0", - "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 - } - } -} + "name": "vite-electron", + "private": true, + "version": "1.3.52", + "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", + "js-md5": "^0.8.3", + "lodash": "^4.17.21", + "pinia": "^2.1.7", + "qrcode": "^1.5.3", + "reconnecting-websocket": "^4.4.0", + "serialport": "^12.0.0", + "swiper": "^11.1.1", + "uuid": "^10.0.0", + "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 diff --git a/public/tag_print.css b/public/tag_print.css index 5f0f354..858bee9 100644 --- a/public/tag_print.css +++ b/public/tag_print.css @@ -9,24 +9,25 @@ html, body { - width: 100%; - height: 100%; + width: 100vw; + height: 100vh; } body { - padding: 2mm; + padding: 10px; } #app { width: 100%; height: 100%; + overflow: hidden; } .print_view { position: relative; width: 100%; height: 100%; - overflow: hidden; + padding-left: 12px; } .print_view .ewm { width: 50px; @@ -59,12 +60,12 @@ body { align-items: flex-end; } .print_view .number_wrap .num { - font-size: 18px; + font-size: 14px; font-weight: bold; } .print_view .number_wrap .info { - margin-left: 12px; - padding-bottom: 4px; + margin-left: 10px; + padding-bottom: 2px; } .print_view .time { font-weight: bold; diff --git a/public/tag_print.scss b/public/tag_print.scss index 7516bf3..623f9d5 100644 --- a/public/tag_print.scss +++ b/public/tag_print.scss @@ -7,21 +7,22 @@ } html, body { - width: 100%; - height: 100%; + width: 100vw; + height: 100vh; } body { - padding: 2mm; + padding: 10px; } -#app{ +#app { width: 100%; height: 100%; + overflow: hidden; } .print_view { position: relative; width: 100%; height: 100%; - overflow: hidden; + padding-left: 12px; .ewm { $size: 50px; width: $size; @@ -46,12 +47,12 @@ body { display: flex; align-items: flex-end; .num { - font-size: 18px; + font-size: 14px; font-weight: bold; } .info { - margin-left: 12px; - padding-bottom: 4px; + margin-left: 10px; + padding-bottom: 2px; } } .time { diff --git a/src/App.vue b/src/App.vue index 7f72c23..f908fc6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -22,6 +22,7 @@ @@ -203,28 +223,20 @@ onMounted(() => { --b-darker: calc(var(--b) * 0.8); --primary-color: rgb(var(--r), var(--g), var(--b)); - --primary-color-hover: rgb( - var(--r-lighter3), - var(--g-lighter3), - var(--b-lighter3) - ); + --primary-color-hover: rgb(var(--r-lighter3), + var(--g-lighter3), + var(--b-lighter3)); --el-color-primary: var(--primary-color) !important; --el-button-hover-bg-color: var(--primary-color) !important; - --el-color-primary-light-3: rgb( - var(--r-lighter), - var(--g-lighter), - var(--b-lighter) - ) !important; - --el-color-primary-dark-2: rgb( - var(--r-darker), - var(--g-darker), - var(--b-darker) - ) !important; - --el-color-primary-light-5: rgb( - var(--r-lighter2), - var(--g-lighter2), - var(--b-lighter2) - ) !important; + --el-color-primary-light-3: rgb(var(--r-lighter), + var(--g-lighter), + var(--b-lighter)) !important; + --el-color-primary-dark-2: rgb(var(--r-darker), + var(--g-darker), + var(--b-darker)) !important; + --el-color-primary-light-5: rgb(var(--r-lighter2), + var(--g-lighter2), + var(--b-lighter2)) !important; --el-font-size-base: 16px !important; --el-message-close-size: var(--el-font-size-base) !important; @@ -279,8 +291,7 @@ html { background-color: #555; margin-right: 0 !important; padding-bottom: 20px !important; - border-radius: var(--el-dialog-border-radius) var(--el-dialog-border-radius) 0 - 0; + border-radius: var(--el-dialog-border-radius) var(--el-dialog-border-radius) 0 0; } .el-dialog__title { @@ -301,8 +312,7 @@ html { } .el-dialog__body { - padding: calc(var(--el-dialog-padding-primary) + 10px) - var(--el-dialog-padding-primary); + padding: calc(var(--el-dialog-padding-primary) + 10px) var(--el-dialog-padding-primary); } .el-dialog__header { @@ -390,7 +400,7 @@ html { display: flex; width: 200%; - & > div { + &>div { width: 50%; } diff --git a/src/components/fastPayCard.vue b/src/components/fastPayCard.vue index d73f84f..9a779dc 100644 --- a/src/components/fastPayCard.vue +++ b/src/components/fastPayCard.vue @@ -80,7 +80,8 @@ @@ -141,7 +142,7 @@ function payTypeChange(index, item) { if (money.value > 0) { scanModalRef.value.show(); } else { - ElMessage.error("请输入大于0的金额"); + ElMessage.error("请输入金额"); return; } } @@ -173,13 +174,13 @@ async function confirmOrder() { try { if (payList.value[payActive.value].payType == "scanCode") { if (money.value <= 0) { - ElMessage.error("请输入大于0的金额"); + ElMessage.error("请输入金额"); return; } scanModalRef.value.show(); } else { if (money.value <= 0) { - ElMessage.error("请输入大于0的金额"); + ElMessage.error("请输入金额"); return; } switch (payList.value[payActive.value].payType) { diff --git a/src/components/takeFoodCode.vue b/src/components/takeFoodCode.vue index bbace25..0577fe9 100644 --- a/src/components/takeFoodCode.vue +++ b/src/components/takeFoodCode.vue @@ -1,7 +1,7 @@ - + {{ item }} @@ -24,11 +24,16 @@