huangxw 1 долоо хоног өмнө
parent
commit
434f95fb94

+ 14 - 0
src/pages.json

@@ -463,6 +463,20 @@
                     "style": {
                         "navigationBarTitleText": "打印步骤"
                     }
+                },
+                // 自行打印
+                {
+                    "path": "print-self/index",
+                    "style": {
+                        "navigationBarTitleText": "自行打印"
+                    }
+                },
+                // 区间打印
+                {
+                    "path": "print-range/index",
+                    "style": {
+                        "navigationBarTitleText": "区间打印"
+                    }
                 }
             ]
         },

+ 1 - 1
src/plant/packaging/list/index.vue

@@ -85,7 +85,7 @@
                                     >查看批次信息</up-button
                                 >
                                 <template v-if="item.refType == '2'">
-                                    <up-button v-if="+item?.actualCount - item?.printCount" class="ml-10" color="#37A954">立即打印</up-button>
+                                    <up-button v-if="+item?.actualCount - item?.printCount" @click="$u.route({ url: '/plant/print/print-self/index', params: { mode: '' } })" class="ml-10" color="#37A954">立即打印</up-button>
                                     <up-button v-if="+item?.printCount" class="ml-10" color="#37A954">查看打印记录</up-button>
                                 </template>
                                 <template v-if="item.refType == '1'">

+ 0 - 0
src/plant/print/print-steps/models/connect-printer.vue → src/plant/print/models/connect-printer.vue


+ 0 - 0
src/plant/print/print-steps/models/encoding-indexes.js → src/plant/print/models/encoding-indexes.js


+ 0 - 0
src/plant/print/print-steps/models/encoding.js → src/plant/print/models/encoding.js


+ 0 - 0
src/plant/print/print-steps/models/esc.js → src/plant/print/models/esc.js


+ 0 - 0
src/plant/print/print-steps/models/print-tem.ts → src/plant/print/models/print-tem.ts


+ 0 - 0
src/plant/print/print-steps/models/print-wrapper.vue → src/plant/print/models/print-wrapper.vue


+ 0 - 0
src/plant/print/print-steps/models/tspl.js → src/plant/print/models/tspl.js


+ 178 - 0
src/plant/print/print-range/index.vue

