This commit is contained in:
gyq
2024-03-11 14:34:17 +08:00
parent 11290d1505
commit 0fbc614c61
13 changed files with 156 additions and 217 deletions

View File

@@ -22,7 +22,7 @@ app.whenReady().then(() => {
if (process.env.VITE_DEV_SERVER_URL) {
win.loadURL(process.env.VITE_DEV_SERVER_URL);
// 使用vite开发服务的url路径访问应用
// win.webContents.openDevTools();
win.webContents.openDevTools();
} else {
win.loadFile(path.resolve(__dirname, "../dist/index.html")); // 打包后使用文件路径访问应用
}
@@ -40,36 +40,37 @@ app.whenReady().then(() => {
});
// 创建打印小票子窗口
const printWin = new BrowserWindow({
show: false,
webPreferences: {
// 集成网页和 Node.js也就是在渲染进程中可以调用 Node.js 方法
nodeIntegration: true,
contextIsolation: false,
},
});
// 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")); // 打包后使用文件路径访问应用
}
// 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")); // 打包后使用文件路径访问应用
// }
// win.webContents.getPrintersAsync().then(res => {
// console.log('list', res)
// // console.log('list', res)
// })
ipcMain.on("printerInfoSync", (event, params) => {
// console.log(JSON.parse(params))
printWin.webContents.send("getParams", params);
});
// ipcMain.on("printerInfoSync", (event, params) => {
// // console.log(JSON.parse(params))
// printWin.webContents.send("getParams", params);
// });
// 执行打印操作
ipcMain.on('printStart', () => {
console.log('开始打印')
ipcMain.on('printStart', (event, arg) => {
// console.log('开始打印', arg)
let name = 'RONGTA 80mm Series Printer'
// let name = 'Xprinter XP-365B'
// // let name = 'Generic / Text Only'
// printWin.webContents.print({
// silent: true,