优化打印

This commit is contained in:
gyq
2024-05-23 14:24:41 +08:00
parent d08ef6f271
commit 6df40c8423
2 changed files with 130 additions and 14 deletions

View File

@@ -107,6 +107,7 @@ const props = defineProps({
const isPrint = ref(true);
const printList = ref([]);
const localPrintList = ref([])
// 获取打印机状态
async function bySubTypeAjax() {
@@ -122,24 +123,53 @@ async function bySubTypeAjax() {
}
}
// 获取本地打印机列表
function getPrintList() {
ipcRenderer.send("getPrintList");
ipcRenderer.on("printList", (event, arg) => {
localPrintList.value = arg;
console.log(localPrintList.value);
});
}
// 检查本地打印机是否能正常使用
function checkLocalPrint(deviceName) {
let print = ''
for (let item of localPrintList.value) {
if (item.name == deviceName) {
print = item
}
}
if (!print.name || !print.status) {
return false
} else {
return true
}
}
// 打印操作
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));
if (!checkLocalPrint(printList.value[0].config.deviceName)) {
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
} else {
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("您还没有添加本地打印设备,将使用网络打印");
try {
@@ -177,6 +207,7 @@ defineExpose({
});
onMounted(() => {
getPrintList();
bySubTypeAjax();
});
</script>