| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <template>
- <z-paging ref="paging" bgColor="#f7f7f7" 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-5"></view>
- </template>
- <view>
- <view v-show="currentStep === 'range'">
- <range-print :info="stepsObject[currentStep]" :opts="opts" @next="nextSteps" @formdata="getFormData" nextStepValue="connect"></range-print>
- </view>
- <view v-show="currentStep === 'connect'" class="bg-fff">
- <!-- 业务组件链接打印机 -->
- <connect-printer :info="stepsObject[currentStep]" @next="nextSteps" @prev="prevSteps" prevStepValue="range" nextStepValue="print"></connect-printer>
- </view>
- <view v-show="currentStep === 'print'" class="bg-fff">
- <!-- 业务组件打印 -->
- <!-- 打印写入打印机 -->
- <print-wrapper :info="stepsObject[currentStep]" :printCount="form?.printCount" @test="printTest" @prev="prevSteps" @print="printCodes" 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';
- import { useClientRequest } from '@/utils/request';
- import RangePrint from '../models/range-print.vue';
- const printSpec = ref('30x30');
- const printCodes = async (data: any) => {
- printSpec.value = data.printSpec;
- // 检查是否正在打印
- if (isPrinting.value) {
- uni.showToast({ icon: 'none', title: '当前打印任务未完成,请稍后' });
- return;
- }
- isPrinting.value = true;
- getPrintCodeList();
- };
- // 打印列表
- const getPrintCodeList = async () => {
- const res = await useClientRequest
- .get(`/plt-api/app/printLog/getPrintCodeList/${opts.value?.id}`, {
- start: form.value?.start,
- end: form.value?.end,
- })
- .catch((err) => {
- isPrinting.value = false;
- });
- if (!res || res.code !== 200) {
- isPrinting.value = false;
- return;
- }
- prepareSend(res?.data, printSpec.value)
- };
- const stepsObject = reactive<any>({
- range: {
- title: '区间打印',
- value: 'range',
- status: 'in-progress', // 为开始、进行中、已完成 三种状态分别值为 'not-started'、'in-progress'、'completed'
- sort: 1,
- },
- connect: {
- title: '连接打印机',
- value: 'connect',
- status: 'not-started', // 为开始、进行中、已完成 三种状态分别值为 'not-started'、'in-progress'、'completed'
- sort: 2,
- },
- print: {
- title: '打印',
- value: 'print',
- status: 'not-started', // 为开始、进行中、已完成 三种状态分别值为 'not-started'、'in-progress'、'completed'
- sort: 3,
- },
- });
- const currentStep = ref('connect');
- const isPrinting = ref(false);
- const opts = ref<any>(null);
- onLoad((options: any) => {
- console.log(options);
- opts.value = options;
- getBatchInfo()
- });
- 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 info = ref<any>(null);
- const form = ref<any>(null);
- const getFormData = (data: any) => {
- console.log(data);
-
- form.value = data;
- };
- const prevSteps = (data: any) => {
- currentStep.value = data?.prevStepValue;
- };
- const testList = reactive([
- {
- padSn: '0000002',
- prefix: 'PCC1W1260311',
- sn: 2,
- traceCode: 'PCC1W12603110000002AV',
- url: 'https://t.yujin.shuziyunyao.com/pt?c=PCC1W12603110000002AV',
- },
- ]);
- const printTest = (data: any) => {
- const device = stepsObject['connect']?.device;
- if (!device) {
- uni.showToast({ icon: 'none', title: '未连接设备' });
- return;
- }
- // 检查是否正在打印
- if (isPrinting.value) {
- uni.showToast({ icon: 'none', title: '当前打印任务未完成,请稍后' });
- return;
- }
- isPrinting.value = true;
- // 测试数据
- prepareSend(testList, data.printSpec);
- };
- // 打印写入
- const prepareSend = (list: any[], spec: string = '30x30') => {
- if (spec == '30x30') {
- 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) => {
- // 首次调用时设置打印状态为进行中
- 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], info.value);
- }
- if (spec == '60x40') {
- // 判断idx是否是奇数
- command.setSize(60, 40);
- command.setGap(10);
- command.setCls();
- command.setDirection(1);
- command = tem60x40(command, list[idx], info.value);
- }
- if (spec == '60x60') {
- // 判断idx是否是奇数
- command.setSize(60, 30);
- command.setGap(10);
- command.setCls();
- command.setDirection(1);
- command = tem60x60(command, list[idx], info.value);
- }
- 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: '打印完成',
- });
- }
- };
- // 获取批次信息接口
- const getBatchInfo = async () => {
- const res = await useClientRequest.get(`/plt-api/app/packTask/getPackTraceSimpleInfo/${opts.value?.packId}`);
- if (!res?.data) return
- info.value = res?.data;
- }
- // 如果是 30x30
- </script>
- <style lang="scss" scoped></style>
|