diff --git a/package.json b/package.json
index 1e6c548..9ce493f 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "vite-electron",
"private": true,
- "version": "1.3.18",
+ "version": "1.3.21",
"main": "dist-electron/main.js",
"scripts": {
"dev": "chcp 65001 && vite",
diff --git a/public/tag_print.css b/public/tag_print.css
index b169bf6..5f0f354 100644
--- a/public/tag_print.css
+++ b/public/tag_print.css
@@ -7,12 +7,26 @@
color: #000;
}
+html,
+body {
+ width: 100%;
+ height: 100%;
+}
+
body {
padding: 2mm;
}
+#app {
+ width: 100%;
+ height: 100%;
+}
+
.print_view {
position: relative;
+ width: 100%;
+ height: 100%;
+ overflow: hidden;
}
.print_view .ewm {
width: 50px;
diff --git a/public/tag_print.scss b/public/tag_print.scss
index 17c8ce2..7516bf3 100644
--- a/public/tag_print.scss
+++ b/public/tag_print.scss
@@ -5,11 +5,23 @@
font-size: 12px;
color: #000;
}
+html,
+body {
+ width: 100%;
+ height: 100%;
+}
body {
padding: 2mm;
}
+#app{
+ width: 100%;
+ height: 100%;
+}
.print_view {
position: relative;
+ width: 100%;
+ height: 100%;
+ overflow: hidden;
.ewm {
$size: 50px;
width: $size;
diff --git a/src/App.vue b/src/App.vue
index 022ccea..f591231 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -28,15 +28,15 @@ import { useRouter, useRoute } from "vue-router";
import leftMenu from "@/components/leftMenu.vue";
import useStorage from '@/utils/useStorage'
import { useUser } from "@/store/user.js";
-import { bySubType } from "@/api/device";
import { dayjs, ElMessage } from "element-plus";
-import { ipcRenderer } from 'electron'
import { scanSendMessage } from '@/api/order/index'
import { useGlobal } from '@/store/global.js'
import { useSocket } from '@/store/socket.js'
+import { usePrint } from '@/store/print.js'
const global = useGlobal()
const socketStore = useSocket()
+const printStore = usePrint()
const leftMenuRef = ref(null)
@@ -78,16 +78,15 @@ watch(route, (to) => {
} else {
// 打开ws
openWs()
- // setTimeout(() => {
- // }, 1000)
}
});
// 登录成功后开始连接ws
function openWs() {
if (store.userInfo && store.userInfo.shopId && ws.value == null) {
- bySubTypeAjax();
initWebSocket()
+ // 更新print
+ printStore.init()
}
}
@@ -106,134 +105,6 @@ router.beforeEach((to, from) => {
}
});
-// 小票打印机列表
-const printList = ref([]);
-// 标签打印机列表
-const printLabelList = ref([]);
-const localPrintList = ref([])
-
-// 获取打印机状态
-async function bySubTypeAjax() {
- try {
- const res1 = await bySubType({
- shopId: store.userInfo.shopId,
- contentType: "local",
- subType: "cash",
- });
- const res2 = await bySubType({
- shopId: store.userInfo.shopId,
- contentType: "local",
- subType: "label",
- });
- printList.value = res1;
- printLabelList.value = res2;
- } catch (error) {
- console.log(error);
- }
-}
-
-// 获取本地打印机列表
-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) {
- return false
- } else {
- return true
- }
-}
-
-// 打印小票
-function printBill(props) {
- if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
- ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
- } else {
- const data = {
- shop_name: store.userInfo.merchantName,
- carts: props.carts,
- 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));
- }
-}
-
-// 检测是否打印标签小票
-function checkLabelPrint(props) {
- if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
- ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
- } else {
- let pids = printLabelList.value[0].config.categoryList.map(item => item.id)
- let labelList = []
-
- // let count = 0
- // let sum = 0
-
- // props.carts.map(item => {
- // if (pids.some(el => el == item.categoryId)) {
- // 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)
- }
-}
-
-// 打印标签
-function printLabel(list) {
- // console.log(list);
- if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
- ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
- } else {
- for (let i = 0; i <= list.length - 1; i++) {
- // ipcRenderer.send('printerTagSync', JSON.stringify(list[i]))
- setTimeout(() => {
- ipcRenderer.send('printerTagSync', JSON.stringify(list[i]))
- }, i * 800)
- }
- }
-}
let ws = ref(null)
let wsIsClose = ref(false)
@@ -276,7 +147,8 @@ function initWebSocket(wsUrl = import.meta.env.VITE_API_WSS) {
// printBill(data)
// 检测是否需要打印标签小票
- checkLabelPrint(data)
+ // checkLabelPrint(data)
+ printStore.labelPrint(data)
}
};
@@ -430,7 +302,6 @@ async function getBarCode(e) {
}
onMounted(() => {
- getPrintList()
document.addEventListener('keydown', (e) => {
getBarCode(e)
})
diff --git a/src/store/print.js b/src/store/print.js
index 8738071..d385e9c 100644
--- a/src/store/print.js
+++ b/src/store/print.js
@@ -1,20 +1,44 @@
import { defineStore } from "pinia";
+import { ipcRenderer } from "electron";
+import { bySubType } from "@/api/device";
+import { useUser } from "@/store/user.js";
+import dayjs from "dayjs";
export const usePrint = defineStore({
id: "print",
state: () => ({
localDevices: [], // 本地打印机列表
- deviceList: [], // 添加的打印机
- data: "", // 要打印的数据
+ deviceNoteList: [], // 添加的打印机
+ deviceLableList: [], // 添加的打印机
+ labelList: [], // 要打印的队列数据
+ printTimer: null,
}),
actions: {
- // 更新本地打印机列表
- updateLocalDevice(list) {
- this.localDevices = list;
- },
- // 更新已添加的打印机
- updateDevice(list) {
- this.deviceList = list;
+ // 获取本地打印机和已添加的可以用打印机列表
+ async init() {
+ const store = useUser();
+
+ // 获取本地打印机
+ ipcRenderer.send("getPrintList");
+ ipcRenderer.on("printList", (event, arg) => {
+ // localPrintList.value = arg;
+ // console.log(localPrintList.value);
+ this.localDevices = arg;
+ });
+
+ // 获取已添加的小票打印机
+ this.deviceNoteList = await bySubType({
+ shopId: store.userInfo.shopId,
+ contentType: "local",
+ subType: "cash",
+ });
+
+ // 获取已添加的标签打印机
+ this.deviceLableList = await bySubType({
+ shopId: store.userInfo.shopId,
+ contentType: "local",
+ subType: "label",
+ });
},
// 检查本地打印机是否能正常使用
checkLocalPrint(deviceName) {
@@ -31,10 +55,62 @@ export const usePrint = defineStore({
return true;
}
},
- // 执行打印操作
- printHandle(state, type = "label") {
- if (type == "label") {
+ // 打印标签小票
+ labelPrint(props) {
+ if (this.checkLocalPrint(this.deviceLableList[0].config.deviceName)) {
+ let pids = this.deviceLableList[0].config.categoryList.map(
+ (item) => item.id
+ );
+
+ let count = 0;
+ let sum = 0;
+
+ props.carts.map((item) => {
+ if (pids.some((el) => el == item.categoryId)) {
+ 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++;
+ this.labelList.push({
+ outNumber: props.outNumber,
+ name: item.name,
+ skuName: item.skuName,
+ masterId: props.orderInfo.tableName,
+ deviceName: this.deviceLableList[0].config.deviceName,
+ createdAt: dayjs(props.createdAt).format("YYYY-MM-DD HH:mm:ss"),
+ isPrint: false,
+ count: `${count}/${sum}`,
+ });
+ }
+ }
+ });
+ // 执行打印操作
+ this.startLabelPrint();
}
},
+ // 开始打印标签数据
+ startLabelPrint() {
+ if (this.printTimer != null) return;
+ this.printTimer = setInterval(() => {
+ let item = "";
+ if (!this.labelList.length) {
+ clearInterval(this.printTimer);
+ this.printTimer = null;
+ } else {
+ item = this.labelList[0];
+ if (!item.isPrint) {
+ ipcRenderer.send("printerTagSync", JSON.stringify(item));
+ this.labelList[0].isPrint = true;
+ this.labelList.splice(0, 1);
+ }
+ }
+ }, 800);
+ },
},
});
diff --git a/src/views/device/add_label.vue b/src/views/device/add_label.vue
index 14776c0..9ea51c1 100644
--- a/src/views/device/add_label.vue
+++ b/src/views/device/add_label.vue
@@ -111,6 +111,7 @@
diff --git a/src/views/order/index.vue b/src/views/order/index.vue
index a346371..ab0277c 100644
--- a/src/views/order/index.vue
+++ b/src/views/order/index.vue
@@ -4,7 +4,9 @@
-
+