优化订单打印
This commit is contained in:
parent
e13727e6ff
commit
0c45fd9de1
|
|
@ -20,10 +20,10 @@ VITE_API_PHP_URL = 'https://newblockwlx.sxczgkj.cn/index.php/api'
|
|||
VITE_API_KP_URL = 'https://invoice.sxczgkj.cn/api'
|
||||
|
||||
# 本地调试连接
|
||||
VITE_API_URL = 'http://192.168.1.31/'
|
||||
# VITE_API_URL = 'http://192.168.1.31/'
|
||||
|
||||
# 线上测试
|
||||
# VITE_API_URL = 'https://tapi.cashier.sxczgkj.cn'
|
||||
|
||||
# 线上正式
|
||||
# VITE_API_URL = 'https://cashier.sxczgkj.com'
|
||||
VITE_API_URL = 'https://cashier.sxczgkj.com'
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "vite-electron",
|
||||
"private": true,
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.3",
|
||||
"main": "dist-electron/main.js",
|
||||
"scripts": {
|
||||
"dev": "chcp 65001 && vite",
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@ export const useGoods = defineStore("goods", {
|
|||
this.goodsListLoading = false;
|
||||
this.goodsList = [];
|
||||
this.originGoodsList = [];
|
||||
|
||||
useStorage.del("printList");
|
||||
},
|
||||
// 清除会员信息
|
||||
clearVipUserInfo() {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export const useSocket = defineStore("socket", {
|
|||
orderList: [],
|
||||
orderListTimer: null,
|
||||
log: false,
|
||||
isPrinting: false,
|
||||
}),
|
||||
actions: {
|
||||
// 关闭ws
|
||||
|
|
@ -147,11 +148,15 @@ export const useSocket = defineStore("socket", {
|
|||
}
|
||||
} else if (data.data_type == "order") {
|
||||
// 收到订单消息,打印订单小票
|
||||
if (!this.orderList.some((el) => el == data.data)) {
|
||||
let printList = useStorage.get("printList") || [];
|
||||
if (!printList.some((el) => el == data.data)) {
|
||||
// 防止重复打印
|
||||
this.orderList.push(data.data);
|
||||
this.startPrintInterval();
|
||||
}
|
||||
|
||||
printList.push(data.data);
|
||||
useStorage.set("printList", _.uniq(printList));
|
||||
} else if (data.data_type == "product_update") {
|
||||
// 商品更新
|
||||
this.updateGoods();
|
||||
|
|
@ -189,28 +194,35 @@ export const useSocket = defineStore("socket", {
|
|||
},
|
||||
// 打印队列开始执行
|
||||
startPrintInterval() {
|
||||
if (this.isPrinting) return; // 如果正在打印,直接返回
|
||||
this.isPrinting = true; // 标记为正在打印
|
||||
|
||||
const printStore = usePrint();
|
||||
if (this.orderListTimer !== null) return;
|
||||
this.orderListTimer = setInterval(async () => {
|
||||
const printNextOrder = async () => {
|
||||
try {
|
||||
if (!this.orderList.length) {
|
||||
clearInterval(this.orderListTimer);
|
||||
this.orderListTimer = null;
|
||||
} else {
|
||||
const orderInfo = await getOrderByIdAjax(this.orderList[0]);
|
||||
if (orderInfo.status == "done" && orderInfo.platformType != "PC") {
|
||||
// 打印小票
|
||||
printStore.pushReceiptData(commOrderPrintData(orderInfo));
|
||||
// 打印标签小票
|
||||
printStore.labelPrint(commOrderPrintData(orderInfo));
|
||||
}
|
||||
this.orderList.splice(0, 1);
|
||||
this.isPrinting = false; // 订单处理完,标记为不在打印
|
||||
return;
|
||||
}
|
||||
const orderInfo = await getOrderByIdAjax(this.orderList[0]);
|
||||
if (orderInfo.status == "done" && orderInfo.platformType != "PC") {
|
||||
// 打印小票
|
||||
printStore.pushReceiptData(commOrderPrintData(orderInfo));
|
||||
// 打印标签小票
|
||||
printStore.labelPrint(commOrderPrintData(orderInfo));
|
||||
}
|
||||
} catch (error) {
|
||||
this.orderList.splice(0, 1);
|
||||
// 递归调用打印下一个订单
|
||||
setTimeout(printNextOrder, 2000);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
// 发生错误时继续尝试下一个订单
|
||||
this.orderList.splice(0, 1);
|
||||
setTimeout(printNextOrder, 2000);
|
||||
}
|
||||
}, 2000);
|
||||
};
|
||||
// 开始打印第一个订单
|
||||
printNextOrder();
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<div class="device_container">
|
||||
<div class="device_container" v-loading="requestLoading">
|
||||
<div class="header" @click="router.back()">
|
||||
<el-icon style="position: relative; top: 2px; margin-right: 4px" size="22">
|
||||
<ArrowLeft />
|
||||
|
|
@ -139,6 +139,7 @@ const route = useRoute();
|
|||
const printList = ref([]);
|
||||
const feets = ref([0, 1, 2, 3, 4, 5, 8]);
|
||||
const loading = ref(false);
|
||||
const requestLoading = ref(false);
|
||||
const form = ref({
|
||||
id: "",
|
||||
name: '', // 设备名称
|
||||
|
|
@ -244,11 +245,13 @@ async function submitHandle() {
|
|||
// 查询打印机详情
|
||||
async function tbPrintMachineDetailAjax(id) {
|
||||
try {
|
||||
requestLoading.value = true;
|
||||
const res = await printerDetail({ id: id });
|
||||
form.value = res;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
requestLoading.value = false;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<div class="device_container">
|
||||
<div class="device_container" v-loading="requestLoading">
|
||||
<div class="header" @click="router.back()">
|
||||
<el-icon style="position: relative; top: 2px; margin-right: 4px" size="22">
|
||||
<ArrowLeft />
|
||||
|
|
@ -125,6 +125,7 @@ const classifyRef = ref(null);
|
|||
const printList = ref([]);
|
||||
const feets = ref([0, 1, 2, 3, 4, 5, 8]);
|
||||
const loading = ref(false);
|
||||
const requestLoading = ref(false);
|
||||
const form = ref({
|
||||
id: "",
|
||||
name: '', // 设备名称
|
||||
|
|
@ -210,6 +211,7 @@ async function submitHandle() {
|
|||
// 查询打印机详情
|
||||
async function tbPrintMachineDetailAjax() {
|
||||
try {
|
||||
requestLoading.value = true;
|
||||
const res = await printerDetail({ id: route.query.id });
|
||||
form.value = res;
|
||||
|
||||
|
|
@ -228,6 +230,7 @@ async function tbPrintMachineDetailAjax() {
|
|||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
requestLoading.value = false;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue