cashier_desktop/dist-electron/main.js

135 lines
3.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
const path = require("path");
const electron = require("electron");
const { PosPrinter } = require("electron-pos-printer-vue");
let win;
electron.app.whenReady().then(() => {
win = new electron.BrowserWindow({
title: "银收客",
width: 1024,
height: 768,
fullscreenable: true,
fullscreen: process.env.VITE_DEV_SERVER_URL ? false : true,
simpleFullscreen: true,
frame: process.env.VITE_DEV_SERVER_URL ? true : false,
webPreferences: {
// 集成网页和 Node.js也就是在渲染进程中可以调用 Node.js 方法
nodeIntegration: true,
contextIsolation: false
}
});
if (process.env.VITE_DEV_SERVER_URL) {
win.loadURL(process.env.VITE_DEV_SERVER_URL);
} else {
win.loadFile(path.resolve(__dirname, "../dist/index.html"));
}
electron.app.on("activate", () => {
if (electron.BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
electron.ipcMain.on("quitHandler", (_, msg) => {
electron.app.quit();
});
electron.ipcMain.on("printStart", (event, arg) => {
console.log("开始打印", arg);
let name = "Xprinter XP-365B";
const options = {
silent: true,
preview: false,
// width of content body
margin: "0 0 0 0",
// margin of content body
copies: 1,
// Number of copies to print
printerName: name,
// printerName: string, check with webContent.getPrinters()
// timeOutPerLine: 400,
pageSize: { height: 22860, width: 30480 }
// page size
};
const data = [
{
type: "text",
// 'text' | 'barCode' | 'qrCode' | 'image' | 'table
value: "#B5 B6",
style: { "font-weight": "700", "font-size": "18px" }
},
{
type: "text",
// 'text' | 'barCode' | 'qrCode' | 'image' | 'table
value: "#B5 B6",
style: { "font-weight": "700", "font-size": "18px" }
},
{
type: "text",
// 'text' | 'barCode' | 'qrCode' | 'image' | 'table
value: "#B5 B6",
style: { "font-weight": "700", "font-size": "18px" }
},
{
type: "text",
// 'text' | 'barCode' | 'qrCode' | 'image' | 'table
value: "#B5 B6",
style: { "font-weight": "700", "font-size": "18px" }
},
{
type: "text",
// 'text' | 'barCode' | 'qrCode' | 'image' | 'table
value: "#B5 B6",
style: { "font-weight": "700", "font-size": "18px" }
},
{
type: "text",
// 'text' | 'barCode' | 'qrCode' | 'image' | 'table
value: "#B5 B6",
style: { "font-weight": "700", "font-size": "18px" }
},
{
type: "text",
// 'text' | 'barCode' | 'qrCode' | 'image' | 'table
value: "#B5 B6",
style: { "font-weight": "700", "font-size": "18px" }
},
{
type: "text",
// 'text' | 'barCode' | 'qrCode' | 'image' | 'table
value: "#B5 B6",
style: { "font-weight": "700", "font-size": "18px" }
},
{
type: "text",
// 'text' | 'barCode' | 'qrCode' | 'image' | 'table
value: "#B5 B6",
style: { "font-weight": "700", "font-size": "18px" }
},
{
type: "text",
// 'text' | 'barCode' | 'qrCode' | 'image' | 'table'
value: "喔喔奶茶 x100",
style: { "font-size": "18px" }
},
{
type: "text",
// 'text' | 'barCode' | 'qrCode' | 'image' | 'table'
value: "麻辣味",
style: { "font-size": "18px" }
},
{
type: "text",
// 'text' | 'barCode' | 'qrCode' | 'image' | 'table'
value: "03-08 16:32 ¥123.00",
style: { "font-size": "18px" }
}
];
PosPrinter.print(data, options).then(() => {
}).catch((error) => {
console.error(error);
});
});
});
electron.app.on("window-all-closed", () => {
if (process.platform !== "darwin")
electron.app.quit();
});