yyb
10 小时以前 3a75daf63f5b64af3388424c3de82662c20aa383
添加了打印超时定时器清除逻辑,确保打印成功后清除超时回调
已修改1个文件
502 ■■■■ 文件已修改
pages/wareHouse/nuclearScale/nuclearscalerecord.vue 502 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/wareHouse/nuclearScale/nuclearscalerecord.vue
@@ -1,17 +1,49 @@
<template>
    <view class="page">
        <view class="finishProductIn-locno-bg" />
        <u-navbar title="核磅记录" :background="background" :border-bottom="false" :title-bold="true" title-color="#000"
            back-icon-color="#000">
    <u-navbar
      title="核磅记录"
      :background="background"
      :border-bottom="false"
      :title-bold="true"
      title-color="#000"
      back-icon-color="#000"
    >
            <view class="navbar-right" slot="right" @click="goPrintAll">
                全部打印
            </view>
        </u-navbar>
        <view class="wrap">
            <scroll-view class="finishProductIn-locno-scroll-list" scroll-y="true" @scrolltolower="getmoreList()">
                <u-cell-group class="finishProductIn-locno-scroll-list-group" :border="false">
                    <view class="content" v-for="(item, index) in list" :key="item.locNo" :index="index"
                        @click="selectNo(item)">
      <!-- 连接和打印状态指示器 -->
      <view
        class="status-indicator"
        :class="{
          connected: connectionStatus === 'connected',
          connecting: connectionStatus === 'connecting',
          disconnected: connectionStatus === 'disconnected',
        }"
      >
        <text class="status-text">{{ getConnectionStatusText() }}</text>
        <text class="print-status" v-if="printStatus !== 'idle'"
          >- {{ getPrintStatusText() }}</text
        >
      </view>
      <scroll-view
        class="finishProductIn-locno-scroll-list"
        scroll-y="true"
        @scrolltolower="getmoreList()"
      >
        <u-cell-group
          class="finishProductIn-locno-scroll-list-group"
          :border="false"
        >
          <view
            class="content"
            v-for="(item, index) in list"
            :key="item.locNo"
            :index="index"
            @click="selectNo(item)"
          >
                        <view class="content-header">
                            <view class="content-header-title">{{ index + 1 }}</view>
                        </view>
@@ -92,43 +124,47 @@
                    </view>
                </u-cell-group>
                <view class="loadmore" @click="getmoreList()">
                    <u-loadmore :status="status" :load-text="loadText" @loadmore="getmoreList()" />
          <u-loadmore
            :status="status"
            :load-text="loadText"
            @loadmore="getmoreList()"
          />
                </view>
            </scroll-view>
        </view>
        <u-toast ref="uToast" />
        <u-modal v-model="maskShow" title=""
            :show-confirm-button="false" >
    <u-modal v-model="maskShow" title="" :show-confirm-button="false">
            <view  @touchmove.stop.prevent="moveHandle" @click="maskclose">
                <scroll-view class="uni-scroll_box" scroll-y @touchmove.stop.prevent="moveHandle"
                    @click.stop="moveHandle">
        <scroll-view
          class="uni-scroll_box"
          scroll-y
          @touchmove.stop.prevent="moveHandle"
          @click.stop="moveHandle"
        >
                    <view class="modal-title">选择蓝牙设备</view>
                    <view v-if="listDevice.length === 0" class="empty-tip">暂无设备</view>
                    <view v-for="(item, index) in listDevice" :key="index" @click="tapQuery(item)" class="device-item">
          <view
            v-for="(item, index) in listDevice"
            :key="index"
            @click="tapQuery(item)"
            class="device-item"
          >
                        <view class="device-name">
                            <text>名称:</text>
                            <text>{{ item.name || '未知设备' }}</text>
              <text>{{ item.name || "未知设备" }}</text>
                        </view>
                        <view class="device-uuid">
                            <text>UUID:</text>
                            <text>{{ item.address || '无地址' }}</text>
              <text>{{ item.address || "无地址" }}</text>
                        </view>
                    </view>
                </scroll-view>
            </view>
        </u-modal>
                <!-- </scroll-view>
            </view>
        </u-modal> -->
        <!-- 连接和打印状态指示器 -->
        <view class="status-indicator" :class="{'connected': connectionStatus === 'connected', 'connecting': connectionStatus === 'connecting', 'disconnected': connectionStatus === 'disconnected'}">
            <text class="status-text">{{ getConnectionStatusText() }}</text>
            <text class="print-status" v-if="printStatus !== 'idle'">- {{ getPrintStatusText() }}</text>
        </view>
    </view>