@@ -0,0 +1,178 @@
+<template>
+    <z-paging ref="paging" bgColor="#fff" safe-area-inset-bottom scroll-with-animation>
+        <template #top>
+            <ut-navbar :title="stepsObject[currentStep].title" :fixed="false" border :breadcrumb="false"></ut-navbar>
+            <view class="pd-24">
+                <ut-steps-title :stepsObject="stepsObject"></ut-steps-title>
+            </view>
+            <view class="pd-5 bg-#f7f7f7"></view>
+        </template>
+        <view>
+            <view v-show="currentStep === 'connect'">
+                <!-- 业务组件链接打印机 -->
+                <connect-printer :info="stepsObject[currentStep]" @next="nextSteps" @prev="prevSteps" prevStepValue="confirm" nextStepValue="print"></connect-printer>
+            </view>
+            <view v-show="currentStep === 'print'">
+                <!-- 业务组件打印 -->
+                <!-- 打印写入打印机 -->
+                <print-wrapper :info="stepsObject[currentStep]" @test="printTest" @prev="prevSteps" prevStepValue="connect"></print-wrapper>
+            </view>
+        </view>
+    </z-paging>
+</template>
+
+<script setup lang="ts">
+import ConnectPrinter from './models/connect-printer.vue';
+import { tem30x30, tem60x40, tem60x60 } from '../models/print-tem';
+import PrintWrapper from './models/print-wrapper.vue';
+import { writeBLECharacteristicSend } from '@/utils/blue-device-services';
+import jpPrinter from '../models/tspl';
+const stepsObject = reactive<any>({
+    check: {
+        title: '核对信息',
+        value: 'check',
+        status: 'completed', // 为开始、进行中、已完成 三种状态分别值为 'not-started'、'in-progress'、'completed'
+        sort: 0,
+    },
+    confirm: {
+        title: '确认数量',
+        value: 'confirm',
+        status: 'completed', // 为开始、进行中、已完成 三种状态分别值为 'not-started'、'in-progress'、'completed'
+        sort: 1,
+    },
+    connect: {
+        title: '连接打印机',
+        value: 'connect',
+        status: 'in-progress', // 为开始、进行中、已完成 三种状态分别值为 'not-started'、'in-progress'、'completed'
+        sort: 2,
+    },
+    print: {
+        title: '打印',
+        value: 'print',
+        status: 'not-started', // 为开始、进行中、已完成 三种状态分别值为 'not-started'、'in-progress'、'completed'
+        sort: 3,
+    },
+});
+// 打印模式
+const mode = ref('self'); // 自行打印, 区间打印 值分别为 self, range
+const currentStep = ref('connect');
+const paging = ref(null);
+const isPrinting = ref(false);
+onLoad((options: any) => {});
+const nextSteps = (data: any) => {
+    if (!data.info || !data?.info?.value) return;
+    stepsObject[data?.info?.value] = {
+        ...data.info,
+    };
+    stepsObject[data?.nextStepValue].status = 'in-progress';
+    currentStep.value = data?.nextStepValue;
+};
+const prevSteps = (data: any) => {
+    currentStep.value = data?.prevStepValue;
+};
+const testList = reactive([
+    {
+        pm: '三七',
+        zl: '20g',
+        scrq: '2012.09.18',
+        zzph: 87391273912,
+        cj: '云南省文山市县中药材有限公司',
+        zsm: 'QX0000005600000318',
+        qr: 'https://t.zycpzs.cn/?c=QCCS412507030000101ND'
+    },
+]);
+const printTest = (data: any) => {
+    // 检查是否正在打印
+    if (isPrinting.value) {
+        uni.showToast({ icon: 'none', title: '当前打印任务未完成,请稍后' });
+        return;
+    }
+    // 测试数据
+    prepareSend(testList, data.printSpec);
+};
+// 打印写入
+const prepareSend = (list: any[], spec: string = '30x30') => {
+    if (spec == '30x30') {
+        // 判断idx是否是奇数
+        writeSend30x30(list);
+    }
+    if (spec == '60x40') {
+        // 40x40
+        writeSendCommand(list, '60x40', 0)
+    }
+    if (spec == '60x60') {
+        // 30x30
+        writeSendCommand(list, '60x60', 0)
+    }
+};
+const writeSend30x30 = (list: any[]) => {
+    // arr两个两个一组,偶数组没有是空
+    const arr = list.reduce((acc: any, cur: any, idx: number) => {
+        if (idx % 2 == 0) {
+            acc.push([cur]);
+        } else {
+            acc[acc.length - 1].push(cur);
+        }
+        return acc;
+    }, []);
+    writeSendCommand(arr, '30x30', 0)
+};
+// writeSend
+const writeSendCommand = async (list: any[], spec: string = '30x30', idx = 0) => {
+    // 首次调用时设置打印状态为进行中
+    if (idx === 0) {
+        isPrinting.value = true;
+    }
+    let command = new jpPrinter();
+    if (spec == '30x30') {
+        // 判断idx是否是奇数
+        command.setSize(60, 30);
+        command.setGap(10);
+        command.setCls();
+        command.setDirection(1);
+        command = tem30x30(command, list[idx]);
+    }
+    if (spec == '60x40') {
+        // 判断idx是否是奇数
+        command.setSize(60, 40);
+        command.setGap(10);
+        command.setCls();
+        command.setDirection(1);
+        command = tem60x40(command, list[idx]);
+    }
+    if (spec == '60x60') {
+        // 判断idx是否是奇数
+        command.setSize(60, 30);
+        command.setGap(10);
+        command.setCls();
+        command.setDirection(1);
+        command = tem60x60(command, list[idx]);
+    }
+    command.setPagePrint()
+    const device = stepsObject['connect']?.device;
+    if (!device) {
+        uni.showToast({ icon: 'none', title: '未连接设备' });
+        return;
+    }
+    console.log(command.getData());
+    
+    await writeBLECharacteristicSend({
+        deviceId: device.deviceId,
+        serviceId: device.serviceId,
+        characteristicId: device.characteristicId,
+        uint8Array: command.getData(),
+    });
+    if (list.length - 1 > idx) {
+        writeSendCommand(list, spec, idx + 1)
+    } else {
+        // 打印完成,重置状态
+        isPrinting.value = false;
+        uni.showToast({
+            icon: 'none',
+            title: '打印完成'
+        })
+    }
+};
+// 如果是 30x30
+</script>
+<style lang="scss" scoped></style>

