调试打印
This commit is contained in:
@@ -7,9 +7,9 @@ app.whenReady().then(() => {
|
||||
width: 1200,
|
||||
height: 800,
|
||||
fullscreenable: true,
|
||||
fullscreen: false,
|
||||
fullscreen: true,
|
||||
simpleFullscreen: true,
|
||||
frame: true,
|
||||
frame: false,
|
||||
webPreferences: {
|
||||
// 集成网页和 Node.js,也就是在渲染进程中,可以调用 Node.js 方法
|
||||
nodeIntegration: true,
|
||||
@@ -24,7 +24,7 @@ app.whenReady().then(() => {
|
||||
// Load your file
|
||||
win.loadFile("dist/index.html");
|
||||
}
|
||||
win.webContents.openDevTools();
|
||||
// win.webContents.openDevTools();
|
||||
app.on("activate", () => {
|
||||
// 在 macOS 系统内, 如果没有已开启的应用窗口
|
||||
// 点击托盘图标时通常会重新创建一个新窗口
|
||||
@@ -38,10 +38,7 @@ app.whenReady().then(() => {
|
||||
});
|
||||
|
||||
ipcMain.on('printerInfoSync', async (event, params) => {
|
||||
console.log('接收到打印消息', params)
|
||||
const res = await printUtils(params)
|
||||
event.returnValue = res
|
||||
console.log('已打印', res)
|
||||
await printUtils(params)
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { BrowserWindow, ipcMain } from 'electron';
|
||||
import path from "path";
|
||||
|
||||
|
||||
export function printUtils(data) {
|
||||
export function printUtils(params) {
|
||||
return new Promise(async (resolvePrint, rejectPrint) => {
|
||||
|
||||
let subMainWindow = new BrowserWindow({
|
||||
show: false,
|
||||
// show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true, // For electron >= 4.0.0
|
||||
contextIsolation: false,
|
||||
@@ -15,26 +13,14 @@ export function printUtils(data) {
|
||||
}
|
||||
});
|
||||
|
||||
function renderPrintDocument(window, data) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
ipcMain.on('load-ok', (event, res) => {
|
||||
//在这里可以添加打印的判断条件等......
|
||||
setTimeout(() => {
|
||||
resolve({ message: 'page-rendered', ...res });
|
||||
}, 500)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// If the subMainWindow is closed, reset the `subMainWindow` var to null
|
||||
subMainWindow.on('closed', () => {
|
||||
subMainWindow = null;
|
||||
});
|
||||
// 加载打印的html文件
|
||||
subMainWindow.loadFile(path.resolve(__dirname, "./public/print.html"));
|
||||
subMainWindow.loadFile(path.join(__dirname, "../public/print.html"));
|
||||
|
||||
subMainWindow.webContents.on('did-finish-load', async (res) => {
|
||||
subMainWindow.webContents.openDevTools();
|
||||
console.log('网页加载完成', res)
|
||||
subMainWindow.webContents.send('getParams', params)
|
||||
return
|
||||
let data = []
|
||||
return renderPrintDocument(subMainWindow, data)
|
||||
.then(async (result) => {
|
||||
@@ -47,10 +33,9 @@ export function printUtils(data) {
|
||||
marginType: 'none'
|
||||
},
|
||||
printBackground: false,
|
||||
deviceName: options.printerName,
|
||||
deviceName: '',
|
||||
copies: 1,
|
||||
}, (success) => {
|
||||
|
||||
if (success) {
|
||||
resolvePrint({ type: 'success' })
|
||||
}
|
||||
@@ -59,5 +44,11 @@ export function printUtils(data) {
|
||||
})
|
||||
.catch(err => console.warn(33, err))
|
||||
})
|
||||
ipcMain.on('printStart', () => {
|
||||
console.log('开始打印')
|
||||
subMainWindow.webContents.print({
|
||||
silent: true
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user