新增标签打印
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
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)
|
||||
// );
|
||||
// const SerialPort = require("serialport");
|
||||
|
||||
let win;
|
||||
app.whenReady().then(() => {
|
||||
@@ -52,6 +47,16 @@ app.whenReady().then(() => {
|
||||
});
|
||||
});
|
||||
|
||||
// ipcMain.on("getSerialPort", () => {
|
||||
// SerialPort.SerialPort.list().then(
|
||||
// (ports) => {
|
||||
// console.log(ports);
|
||||
// win.webContents.send("seriaportList", ports);
|
||||
// },
|
||||
// (err) => console.error(err)
|
||||
// );
|
||||
// });
|
||||
|
||||
// 创建打印小票子窗口
|
||||
const printWin = new BrowserWindow({
|
||||
show: false,
|
||||
@@ -156,6 +161,58 @@ app.whenReady().then(() => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// 标签小票的窗口
|
||||
const tagPrintWin = new BrowserWindow({
|
||||
show: true,
|
||||
width: 320,
|
||||
height: 240,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
contextIsolation: false,
|
||||
},
|
||||
});
|
||||
|
||||
if (process.env.VITE_DEV_SERVER_URL) {
|
||||
// 加载打印的html文件
|
||||
tagPrintWin.loadFile(path.join(__dirname, "../public/tag_print.html"));
|
||||
} else {
|
||||
tagPrintWin.loadFile(path.resolve(__dirname, "../dist/tag_print.html")); // 打包后使用文件路径访问应用
|
||||
}
|
||||
|
||||
// 接收渲染进程发送的数据
|
||||
ipcMain.on("printerTagSync", (event, arg) => {
|
||||
tagPrintWin.webContents.send("getParams", arg);
|
||||
});
|
||||
|
||||
// 执行标签小票的打印操作
|
||||
ipcMain.on("printTagStart", (event, arg) => {
|
||||
console.log(arg);
|
||||
const _parmas = JSON.parse(arg);
|
||||
// console.log(_parmas)
|
||||
let name = _parmas.deviceName;
|
||||
tagPrintWin.webContents.print({
|
||||
silent: true,
|
||||
deviceName: name,
|
||||
pageSize: {
|
||||
width: 40000,
|
||||
height: 30000,
|
||||
},
|
||||
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", () => {
|
||||
|
||||
Reference in New Issue
Block a user