+ 178 - 0
src/plant/print/print-self/index.vue

@@ -0,0 +1,178 @@
+<template>
+    <z-paging ref="paging" bgColor="#fff" safe-area-inset-bottom scroll-with-animation>
+        <template #top>
+            <ut-navbar :title="stepsObject[currentStep].title" :fixed="false" border :breadcrumb="false"></ut-navbar>
+            <view class="pd-24">
+                <ut-steps-title :stepsObject="stepsObject"></ut-steps-title>
+            </view>
+            <view class="pd-5 bg-#f7f7f7"></view>
+        </template>
+        <view>
+            <view v-show="currentStep === 'connect'">
+                <!-- 业务组件链接打印机 -->
+                <connect-printer :info="stepsObject[currentStep]" @next="nextSteps" @prev="prevSteps" prevStepValue="confirm" nextStepValue="print"></connect-printer>
+            </view>
+            <view v-show="currentStep === 'print'">
+                <!-- 业务组件打印 -->
+                <!-- 打印写入打印机 -->
+                <print-wrapper :info="stepsObject[currentStep]" @test="printTest" @prev="prevSteps" prevStepValue="connect"></print-wrapper>
+            </view>
+        </view>
+    </z-paging>
+</template>
+
+<script setup lang="ts">
+import ConnectPrinter from './models/connect-printer.vue';
+import { tem30x30, tem60x40, tem60x60 } from '../models/print-tem';
+import PrintWrapper from './models/print-wrapper.vue';
+import { writeBLECharacteristicSend } from '@/utils/blue-device-services';
+import jpPrinter from '../models/tspl';
+const stepsObject = reactive<any>({
+    check: {
+        title: '核对信息',
+        value: 'check',
+        status: 'completed', // 为开始、进行中、已完成 三种状态分别值为 'not-started'、'in-progress'、'completed'
+        sort: 0,
+    },
+    confirm: {
+        title: '确认数量',
+        value: 'confirm',
+        status: 'completed', // 为开始、进行中、已完成 三种状态分别值为 'not-started'、'in-progress'、'completed'
+        sort: 1,
+    },
+    connect: {
+        title: '连接打印机',
+        value: 'connect',
+        status: 'in-progress', // 为开始、进行中、已完成 三种状态分别值为 'not-started'、'in-progress'、'completed'
+        sort: 2,
+    },
+    print: {
+        title: '打印',
+        value: 'print',
+        status: 'not-started', // 为开始、进行中、已完成 三种状态分别值为 'not-started'、'in-progress'、'completed'
+        sort: 3,
+    },
+});
+// 打印模式
+const mode = ref('self'); // 自行打印, 区间打印 值分别为 self, range
+const currentStep = ref('connect');
+const paging = ref(null);
+const isPrinting = ref(false);
+onLoad((options: any) => {});
+const nextSteps = (data: any) => {
+    if (!data.info || !data?.info?.value) return;
+    stepsObject[data?.info?.value] = {
+        ...data.info,
+    };
+    stepsObject[data?.nextStepValue].status = 'in-progress';
+    currentStep.value = data?.nextStepValue;
+};
+const prevSteps = (data: any) => {
+    currentStep.value = data?.prevStepValue;
+};
+const testList = reactive([
+    {
+        pm: '三七',
+        zl: '20g',
+        scrq: '2012.09.18',
+        zzph: 87391273912,
+        cj: '云南省文山市县中药材有限公司',
+        zsm: 'QX0000005600000318',
+        qr: 'https://t.zycpzs.cn/?c=QCCS412507030000101ND'
+    },
+]);
+const printTest = (data: any) => {
+    // 检查是否正在打印
+    if (isPrinting.value) {
+        uni.showToast({ icon: 'none', title: '当前打印任务未完成,请稍后' });
+        return;
+    }
+    // 测试数据
+    prepareSend(testList, data.printSpec);
+};
+// 打印写入
+const prepareSend = (list: any[], spec: string = '30x30') => {
+    if (spec == '30x30') {
+        // 判断idx是否是奇数
+        writeSend30x30(list);
+    }
+    if (spec == '60x40') {
+        // 40x40
+        writeSendCommand(list, '60x40', 0)
+    }
+    if (spec == '60x60') {
+        // 30x30
+        writeSendCommand(list, '60x60', 0)
+    }
+};
+const writeSend30x30 = (list: any[]) => {
+    // arr两个两个一组,偶数组没有是空
+    const arr = list.reduce((acc: any, cur: any, idx: number) => {
+        if (idx % 2 == 0) {
+            acc.push([cur]);
+        } else {
+            acc[acc.length - 1].push(cur);
+        }
+        return acc;
+    }, []);
+    writeSendCommand(arr, '30x30', 0)
+};
+// writeSend
+const writeSendCommand = async (list: any[], spec: string = '30x30', idx = 0) => {
+    // 首次调用时设置打印状态为进行中
+    if (idx === 0) {
+        isPrinting.value = true;
+    }
+    let command = new jpPrinter();
+    if (spec == '30x30') {
+        // 判断idx是否是奇数
+        command.setSize(60, 30);
+        command.setGap(10);
+        command.setCls();
+        command.setDirection(1);
+        command = tem30x30(command, list[idx]);
+    }
+    if (spec == '60x40') {
+        // 判断idx是否是奇数
+        command.setSize(60, 40);
+        command.setGap(10);
+        command.setCls();
+        command.setDirection(1);
+        command = tem60x40(command, list[idx]);
+    }
+    if (spec == '60x60') {
+        // 判断idx是否是奇数
+        command.setSize(60, 30);
+        command.setGap(10);
+        command.setCls();
+        command.setDirection(1);
+        command = tem60x60(command, list[idx]);
+    }
+    command.setPagePrint()
+    const device = stepsObject['connect']?.device;
+    if (!device) {
+        uni.showToast({ icon: 'none', title: '未连接设备' });
+        return;
+    }
+    console.log(command.getData());
+    
+    await writeBLECharacteristicSend({
+        deviceId: device.deviceId,
+        serviceId: device.serviceId,
+        characteristicId: device.characteristicId,
+        uint8Array: command.getData(),
+    });
+    if (list.length - 1 > idx) {
+        writeSendCommand(list, spec, idx + 1)
+    } else {
+        // 打印完成,重置状态
+        isPrinting.value = false;
+        uni.showToast({
+            icon: 'none',
+            title: '打印完成'
+        })
+    }
+};
+// 如果是 30x30
+</script>
+<style lang="scss" scoped></style>

+ 4 - 3
src/plant/print/print-steps/index.vue

@@ -23,10 +23,10 @@
 
 <script setup lang="ts">
 import ConnectPrinter from './models/connect-printer.vue';
-import { tem30x30, tem60x40, tem60x60 } from './models/print-tem';
+import { tem30x30, tem60x40, tem60x60 } from '../models/print-tem';
 import PrintWrapper from './models/print-wrapper.vue';
 import { writeBLECharacteristicSend } from '@/utils/blue-device-services';
-import jpPrinter from './models/tspl';
+import jpPrinter from '../models/tspl';
 const stepsObject = reactive<any>({
     check: {
         title: '核对信息',
@@ -53,6 +53,8 @@ const stepsObject = reactive<any>({
         sort: 3,
     },
 });
+// 打印模式
+const mode = ref('self'); // 自行打印, 区间打印 值分别为 self, range
 const currentStep = ref('connect');
 const paging = ref(null);
 const isPrinting = ref(false);
@@ -160,7 +162,6 @@ const writeSendCommand = async (list: any[], spec: string = '30x30', idx = 0) =>
         characteristicId: device.characteristicId,
         uint8Array: command.getData(),
     });
-    console.log('打印第' + idx + 1 + '张');
     if (list.length - 1 > idx) {
         writeSendCommand(list, spec, idx + 1)
     } else {