| | |
| | | <view class="page"> |
| | | <view class="finishProductIn-locno-bg" /> |
| | | <u-navbar |
| | | title="核磅记录" |
| | | 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 class="navbar-right" slot="right"> |
| | | <text class="bluetooth-btn" @click="searchDevice"> |
| | | {{ connectedDevice ? `已连接:${connectedDevice.name}` : "连接蓝牙" }} |
| | | </text> |
| | | <text class="print-all-btn" @click="goPrintAll">全部打印</text> |
| | | </view> |
| | | </u-navbar> |
| | | <view class="wrap"> |
| | |
| | | @click="selectNo(item)" |
| | | > |
| | | <view class="content-header"> |
| | | <view class="content-header-title">{{ index + 1 }}</view> |
| | | <view class="content-header-title">{{ |
| | | list.length - index |
| | | }}</view> |
| | | </view> |
| | | <view class="content-body"> |
| | | <view class="row-list"> |
| | |
| | | <view class="_label-name">批次号:</view> |
| | | </view> |
| | | <view class="_content"> |
| | | {{ item.outBatchNo }} |
| | | {{ item.batchNo }} |
| | | </view> |
| | | </view> |
| | | <view class="row-list"> |
| | |
| | | <view class="_label-name">产品描述:</view> |
| | | </view> |
| | | <view class="_content"> |
| | | {{ item.netWeight }} |
| | | {{ item.partDescription }} |
| | | </view> |
| | | </view> |
| | | <view class="row-list"> |
| | |
| | | <view class="_label-name">毛重:</view> |
| | | </view> |
| | | <view class="_content"> |
| | | {{ item.grossWeight }} |
| | | {{ item.newGrossWeight }} |
| | | </view> |
| | | </view> |
| | | <view class="row-list"> |
| | |
| | | <view class="_label-name">盘重:</view> |
| | | </view> |
| | | <view class="_content"> |
| | | {{ item.trayWeight }} |
| | | {{ item.newWeight }} |
| | | </view> |
| | | </view> |
| | | <view class="row-list"> |
| | |
| | | <view class="_label-name">净重:</view> |
| | | </view> |
| | | <view class="_content"> |
| | | {{ item.value5 }} |
| | | {{ item.newNetWeight }} |
| | | </view> |
| | | </view> |
| | | <view class="row-list"> |
| | |
| | | <view class="_label-name">核磅重量:</view> |
| | | </view> |
| | | <view class="_content"> |
| | | {{ item.netWeight }} |
| | | {{ item.verificationWeight }} |
| | | </view> |
| | | </view> |
| | | <view class="row-list"> |
| | |
| | | <view class="_label-name">叉车盘重:</view> |
| | | </view> |
| | | <view class="_content"> |
| | | {{ item.value7 }} |
| | | {{ item.forkliftWeight }} |
| | | </view> |
| | | </view> |
| | | </view> |
| | |
| | | </template> |
| | | <script> |
| | | import content_bg from "@/static/custom/finishProductIn/locNoBg.png"; |
| | | import bluetooth from "@/common/bluetoothPrinter.js"; |
| | | |
| | | const jcapi = uni.requireNativePlugin("JCSDK-JCApiModule"); |
| | | |
| | | // 二维码类型 |
| | |
| | | listDevice: [], //蓝牙设备数据 |
| | | printQueue: [], // 打印队列 |
| | | printing: false, // 是否正在打印 |
| | | printDensity: 3, // 默认打印浓度 |
| | | printDensity: 10, // 默认打印浓度 |
| | | labelType: 1, // 默认标签类型 |
| | | // 1:间隙纸 |
| | | // 2:黑标纸 |
| | |
| | | printMode: 2, // 默认打印模式 |
| | | // 1:热敏 |
| | | // 2:热转印 |
| | | connectedDevice: null, // 已连接的打印机 |
| | | connectionStatus: "disconnected", // 连接状态: disconnected, connecting, connected |
| | | connectedDevice: null, |
| | | connectionStatus: "disconnected", |
| | | printStatus: "idle", // 打印状态: idle, printing, error |
| | | errorMessage: "", // 错误信息 |
| | | verificationNo: "", |
| | | failedPrintJobs: [], |
| | | }; |
| | | }, |
| | | onLoad() { |
| | | this.getlist(); |
| | | // 初始化SDK |
| | | jcapi.initSDK(); |
| | | // 监听页码回调 |
| | | jcapi.didReadPrintCountInfo(function (r) { |
| | | console.log(r); |
| | | onLoad(options) { |
| | | this.verificationNo = JSON.parse( |
| | | decodeURIComponent(options.verificationNo) |
| | | ); |
| | | |
| | | bluetooth.init(); |
| | | |
| | | bluetooth.onChange(({ connectedDevice, connectionStatus }) => { |
| | | this.connectedDevice = connectedDevice; |
| | | this.connectionStatus = connectionStatus; |
| | | }); |
| | | |
| | | // 监听错误回调 |
| | | jcapi.didReadPrintErrorInfo((r) => { |
| | | console.log(r); |
| | | if (r.code == 23) { |
| | | // 打印机断开连接 |
| | | this.connectedDevice = null; |
| | | uni.showToast({ |
| | | icon: "none", |
| | | title: "打印机连接已断开,请重新连接", |
| | | duration: 2 * 1000, |
| | | }); |
| | | } else { |
| | | uni.showToast({ |
| | | icon: "none", |
| | | title: JSON.stringify(r), |
| | | duration: 2 * 1000, |
| | | }); |
| | | } |
| | | }); |
| | | this.getlist(); |
| | | }, |
| | | |
| | | // 页面卸载时不主动断开蓝牙连接,保持连接状态 |
| | | onUnload() { |
| | | // 不执行断开连接操作,保持蓝牙连接 |
| | | }, |
| | | methods: { |
| | | // restoreBluetoothConnection() { |
| | | // try { |
| | | // // 从本地存储获取之前保存的连接信息 |
| | | // const savedConnection = uni.getStorageSync("bluetoothConnection"); |
| | | // if (savedConnection && savedConnection.address) { |
| | | // console.log("尝试恢复蓝牙连接:", savedConnection); |
| | | // // 直接设置为已连接状态,避免不必要的重连 |
| | | // // 实际连接状态会通过SDK的回调自动更新 |
| | | // this.connectedDevice = savedConnection; |
| | | // this.connectionStatus = "connected"; |
| | | // console.log("蓝牙连接状态已恢复"); |
| | | |
| | | // // 验证连接是否真的有效,通过发送一个简单的命令或检查状态 |
| | | // // 这里不执行实际的重连操作,而是依赖SDK的连接状态回调 |
| | | // // 如果连接已断开,SDK会通过didReadPrintErrorInfo回调通知我们 |
| | | // } |
| | | // } catch (e) { |
| | | // console.error("恢复蓝牙连接失败:", e); |
| | | // this.connectionStatus = "disconnected"; |
| | | // } |
| | | // }, |
| | | getmoreList() { |
| | | if (this.pageSize >= this.total) { |
| | | this.status = "nomore"; |
| | |
| | | }, 1000); |
| | | }, |
| | | getlist() { |
| | | this.$u.api.workReporting |
| | | .getWorkshopOrder({ |
| | | this.$u.api.NuclearScaleEntry.queryPacking({ |
| | | current: this.pageNum, |
| | | size: this.pageSize, |
| | | verificationNo: this.verificationNo, |
| | | }).then((res) => { |
| | | this.list = res.data; |
| | | this.total = res.data.length; |
| | | if (this.pageSize >= this.total) { |
| | | this.status = "nomore"; |
| | | } else { |
| | | this.status = "loadmore"; |
| | | } |
| | | }); |
| | | }, |
| | | search(value) { |
| | | if (value) { |
| | | this.list = []; |
| | | this.pageSize = 10; |
| | | this.$u.api.NuclearScaleEntry.queryPacking({ |
| | | current: this.pageNum, |
| | | size: this.pageSize, |
| | | }) |
| | | .then((res) => { |
| | | moNo: value, |
| | | }).then((res) => { |
| | | this.list = res.data.records; |
| | | this.total = res.data.total; |
| | | if (this.pageSize >= this.total) { |
| | |
| | | this.status = "loadmore"; |
| | | } |
| | | }); |
| | | }, |
| | | search(value) { |
| | | if (value) { |
| | | this.list = []; |
| | | this.pageSize = 10; |
| | | this.$u.api.workReporting |
| | | .getWorkshopOrder({ |
| | | current: this.pageNum, |
| | | size: this.pageSize, |
| | | moNo: value, |
| | | }) |
| | | .then((res) => { |
| | | this.list = res.data.records; |
| | | this.total = res.data.total; |
| | | if (this.pageSize >= this.total) { |
| | | this.status = "nomore"; |
| | | } else { |
| | | this.status = "loadmore"; |
| | | } |
| | | }); |
| | | } else { |
| | | this.getlist(); |
| | | } |
| | | }, |
| | | // 检查蓝牙连接状态 |
| | | async checkBluetoothConnection() { |
| | | if (!this.connectedDevice) { |
| | | this.connectionStatus = "disconnected"; |
| | | return false; |
| | | } |
| | | |
| | | // 设置为连接中状态 |
| | | this.connectionStatus = "connecting"; |
| | | |
| | | // 增强连接状态检测 |
| | | return new Promise((resolve) => { |
| | | // 简化连接状态检测,直接使用已记录的连接状态 |
| | | if (this.connectedDevice) { |
| | | this.connectionStatus = "connected"; |
| | | resolve(true); |
| | | } else { |
| | | this.connectionStatus = "disconnected"; |
| | | uni.showToast({ |
| | | icon: "none", |
| | | title: "打印机未连接,请先连接", |
| | | duration: 2000, |
| | | }); |
| | | resolve(false); |
| | | } |
| | | }); |
| | | checkBluetoothConnection() { |
| | | return bluetooth.isConnected(); |
| | | }, |
| | | |
| | | // // 直接使用已记录的连接状态,避免不必要的连接检查 |
| | | // // 实际连接状态会通过SDK的回调自动更新 |
| | | // this.connectionStatus = "connected"; |
| | | // return true; |
| | | // }, |
| | | |
| | | // 添加到打印队列 |
| | | addToPrintQueue(items) { |
| | |
| | | uni.showModal({ |
| | | title: "提示", |
| | | content: "是否打印装箱单?", |
| | | showCancel: true, |
| | | success: async function (res) { |
| | | success(res) { |
| | | if (res.confirm) { |
| | | // 添加到打印队列 |
| | | that.addToPrintQueue(item); |
| | | // 按 batchNo 合并 |
| | | const sameBatchList = that.list.filter( |
| | | (i) => i.batchNo === item.batchNo |
| | | ); |
| | | that.addToPrintQueue(sameBatchList); |
| | | } |
| | | }, |
| | | }); |
| | |
| | | moveHandle() {}, |
| | | maskclose() {}, |
| | | //打印二维码 |
| | | async printQrCode(item) { |
| | | printQrCode(item) { |
| | | return new Promise(async (resolve, reject) => { |
| | | const params = { |
| | | rwMatlBindId: item.id |
| | | }; |
| | | // const params = { |
| | | // rwMatlBindId: item.id |
| | | // }; |
| | | try { |
| | | let res = await this.$u.api.dailyPaper.zongjianLabelInfo(params) |
| | | if (!res.data) { |
| | | // let res = await this.$u.api.dailyPaper.zongjianLabelInfo(params) |
| | | if (!item) { |
| | | this.$refs.uToast.show({ |
| | | title: "未查询到该标签信息!", |
| | | type: "warning ", |
| | |
| | | return; |
| | | } |
| | | |
| | | // 从API响应中提取所需数据 |
| | | const { ht, lj, ljms, fh, scdt, scph, fhdw, shdw } = res.data; |
| | | const ht = item.contractNo; |
| | | const lj = item.partNo; |
| | | const ljms = item.ccontrProModel; |
| | | const fh = item.newNetWeight; |
| | | const scdt = item.productionDate; |
| | | const scph = item.batchNo; |
| | | const shdw = item.customerName; |
| | | const fhdw = "江东合金技术有限公司"; |
| | | |
| | | // 初始化画板 |
| | | jcapi.initDrawingBoard({ |
| | |
| | | }); |
| | | |
| | | // 绘制二维码 |
| | | const qrContent = `ht:${ht}\nlj:${lj}\nljms:${ljms}\nfh:${fh}\nscdt:${scdt}\nscph:${scph}\nfhdw:${fhdw}\nshdw:${shdw}`; |
| | | const qrContent = { |
| | | company: item.customerNo, |
| | | line_no: item.lineNo, |
| | | lot_batch_no: item.batchNo, |
| | | order_no: item.contractNo, |
| | | part_no: item.partNo, |
| | | total_qty: item.newNetWeight, |
| | | qty_arrived: item.newNetWeight, |
| | | release_no: item.relNo, |
| | | }; |
| | | |
| | | jcapi.drawLabelQrCode({ |
| | | x: 43.5, |
| | | y: 2, |
| | |
| | | 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, 23, 42, 0.3, 0, LineType.Solid); |
| | | this.getDrawLabelLine(1, 27.5, 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(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, |
| | | 23.5, |
| | | 25, |
| | | 8, |
| | | "发货/装箱数:", |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 2, |
| | | 28.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, |
| | | 23.5, |
| | | 27, |
| | | 8, |
| | | fh, |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 14, |
| | | 28.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(); |
| | | |
| | |
| | | } |
| | | }); |
| | | }, |
| | | tapQuery(item) { |
| | | async tapQuery(item) { |
| | | this.maskShow = false; |
| | | // 连接打印机 |
| | | let _this = this; |
| | | try { |
| | | await bluetooth.connect(item); |
| | | uni.showToast({ title: "连接成功" }); |
| | | |
| | | // 设置为连接中状态 |
| | | this.connectionStatus = "connecting"; |
| | | |
| | | jcapi.openPrinterByDevice( |
| | | { |
| | | address: item.address, |
| | | name: item.name, |
| | | deviceType: 0, // 设备类型:0-蓝牙,1-网络 |
| | | }, |
| | | function (r) { |
| | | if (r.code == 0) { |
| | | _this.connectedDevice = item; |
| | | _this.connectionStatus = "connected"; |
| | | uni.showToast({ |
| | | title: "连接成功", |
| | | duration: 1500, |
| | | }); |
| | | // 开始处理打印队列 |
| | | if (_this.printQueue.length > 0) { |
| | | _this.processPrintQueue(); |
| | | } |
| | | } else { |
| | | _this.connectionStatus = "disconnected"; |
| | | uni.showToast({ |
| | | title: "连接失败: " + (r.msg || "未知错误"), |
| | | icon: "none", |
| | | duration: 2000, |
| | | }); |
| | | } |
| | | // 如果有打印任务,继续打印 |
| | | if (this.printQueue.length) { |
| | | this.processPrintQueue(); |
| | | } |
| | | ); |
| | | } catch (e) { |
| | | uni.showToast({ |
| | | icon: "none", |
| | | title: "连接失败", |
| | | }); |
| | | } |
| | | }, |
| | | |
| | | //打印相关 |
| | | searchDevice() { |
| | | let _this = this; |
| | | uni.openBluetoothAdapter({ |
| | | // 确认蓝牙是否打开 |
| | | success(r) { |
| | | uni.showLoading({ |
| | | title: "搜索中...", |
| | | }); |
| | | // 未授予蓝牙相关权限和未打开手机定位会搜索不到设备 |
| | | jcapi.getBluetoothDevices(function (r) { |
| | | console.log("device:" + JSON.stringify(r)); |
| | | // 搜索到设备回调 |
| | | uni.hideLoading(); |
| | | // 如果之前有连接的设备但不在搜索结果中,说明设备已更换 |
| | | if ( |
| | | _this.connectedDevice && |
| | | !r.some((dev) => dev.address === _this.connectedDevice.address) |
| | | ) { |
| | | _this.connectedDevice = null; |
| | | uni.showToast({ |
| | | icon: "none", |
| | | title: "已连接的蓝牙设备已更换,请重新选择", |
| | | duration: 2000, |
| | | }); |
| | | } |
| | | _this.listDevice = r; |
| | | _this.maskShow = true; |
| | | }); |
| | | }, |
| | | fail(e) { |
| | | uni.showModal({ |
| | | title: "提示", |
| | | content: "打开蓝牙失败,请检查蓝牙是否开启", |
| | | showCancel: false, |
| | | }); |
| | | console.log("开启蓝牙设备失败" + e); |
| | | }, |
| | | }); |
| | | async searchDevice() { |
| | | try { |
| | | uni.showLoading({ title: "搜索中..." }); |
| | | const devices = await bluetooth.searchDevices(); |
| | | uni.hideLoading(); |
| | | |
| | | this.listDevice = devices; |
| | | this.maskShow = true; |
| | | } catch (e) { |
| | | uni.hideLoading(); |
| | | uni.showModal({ |
| | | title: "提示", |
| | | content: "请确认蓝牙和定位已开启", |
| | | showCancel: false, |
| | | }); |
| | | } |
| | | }, |
| | | |
| | | // 绘制横线 |
| | | getDrawLabelLine(x, y, width, height, rotate, lineType) { |
| | | jcapi.drawLabelLine({ |