diff --git a/package.json b/package.json
index ee0e140..f113438 100644
--- a/package.json
+++ b/package.json
@@ -30,8 +30,10 @@
"pinia": "2.1.7",
"pinyin-pro": "^3.26.0",
"select2": "^4.1.0-rc.0",
+ "socket.io-client": "^4.8.1",
"vue": "3.4.0",
"vue-cropper": "1.1.1",
+ "vue-plugin-hiprint": "^0.0.60",
"vue-router": "4.2.5",
"vue3-print-nb": "^0.1.4",
"vue3-select2-component": "^0.1.7",
diff --git a/src/components/tableCom/index.vue b/src/components/tableCom/index.vue
index 5b2ca6b..195c3af 100644
--- a/src/components/tableCom/index.vue
+++ b/src/components/tableCom/index.vue
@@ -17,24 +17,23 @@
:width="config.indexWidth || 60" :fixed="config.indexFixed" align="center" :index="getIndex" />
-
+
-
+
-
+
-
+
-
-
+
+
@@ -70,7 +69,7 @@ import { computed, ref, watch, PropType } from "vue";
import { TableColumnCtx } from 'element-plus';
interface TableColumn {
prop?: string;
- key?: string;
+ key?: string | number;
label?: string;
width?: string | number;
minWidth?: string | number;
diff --git a/src/store/modules/printStore.ts b/src/store/modules/printStore.ts
new file mode 100644
index 0000000..2002197
--- /dev/null
+++ b/src/store/modules/printStore.ts
@@ -0,0 +1,26 @@
+// 打印状态管理
+import { defineStore } from 'pinia'
+
+export const usePrintStore = defineStore('printStore', {
+ state: () => ({
+ isConnected: false, // 存储连接状态
+ clientInfo: null, // 存储客户端信息
+ printerList: [] as any[], // 存储打印机列表
+ defaultPrinter: '' as string, // 存储默认打印机名称
+ }),
+ actions: {
+ setConnected(status: boolean) {
+ this.isConnected = status
+ },
+ setClientInfo(info: any) {
+ this.clientInfo = info
+ },
+ setPrinterList(list: any[]) {
+ this.printerList = list
+ this.defaultPrinter = list.find((p) => p.isDefault)?.name || ''
+ },
+ setDefaultPrinter(printerName: string) {
+ this.defaultPrinter = printerName
+ }
+ }
+})
\ No newline at end of file
diff --git a/src/utils/print-utils.ts b/src/utils/print-utils.ts
new file mode 100644
index 0000000..8797d90
--- /dev/null
+++ b/src/utils/print-utils.ts
@@ -0,0 +1,146 @@
+// src/utils/print-utils.ts
+import { io, Socket } from "socket.io-client";
+import { ElMessage, ElMessageBox } from 'element-plus'
+import { usePrintStore } from '@/store/modules/printStore'
+
+// ... 类型定义 ...
+type PrinterInfo = {
+ name: string;
+ isDefault?: boolean;
+ [key: string]: any;
+};
+
+
+type ClientInfo = any;
+type OnPrinterUpdate = (printerList: PrinterInfo[]) => void;
+let socket: Socket | null = null;
+
+let clientInfo: ClientInfo = null;
+// 初始化 Socket 连接
+function initSocket(onPrinterUpdate?: OnPrinterUpdate) {
+ const printStore = usePrintStore();
+
+ if (socket) {
+ socket.disconnect();
+ }
+
+ socket = io("http://localhost:17521", {
+ transports: ["websocket"],
+ reconnection: false, //闭自动重连
+ auth: {
+ token: "vue-plugin-hiprint",
+ },
+ });
+ // 连接成功
+ socket.on("connect", () => {
+ printStore.setConnected(true);
+ console.log("✅ 已连接 electron-hiprint 客户端");
+ socket?.emit("getClientInfo");
+ socket?.emit("refreshPrinterList");
+ });
+ // 客户端信息
+ socket.on("clientInfo", (info: ClientInfo) => {
+ printStore.setClientInfo(info);
+ console.log("📱 客户端信息:", info);
+ });
+ // 打印机列表 (更新默认打印机)
+ socket.on("printerList", (list: PrinterInfo[]) => {
+ printStore.setPrinterList(list);
+ onPrinterUpdate?.(list);
+ console.log("🖨️ 打印机列表更新:", list);
+ });
+ // 连接断开
+ socket.on("disconnect", (reason: string) => {
+ printStore.setConnected(false);
+ console.error("❌ 客户端连接断开:", reason);
+ if (reason === "io server disconnect") {
+ socket?.connect();
+ }
+ });
+
+ socket.on("connect_error", (err: Error) => {
+ console.log('连接错误', err);
+ ElMessageBox.alert(
+ `连接失败!
请确保目标服务器已 下载 并运行 打印服务!`,
+ "客户端未连接",
+ {
+ dangerouslyUseHTMLString: true,
+ }
+ )
+ printStore.setConnected(false);
+ socket?.close();
+ });
+}
+
+function silentPrintPdf(url: string, printOptions?: object) {
+ const printStore = usePrintStore();
+ if (!url) {
+ console.log("请传入有效的PDF文件路径!");
+ return;
+ }
+ const templateId = `pdf-print-${Date.now()}`;
+ // 检查是否连接客户端
+ if (!printStore.isConnected) {
+ initSocket((printerList) => {
+ if (printerList.length > 0) {
+ socket?.emit("news", {
+ client: clientInfo,
+ printer: targetPrinter,
+ type: "url_pdf",
+ templateId: templateId,
+ pdf_path: url,
+ });
+ ElMessage.success('正在打印文件,请稍候...')
+ }
+ return
+ });
+ }
+ const targetPrinter = printStore.defaultPrinter;
+ if (!targetPrinter) {
+ console.log("未检测到打印机,请先连接打印机!");
+ return;
+ }
+ socket?.emit("news", {
+ client: clientInfo,
+ printer: targetPrinter,
+ type: "url_pdf",
+ templateId: templateId,
+ pdf_path: url,
+ });
+ ElMessage.success('正在打印文件,请稍候...')
+ // console.log(`🚀 PDF打印请求已发送,任务ID:${templateId},打印机:${targetPrinter}`);
+
+}
+// 销毁
+function destroy() {
+ const printStore = usePrintStore();
+ if (socket) {
+ socket.disconnect();
+ socket = null;
+ printStore.setConnected(false);
+ console.log("🔌 已断开与 electron-hiprint 的连接");
+ }
+}
+
+// 更新 getter 函数以从 store 获取值
+export const HiprintPrinter = {
+ initSocket,
+ silentPrintPdf,
+ destroy,
+ get isConnected() {
+ const printStore = usePrintStore();
+ return printStore.isConnected;
+ },
+ get clientInfo() {
+ const printStore = usePrintStore();
+ return printStore.clientInfo;
+ },
+ get printerList() {
+ const printStore = usePrintStore();
+ return printStore.printerList;
+ },
+ get defaultPrinter() {
+ const printStore = usePrintStore();
+ return printStore.defaultPrinter;
+ },
+};
\ No newline at end of file
diff --git a/src/views/checkCode/index.vue b/src/views/checkCode/index.vue
index 4253033..ae085a8 100644
--- a/src/views/checkCode/index.vue
+++ b/src/views/checkCode/index.vue
@@ -44,13 +44,13 @@
条码生成
- 生成条码
+ 生成条码
选中所有未打印
- 打印
+ 打印
采样登记
@@ -143,11 +143,15 @@