新增本地USB打印
This commit is contained in:
@@ -3,6 +3,7 @@ import { ipcRenderer } from "electron";
|
||||
import { bySubType } from "@/api/device";
|
||||
import { useUser } from "@/store/user.js";
|
||||
import dayjs from "dayjs";
|
||||
import receiptPrint from "@/components/lodop/receiptPrint.js";
|
||||
|
||||
export const usePrint = defineStore({
|
||||
id: "print",
|
||||
@@ -12,6 +13,8 @@ export const usePrint = defineStore({
|
||||
deviceLableList: [], // 添加的打印机
|
||||
labelList: [], // 要打印的队列数据
|
||||
printTimer: null,
|
||||
receiptList: [], // 小票队列数据
|
||||
receiptTimer: null,
|
||||
}),
|
||||
actions: {
|
||||
// 获取本地打印机和已添加的可以用打印机列表
|
||||
@@ -98,7 +101,7 @@ export const usePrint = defineStore({
|
||||
// 执行打印操作
|
||||
this.startLabelPrint();
|
||||
} else {
|
||||
console.log("没有打印机");
|
||||
console.log("没有标签打印机");
|
||||
}
|
||||
},
|
||||
// 开始打印标签数据
|
||||
@@ -119,5 +122,43 @@ export const usePrint = defineStore({
|
||||
}
|
||||
}, 800);
|
||||
},
|
||||
// 添加小票打印对列表数据
|
||||
pushReceiptData(props) {
|
||||
if (
|
||||
this.deviceNoteList.length &&
|
||||
this.checkLocalPrint(this.deviceNoteList[0].config.deviceName)
|
||||
) {
|
||||
console.log(props);
|
||||
|
||||
const store = useUser();
|
||||
props.deviceName = this.deviceNoteList[0].config.deviceName;
|
||||
props.shop_name = store.userInfo.shopName;
|
||||
props.loginAccount = store.userInfo.loginAccount;
|
||||
props.createdAt = dayjs(props.createdAt).format("YYYY-MM-DD HH:mm:ss");
|
||||
props.printTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
||||
if (!props.orderInfo.masterId) {
|
||||
props.orderInfo.masterId = props.orderInfo.tableName;
|
||||
}
|
||||
props.orderInfo.outNumber = props.outNumber;
|
||||
|
||||
this.receiptList.push(props);
|
||||
this.startReceiptPrint();
|
||||
} else {
|
||||
console.log("没有小票打印机");
|
||||
}
|
||||
},
|
||||
// 开始打印小票
|
||||
startReceiptPrint() {
|
||||
if (this.receiptTimer !== null) return;
|
||||
this.receiptTimer = setInterval(() => {
|
||||
if (!this.receiptList.length) {
|
||||
clearInterval(this.receiptTimer);
|
||||
this.receiptTimer = null;
|
||||
} else {
|
||||
receiptPrint(this.receiptList[0]);
|
||||
this.receiptList.splice(0, 1);
|
||||
}
|
||||
}, 800);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import _ from "lodash";
|
||||
import { dayjs } from "element-plus";
|
||||
import { defineStore } from "pinia";
|
||||
import { useUser } from "@/store/user.js";
|
||||
import { usePrint } from "@/store/print.js";
|
||||
@@ -96,6 +97,7 @@ export const useSocket = defineStore({
|
||||
if (!this.orderList.some((el) => el == data.orderInfo.orderNo)) {
|
||||
// console.log("打印", data);
|
||||
printStore.labelPrint(data);
|
||||
printStore.pushReceiptData(data);
|
||||
this.orderList.push(data.orderInfo.orderNo);
|
||||
if (this.orderList.length > 30) {
|
||||
this.orderList.splice(0, 1);
|
||||
|
||||
Reference in New Issue
Block a user