This commit is contained in:
parent
f1982a73f6
commit
51fe3266ce
|
|
@ -1,87 +1 @@
|
||||||
"use strict";
|
"use strict";const r=require("path"),e=require("electron");let t;e.app.whenReady().then(()=>{t=new e.BrowserWindow({title:"银收客",width:1024,height:768,fullscreenable:!0,fullscreen:!process.env.VITE_DEV_SERVER_URL,simpleFullscreen:!0,frame:!!process.env.VITE_DEV_SERVER_URL,webPreferences:{nodeIntegration:!0,contextIsolation:!1}}),process.env.VITE_DEV_SERVER_URL?t.loadURL(process.env.VITE_DEV_SERVER_URL):t.loadFile(r.resolve(__dirname,"../dist/index.html")),e.app.on("activate",()=>{e.BrowserWindow.getAllWindows().length===0&&createWindow()}),e.ipcMain.on("quitHandler",(o,n)=>{e.app.quit()}),e.ipcMain.on("getPrintList",()=>{t.webContents.getPrintersAsync().then(o=>{t.webContents.send("printList",o)})});const i=new e.BrowserWindow({show:!1,width:464,height:2206,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?i.loadFile(r.join(__dirname,"../public/print.html")):i.loadFile(r.resolve(__dirname,"../dist/print.html")),e.ipcMain.on("printerInfoSync",(o,n)=>{i.webContents.send("getParams",n)}),e.ipcMain.on("printStart",(o,n)=>{console.log(n);const s=JSON.parse(n);console.log(s);let a=s.deviceName;i.webContents.print({silent:!0,deviceName:a,pageSize:{width:58e3,height:276e3},scaleFactor:80,landscape:!1,margins:{marginType:"none",top:0,bottom:0,left:0,right:0},dpi:{horizontal:203,vertical:203}})})});e.app.on("window-all-closed",()=>{process.platform!=="darwin"&&e.app.quit()});
|
||||||
const path = require("path");
|
|
||||||
const electron = require("electron");
|
|
||||||
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("getPrintList", () => {
|
|
||||||
win.webContents.getPrintersAsync().then((res) => {
|
|
||||||
win.webContents.send("printList", res);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
const printWin = new electron.BrowserWindow({
|
|
||||||
show: false,
|
|
||||||
width: 464,
|
|
||||||
height: 2206,
|
|
||||||
webPreferences: {
|
|
||||||
// 集成网页和 Node.js,也就是在渲染进程中,可以调用 Node.js 方法
|
|
||||||
nodeIntegration: true,
|
|
||||||
contextIsolation: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (process.env.VITE_DEV_SERVER_URL) {
|
|
||||||
printWin.loadFile(path.join(__dirname, "../public/print.html"));
|
|
||||||
} else {
|
|
||||||
printWin.loadFile(path.resolve(__dirname, "../dist/print.html"));
|
|
||||||
}
|
|
||||||
electron.ipcMain.on("printerInfoSync", (event, arg) => {
|
|
||||||
printWin.webContents.send("getParams", arg);
|
|
||||||
});
|
|
||||||
electron.ipcMain.on("printStart", (event, arg) => {
|
|
||||||
console.log(arg);
|
|
||||||
const _parmas = JSON.parse(arg);
|
|
||||||
console.log(_parmas);
|
|
||||||
let name = _parmas.deviceName;
|
|
||||||
printWin.webContents.print({
|
|
||||||
silent: true,
|
|
||||||
deviceName: name,
|
|
||||||
pageSize: {
|
|
||||||
width: 58e3,
|
|
||||||
height: 276e3
|
|
||||||
},
|
|
||||||
scaleFactor: 80,
|
|
||||||
landscape: false,
|
|
||||||
margins: {
|
|
||||||
marginType: "none",
|
|
||||||
top: 0,
|
|
||||||
bottom: 0,
|
|
||||||
left: 0,
|
|
||||||
right: 0
|
|
||||||
},
|
|
||||||
dpi: {
|
|
||||||
horizontal: 203,
|
|
||||||
vertical: 203
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
electron.app.on("window-all-closed", () => {
|
|
||||||
if (process.platform !== "darwin")
|
|
||||||
electron.app.quit();
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "vite-electron",
|
"name": "vite-electron",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.0.18",
|
"version": "1.0.20",
|
||||||
"main": "dist-electron/main.js",
|
"main": "dist-electron/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "chcp 65001 && vite",
|
"dev": "chcp 65001 && vite",
|
||||||
|
|
|
||||||
|
|
@ -151,47 +151,47 @@ async function bySubTypeAjax() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function printHandle() {
|
async function printHandle() {
|
||||||
|
// try {
|
||||||
|
// if (!isPrint.value) return;
|
||||||
|
// if (printList.value.length) {
|
||||||
|
// const data = {
|
||||||
|
// shop_name: store.userInfo.merchantName,
|
||||||
|
// carts: props.cart,
|
||||||
|
// amount: props.amount,
|
||||||
|
// remark: props.remark,
|
||||||
|
// orderInfo: props.orderInfo,
|
||||||
|
// deviceName: printList.value[0].config.deviceName,
|
||||||
|
// createdAt: dayjs(props.orderInfo.createdAt).format(
|
||||||
|
// "YYYY-MM-DD HH:mm:ss"
|
||||||
|
// ),
|
||||||
|
// printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
// };
|
||||||
|
// ipcRenderer.send("printerInfoSync", JSON.stringify(data));
|
||||||
|
// } else {
|
||||||
|
// ElMessage.error("您还没有添加打印设备");
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// console.log(error);
|
||||||
|
// }
|
||||||
try {
|
try {
|
||||||
if (!isPrint.value) return;
|
printLoading.value = true;
|
||||||
if (printList.value.length) {
|
await print({
|
||||||
const data = {
|
type: "normal",
|
||||||
shop_name: store.userInfo.merchantName,
|
ispre: true,
|
||||||
carts: props.cart,
|
orderId: props.orderInfo.id,
|
||||||
amount: props.amount,
|
});
|
||||||
remark: props.remark,
|
printLoading.value = false;
|
||||||
orderInfo: props.orderInfo,
|
ElMessage.success("打印成功");
|
||||||
deviceName: printList.value[0].config.deviceName,
|
|
||||||
createdAt: dayjs(props.orderInfo.createdAt).format(
|
|
||||||
"YYYY-MM-DD HH:mm:ss"
|
|
||||||
),
|
|
||||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
|
||||||
};
|
|
||||||
ipcRenderer.send("printerInfoSync", JSON.stringify(data));
|
|
||||||
} else {
|
|
||||||
ElMessage.error("您还没有添加打印设备");
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
printLoading.value = false;
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
// try {
|
|
||||||
// printLoading.value = true
|
|
||||||
// await print({
|
|
||||||
// type: 'normal',
|
|
||||||
// ispre: true,
|
|
||||||
// orderId: props.orderInfo.id
|
|
||||||
// })
|
|
||||||
// printLoading.value = false
|
|
||||||
// ElMessage.success('打印成功')
|
|
||||||
// } catch (error) {
|
|
||||||
// printLoading.value = false
|
|
||||||
// console.log(error)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 订单已支付
|
// 订单已支付
|
||||||
function paySuccess() {
|
function paySuccess() {
|
||||||
dialogVisible.value = false;
|
dialogVisible.value = false;
|
||||||
printHandle();
|
// printHandle();
|
||||||
emit("paySuccess");
|
emit("paySuccess");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue