// 打印方法
print = () => {
//const electron = require("electron"); // electrong原始配置
const electron = window.electron; //react 配置用法
var BrowserWindow = electron.remote.BrowserWindow;
var printResultWindow = new BrowserWindow({
show: false, //打印窗口不展示
webPreferences: {
nodeIntegration: true
}
});
// 打印地址
printResultWindow.loadFile(‘./src/print.html‘);
//需要传参子页面的数据
printResultWindow.webContents.on(‘did-finish-load‘, function () {
printResultWindow.webContents.send(‘dataJsonPort‘, { a: "呵呵呵" });
});
printResultWindow.once(‘ready-to-show‘, () => {
printResultWindow.setAlwaysOnTop(true);
setTimeout(() => { //页面加载完成后一秒后开始倒计时,可以不要
printResultWindow.webContents.print(
{
silent: false,
printBackground: false
},
(data) => {
console.log("回调", data);
});
}, 1000);
})
}
// electron接收参数方法
let = { remote, ipcRenderer } = require(‘electron‘);
ipcRenderer.on(‘dataJsonPort‘, function (event, message) { // 监听父页面定义的端口
document.getElementById("test").innerHTML = message.a
// initTable(message, pIndex); //把数据传给函数 initTable
});