Merge branch 'gyq' of https://gitee.com/shaanxi-super-shopkeeper_1/cashierdesktop into wwz
This commit is contained in:
commit
48d6583a03
|
|
@ -0,0 +1,6 @@
|
|||
# 本地环境
|
||||
ENV = development
|
||||
|
||||
# 本地环境接口地址
|
||||
# VITE_API_URL = 'http://192.168.2.87:10587/cashier-client'
|
||||
VITE_API_URL = 'https://cashierclient.sxczgkj.cn/cashier-client'
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
# 线上环境
|
||||
ENV = production
|
||||
|
||||
# 线上环境接口地址
|
||||
VITE_API_URL = 'https://cashierclient.sxczgkj.cn/cashier-client/'
|
||||
|
|
@ -8,6 +8,8 @@ pnpm-debug.log*
|
|||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
release
|
||||
dist-electron
|
||||
|
||||
dist
|
||||
dist-ssr
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
"use strict";
|
||||
const electron = require("electron");
|
||||
const path = require("path");
|
||||
function printUtils(data) {
|
||||
const path$1 = require("path");
|
||||
function printUtils(params) {
|
||||
return new Promise(async (resolvePrint, rejectPrint) => {
|
||||
let subMainWindow = new electron.BrowserWindow({
|
||||
show: false,
|
||||
// show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
// For electron >= 4.0.0
|
||||
|
|
@ -13,50 +13,31 @@ function printUtils(data) {
|
|||
enableRemoteModule: true
|
||||
}
|
||||
});
|
||||
function renderPrintDocument(window, data2) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
electron.ipcMain.on("load-ok", (event, res) => {
|
||||
setTimeout(() => {
|
||||
resolve({ message: "page-rendered", ...res });
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
}
|
||||
subMainWindow.on("closed", () => {
|
||||
subMainWindow = null;
|
||||
});
|
||||
subMainWindow.loadFile(path.resolve(__dirname, "./public/print.html"));
|
||||
subMainWindow.loadFile(path$1.join(__dirname, "../public/print.html"));
|
||||
subMainWindow.webContents.on("did-finish-load", async (res) => {
|
||||
return renderPrintDocument().then(async (result) => {
|
||||
let height = Math.ceil((result.height + 60) * 264.5833);
|
||||
console.info("height", result, height);
|
||||
subMainWindow.webContents.openDevTools();
|
||||
console.log("网页加载完成", res);
|
||||
subMainWindow.webContents.send("getParams", params);
|
||||
return;
|
||||
});
|
||||
electron.ipcMain.on("printStart", () => {
|
||||
console.log("开始打印");
|
||||
subMainWindow.webContents.print({
|
||||
silent: true,
|
||||
margins: {
|
||||
marginType: "none"
|
||||
},
|
||||
printBackground: false,
|
||||
deviceName: options.printerName,
|
||||
copies: 1
|
||||
}, (success) => {
|
||||
if (success) {
|
||||
resolvePrint({ type: "success" });
|
||||
}
|
||||
subMainWindow.close();
|
||||
silent: true
|
||||
});
|
||||
}).catch((err) => console.warn(33, err));
|
||||
});
|
||||
});
|
||||
}
|
||||
const NODE_ENV = process.env.NODE_ENV;
|
||||
electron.app.whenReady().then(() => {
|
||||
const win = new electron.BrowserWindow({
|
||||
title: "Main window",
|
||||
title: "银收客",
|
||||
width: 1200,
|
||||
height: 800,
|
||||
fullscreenable: true,
|
||||
fullscreen: false,
|
||||
fullscreen: true,
|
||||
simpleFullscreen: true,
|
||||
frame: true,
|
||||
frame: false,
|
||||
webPreferences: {
|
||||
// 集成网页和 Node.js,也就是在渲染进程中,可以调用 Node.js 方法
|
||||
nodeIntegration: true,
|
||||
|
|
@ -66,9 +47,11 @@ electron.app.whenReady().then(() => {
|
|||
if (process.env.VITE_DEV_SERVER_URL) {
|
||||
win.loadURL(process.env.VITE_DEV_SERVER_URL);
|
||||
} else {
|
||||
win.loadFile("dist/index.html");
|
||||
win.loadFile(path.join(__dirname, "../dist/index.html"));
|
||||
}
|
||||
if (NODE_ENV == "development") {
|
||||
win.webContents.openDevTools();
|
||||
}
|
||||
electron.app.on("activate", () => {
|
||||
if (electron.BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow();
|
||||
|
|
@ -78,10 +61,7 @@ electron.app.whenReady().then(() => {
|
|||
electron.app.quit();
|
||||
});
|
||||
electron.ipcMain.on("printerInfoSync", async (event, params) => {
|
||||
console.log("接收到打印消息", params);
|
||||
const res = await printUtils();
|
||||
event.returnValue = res;
|
||||
console.log("已打印", res);
|
||||
await printUtils(params);
|
||||
});
|
||||
});
|
||||
electron.app.on("window-all-closed", () => {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
import { app, BrowserWindow, ipcMain } from "electron";
|
||||
import { printUtils } from './printUtils'
|
||||
|
||||
const NODE_ENV = process.env.NODE_ENV
|
||||
|
||||
app.whenReady().then(() => {
|
||||
const win = new BrowserWindow({
|
||||
title: "Main window",
|
||||
title: "银收客",
|
||||
width: 1200,
|
||||
height: 800,
|
||||
fullscreenable: true,
|
||||
fullscreen: false,
|
||||
fullscreen: true,
|
||||
simpleFullscreen: true,
|
||||
frame: true,
|
||||
frame: false,
|
||||
webPreferences: {
|
||||
// 集成网页和 Node.js,也就是在渲染进程中,可以调用 Node.js 方法
|
||||
nodeIntegration: true,
|
||||
|
|
@ -19,12 +21,15 @@ app.whenReady().then(() => {
|
|||
|
||||
// You can use `process.env.VITE_DEV_SERVER_URL` when the vite command is called `serve`
|
||||
if (process.env.VITE_DEV_SERVER_URL) {
|
||||
win.loadURL(process.env.VITE_DEV_SERVER_URL);
|
||||
win.loadURL(process.env.VITE_DEV_SERVER_URL); // 使用vite开发服务的url路径访问应用
|
||||
} else {
|
||||
// Load your file
|
||||
win.loadFile("dist/index.html");
|
||||
win.loadFile(path.join(__dirname, '../dist/index.html')); // 打包后使用文件路径访问应用
|
||||
}
|
||||
|
||||
if (NODE_ENV == 'development') {
|
||||
win.webContents.openDevTools();
|
||||
}
|
||||
|
||||
app.on("activate", () => {
|
||||
// 在 macOS 系统内, 如果没有已开启的应用窗口
|
||||
// 点击托盘图标时通常会重新创建一个新窗口
|
||||
|
|
@ -38,10 +43,7 @@ app.whenReady().then(() => {
|
|||
});
|
||||
|
||||
ipcMain.on('printerInfoSync', async (event, params) => {
|
||||
console.log('接收到打印消息', params)
|
||||
const res = await printUtils(params)
|
||||
event.returnValue = res
|
||||
console.log('已打印', res)
|
||||
await printUtils(params)
|
||||
})
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
import { BrowserWindow, ipcMain } from 'electron';
|
||||
import path from "path";
|
||||
|
||||
|
||||
export function printUtils(data) {
|
||||
export function printUtils(params) {
|
||||
return new Promise(async (resolvePrint, rejectPrint) => {
|
||||
|
||||
let subMainWindow = new BrowserWindow({
|
||||
show: false,
|
||||
// show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true, // For electron >= 4.0.0
|
||||
contextIsolation: false,
|
||||
|
|
@ -15,26 +13,14 @@ export function printUtils(data) {
|
|||
}
|
||||
});
|
||||
|
||||
function renderPrintDocument(window, data) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
ipcMain.on('load-ok', (event, res) => {
|
||||
//在这里可以添加打印的判断条件等......
|
||||
setTimeout(() => {
|
||||
resolve({ message: 'page-rendered', ...res });
|
||||
}, 500)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// If the subMainWindow is closed, reset the `subMainWindow` var to null
|
||||
subMainWindow.on('closed', () => {
|
||||
subMainWindow = null;
|
||||
});
|
||||
// 加载打印的html文件
|
||||
subMainWindow.loadFile(path.resolve(__dirname, "./public/print.html"));
|
||||
subMainWindow.loadFile(path.join(__dirname, "../public/print.html"));
|
||||
|
||||
subMainWindow.webContents.on('did-finish-load', async (res) => {
|
||||
subMainWindow.webContents.openDevTools();
|
||||
console.log('网页加载完成', res)
|
||||
subMainWindow.webContents.send('getParams', params)
|
||||
return
|
||||
let data = []
|
||||
return renderPrintDocument(subMainWindow, data)
|
||||
.then(async (result) => {
|
||||
|
|
@ -47,10 +33,9 @@ export function printUtils(data) {
|
|||
marginType: 'none'
|
||||
},
|
||||
printBackground: false,
|
||||
deviceName: options.printerName,
|
||||
deviceName: '',
|
||||
copies: 1,
|
||||
}, (success) => {
|
||||
|
||||
if (success) {
|
||||
resolvePrint({ type: 'success' })
|
||||
}
|
||||
|
|
@ -59,5 +44,11 @@ export function printUtils(data) {
|
|||
})
|
||||
.catch(err => console.warn(33, err))
|
||||
})
|
||||
ipcMain.on('printStart', () => {
|
||||
console.log('开始打印')
|
||||
subMainWindow.webContents.print({
|
||||
silent: true
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
28
package.json
28
package.json
|
|
@ -5,14 +5,13 @@
|
|||
"main": "dist-electron/main.js",
|
||||
"scripts": {
|
||||
"dev": "chcp 65001 && vite",
|
||||
"build": "vite build",
|
||||
"build": "vite build && electron-builder",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.1",
|
||||
"axios": "^1.6.2",
|
||||
"dayjs": "^1.11.10",
|
||||
"electron": "^29.0.1",
|
||||
"element-plus": "^2.4.3",
|
||||
"lodash": "^4.17.21",
|
||||
"pinia": "^2.1.7",
|
||||
|
|
@ -22,6 +21,7 @@
|
|||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^4.5.0",
|
||||
"electron": "^28.2.3",
|
||||
"electron-builder": "^24.13.3",
|
||||
"path": "^0.12.7",
|
||||
"sass": "^1.69.5",
|
||||
"sass-loader": "^13.3.2",
|
||||
|
|
@ -29,5 +29,29 @@
|
|||
"vite": "^5.0.0",
|
||||
"vite-plugin-electron": "^0.15.4",
|
||||
"vite-plugin-electron-renderer": "^0.14.5"
|
||||
},
|
||||
"build": {
|
||||
"appId": "com.example.app",
|
||||
"productName": "cashier_desktop",
|
||||
"asar": true,
|
||||
"directories": {
|
||||
"buildResources": "build",
|
||||
"output": "release"
|
||||
},
|
||||
"win": {
|
||||
"icon": "./src/assets/logo.ico",
|
||||
"target": "nsis"
|
||||
},
|
||||
"nsis": {
|
||||
"oneClick": false,
|
||||
"allowElevation": true,
|
||||
"allowToChangeInstallationDirectory": true,
|
||||
"installerIcon": "./src/assets/logo.ico",
|
||||
"uninstallerIcon": "./src/assets/logo.ico",
|
||||
"installerHeaderIcon": "./src/assets/logo.ico",
|
||||
"createDesktopShortcut": true,
|
||||
"createStartMenuShortcut": true,
|
||||
"license": "LICENSE.txt"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,25 +10,99 @@
|
|||
@page {
|
||||
size: auto;
|
||||
}
|
||||
|
||||
html {
|
||||
padding-bottom: 100px;
|
||||
}
|
||||
|
||||
.title_wrap {
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 50px 0;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.min_title {
|
||||
font-size: 18px;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
.item {
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.item.b {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.img {
|
||||
width: 100%;
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<section id="main">测试打印</section>
|
||||
<!-- <script type="module">
|
||||
<br />
|
||||
<section id="app">
|
||||
<div class="title_wrap">
|
||||
<div class="title">
|
||||
<b>{{data.shop_name}}</b>
|
||||
</div>
|
||||
<div class="min_title">结账单</div>
|
||||
</div>
|
||||
<div class="item b">NO:{{data.orderId}}</div>
|
||||
<div class="item b">开始时间:2023-3-4 16:32:54</div>
|
||||
<div class="item b">结束时间:2023-3-4 16:32:54</div>
|
||||
<div class="item b">打印人:002-蔡紫薇 打印次数:第一次打印</div>
|
||||
<div class="item b">品相费:450</div>
|
||||
<div class="item b">服务费:280</div>
|
||||
<div v-for="(item,index) in data.carts" :key="index">
|
||||
<div class="item">{{item.name}} {{item.number}}</div>
|
||||
<br />
|
||||
</div>
|
||||
<div class="item b">收银员:张三</div>
|
||||
</section>
|
||||
<div class="item b">电话</div>
|
||||
<br />
|
||||
<div class="item b">地址:陕西省西安市灞桥区后海餐厅一二三</div>
|
||||
<br />
|
||||
<div class="item b">--------------------------------</div>
|
||||
<br />
|
||||
<div class="item b">--------------------------------</div>
|
||||
<br />
|
||||
<div class="item b">--------------------------------</div>
|
||||
<br />
|
||||
<script type="module">
|
||||
const { ipcRenderer } = require("electron");
|
||||
window.onload = () => {
|
||||
ipcRenderer.on("webview-print-render", (event, info) => {
|
||||
// 执行渲染
|
||||
const main = document.getElementById("main");
|
||||
main.appendChild(info.shop_name);
|
||||
ipcRenderer.send("load-ok", {
|
||||
width: document.body.clientWidth,
|
||||
height: document.body.clientHeight,
|
||||
import {
|
||||
createApp,
|
||||
ref,
|
||||
onMounted,
|
||||
} from "../node_modules/vue/dist/vue.esm-browser.js";
|
||||
|
||||
createApp({
|
||||
setup() {
|
||||
const data = ref({});
|
||||
|
||||
onMounted(() => {
|
||||
ipcRenderer.on("getParams", (event, arg) => {
|
||||
data.value = JSON.parse(arg);
|
||||
});
|
||||
ipcRenderer.sendToHost("did-finish-load");
|
||||
ipcRenderer.send("printStart");
|
||||
});
|
||||
|
||||
return {
|
||||
data,
|
||||
};
|
||||
</script> -->
|
||||
},
|
||||
}).mount("#app");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
|
|
@ -4,7 +4,7 @@ import useStorage from '@/utils/useStorage'
|
|||
import router from '@/router'
|
||||
|
||||
const service = axios.create({
|
||||
baseURL: import.meta.env.MODE == 'development' ? '/api/' : '/api/admin',
|
||||
baseURL: import.meta.env.MODE == 'development' ? '/api/' : import.meta.env.VITE_API_URL,
|
||||
// withCredentials: true, // 跨域请求时发送 cookies
|
||||
timeout: 5000, // 请求超时
|
||||
});
|
||||
|
|
|
|||
|
|
@ -94,19 +94,19 @@ const isPrint = ref(true)
|
|||
|
||||
function printHandle() {
|
||||
if (!isPrint.value) return
|
||||
// const data = {
|
||||
// shop_name: '测试打印',
|
||||
// carts: props.cart,
|
||||
// amount: props.amount,
|
||||
// remark: props.remark
|
||||
// }
|
||||
ipcRenderer.sendSync('printerInfoSync', '测试打印')
|
||||
const data = {
|
||||
shop_name: '大客餐饮',
|
||||
carts: props.cart,
|
||||
amount: props.amount,
|
||||
remark: props.remark,
|
||||
orderId: props.orderId
|
||||
}
|
||||
ipcRenderer.sendSync('printerInfoSync', JSON.stringify(data))
|
||||
}
|
||||
|
||||
// 订单已支付
|
||||
function paySuccess() {
|
||||
dialogVisible.value = false
|
||||
printHandle()
|
||||
emit('paySuccess')
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue