优化打印标签逻辑
This commit is contained in:
parent
0b2b4b44d0
commit
44495c3ee7
|
|
@ -1 +1 @@
|
|||
"use strict";const i=require("path"),e=require("electron");let a;e.app.whenReady().then(()=>{a=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?a.loadURL(process.env.VITE_DEV_SERVER_URL):a.loadFile(i.resolve(__dirname,"../dist/index.html")),e.app.on("activate",()=>{e.BrowserWindow.getAllWindows().length===0&&createWindow()}),e.ipcMain.on("quitHandler",(t,n)=>{e.app.quit()}),e.ipcMain.on("getPrintList",()=>{a.webContents.getPrintersAsync().then(t=>{a.webContents.send("printList",t)})});const o=new e.BrowserWindow({show:!1,width:464,height:1726,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?o.loadFile(i.join(__dirname,"../public/print.html")):o.loadFile(i.resolve(__dirname,"../dist/print.html")),e.ipcMain.on("printerInfoSync",(t,n)=>{o.webContents.send("getParams",n)}),e.ipcMain.on("printStart",(t,n)=>{console.log(n);let r=JSON.parse(n).deviceName;o.webContents.print({silent:!0,deviceName:r,pageSize:{width:58e3,height:216e3},scaleFactor:80,landscape:!1,margins:{marginType:"none",top:0,bottom:0,left:0,right:0},dpi:{horizontal:203,vertical:203}})});const s=new e.BrowserWindow({show:!1,width:464,height:1726,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?s.loadFile(i.join(__dirname,"../public/work_print.html")):s.loadFile(i.resolve(__dirname,"../dist/work_print.html")),e.ipcMain.on("printerWorkSync",(t,n)=>{s.webContents.send("getParams",n)}),e.ipcMain.on("printWorkStart",(t,n)=>{let r=JSON.parse(n).deviceName;s.webContents.print({silent:!0,deviceName:r,pageSize:{width:58e3,height:216e3},scaleFactor:80,landscape:!1,margins:{marginType:"none",top:0,bottom:0,left:0,right:0},dpi:{horizontal:203,vertical:203}})});const l=new e.BrowserWindow({show:!1,width:320,height:240,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?l.loadFile(i.join(__dirname,"../public/tag_print.html")):l.loadFile(i.resolve(__dirname,"../dist/tag_print.html")),e.ipcMain.on("printerTagSync",(t,n)=>{console.log(n),l.webContents.send("getParams",n)}),e.ipcMain.on("printTagStart",(t,n)=>{let r=JSON.parse(n).deviceName;l.webContents.print({silent:!0,deviceName:r,pageSize:{width:4e4,height:3e4},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 i=require("path"),e=require("electron");let a;e.app.whenReady().then(()=>{a=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?a.loadURL(process.env.VITE_DEV_SERVER_URL):a.loadFile(i.resolve(__dirname,"../dist/index.html")),e.app.on("activate",()=>{e.BrowserWindow.getAllWindows().length===0&&createWindow()}),e.ipcMain.on("quitHandler",(t,n)=>{e.app.quit()}),e.ipcMain.on("getPrintList",()=>{a.webContents.getPrintersAsync().then(t=>{a.webContents.send("printList",t)})});const o=new e.BrowserWindow({show:!1,width:464,height:1726,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?o.loadFile(i.join(__dirname,"../public/print.html")):o.loadFile(i.resolve(__dirname,"../dist/print.html")),e.ipcMain.on("printerInfoSync",(t,n)=>{o.webContents.send("getParams",n)}),e.ipcMain.on("printStart",(t,n)=>{console.log(n);let r=JSON.parse(n).deviceName;o.webContents.print({silent:!0,deviceName:r,pageSize:{width:58e3,height:216e3},scaleFactor:80,landscape:!1,margins:{marginType:"none",top:0,bottom:0,left:0,right:0},dpi:{horizontal:203,vertical:203}})});const s=new e.BrowserWindow({show:!1,width:464,height:1726,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?s.loadFile(i.join(__dirname,"../public/work_print.html")):s.loadFile(i.resolve(__dirname,"../dist/work_print.html")),e.ipcMain.on("printerWorkSync",(t,n)=>{s.webContents.send("getParams",n)}),e.ipcMain.on("printWorkStart",(t,n)=>{let r=JSON.parse(n).deviceName;s.webContents.print({silent:!0,deviceName:r,pageSize:{width:58e3,height:216e3},scaleFactor:80,landscape:!1,margins:{marginType:"none",top:0,bottom:0,left:0,right:0},dpi:{horizontal:203,vertical:203}})});const l=new e.BrowserWindow({show:!0,width:320,height:240,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?l.loadFile(i.join(__dirname,"../public/tag_print.html")):l.loadFile(i.resolve(__dirname,"../dist/tag_print.html")),e.ipcMain.on("printerTagSync",(t,n)=>{console.log(n),l.webContents.send("getParams",n)}),e.ipcMain.on("printTagStart",(t,n)=>{let r=JSON.parse(n).deviceName;l.webContents.print({silent:!0,deviceName:r,pageSize:{width:4e4,height:3e4},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()});
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ app.whenReady().then(() => {
|
|||
|
||||
// 标签小票的窗口
|
||||
const tagPrintWin = new BrowserWindow({
|
||||
show: false,
|
||||
show: true,
|
||||
width: 320,
|
||||
height: 240,
|
||||
webPreferences: {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "vite-electron",
|
||||
"private": true,
|
||||
"version": "1.3.5",
|
||||
"version": "1.3.6",
|
||||
"main": "dist-electron/main.js",
|
||||
"scripts": {
|
||||
"dev": "chcp 65001 && vite",
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@
|
|||
data.value = JSON.parse(arg);
|
||||
console.log(data.value);
|
||||
|
||||
let size = 40;
|
||||
let size = 46;
|
||||
let qrcode = new QRCode(document.getElementById("ewm"), {
|
||||
text: data.value.outNumber,
|
||||
width: size,
|
||||
|
|
|
|||
54
src/App.vue
54
src/App.vue
|
|
@ -32,8 +32,15 @@ import { bySubType } from "@/api/device";
|
|||
import { dayjs, ElMessage } from "element-plus";
|
||||
import { ipcRenderer } from 'electron'
|
||||
|
||||
if (!useStorage.get('uuid')) {
|
||||
useStorage.set('uuid', uuidv4())
|
||||
const uuid = ref('')
|
||||
|
||||
function createUUID() {
|
||||
if (!useStorage.get('uuid')) {
|
||||
useStorage.set('uuid', uuidv4())
|
||||
uuid.value = useStorage.get('uuid')
|
||||
} else {
|
||||
uuid.value = useStorage.get('uuid')
|
||||
}
|
||||
}
|
||||
|
||||
const store = useUser();
|
||||
|
|
@ -57,12 +64,14 @@ watch(route, (to) => {
|
|||
if (ws.value != null) {
|
||||
console.log('关闭ws');
|
||||
ws.value.close()
|
||||
ws.value = null
|
||||
wsIsClose.value = true
|
||||
}
|
||||
} else {
|
||||
// 打开ws
|
||||
console.log('打开ws');
|
||||
openWs()
|
||||
// setTimeout(() => {
|
||||
// }, 1000)
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -168,9 +177,20 @@ function checkLabelPrint(props) {
|
|||
} else {
|
||||
let pids = printLabelList.value[0].config.categoryList.map(item => item.id)
|
||||
let labelList = []
|
||||
|
||||
let count = 0
|
||||
let sum = 0
|
||||
|
||||
props.carts.map(item => {
|
||||
for (let i = 0; i < item.number; i++) {
|
||||
sum++
|
||||
}
|
||||
})
|
||||
|
||||
props.carts.map(item => {
|
||||
if (pids.some(el => el == item.categoryId)) {
|
||||
for (let i = 0; i < item.number; i++) {
|
||||
count++
|
||||
labelList.push(
|
||||
{
|
||||
outNumber: props.outNumber,
|
||||
|
|
@ -178,7 +198,8 @@ function checkLabelPrint(props) {
|
|||
skuName: item.skuName,
|
||||
masterId: props.orderInfo.tableName,
|
||||
deviceName: printLabelList.value[0].config.deviceName,
|
||||
createdAt: dayjs(props.createdAt).format('YYYY-MM-DD HH:mm:ss')
|
||||
createdAt: dayjs(props.createdAt).format('YYYY-MM-DD HH:mm:ss'),
|
||||
count: `${count}/${sum}`
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
@ -190,24 +211,13 @@ function checkLabelPrint(props) {
|
|||
}
|
||||
|
||||
// 打印标签
|
||||
let labelCount = ref(0)
|
||||
let labelPrintTimer = ref(null)
|
||||
function printLabel(list) {
|
||||
console.log(list);
|
||||
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
|
||||
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
|
||||
} else {
|
||||
labelPrintTimer.value = setInterval(() => {
|
||||
// console.log('labelCount', labelCount.value);
|
||||
list[labelCount.value].count = `${list.length - labelCount.value}/${list.length}`
|
||||
ipcRenderer.send('printerTagSync', JSON.stringify(list[labelCount.value]))
|
||||
labelCount.value++
|
||||
if (labelCount.value > list.length - 1) {
|
||||
clearInterval(labelPrintTimer.value)
|
||||
labelPrintTimer.value = null
|
||||
labelCount.value = 0
|
||||
}
|
||||
}, 1000)
|
||||
list.map(item => {
|
||||
ipcRenderer.send('printerTagSync', JSON.stringify(item))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -215,9 +225,11 @@ let ws = ref(null)
|
|||
let wsIsClose = ref(false)
|
||||
// 初始化websocket
|
||||
function initWebSocket(wsUrl = import.meta.env.VITE_API_WSS) {
|
||||
createUUID()
|
||||
|
||||
wsIsClose.value = false
|
||||
ws.value = new WebSocket(wsUrl);
|
||||
console.log("websocket:", ws.value);
|
||||
// console.log("websocket:", ws.value);
|
||||
|
||||
ws.value.onopen = function () {
|
||||
console.log('wss连接成功');
|
||||
|
|
@ -234,7 +246,7 @@ function initWebSocket(wsUrl = import.meta.env.VITE_API_WSS) {
|
|||
ws.value.send(JSON.stringify({
|
||||
type: "connect",
|
||||
shopId: store.userInfo.shopId,
|
||||
clientId: useStorage.get('uuid')
|
||||
clientId: uuid.value
|
||||
}))
|
||||
};
|
||||
|
||||
|
|
@ -308,7 +320,7 @@ function reConnect(wsUrl) {
|
|||
}
|
||||
|
||||
onMounted(() => {
|
||||
getPrintList();
|
||||
getPrintList()
|
||||
})
|
||||
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<template>
|
||||
<el-dialog :title="props.title" width="600" v-model="dialogVisible" @open="opne">
|
||||
<!-- <el-input v-model="number" :placeholder="props.placeholder" readonly></el-input> -->
|
||||
<el-input ref="inputRef" v-model="number" :placeholder="props.placeholder" clearable
|
||||
<el-input ref="inputRef" v-model="number" :placeholder="props.placeholder" :readonly="loading" clearable
|
||||
@change="inputChange"></el-input>
|
||||
<div class="tips">注意:扫码请确保输入口获得焦点</div>
|
||||
<!-- <div class="keybord_wrap">
|
||||
|
|
@ -119,7 +119,7 @@ function delHandle() {
|
|||
const inputChange = _.debounce(function (e) {
|
||||
// console.log(e);
|
||||
confirmHandle();
|
||||
}, 500);
|
||||
}, 100);
|
||||
|
||||
// 页码改变
|
||||
function handleCurrentChange() {
|
||||
|
|
@ -151,6 +151,7 @@ const confirmHandle = _.throttle(async function () {
|
|||
try {
|
||||
if (!number.value) return
|
||||
loading.value = true
|
||||
|
||||
const res = await scanSendMessage({
|
||||
outNumber: number.value,
|
||||
shopId: store.userInfo.shopId,
|
||||
|
|
@ -167,6 +168,7 @@ const confirmHandle = _.throttle(async function () {
|
|||
} catch (error) {
|
||||
getsendMessageAjax()
|
||||
loading.value = false
|
||||
number.value = ''
|
||||
console.log(error);
|
||||
setTimeout(() => {
|
||||
inputRef.value.focus();
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ async function submitHandle() {
|
|||
fastOrder.value = error.data
|
||||
autoCheckOrder()
|
||||
} else {
|
||||
scanCode.value = "";
|
||||
loading.value = false;
|
||||
console.log(error);
|
||||
}
|
||||
|
|
@ -279,7 +280,7 @@ function delHandle() {
|
|||
const inputChange = _.debounce(function (e) {
|
||||
// console.log(e);
|
||||
submitHandle();
|
||||
}, 500);
|
||||
}, 100);
|
||||
|
||||
function show() {
|
||||
dialogVisible.value = true;
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@
|
|||
</template>
|
||||
|
||||
<script setup>
|
||||
import _ from 'lodash'
|
||||
import { onMounted, ref } from "vue";
|
||||
import { useUser } from "@/store/user.js";
|
||||
import payCard from "@/components/payCard/payCard.vue";
|
||||
|
|
@ -114,18 +115,28 @@ const props = defineProps({
|
|||
|
||||
const isPrint = ref(true);
|
||||
|
||||
// 小票打印机列表
|
||||
const printList = ref([]);
|
||||
|
||||
// 标签打印机列表
|
||||
const printLabelList = ref([]);
|
||||
const localPrintList = ref([])
|
||||
|
||||
// 获取打印机状态
|
||||
async function bySubTypeAjax() {
|
||||
try {
|
||||
const res = await bySubType({
|
||||
const res1 = await bySubType({
|
||||
shopId: store.userInfo.shopId,
|
||||
contentType: "local",
|
||||
subType: "cash",
|
||||
});
|
||||
printList.value = res;
|
||||
const res2 = await bySubType({
|
||||
shopId: store.userInfo.shopId,
|
||||
contentType: "local",
|
||||
subType: "label",
|
||||
});
|
||||
printList.value = res1;
|
||||
printLabelList.value = res2;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
|
@ -156,26 +167,78 @@ function checkLocalPrint(deviceName) {
|
|||
}
|
||||
}
|
||||
|
||||
// 检测是否打印标签小票
|
||||
function checkLabelPrint(props) {
|
||||
console.log(props);
|
||||
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
|
||||
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接1");
|
||||
} else {
|
||||
let pids = printLabelList.value[0].config.categoryList.map(item => item.id)
|
||||
let labelList = []
|
||||
let count = 0
|
||||
let sum = 0
|
||||
|
||||
props.carts.map(item => {
|
||||
for (let i = 0; i < item.number; i++) {
|
||||
sum++
|
||||
}
|
||||
})
|
||||
|
||||
props.carts.map(item => {
|
||||
if (pids.some(el => el == item.categoryId)) {
|
||||
for (let i = 0; i < item.number; i++) {
|
||||
count++
|
||||
labelList.push(
|
||||
{
|
||||
outNumber: props.outNumber,
|
||||
name: item.name,
|
||||
skuName: item.skuName,
|
||||
masterId: props.orderInfo.tableName,
|
||||
deviceName: printLabelList.value[0].config.deviceName,
|
||||
createdAt: dayjs(props.createdAt).format('YYYY-MM-DD HH:mm:ss'),
|
||||
count: `${count}/${sum}`
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
printLabel(labelList)
|
||||
}
|
||||
}
|
||||
|
||||
// 打印标签
|
||||
const printLabel = (list) => {
|
||||
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
|
||||
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
|
||||
} else {
|
||||
list.map(item => {
|
||||
ipcRenderer.send('printerTagSync', JSON.stringify(item))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 打印操作
|
||||
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"),
|
||||
};
|
||||
checkLabelPrint(data)
|
||||
if (!checkLocalPrint(printList.value[0].config.deviceName)) {
|
||||
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
|
||||
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接3");
|
||||
} 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 {
|
||||
|
|
|
|||
|
|
@ -314,9 +314,19 @@ function checkLabelPrint(props) {
|
|||
} else {
|
||||
let pids = printLabelList.value[0].config.categoryList.map(item => item.id)
|
||||
let labelList = []
|
||||
let count = 0
|
||||
let sum = 0
|
||||
|
||||
props.skuInfos.map(item => {
|
||||
for (let i = 0; i < item.num; i++) {
|
||||
sum++
|
||||
}
|
||||
})
|
||||
|
||||
props.skuInfos.map(item => {
|
||||
if (pids.some(el => el == item.categoryId)) {
|
||||
for (let i = 0; i < item.num; i++) {
|
||||
count++
|
||||
labelList.push(
|
||||
{
|
||||
outNumber: props.outNumber,
|
||||
|
|
@ -324,7 +334,8 @@ function checkLabelPrint(props) {
|
|||
skuName: item.productSkuName,
|
||||
masterId: props.tableName,
|
||||
deviceName: printLabelList.value[0].config.deviceName,
|
||||
createdAt: dayjs(props.createAt).format('YYYY-MM-DD HH:mm:ss')
|
||||
createdAt: dayjs(props.createAt).format('YYYY-MM-DD HH:mm:ss'),
|
||||
count: `${count}/${sum}`
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
@ -335,28 +346,13 @@ function checkLabelPrint(props) {
|
|||
}
|
||||
|
||||
// 打印标签
|
||||
let labelCount = ref(0)
|
||||
let labelPrintTimer = ref(null)
|
||||
const printLabel = lodash.throttle(function (list) {
|
||||
// console.log('printLabel===', list);
|
||||
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
|
||||
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
|
||||
} else {
|
||||
clearInterval(labelPrintTimer.value)
|
||||
labelPrintTimer.value = null
|
||||
labelCount.value = 0
|
||||
labelPrintTimer.value = setInterval(() => {
|
||||
// console.log('labelCount', labelCount.value);
|
||||
list[labelCount.value].count = `${list.length - labelCount.value}/${list.length}`
|
||||
ipcRenderer.send('printerTagSync', JSON.stringify(list[labelCount.value]))
|
||||
labelCount.value++
|
||||
console.log(labelCount.value);
|
||||
if (labelCount.value > list.length - 1) {
|
||||
clearInterval(labelPrintTimer.value)
|
||||
labelPrintTimer.value = null
|
||||
labelCount.value = 0
|
||||
}
|
||||
}, 1000)
|
||||
list.map(item => {
|
||||
ipcRenderer.send('printerTagSync', JSON.stringify(item))
|
||||
})
|
||||
}
|
||||
}, 1500, { leading: true, trailing: false })
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue