huangxw 6 дней назад
Родитель
Сommit
dbd61da7ff

+ 22 - 5
src/plant/print/models/connect-printer.vue

@@ -89,6 +89,12 @@ const toast = (title: string) => {
     uni.showToast({ title, icon: 'none', duration: 2000 });
 };
 
+const isBLEAlreadyConnectedError = (error: any) => {
+    const errCode = Number(error?.errCode);
+    const errMsg = String(error?.errMsg || '').toLowerCase();
+    return errCode === 10003 || errMsg.includes('already connected');
+};
+
 const updateDeviceList = (device: any) => {
     if (!device?.deviceId) return;
     const deviceName = device.name || '';
@@ -230,15 +236,28 @@ const handleConnectDevice = async (device: any) => {
         await stopSearch();
 
         if (connectedDevice.value?.deviceId) {
+            const previousDeviceId = connectedDevice.value.deviceId;
+            if (previousDeviceId !== device.deviceId) {
+                toast('已连接其他设备,正在切换...');
+            }
             try {
-                await closeBLEConnection(connectedDevice.value.deviceId);
+                await closeBLEConnection(previousDeviceId);
             } catch {
                 // ignore
             }
             connectedDevice.value = null;
+            emit('disconnected', { deviceId: previousDeviceId, reason: 'switch-device' });
+            // 某些机型在断开后立刻重连会失败,给系统短暂释放时间。
+            await new Promise((resolve) => setTimeout(resolve, 200));
         }
 
-        await connectBLEDevice(device.deviceId);
+        try {
+            await connectBLEDevice(device.deviceId);
+        } catch (error) {
+            if (!isBLEAlreadyConnectedError(error)) {
+                throw error;
+            }
+        }
 
         const { services, characteristicsMap } = await getBLEDeviceServicesAndCharacteristics(device.deviceId);
         console.log('已获取服务', services);
@@ -289,9 +308,7 @@ const handleConnectDevice = async (device: any) => {
 
 const handleDisconnect = async (silent = false) => {
     if (!connectedDevice.value?.deviceId) return;
-
     const deviceId = connectedDevice.value.deviceId;
-
     try {
         await closeBLEConnection(deviceId);
         if (!silent) {
@@ -409,7 +426,7 @@ onBeforeUnmount(async () => {
 
             &.active {
                 background-color: #e8f4ff;
-                border: 2rpx solid #1989fa;
+                border: 2rpx solid $u-primary;
             }
 
             &:active {

+ 37 - 14
src/plant/print/models/print-tem.ts

@@ -4,31 +4,54 @@ export const tem30x30 = (command: any, info: any[], item: any) => {
     const leftInfo = info[0];
     const rightInfo = info?.[1];
     command.setText(30, 10, 'TSS16.BF2', 1, 1, '品名:' + item.proName);
-    command.setText(30, 40, 'TSS16.BF2', 1, 1, '数量(重量):' + item.specn);
+    if (+leftInfo?.restFlag) {
+        command.setText(30, 40, 'TSS16.BF2', 1, 1, '数量(重量):' + item.restSpecn);
+    } else {
+        command.setText(30, 40, 'TSS16.BF2', 1, 1, '数量(重量):' + item.specn);
+    }
+    
     command.setQR(55, 75, 'L', 4, 'A', leftInfo.url);
     // 底部加sn序号
-    command.setText(80, 190, 'TSS16.BF2', 1, 1, leftInfo.padSn);
+    command.setText(90, 195, 'TSS16.BF2', 1, 1, leftInfo.padSn);
     if (rightInfo) {
         command.setText(280, 10, 'TSS16.BF2', 1, 1, '品名:' + item.proName);
-        command.setText(280, 40, 'TSS16.BF2', 1, 1, '数量(重量):' + item.specn);
+        if (+rightInfo?.restFlag) {
+            command.setText(280, 40, 'TSS16.BF2', 1, 1, '数量(重量):' + item.restSpecn);
+        } else {
+            command.setText(280, 40, 'TSS16.BF2', 1, 1, '数量(重量):' + item.specn);
+        }
         command.setQR(315, 75, 'L', 4, 'A', rightInfo.url);
-        command.setText(330, 190, 'TSS16.BF2', 1, 1, rightInfo.padSn);
+        command.setText(345, 195, 'TSS16.BF2', 1, 1, rightInfo.padSn);
     }
     return command;
 };
 export const tem60x40 = (command: any, info: any, item: any) => {
-    command.setQR(320, 150, 'L', 4, 'A', info.traceCode);
-    command.setText(30, 30, 'TSS16.BF2', 1, 1, '品名:' + item.proName);
-    command.setText(30, 60, 'TSS16.BF2', 1, 1, '规格等级:' + item.proSpecn);
-    command.setText(30, 90, 'TSS16.BF2', 1, 1, '产地:' + item.proAdcodeDesc);
-    command.setText(30, 120, 'TSS16.BF2', 1, 1, '供应商:' + item.cpyName);
+    command.setText(30, 10, 'TSS16.BF2', 1, 1, '品名:' + item.proName);
+    command.setText(30, 35, 'TSS16.BF2', 1, 1, '批号:' + item.batchSn);
+    if (+info.restFlag) {
+        command.setText(30, 60, 'TSS16.BF2', 1, 1, '数量/重量:' + item.restSpecn);
+    } else {
+        command.setText(30, 60, 'TSS16.BF2', 1, 1, '数量/重量:' + item.specn);
+    }
+    command.setText(280, 60, 'TSS16.BF2', 1, 1, '规格等级:' + item.proLevel);
+    command.setText(30, 85, 'TSS16.BF2', 1, 1, '产地:' + item.proAdcodeDesc);
+    command.setText(30, 110, 'TSS16.BF2', 1, 1, '供应商:' + item.cpyName);
+    command.setQR(50, 135, 'L', 4, 'A', info.url);
+    command.setText(80, 255, 'TSS16.BF2', 1, 1, info.padSn);
     return command;
 };
 export const tem60x60 = (command: any, info: any, item: any) => {
-    command.setQR(320, 150, 'L', 4, 'A', info.traceCode);
-    command.setText(30, 30, 'TSS16.BF2', 1, 1, '品名:' + item.proName);
-    command.setText(30, 60, 'TSS16.BF2', 1, 1, '规格等级:' + item.proSpecn);
-    command.setText(30, 90, 'TSS16.BF2', 1, 1, '产地:' + item.proAdcodeDesc);
-    command.setText(30, 120, 'TSS16.BF2', 1, 1, '供应商:' + item.cpyName);
+    command.setText(30, 10, 'TSS16.BF2', 1, 1, '品名:' + item.proName);
+    if (+info.restFlag) {
+        command.setText(30, 35, 'TSS16.BF2', 1, 1, '数量/重量:' + item.restSpecn);
+    } else {
+        command.setText(30, 35, 'TSS16.BF2', 1, 1, '数量/重量:' + item.specn);
+    }
+    command.setText(30, 60, 'TSS16.BF2', 1, 1, '规格等级:' + item.proLevel);
+    command.setText(30, 85, 'TSS16.BF2', 1, 1, '批号:' + item.batchSn);
+    command.setText(30, 110, 'TSS16.BF2', 1, 1, '产地:' + item.proAdcodeDesc);
+    command.setText(30, 135, 'TSS16.BF2', 1, 1, '供应商:' + item.cpyName);
+    command.setQR(50, 160, 'L', 4, 'A', info.url);
+    command.setText(80, 280, 'TSS16.BF2', 1, 1, info.padSn);
     return command;
 };

+ 28 - 1
src/plant/print/print-all/index.vue

@@ -8,7 +8,13 @@
     
             <view v-show="currentStep === 'connect'" class="bg-fff">
                 <!-- 业务组件链接打印机 -->
-                <connect-printer :info="stepsObject[currentStep]" @next="nextSteps" nextStepValue="print"></connect-printer>
+                <connect-printer
+                    :info="stepsObject[currentStep]"
+                    @connected="handlePrinterConnected"
+                    @disconnected="handlePrinterDisconnected"
+                    @next="nextSteps"
+                    nextStepValue="print"
+                ></connect-printer>
             </view>
             <view v-show="currentStep === 'print'" class="bg-fff">
                 <!-- 业务组件打印 -->
@@ -96,6 +102,27 @@ const getFormData = (data: any) => {
 const prevSteps = (data: any) => {
     currentStep.value = data?.prevStepValue;
 };
+const handlePrinterConnected = (device: any) => {
+    stepsObject.connect = {
+        ...stepsObject.connect,
+        status: 'completed',
+        device,
+    };
+};
+const handlePrinterDisconnected = (payload: any) => {
+    const currentDeviceId = stepsObject.connect?.device?.deviceId;
+    if (!currentDeviceId || (payload?.deviceId && payload.deviceId !== currentDeviceId)) return;
+
+    stepsObject.connect = {
+        ...stepsObject.connect,
+        status: 'in-progress',
+        device: null,
+    };
+    if (currentStep.value === 'print') {
+        stepsObject.print.status = 'not-started';
+        currentStep.value = 'connect';
+    }
+};
 const testList = reactive([
     {
         padSn: '0000002',

+ 30 - 1
src/plant/print/print-range/index.vue

@@ -10,7 +10,15 @@
             </view>
             <view v-show="currentStep === 'connect'" class="bg-fff">
                 <!-- 业务组件链接打印机 -->
-                <connect-printer :info="stepsObject[currentStep]" @next="nextSteps" @prev="prevSteps" prevStepValue="range" nextStepValue="print"></connect-printer>
+                <connect-printer
+                    :info="stepsObject[currentStep]"
+                    @connected="handlePrinterConnected"
+                    @disconnected="handlePrinterDisconnected"
+                    @next="nextSteps"
+                    @prev="prevSteps"
+                    prevStepValue="range"
+                    nextStepValue="print"
+                ></connect-printer>
             </view>
             <view v-show="currentStep === 'print'" class="bg-fff">
                 <!-- 业务组件打印 -->
@@ -104,6 +112,27 @@ const getFormData = (data: any) => {
 const prevSteps = (data: any) => {
     currentStep.value = data?.prevStepValue;
 };
+const handlePrinterConnected = (device: any) => {
+    stepsObject.connect = {
+        ...stepsObject.connect,
+        status: 'completed',
+        device,
+    };
+};
+const handlePrinterDisconnected = (payload: any) => {
+    const currentDeviceId = stepsObject.connect?.device?.deviceId;
+    if (!currentDeviceId || (payload?.deviceId && payload.deviceId !== currentDeviceId)) return;
+
+    stepsObject.connect = {
+        ...stepsObject.connect,
+        status: 'in-progress',
+        device: null,
+    };
+    if (currentStep.value === 'print') {
+        stepsObject.print.status = 'not-started';
+        currentStep.value = 'connect';
+    }
+};
 const testList = reactive([
     {
         padSn: '0000002',

+ 30 - 1
src/plant/print/print-self/index.vue

@@ -18,7 +18,15 @@
             </view>
             <view v-show="currentStep === 'connect'" class="bg-fff">
                 <!-- 业务组件链接打印机 -->
-                <connect-printer :info="stepsObject[currentStep]" @next="nextSteps" @prev="prevSteps" prevStepValue="confirm" nextStepValue="print"></connect-printer>
+                <connect-printer
+                    :info="stepsObject[currentStep]"
+                    @connected="handlePrinterConnected"
+                    @disconnected="handlePrinterDisconnected"
+                    @next="nextSteps"
+                    @prev="prevSteps"
+                    prevStepValue="confirm"
+                    nextStepValue="print"
+                ></connect-printer>
             </view>
             <view v-show="currentStep === 'print'" class="bg-fff">
                 <!-- 业务组件打印 -->
@@ -137,6 +145,27 @@ const getFormData = (data: any) => {
 const prevSteps = (data: any) => {
     currentStep.value = data?.prevStepValue;
 };
+const handlePrinterConnected = (device: any) => {
+    stepsObject.connect = {
+        ...stepsObject.connect,
+        status: 'completed',
+        device,
+    };
+};
+const handlePrinterDisconnected = (payload: any) => {
+    const currentDeviceId = stepsObject.connect?.device?.deviceId;
+    if (!currentDeviceId || (payload?.deviceId && payload.deviceId !== currentDeviceId)) return;
+
+    stepsObject.connect = {
+        ...stepsObject.connect,
+        status: 'in-progress',
+        device: null,
+    };
+    if (currentStep.value === 'print') {
+        stepsObject.print.status = 'not-started';
+        currentStep.value = 'connect';
+    }
+};
 const testList = reactive([
     {
         padSn: '0000002',