优化打印效果
This commit is contained in:
@@ -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
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user