优化打印效果

This commit is contained in:
gyq
2024-03-07 09:07:22 +08:00
parent 5d96435125
commit b550cf3fd8
12 changed files with 176 additions and 235 deletions

View File

@@ -1,12 +1,11 @@
import { app, BrowserWindow, ipcMain } from "electron";
import path from 'path'
import { printUtils } from './printUtils'
app.whenReady().then(() => {
const win = new BrowserWindow({
title: "银收客",
width: 1200,
height: 800,
width: 1024,
height: 768,
fullscreenable: true,
fullscreen: false,
simpleFullscreen: true,
@@ -22,10 +21,10 @@ app.whenReady().then(() => {
if (process.env.VITE_DEV_SERVER_URL) {
win.loadURL(process.env.VITE_DEV_SERVER_URL);
// 使用vite开发服务的url路径访问应用
// win.webContents.openDevTools();
} else {
win.loadFile(path.resolve(__dirname, '../dist/index.html')); // 打包后使用文件路径访问应用
}
win.webContents.openDevTools();
app.on("activate", () => {
// 在 macOS 系统内, 如果没有已开启的应用窗口
@@ -39,8 +38,36 @@ app.whenReady().then(() => {
app.quit();
});
ipcMain.on('printerInfoSync', async (event, params) => {
await printUtils(params)
// 创建打印小票子窗口
const printWin = new BrowserWindow({
show: false,
webPreferences: {
// 集成网页和 Node.js也就是在渲染进程中可以调用 Node.js 方法
nodeIntegration: true,
contextIsolation: false,
}
})
if (process.env.VITE_DEV_SERVER_URL) {
// 加载打印的html文件
printWin.loadFile(path.join(__dirname, "../public/print.html"));
} else {
printWin.loadFile(path.resolve(__dirname, '../dist/print.html')); // 打包后使用文件路径访问应用
}
printWin.webContents.openDevTools()
ipcMain.on('printerInfoSync', (event, params) => {
console.log(JSON.parse(params))
printWin.webContents.send('getParams', params)
})
// 执行打印操作
ipcMain.on('printStart', () => {
console.log('开始打印')
printWin.webContents.print({
silent: true
})
})
});