优化打印机
This commit is contained in:
parent
a57b45160e
commit
ca4eec636a
|
|
@ -1 +1,87 @@
|
||||||
"use strict";const s=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(s.resolve(__dirname,"../dist/index.html")),e.app.on("activate",()=>{e.BrowserWindow.getAllWindows().length===0&&createWindow()}),e.ipcMain.on("quitHandler",(i,r)=>{e.app.quit()}),e.ipcMain.on("getPrintList",()=>{t.webContents.getPrintersAsync().then(i=>{t.webContents.send("printList",i)})});const n=new e.BrowserWindow({show:!0,width:464,height:2206,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?n.loadFile(s.join(__dirname,"../public/print.html")):n.loadFile(s.resolve(__dirname,"../dist/print.html")),e.ipcMain.on("printerInfoSync",(i,r)=>{n.webContents.send("getParams",r)}),n.on("printStart",(i,r)=>{let o=JSON.parse(r).deviceName;n.webContents.print({silent:!0,deviceName:o,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()});
|
"use strict";
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ app.whenReady().then(() => {
|
||||||
|
|
||||||
// 创建打印小票子窗口
|
// 创建打印小票子窗口
|
||||||
const printWin = new BrowserWindow({
|
const printWin = new BrowserWindow({
|
||||||
show: true,
|
show: false,
|
||||||
width: 464,
|
width: 464,
|
||||||
height: 2206,
|
height: 2206,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
|
|
@ -71,8 +71,10 @@ app.whenReady().then(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
// 执行打印操作
|
// 执行打印操作
|
||||||
printWin.on('printStart', (event, arg) => {
|
ipcMain.on('printStart', (event, arg) => {
|
||||||
|
console.log(arg);
|
||||||
const _parmas = JSON.parse(arg)
|
const _parmas = JSON.parse(arg)
|
||||||
|
console.log(_parmas)
|
||||||
let name = _parmas.deviceName
|
let name = _parmas.deviceName
|
||||||
printWin.webContents.print({
|
printWin.webContents.print({
|
||||||
silent: true,
|
silent: true,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "vite-electron",
|
"name": "vite-electron",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.0.14",
|
"version": "1.0.18",
|
||||||
"main": "dist-electron/main.js",
|
"main": "dist-electron/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "chcp 65001 && vite",
|
"dev": "chcp 65001 && vite",
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,13 @@
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<div class="print_view">
|
<div class="print_view">
|
||||||
<div class="title t1">{{data.shop_name}}</div>
|
<div class="title t1">{{data.shop_name}}</div>
|
||||||
<div class="title t2">结算单【{{data.carts[0].masterId}}】</div>
|
<div class="title t2">
|
||||||
<div class="row">订单号:202404021023542223445</div>
|
结算单【{{data.orderInfo && data.orderInfo.masterId}}】
|
||||||
<div class="row">交易时间:2024-04-02 10:15</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
订单号:{{data.orderInfo && data.orderInfo.orderNo}}
|
||||||
|
</div>
|
||||||
|
<div class="row">交易时间:{{data.createdAt}}</div>
|
||||||
<div class="row">收银员:【POS-1】1</div>
|
<div class="row">收银员:【POS-1】1</div>
|
||||||
<div class="line"></div>
|
<div class="line"></div>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
|
|
@ -38,14 +42,14 @@
|
||||||
<div class="line"></div>
|
<div class="line"></div>
|
||||||
<div class="row between">
|
<div class="row between">
|
||||||
<span>合计:</span>
|
<span>合计:</span>
|
||||||
<span>30.00</span>
|
<span>{{data.amount}}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="row between">
|
<!-- <div class="row between">
|
||||||
<span>合计:</span>
|
<span>合计:</span>
|
||||||
<span>30.00</span>
|
<span>30.00</span>
|
||||||
</div>
|
</div> -->
|
||||||
<div class="row between">
|
<div class="row between">
|
||||||
<span>原价:20.00,节省了0</span>
|
<span>原价:{{data.amount}},节省了0</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="row between">
|
<div class="row between">
|
||||||
<span>积分:</span>
|
<span>积分:</span>
|
||||||
|
|
@ -57,7 +61,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="line"></div>
|
<div class="line"></div>
|
||||||
<div class="row">备注:</div>
|
<div class="row">备注:</div>
|
||||||
<div class="row">打印时间:2024-04-02 10:15</div>
|
<div class="row">打印时间:{{data.printTime}}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
|
|
@ -77,9 +81,12 @@
|
||||||
data.value = JSON.parse(arg);
|
data.value = JSON.parse(arg);
|
||||||
console.log(data.value);
|
console.log(data.value);
|
||||||
|
|
||||||
// setTimeout(() => {
|
setTimeout(() => {
|
||||||
// ipcRenderer.send("printStart");
|
ipcRenderer.send(
|
||||||
// }, 500);
|
"printStart",
|
||||||
|
JSON.stringify({ deviceName: data.value.deviceName })
|
||||||
|
);
|
||||||
|
}, 500);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,3 +50,16 @@ export function tbPrintMachineDelete(params) {
|
||||||
params
|
params
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据类型查询打印机列表
|
||||||
|
* @param {*} params
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function bySubType(params) {
|
||||||
|
return request({
|
||||||
|
method: "get",
|
||||||
|
url: "/tbPrintMachine/bySubType",
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -192,7 +192,7 @@ const form = ref({
|
||||||
},
|
},
|
||||||
name: "小票打印机",
|
name: "小票打印机",
|
||||||
subType: "cash", // 打印类型
|
subType: "cash", // 打印类型
|
||||||
status: 0,
|
status: 1,
|
||||||
sort: "",
|
sort: "",
|
||||||
shopId: store.userInfo.shopId,
|
shopId: store.userInfo.shopId,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@
|
||||||
inline-prompt
|
inline-prompt
|
||||||
active-text="开"
|
active-text="开"
|
||||||
inactive-text="关"
|
inactive-text="关"
|
||||||
:active-value="0"
|
:active-value="1"
|
||||||
:inactive-value="1"
|
:inactive-value="0"
|
||||||
width="90"
|
width="90"
|
||||||
@change="statusChange($event, item)"
|
@change="statusChange($event, item)"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -92,10 +92,11 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from "vue";
|
import { onMounted, ref } from "vue";
|
||||||
import { useUser } from "@/store/user.js";
|
import { useUser } from "@/store/user.js";
|
||||||
import payCard from "@/components/payCard/payCard.vue";
|
import payCard from "@/components/payCard/payCard.vue";
|
||||||
import { print } from "@/api/pay";
|
import { print } from "@/api/pay";
|
||||||
|
import { bySubType } from "@/api/device";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
|
@ -133,17 +134,45 @@ const props = defineProps({
|
||||||
|
|
||||||
const isPrint = ref(true);
|
const isPrint = ref(true);
|
||||||
|
|
||||||
|
const printList = ref([]);
|
||||||
|
|
||||||
|
// 获取打印机状态
|
||||||
|
async function bySubTypeAjax() {
|
||||||
|
try {
|
||||||
|
const res = await bySubType({
|
||||||
|
shopId: store.userInfo.shopId,
|
||||||
|
contentType: "local",
|
||||||
|
subType: "cash",
|
||||||
|
});
|
||||||
|
printList.value = res;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function printHandle() {
|
async function printHandle() {
|
||||||
|
try {
|
||||||
if (!isPrint.value) return;
|
if (!isPrint.value) return;
|
||||||
|
if (printList.value.length) {
|
||||||
const data = {
|
const data = {
|
||||||
shop_name: store.userInfo.merchantName,
|
shop_name: store.userInfo.merchantName,
|
||||||
carts: props.cart,
|
carts: props.cart,
|
||||||
amount: props.amount,
|
amount: props.amount,
|
||||||
remark: props.remark,
|
remark: props.remark,
|
||||||
orderInfo: props.orderInfo,
|
orderInfo: props.orderInfo,
|
||||||
deviceName: printForm.value.deviceName,
|
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));
|
ipcRenderer.send("printerInfoSync", JSON.stringify(data));
|
||||||
|
} else {
|
||||||
|
ElMessage.error("您还没有添加打印设备");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
// try {
|
// try {
|
||||||
// printLoading.value = true
|
// printLoading.value = true
|
||||||
// await print({
|
// await print({
|
||||||
|
|
@ -162,6 +191,7 @@ async function printHandle() {
|
||||||
// 订单已支付
|
// 订单已支付
|
||||||
function paySuccess() {
|
function paySuccess() {
|
||||||
dialogVisible.value = false;
|
dialogVisible.value = false;
|
||||||
|
printHandle();
|
||||||
emit("paySuccess");
|
emit("paySuccess");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,6 +202,10 @@ function show() {
|
||||||
defineExpose({
|
defineExpose({
|
||||||
show,
|
show,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
bySubTypeAjax();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
||||||
|
|
@ -331,8 +331,8 @@ async function addCart(params, type = "add") {
|
||||||
shopId: store.userInfo.shopId,
|
shopId: store.userInfo.shopId,
|
||||||
skuId: type == "add" ? params.id : params.skuId,
|
skuId: type == "add" ? params.id : params.skuId,
|
||||||
number: params.number || 1,
|
number: params.number || 1,
|
||||||
isPack: allSelected.value ? true : params.isPack || false,
|
isPack: params.isPack || "false",
|
||||||
isGift: params.isGift || false,
|
isGift: params.isGift || 'false',
|
||||||
cartId: type == "add" ? "" : params.id,
|
cartId: type == "add" ? "" : params.id,
|
||||||
uuid: params.uuid || store.userInfo.uuid,
|
uuid: params.uuid || store.userInfo.uuid,
|
||||||
type: type,
|
type: type,
|
||||||
|
|
@ -367,6 +367,8 @@ async function queryCartAjax() {
|
||||||
});
|
});
|
||||||
if (i == res.list.length) {
|
if (i == res.list.length) {
|
||||||
allSelected.value = true;
|
allSelected.value = true;
|
||||||
|
} else {
|
||||||
|
allSelected.value = false;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("获取购物车商品", error);
|
console.log("获取购物车商品", error);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue