From ce259180a1a76db6a7e89d651dc3eb1f49932202 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期六, 10 十月 2026 19:48:50 +0800
Subject: [PATCH] 修改装箱清单打印样式
---
common/bluetoothPrinter.js | 42 +++++++++++++++++++++++++++++++++++++-----
1 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/common/bluetoothPrinter.js b/common/bluetoothPrinter.js
index dc018e0..2bee9e5 100644
--- a/common/bluetoothPrinter.js
+++ b/common/bluetoothPrinter.js
@@ -1,4 +1,25 @@
-const jcapi = uni.requireNativePlugin("JCSDK-JCApiModule");
+// 绮捐嚕鎵撳嵃鏈哄師鐢熸彃浠躲�傛彃浠剁敱 DCloud 璐﹀彿缁戝畾锛岃处鍙锋湭璐拱/鏈墦鍏ュ熀搴ф椂涓嶈兘鎶涢敊锛�
+// 鍚﹀垯椤甸潰涓�鍔犺浇灏辩櫧灞忥紝鎵�浠ヨ繖閲屽仛瀹归敊鍔犺浇锛岀己澶辨椂鎵撳嵃鍔熻兘缁欏嚭鎻愮ず鑰屼笉鏄穿婧冦��
+let jcapi = null;
+let pluginMissing = false;
+try {
+ jcapi = uni.requireNativePlugin("JCSDK-JCApiModule");
+ if (!jcapi) {
+ pluginMissing = true;
+ }
+} catch (e) {
+ pluginMissing = true;
+}
+
+const PLUGIN_MISSING_MSG = "鏈娴嬪埌绮捐嚕鎵撳嵃鎻掍欢锛岃纭鎵撳寘鏃跺凡璐拱骞跺嬀閫夎鍘熺敓鎻掍欢";
+
+function requirePlugin() {
+ if (pluginMissing || !jcapi) {
+ uni.showToast({ title: PLUGIN_MISSING_MSG, icon: "none", duration: 3000 });
+ return null;
+ }
+ return jcapi;
+}
let state = {
connectedDevice: null,
@@ -25,7 +46,10 @@
/** 鍒濆鍖栵紙鍏ㄥ眬鍙渶涓�娆★級 */
function init() {
- jcapi.initSDK();
+ const api = requirePlugin();
+ if (!api) return;
+
+ api.initSDK();
const saved = uni.getStorageSync("bluetoothConnection");
if (saved) {
@@ -34,7 +58,7 @@
}
// 鏂紑鐩戝惉
- jcapi.didReadPrintErrorInfo((r) => {
+ api.didReadPrintErrorInfo((r) => {
if (r.code === 23) {
state.connectedDevice = null;
state.connectionStatus = "disconnected";
@@ -47,9 +71,13 @@
/** 鎼滅储璁惧 */
function searchDevices() {
return new Promise((resolve, reject) => {
+ const api = requirePlugin();
+ if (!api) {
+ return reject(new Error(PLUGIN_MISSING_MSG));
+ }
uni.openBluetoothAdapter({
success() {
- jcapi.getBluetoothDevices(list => {
+ api.getBluetoothDevices(list => {
resolve(list || []);
});
},
@@ -61,10 +89,14 @@
/** 杩炴帴璁惧 */
function connect(device) {
return new Promise((resolve, reject) => {
+ const api = requirePlugin();
+ if (!api) {
+ return reject(new Error(PLUGIN_MISSING_MSG));
+ }
state.connectionStatus = "connecting";
notify();
- jcapi.openPrinterByDevice({
+ api.openPrinterByDevice({
address: device.address,
name: device.name,
deviceType: 0,
--
Gitblit v1.9.3