|
@@ -7,6 +7,7 @@ import {PrintEvent} from "../event/PrintEvent";
|
|
|
import {Channel} from "../channel/Channel";
|
|
import {Channel} from "../channel/Channel";
|
|
|
import {PrintTaskQueue} from "../utils/PrintTaskQueue";
|
|
import {PrintTaskQueue} from "../utils/PrintTaskQueue";
|
|
|
import {randomUUID} from "node:crypto";
|
|
import {randomUUID} from "node:crypto";
|
|
|
|
|
+import { appConfigService } from './database/AppConfigService'
|
|
|
/**
|
|
/**
|
|
|
* 打印服务
|
|
* 打印服务
|
|
|
*/
|
|
*/
|
|
@@ -59,17 +60,27 @@ class PrintService {
|
|
|
|
|
|
|
|
async printData(data: any) {
|
|
async printData(data: any) {
|
|
|
return new Promise(async (resolve, reject) => {
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
|
+ const appConfig = await appConfigService.getConfig()
|
|
|
getMainWindow().webContents.send(Channel.PRINT_START)
|
|
getMainWindow().webContents.send(Channel.PRINT_START)
|
|
|
const printWindow = new BrowserWindow({ show: false });
|
|
const printWindow = new BrowserWindow({ show: false });
|
|
|
const printData = `<html><body>${data.html}</body></html>`
|
|
const printData = `<html><body>${data.html}</body></html>`
|
|
|
getMainWindow().webContents.send(Channel.PRINT_DATA, printData)
|
|
getMainWindow().webContents.send(Channel.PRINT_DATA, printData)
|
|
|
await printWindow.loadURL(`data:text/html, ${printData}`);
|
|
await printWindow.loadURL(`data:text/html, ${printData}`);
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ const deviceName = appConfig ? appConfig.defaultPrintName ? appConfig.defaultPrintName : '' : ''
|
|
|
|
|
+ if (!deviceName) {
|
|
|
|
|
+ getMainWindow().webContents.send(Channel.PRINT_RESULT, {
|
|
|
|
|
+ success: false,
|
|
|
|
|
+ failureReason: '未找到默认打印机'
|
|
|
|
|
+ })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
printWindow.webContents.on('did-finish-load', () => {
|
|
printWindow.webContents.on('did-finish-load', () => {
|
|
|
getMainWindow().webContents.send(Channel.PRINT_PROGRESS)
|
|
getMainWindow().webContents.send(Channel.PRINT_PROGRESS)
|
|
|
printWindow.webContents.print({
|
|
printWindow.webContents.print({
|
|
|
silent: true,
|
|
silent: true,
|
|
|
printBackground: true,
|
|
printBackground: true,
|
|
|
- deviceName: data.deviceName ,
|
|
|
|
|
|
|
+ deviceName: deviceName,
|
|
|
margins:data.margins||{
|
|
margins:data.margins||{
|
|
|
marginType :'none'
|
|
marginType :'none'
|
|
|
},
|
|
},
|