优化新增本地打印交班小票

This commit is contained in:
gyq
2024-06-14 11:41:46 +08:00
parent fde0ed0eaf
commit 1439f12ee5
9 changed files with 473 additions and 264 deletions

View File

@@ -1,5 +1,11 @@
import path from "path";
import { app, BrowserWindow, ipcMain } from "electron";
// import SerialPort from "serialport";
// SerialPort.list().then(
// (ports) => ports.forEach(console.log),
// (err) => console.error(err)
// );
let win;
app.whenReady().then(() => {
@@ -100,58 +106,56 @@ app.whenReady().then(() => {
});
// 交班小票的窗口
// const workPrintWin = new BrowserWindow({
// show: true,
// width: 464,
// height: 1726,
// webPreferences: {
// nodeIntegration: true,
// contextIsolation: false,
// },
// });
const workPrintWin = new BrowserWindow({
show: false,
width: 464,
height: 1726,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
// if (process.env.VITE_DEV_SERVER_URL) {
// // 加载打印的html文件
// workPrintWin.loadFile(path.join(__dirname, "../public/work_print.html"));
// } else {
// workPrintWin.loadFile(path.resolve(__dirname, "../dist/work_print.html")); // 打包后使用文件路径访问应用
// }
// // 接收渲染进程发送的数据
// ipcMain.on("printerWorkSync", (event, arg) => {
// workPrintWin.webContents.send("getParams", arg);
// });
// // 执行交班小票的打印操作
// ipcMain.on("printWorkStart", (event, arg) => {
// console.log(arg);
// const _parmas = JSON.parse(arg);
// // console.log(_parmas)
// let name = _parmas.deviceName;
// printWin.webContents.print({
// silent: true,
// deviceName: name,
// pageSize: {
// width: 58000,
// height: 216000,
// },
// scaleFactor: 80,
// landscape: false,
// margins: {
// marginType: "none",
// top: 0,
// bottom: 0,
// left: 0,
// right: 0,
// },
// dpi: {
// horizontal: 203,
// vertical: 203,
// },
// });
// });
if (process.env.VITE_DEV_SERVER_URL) {
// 加载打印的html文件
workPrintWin.loadFile(path.join(__dirname, "../public/work_print.html"));
} else {
workPrintWin.loadFile(path.resolve(__dirname, "../dist/work_print.html")); // 打包后使用文件路径访问应用
}
// 接收渲染进程发送的数据
ipcMain.on("printerWorkSync", (event, arg) => {
workPrintWin.webContents.send("getParams", arg);
});
// 执行交班小票的打印操作
ipcMain.on("printWorkStart", (event, arg) => {
console.log(arg);
const _parmas = JSON.parse(arg);
// console.log(_parmas)
let name = _parmas.deviceName;
workPrintWin.webContents.print({
silent: true,
deviceName: name,
pageSize: {
width: 58000,
height: 216000,
},
scaleFactor: 80,
landscape: false,
margins: {
marginType: "none",
top: 0,
bottom: 0,
left: 0,
right: 0,
},
dpi: {
horizontal: 203,
vertical: 203,
},
});
});
});
app.on("window-all-closed", () => {