</template>
<script>
    import content_bg from '@/static/custom/finishProductIn/locNoBg.png'
import content_bg from "@/static/custom/finishProductIn/locNoBg.png";
    const jcapi = uni.requireNativePlugin("JCSDK-JCApiModule");
    // 二维码类型
@@ -136,35 +172,35 @@
        QrCode: 31,
        PDF417: 32,
        DataMatrix: 33,
        AZTEC: 34
    }
  AZTEC: 34,
};
    // 线条类型
    const LineType = {
        Solid: 1, // 实线
        Dotted: 2, // 虚线(默认虚实1:1相间)
    }
};
    // 换行方式
    const LineModeType = {
        Justified: 1, // 宽高固定,内容自适应(字号/字间距/行间距按比例缩放)
        AutoHeight: 2, // 宽度固定,高度自适应
        Fixed: 4, // 宽高固定,超出部分裁剪
        Adapt: 6, // 宽高固定,内容超过时预设宽高自动缩小
    }
};
    export default {
        data() {
            return {
                background: {
                    backgroundImage: `url(${content_bg})`,
                    backgroundAttachment: 'fixed',
                    backgroundSize: '100% auto',
                    backgroundRepeat: 'no-repeat',
        backgroundAttachment: "fixed",
        backgroundSize: "100% auto",
        backgroundRepeat: "no-repeat",
                },
                keywords: '',
      keywords: "",
                list: [],
                total: 0,
                pageNum: 1,
                pageSize: 10,
                status: 'loading',
      status: "loading",
                loadText: {
                    loadmore: "加载更多...",
                    loading: "努力加载中...",
@@ -185,39 +221,39 @@
                //    1:热敏
                //     2:热转印
                connectedDevice: null, // 已连接的打印机
                connectionStatus: 'disconnected', // 连接状态: disconnected, connecting, connected
                printStatus: 'idle', // 打印状态: idle, printing, error
                errorMessage: '' // 错误信息
      connectionStatus: "disconnected", // 连接状态: disconnected, connecting, connected
      printStatus: "idle", // 打印状态: idle, printing, error
      errorMessage: "", // 错误信息
            };
        },
        onLoad() {
            this.getlist()
    this.getlist();
            // 初始化SDK
            jcapi.initSDK()
    jcapi.initSDK();
            // 监听页码回调
            jcapi.didReadPrintCountInfo(function(r) {
                console.log(r)
            })
      console.log(r);
    });
            // 监听错误回调
            jcapi.didReadPrintErrorInfo((r) => {
                console.log(r)
      console.log(r);
                if (r.code == 23) {
                    // 打印机断开连接
                    this.connectedDevice = null
        this.connectedDevice = null;
                    uni.showToast({
                        icon: 'none',
                        title: '打印机连接已断开,请重新连接',
                        duration: 2 * 1000
                    })
          icon: "none",
          title: "打印机连接已断开,请重新连接",
          duration: 2 * 1000,
        });
                } else {
                    uni.showToast({
                        icon: 'none',
          icon: "none",
                        title: JSON.stringify(r),
                        duration: 2 * 1000
                    })
          duration: 2 * 1000,
        });
                }
            })
    });
        },
        methods: {
            getmoreList() {
@@ -235,7 +271,7 @@
                this.$u.api.workReporting
                    .getWorkshopOrder({
                        current: this.pageNum,
                        size: this.pageSize
          size: this.pageSize,
                    })
                    .then((res) => {
                        this.list = res.data.records;
@@ -272,29 +308,26 @@
            },
            // 检查蓝牙连接状态
            async checkBluetoothConnection() {
                console.log('disconnected1111111111111')
                if (!this.connectedDevice) {
                    this.connectionStatus = 'disconnected';
        this.connectionStatus = "disconnected";
                    return false;
                }
                console.log('disconnected2222222222')
                // 设置为连接中状态
                this.connectionStatus = 'connecting';
                console.log('disconnected33333333333')
      this.connectionStatus = "connecting";
                // 增强连接状态检测
                return new Promise(resolve => {
      return new Promise((resolve) => {
                    // 简化连接状态检测,直接使用已记录的连接状态
                    if (this.connectedDevice) {
                        this.connectionStatus = 'connected';
          this.connectionStatus = "connected";
                        resolve(true);
                    } else {
                        this.connectionStatus = 'disconnected';
          this.connectionStatus = "disconnected";
                        uni.showToast({
                            icon: 'none',
                            title: '打印机未连接,请先连接',
                            duration: 2000
            icon: "none",
            title: "打印机未连接,请先连接",
            duration: 2000,
                        });
                        resolve(false);
                    }
@@ -317,12 +350,8 @@
            // 处理打印队列
            async processPrintQueue() {
                while (this.printQueue.length > 0) {
                    console.log('111111111111111', this.printQueue.length)
                    // 检查连接状态
                    console.log('12222222222222222')
                    const isConnected = await this.checkBluetoothConnection();
                    console.log('isConnected',isConnected)
                    if (!isConnected) {
                        // 如果未连接,显示蓝牙连接对话框
                        this.searchDevice();
@@ -331,11 +360,10 @@
                    }
                    this.printing = true;
                    this.printStatus = 'printing';
        this.printStatus = "printing";
                    // 取出队列中的第一个任务
                    const item = this.printQueue.shift();
                    console.log('打印的任务',item)
                    try {
                        // 执行打印
@@ -343,17 +371,17 @@
                        // 打印成功后继续处理下一个
                        uni.showToast({
                            title: '打印成功',
                            icon: 'success',
                            duration: 1000
            title: "打印成功",
            icon: "success",
            duration: 1000,
                        });
                        // 短暂延迟,避免打印机缓存溢出
                        await new Promise(resolve => setTimeout(resolve, 1000));
          await new Promise((resolve) => setTimeout(resolve, 1000));
                    } catch (error) {
                        console.error('打印出错:', error);
                        this.printStatus = 'error';
                        this.errorMessage = error.message || '打印时发生未知错误';
          console.error("打印出错:", error);
          this.printStatus = "error";
          this.errorMessage = error.message || "打印时发生未知错误";
                        this.printing = false;
                        // 记录失败的任务,不重新添加到队列
@@ -362,8 +390,8 @@
                        uni.showToast({
                            title: `打印失败: ${this.errorMessage}`,
                            icon: 'none',
                            duration: 2000
            icon: "none",
            duration: 2000,
                        });
                        // 继续处理下一个任务
                        continue;
@@ -371,29 +399,29 @@
                }
                this.printing = false;
                this.printStatus = 'idle';
      this.printStatus = "idle";
            },
            // 打印单个信息
            selectNo(item) {
                let that = this
      let that = this;
                uni.showModal({
                    title: '提示',
                    content: '是否打印装箱单?',
        title: "提示",
        content: "是否打印装箱单?",
                    showCancel: true,
                    success: async function(res) {
                        if (res.confirm) {
                            // 添加到打印队列
                            that.addToPrintQueue(item);
                        }
                    }
        },
                });
            },
            // 打印全部信息
            goPrintAll() {
                let that = this
      let that = this;
                uni.showModal({
                    title: '提示',
        title: "提示",
                    content: `是否打印全部${that.list.length}条装箱单?`,
                    showCancel: true,
                    success: async function(res) {
@@ -401,66 +429,40 @@
                            // 添加到打印队列
                            that.addToPrintQueue([...that.list]);
                        }
                    }
        },
                });
            },
            moveHandle() {
            },
            maskclose() {
            },
    moveHandle() {},
    maskclose() {},
            //打印二维码
            async printQrCode(item) {
                return new Promise(async (resolve, reject) => {
                    console.log('item de shuju ', item)
                    // const params = {
                    //     rwMatlBindId: item.id
                    // };
        const params = {
            rwMatlBindId: item.id
        };
                    try {
                        let res = {
                            data: {
                            ht:'1',
                            lj:'1',
                            ljms:'1',
                            fh:'1',
                            scdt:'1',
                            scph:'1',
                            fhdw:'1',
                            shdw:'1',
                        }}
                        // let res = await this.$u.api.dailyPaper.zongjianLabelInfo(params)
          let res = await this.$u.api.dailyPaper.zongjianLabelInfo(params)
                        if (!res.data) {
                            this.$refs.uToast.show({
                                title: '未查询到该标签信息!',
                                type: 'warning '
                            })
                            reject(new Error('未查询到该标签信息'));
                            return
              title: "未查询到该标签信息!",
              type: "warning ",
            });
            reject(new Error("未查询到该标签信息"));
            return;
                        }
                        // 从API响应中提取所需数据
                        const {
                            ht,
                            lj,
                            ljms,
                            fh,
                            scdt,
                            scph,
                            fhdw,
                            shdw
                        } = res.data
          const { ht, lj, ljms, fh, scdt, scph, fhdw, shdw } = res.data;
                        // 初始化画板
                        jcapi.initDrawingBoard({
                            width: 70,
                            height: 49,
                            rotate: 90
            rotate: 90,
                        });
                        // 绘制二维码
                        const qrContent =
                            `ht:${ht}\nlj:${lj}\nljms:${ljms}\nfh:${fh}\nscdt:${scdt}\nscph:${scph}\nfhdw:${fhdw}\nshdw:${shdw}`;
          const qrContent = `ht:${ht}\nlj:${lj}\nljms:${ljms}\nfh:${fh}\nscdt:${scdt}\nscph:${scph}\nfhdw:${fhdw}\nshdw:${shdw}`;
                        jcapi.drawLabelQrCode({
                            x: 43.5,
                            y: 2,
@@ -472,63 +474,66 @@
                        });
                        // 绘制横线
                        this.getDrawLabelLine(1, 1, 67, 0.5, 0, LineType.Solid)
                        this.getDrawLabelLine(1, 6, 42, 0.3, 0, LineType.Solid)
                        this.getDrawLabelLine(1, 11, 42, 0.3, 0, LineType.Solid)
                        this.getDrawLabelLine(1, 16, 42, 0.3, 0, LineType.Solid)
                        this.getDrawLabelLine(1, 21, 42, 0.3, 0, LineType.Solid)
                        this.getDrawLabelLine(1, 27, 67, 0.3, 0, LineType.Solid)
                        this.getDrawLabelLine(1, 32, 67, 0.3, 0, LineType.Solid)
                        this.getDrawLabelLine(1, 37, 67, 0.3, 0, LineType.Solid)
                        this.getDrawLabelLine(1, 42, 67, 0.3, 0, LineType.Solid)
                        this.getDrawLabelLine(1, 47, 67, 0.5, 0, LineType.Solid)
          this.getDrawLabelLine(1, 1, 67, 0.5, 0, LineType.Solid);
          this.getDrawLabelLine(1, 6, 42, 0.3, 0, LineType.Solid);
          this.getDrawLabelLine(1, 11, 42, 0.3, 0, LineType.Solid);
          this.getDrawLabelLine(1, 16, 42, 0.3, 0, LineType.Solid);
          this.getDrawLabelLine(1, 21, 42, 0.3, 0, LineType.Solid);
          this.getDrawLabelLine(1, 27, 67, 0.3, 0, LineType.Solid);
          this.getDrawLabelLine(1, 32, 67, 0.3, 0, LineType.Solid);
          this.getDrawLabelLine(1, 37, 67, 0.3, 0, LineType.Solid);
          this.getDrawLabelLine(1, 42, 67, 0.3, 0, LineType.Solid);
          this.getDrawLabelLine(1, 47, 67, 0.5, 0, LineType.Solid);
                        //绘制竖线
                        this.getDrawLabelLine(1, 1, 0.5, 46, 0, LineType.Solid) // 竖线1
                        this.getDrawLabelLine(43, 1, 0.3, 26, 0, LineType.Solid) // 竖线2
                        this.getDrawLabelLine(68, 1, 0.5, 46, 0, LineType.Solid) // 竖线3
          this.getDrawLabelLine(1, 1, 0.5, 46, 0, LineType.Solid); // 竖线1
          this.getDrawLabelLine(43, 1, 0.3, 26, 0, LineType.Solid); // 竖线2
          this.getDrawLabelLine(68, 1, 0.5, 46, 0, LineType.Solid); // 竖线3
                        // 绘制文本
                        this.getDrawLabelText(3, 2.5, 40, 8, '中天科技装箱清单', 2.5, 0, LineModeType.AutoHeight, 0, 0, 1, 1, 1)
                        this.getDrawLabelText(2, 7, 25, 8, '合同号:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1, 1)
                        this.getDrawLabelText(2, 12, 25, 8, '零件号:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1, 1)
                        this.getDrawLabelText(2, 17, 25, 8, '零件描述:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1, 1)
                        this.getDrawLabelText(2, 22.5, 25, 8, '发货/装箱数:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1, 1)
                        this.getDrawLabelText(2, 27.5, 25, 8, '生产日期:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1, 1)
                        this.getDrawLabelText(2, 32.5, 25, 8, '生产批号:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1, 1)
                        this.getDrawLabelText(2, 37.5, 25, 8, '发货单位:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1, 1)
                        this.getDrawLabelText(2, 42.5, 25, 8, '收货单位:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1, 1)
          this.getDrawLabelText(3,2.5,40,8,"中天科技装箱清单",2.5,0,LineModeType.AutoHeight,0,0,1,1,1);
          this.getDrawLabelText(2,7,25,8,"合同号:",2.5,0,LineModeType.AutoHeight,0,0,0,1,1);
          this.getDrawLabelText(2,12,25,8,"零件号:",2.5,0,LineModeType.AutoHeight,0,0,0,1,1);
          this.getDrawLabelText(2,17,25,8,"零件描述:",2.5,0,LineModeType.AutoHeight,0,0,0,1,1);
          this.getDrawLabelText(2,22.5,25,8,"发货/装箱数:",2.5,0,LineModeType.AutoHeight,0,0,0,1,1);
          this.getDrawLabelText(2,27.5,25,8,"生产日期:",2.5,0,LineModeType.AutoHeight,0,0,0,1,1);
          this.getDrawLabelText(2,32.5,25,8,"生产批号:",2.5,0,LineModeType.AutoHeight,0,0,0,1,1);
          this.getDrawLabelText(2,37.5,25,8,"发货单位:",2.5,0,LineModeType.AutoHeight,0,0,0,1,1);
          this.getDrawLabelText(2,42.5,25,8,"收货单位:",2.5,0,LineModeType.AutoHeight,0,0,0,1,1);
                        // 填充参数值
                        this.getDrawLabelText(11, 7, 30, 8, ht, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0, 1)
                        this.getDrawLabelText(11, 12, 32, 8, lj, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0, 1)
                        this.getDrawLabelText(14, 17, 30, 8, ljms, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0, 1)
                        this.getDrawLabelText(17, 22.5, 27, 8, fh, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0, 1)
                        this.getDrawLabelText(14, 27.5, 55, 8, scdt, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0, 1)
                        this.getDrawLabelText(14, 32.7, 55, 8, scph, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0, 1)
                        this.getDrawLabelText(14, 37.5, 55, 8, fhdw, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0, 1)
                        this.getDrawLabelText(14, 42.5, 55, 8, shdw, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0, 1)
          this.getDrawLabelText(11,7,30,8,ht,2.5,0,LineModeType.AutoHeight,0,0,0,0,1);
          this.getDrawLabelText(11,12,32,8,lj,2.5,0,LineModeType.AutoHeight,0,0,0,0,1);
          this.getDrawLabelText(14,17,30,8,ljms,2.5,0,LineModeType.AutoHeight,0,0,0,0,1);
          this.getDrawLabelText(17,22.5,27,8,fh,2.5,0,LineModeType.AutoHeight,0,0,0,0,1);
          this.getDrawLabelText(14,27.5,55,8,scdt,2.5,0,LineModeType.AutoHeight,0,0,0,0,1);
          this.getDrawLabelText(14,32.7,55,8,scph,2.5,0,LineModeType.AutoHeight,0,0,0,0,1);
          this.getDrawLabelText(14,37.5,55,8,fhdw,2.5,0,LineModeType.AutoHeight,0,0,0,0,1);
          this.getDrawLabelText(14,42.5,55,8,shdw,2.5,0,LineModeType.AutoHeight,0,0,0,0,1);
                        // 生成打印数据
                        let imageJsonObj = jcapi.generateLabelJson()
                        console.log('打印的数据',imageJsonObj)
          let imageJsonObj = jcapi.generateLabelJson();
                        // 设置打印任务
                        jcapi.startJob({
          jcapi.startJob(
            {
                            totalCount: 1,
                            density: this.printDensity,
                            labelType: this.labelType,
                            printMode: this.printMode,
                        }, function(r) {
            },
            function (r) {
                            if (r.code == 0) {
                                // 打印数据
                                // 存储原始打印计数回调
                                const originalPrintCountCallback = jcapi.didReadPrintCountInfo._callback;
                const originalPrintCountCallback =
                  jcapi.didReadPrintCountInfo._callback;
                                // 临时打印计数回调,用于确认打印完成
                                const tempPrintCountCallback = (printResult) => {
                                    console.log("打印计数回调:", printResult);
                                    // 恢复原始回调
                                    jcapi.didReadPrintCountInfo(originalPrintCountCallback);
                  // 清除打印超时
                  clearTimeout(printTimeout);
                                    // 结束当前打印任务
                                    // 解析Promise表示打印完成
                                    resolve();
@@ -539,107 +544,112 @@
                                // 添加打印超时处理
                                const printTimeout = setTimeout(() => {
                                    jcapi.didReadPrintCountInfo(originalPrintCountCallback);
                                    reject(new Error('打印超时未响应'));
                                }, 10000);
                  reject(new Error("打印超时未响应"));
                }, 20000);
                                jcapi.printData(imageJsonObj, {
                                    "printQuantity": 1,
                                }, function(r) {
                jcapi.printData(
                  imageJsonObj,
                  {
                    printQuantity: 1,
                  },
                  function (r) {
                                    if (r.code != 0) {
                                        console.log("打印失败", r);
                                        // 恢复原始回调
                                        jcapi.didReadPrintCountInfo(originalPrintCountCallback);
                                        // 结束当前打印任务
                                        reject(new Error(r.msg || '打印失败'));
                      reject(new Error(r.msg || "打印失败"));
                                    }
                                    // ��印数据发送成功后等待打印计数回调确认实际打印完成
                                })
                    // 打印数据发送成功后等待打印计数回调确认实际打印完成
                  }
                );
                            } else {
                                console.log("设置打印任务失败", r)
                                reject(new Error(r.msg || '设置打印任务失败'));
                reject(new Error(r.msg || "设置打印任务失败"));
                            }
                        })
            }
          );
                    } catch (error) {
                        console.log(error)
                        reject(error);
                    }
                });
            },
            tapQuery(item) {
                this.maskShow = false
      this.maskShow = false;
                // 连接打印机
                let _this = this;
                console.log(item)
                // 设置为连接中状态
                this.connectionStatus = 'connecting';
      this.connectionStatus = "connecting";
                jcapi.openPrinterByDevice({
      jcapi.openPrinterByDevice(
        {
                    address: item.address,
                    name: item.name,
                    deviceType: 0 // 设备类型:0-蓝牙,1-网络
                }, function(r) {
          deviceType: 0, // 设备类型:0-蓝牙,1-网络
        },
        function (r) {
                    if (r.code == 0) {
                        _this.connectedDevice = item
                        _this.connectionStatus = 'connected';
            _this.connectedDevice = item;
            _this.connectionStatus = "connected";
                        uni.showToast({
                            title: "连接成功",
                            duration: 1500
                        })
              duration: 1500,
            });
                        // 开始处理打印队列
                        console.log('打印队列',_this.printQueue)
                        if (_this.printQueue.length > 0) {
                            _this.processPrintQueue();
                        }
                    } else {
                        _this.connectionStatus = 'disconnected';
            _this.connectionStatus = "disconnected";
                        uni.showToast({
                            title: "连接失败: " + (r.msg || '未知错误'),
                            icon: 'none',
                            duration: 2000
                        })
              title: "连接失败: " + (r.msg || "未知错误"),
              icon: "none",
              duration: 2000,
            });
                    }
                })
        }
      );
            },
            //打印相关
            searchDevice() {
                let _this = this
                uni.openBluetoothAdapter({ // 确认蓝牙是否打开
      let _this = this;
      uni.openBluetoothAdapter({
        // 确认蓝牙是否打开
                    success(r) {
                        uni.showLoading({
                            title: "搜索中..."
                        })
            title: "搜索中...",
          });
                        // 未授予蓝牙相关权限和未打开手机定位会搜索不到设备
                        jcapi.getBluetoothDevices(function(r) {
                            console.log("device:" + JSON.stringify(r))
            console.log("device:" + JSON.stringify(r));
                            // 搜索到设备回调
                            uni.hideLoading()
            uni.hideLoading();
                            // 如果之前有连接的设备但不在搜索结果中,说明设备已更换
                            if (_this.connectedDevice && !r.some(dev => dev.address === _this
                                    .connectedDevice.address)) {
            if (
              _this.connectedDevice &&
              !r.some((dev) => dev.address === _this.connectedDevice.address)
            ) {
                                _this.connectedDevice = null;
                                uni.showToast({
                                    icon: 'none',
                                    title: '已连接的蓝牙设备已更换,请重新选择',
                                    duration: 2000
                icon: "none",
                title: "已连接的蓝牙设备已更换,请重新选择",
                duration: 2000,
                                });
                            }
                            _this.listDevice = r;
                            _this.maskShow = true
                        })
            _this.maskShow = true;
          });
                    },
                    fail(e) {
                        uni.showModal({
                            title: '提示',
                            content: '打开蓝牙失败,请检查蓝牙是否开启',
                            showCancel: false
                        })
                        console.log("开启蓝牙设备失败" + e)
                    }
                })
            title: "提示",
            content: "打开蓝牙失败,请检查蓝牙是否开启",
            showCancel: false,
          });
          console.log("开启蓝牙设备失败" + e);
            },
            // 绘制横线 ���线
      });
    },
    // 绘制横线
            getDrawLabelLine(x, y, width, height, rotate, lineType) {
                jcapi.drawLabelLine({
                    x: x,
@@ -647,13 +657,25 @@
                    width: width,
                    height: height,
                    rotate: rotate,
                    lineType: lineType
        lineType: lineType,
                });
            },
            // 填冲文字标题
            getDrawLabelText(x, y, width, height, value, fontSize, rotate, lineMode, lineSpace, letterSpace,
                textAlignHorizontal, textAlignVertical, bold) {
    getDrawLabelText(
      x,
      y,
      width,
      height,
      value,
      fontSize,
      rotate,
      lineMode,
      lineSpace,
      letterSpace,
      textAlignHorizontal,
      textAlignVertical,
      bold
    ) {
                jcapi.drawLabelText({
                    x: x,
                    y: y,
@@ -667,56 +689,55 @@
                    letterSpace: letterSpace,
                    textAlignHorizontal: textAlignHorizontal,
                    textAlignVertical: textAlignVertical,
                    bold: bold
                })
        bold: bold,
      });
            },
            //刷新上一个页面
            getConnectionStatusText() {
                switch(this.connectionStatus) {
                    case 'connected':
                        return '蓝牙已连接';
                    case 'connecting':
                        return '蓝牙连接中...';
        case "connected":
          return "蓝牙已连接";
        case "connecting":
          return "蓝牙连接中...";
                    default:
                        return '蓝牙未连接';
          return "蓝牙未连接";
                }
            },
            getPrintStatusText() {
                switch(this.printStatus) {
                    case 'printing':
        case "printing":
                        const total = this.printQueue.length + 1; // 队列中剩余 + 当前正在打印
                        const current = total - this.printQueue.length;
                        return `打印中(${current}/${total})`;
                    case 'error':
        case "error":
                        return `打印错误: ${this.errorMessage}`;
                    default:
                        return '就绪';
          return "就绪";
                }
            },
    //刷新上一个页面
            refreshLastPage(no) {
                // 告知 A.vue 更新数据
                // 获取页面栈
                let pages = getCurrentPages()
      let pages = getCurrentPages();
                // 获取上一页栈
                let prevPage = pages[pages.length - 2]
      let prevPage = pages[pages.length - 2];
                // 触发上一页 upData 函数(并携带参数)
                prevPage.$vm.setNo(no)
      prevPage.$vm.setNo(no);
                // 返回上一页
                uni.navigateBack({
                    delta: 1
                })
        delta: 1,
      });
            },
        }
  },
    };
</script>
<style lang="scss">
    .finishProductIn-locno-bg {
        background-color: #F6F9FF;
        background-image: url('~@/static/custom/finishProductIn/locNoBg.png');
  background-color: #f6f9ff;
  background-image: url("~@/static/custom/finishProductIn/locNoBg.png");
        // background: linear-gradient(180deg,rgba(206,227,254,1),rgba(206,227,254,1) 20%,rgba(206,227,254,0.5) 40%,rgba(206,227,254,0.25) 60%,rgba(206,227,254,0.08) 80%,rgba(206,227,254,0));
        padding: 0 20rpx;
        background-attachment: fixed;
@@ -885,9 +906,12 @@
    /* UUID文本样式 */
    .device-uuid {
        font-size: 24rpx;
        color: #666666;
        word-break: break-all;
  font-size: 28rpx;
  font-weight: 500;
  color: #333333;
  margin-bottom: 10rpx;
  display: flex;
  justify-content: space-between;
    }
    /* 模态框标题 */