对接完毕下单

This commit is contained in:
gyq
2024-03-04 15:48:40 +08:00
parent 6e796c1855
commit 27721ca096
21 changed files with 1010 additions and 237 deletions

View File

@@ -1,5 +1,53 @@
"use strict";
const electron = require("electron");
const path = require("path");
function printUtils(data) {
return new Promise(async (resolvePrint, rejectPrint) => {
let subMainWindow = new electron.BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
// For electron >= 4.0.0
contextIsolation: false,
webSecurity: false,
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.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.print({
silent: true,
margins: {
marginType: "none"
},
printBackground: false,
deviceName: options.printerName,
copies: 1
}, (success) => {
if (success) {
resolvePrint({ type: "success" });
}
subMainWindow.close();
});
}).catch((err) => console.warn(33, err));
});
});
}
electron.app.whenReady().then(() => {
const win = new electron.BrowserWindow({
title: "Main window",
@@ -22,13 +70,19 @@ electron.app.whenReady().then(() => {
}
win.webContents.openDevTools();
electron.app.on("activate", () => {
if (electron.BrowserWindow.getAllWindows().length === 0)
if (electron.BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
electron.ipcMain.on("quitHandler", (_, msg) => {
console.log(msg);
electron.app.quit();
});
electron.ipcMain.on("printerInfoSync", async (event, params) => {
console.log("接收到打印消息", params);
const res = await printUtils();
event.returnValue = res;
console.log("已打印", res);
});
});
electron.app.on("window-all-closed", () => {
if (process.platform !== "darwin")