From eeff5fca55deb0de745405871ff1ae52061bc98d Mon Sep 17 00:00:00 2001 From: yyb <995253665@qq.com> Date: 星期五, 18 七月 2025 11:26:12 +0800 Subject: [PATCH] 优化打印蓝牙连接弹出框,增加监听打印回调解决全部打印只能打印一张问题 --- pages/wareHouse/nuclearScale/nuclearscalerecord.vue | 608 ++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 405 insertions(+), 203 deletions(-) diff --git a/pages/wareHouse/nuclearScale/nuclearscalerecord.vue b/pages/wareHouse/nuclearScale/nuclearscalerecord.vue index 09b4a22..2da0918 100644 --- a/pages/wareHouse/nuclearScale/nuclearscalerecord.vue +++ b/pages/wareHouse/nuclearScale/nuclearscalerecord.vue @@ -97,31 +97,34 @@ </scroll-view> </view> <u-toast ref="uToast" /> - <u-modal v-model="maskShow" title="" v-for="(item, index) in listDevice" :key="index" - :show-confirm-button="true" @confirm="tapQuery(item)"> - <view class="packing-registration-param-view" @touchmove.stop.prevent="moveHandle" @click="maskclose"> + <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"> - <view class="packing-registration-param-item param-extra"> - <view class="packing-registration-param-item-left"> - <text class="item-one">鍚嶇О锛�</text> + <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 class="device-name"> + <text>鍚嶇О锛�</text> + <text>{{ item.name || '鏈煡璁惧' }}</text> </view> - <view class="packing-registration-param-item-right"> - <text class="item-one">{{ item.name }}</text> - </view> - </view> - <view class="packing-registration-param-item param-extra"> - <view class="packing-registration-param-item-left"> - <text class="item-one">UUID:</text> - </view> - <view class="packing-registration-param-item-right"> - <text class="item-one">{{ item.address }}</text> - + <view class="device-uuid"> + <text>UUID:</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> @@ -169,9 +172,10 @@ }, maskShow: false, listDevice: [], //钃濈墮璁惧鏁版嵁 - pritList: [], + printQueue: [], // 鎵撳嵃闃熷垪 + printing: false, // 鏄惁姝e湪鎵撳嵃 printDensity: 3, // 榛樿鎵撳嵃娴撳害 - labelType: 1, // 榛樿鏍囩绫诲瀷 * + labelType: 1, // 榛樿鏍囩绫诲瀷 // 1锛氶棿闅欑焊 // 2锛氶粦鏍囩焊 // 3锛氳繛缁焊 @@ -180,7 +184,10 @@ printMode: 2, // 榛樿鎵撳嵃妯″紡 // 1锛氱儹鏁� // 2锛氱儹杞嵃 - connectedDevice: null // 宸茶繛鎺ョ殑鎵撳嵃鏈� + connectedDevice: null, // 宸茶繛鎺ョ殑鎵撳嵃鏈� + connectionStatus: 'disconnected', // 杩炴帴鐘舵��: disconnected, connecting, connected + printStatus: 'idle', // 鎵撳嵃鐘舵��: idle, printing, error + errorMessage: '' // 閿欒淇℃伅 }; }, onLoad() { @@ -263,25 +270,110 @@ this.getlist(); } }, - // 鎵撳嵃鍗曚釜淇℃伅 // 妫�鏌ヨ摑鐗欒繛鎺ョ姸鎬� async checkBluetoothConnection() { - if (!this.connectedDevice) return false; + console.log('disconnected1111111111111') + if (!this.connectedDevice) { + this.connectionStatus = 'disconnected'; + return false; + } + console.log('disconnected2222222222') - // 灏濊瘯鍙戦�佷竴涓畝鍗曞懡浠ゆ鏌ヨ繛鎺ョ姸鎬� + // 璁剧疆涓鸿繛鎺ヤ腑鐘舵�� + this.connectionStatus = 'connecting'; + console.log('disconnected33333333333') + + // 澧炲己杩炴帴鐘舵�佹娴� return new Promise(resolve => { - jcapi.checkPrinterStatus(this.connectedDevice.address, r => { - if (r && r.code === 0) { - resolve(true); - } else { - // 杩炴帴宸叉柇寮� - this.connectedDevice = null; - resolve(false); - } - }); + // 绠�鍖栬繛鎺ョ姸鎬佹娴嬶紝鐩存帴浣跨敤宸茶褰曠殑杩炴帴鐘舵�� + if (this.connectedDevice) { + this.connectionStatus = 'connected'; + resolve(true); + } else { + this.connectionStatus = 'disconnected'; + uni.showToast({ + icon: 'none', + title: '鎵撳嵃鏈烘湭杩炴帴锛岃鍏堣繛鎺�', + duration: 2000 + }); + resolve(false); + } }); }, + // 娣诲姞鍒版墦鍗伴槦鍒� + addToPrintQueue(items) { + if (!Array.isArray(items)) { + items = [items]; + } + + this.printQueue.push(...items); + // 濡傛灉涓嶅湪鎵撳嵃涓紝鍒欏紑濮嬪鐞嗛槦鍒� + if (!this.printing) { + this.processPrintQueue(); + } + }, + + // 澶勭悊鎵撳嵃闃熷垪 + 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(); + // 涓嶆槸鐩存帴return锛岃�屾槸绛夊緟鐢ㄦ埛杩炴帴鍚庡啀缁х画澶勭悊 + return; + } + + this.printing = true; + this.printStatus = 'printing'; + + // 鍙栧嚭闃熷垪涓殑绗竴涓换鍔� + const item = this.printQueue.shift(); + console.log('鎵撳嵃鐨勪换鍔�',item) + + try { + // 鎵ц鎵撳嵃 + await this.printQrCode(item); + + // 鎵撳嵃鎴愬姛鍚庣户缁鐞嗕笅涓�涓� + uni.showToast({ + title: '鎵撳嵃鎴愬姛', + icon: 'success', + duration: 1000 + }); + + // 鐭殏寤惰繜锛岄伩鍏嶆墦鍗版満缂撳瓨婧㈠嚭 + await new Promise(resolve => setTimeout(resolve, 1000)); + } catch (error) { + console.error('鎵撳嵃鍑洪敊:', error); + this.printStatus = 'error'; + this.errorMessage = error.message || '鎵撳嵃鏃跺彂鐢熸湭鐭ラ敊璇�'; + this.printing = false; + + // 璁板綍澶辫触鐨勪换鍔★紝涓嶉噸鏂版坊鍔犲埌闃熷垪 + this.failedPrintJobs = this.failedPrintJobs || []; + this.failedPrintJobs.push(item); + + uni.showToast({ + title: `鎵撳嵃澶辫触: ${this.errorMessage}`, + icon: 'none', + duration: 2000 + }); + // 缁х画澶勭悊涓嬩竴涓换鍔� + continue; + } + } + + this.printing = false; + this.printStatus = 'idle'; + }, + // 鎵撳嵃鍗曚釜淇℃伅 selectNo(item) { let that = this uni.showModal({ @@ -290,45 +382,24 @@ showCancel: true, success: async function(res) { if (res.confirm) { - // 妫�鏌ヨ摑鐗欒繛鎺ョ姸鎬� - const isConnected = await that.checkBluetoothConnection(); - if (isConnected) { - // 宸茶繛鎺ワ紝鐩存帴鎵撳嵃 - that.pritList = [item] - that.pritList.forEach(async item => { - await that.printQrCode(item) - }) - } else { - // 鏈繛鎺ユ垨杩炴帴宸叉柇寮�锛屾悳绱㈣澶� - that.searchDevice() - that.pritList = [item] - } + // 娣诲姞鍒版墦鍗伴槦鍒� + that.addToPrintQueue(item); } } }); }, + // 鎵撳嵃鍏ㄩ儴淇℃伅 goPrintAll() { let that = this uni.showModal({ title: '鎻愮ず', - content: '鏄惁鎵撳嵃瑁呯鍗曪紵', + content: `鏄惁鎵撳嵃鍏ㄩ儴${that.list.length}鏉¤绠卞崟锛焋, showCancel: true, success: async function(res) { if (res.confirm) { - // 妫�鏌ヨ摑鐗欒繛鎺ョ姸鎬� - const isConnected = await that.checkBluetoothConnection(); - if (isConnected) { - // 宸茶繛鎺ワ紝鐩存帴鎵撳嵃 - that.pritList = that.list - that.pritList.forEach(async item => { - await that.printQrCode(item) - }) - } else { - // 鏈繛鎺ユ垨杩炴帴宸叉柇寮�锛屾悳绱㈣澶� - that.searchDevice() - that.pritList = that.list - } + // 娣诲姞鍒版墦鍗伴槦鍒� + that.addToPrintQueue([...that.list]); } } }); @@ -341,166 +412,192 @@ }, //鎵撳嵃浜岀淮鐮� async printQrCode(item) { - console.log('item de shuju ', item) - const params = { - rwMatlBindId: item.id - }; - try { - let res = await this.$u.api.dailyPaper.zongjianLabelInfo(params) - if (!res.data) { - this.$refs.uToast.show({ - title: '鏈煡璇㈠埌璇ユ爣绛句俊鎭紒', - type: 'warning ' - }) - return - } - // const res = { - // ht: 'HT20250717995352665', - // lj: '88.118.1/A0611091', - // ljms: '閾滃崟绾� 瑁搁摐-TY-鍦嗗舰-3.0', - // fh: '1083.6', - // scdt: '2025-07-14 13:46:55.0', - // scph: '2025071273-3', - // fhdw: '姹熶笢鍚堥噾鎶�鏈湁闄愬叕鍙�', - // shdw: '鏄嗗北娉板痉閫氶摐涓氭湁闄愬叕鍙�', - // } - // 浠嶢PI鍝嶅簲涓彁鍙栨墍闇�鏁版嵁 - const { - ht, - lj, - ljms, - fh, - scdt, - scph, - fhdw, - shdw - } = res.data - // const jsonString = JSON.stringify(res.data) - - // 鍒濆鍖栫敾鏉� - jcapi.initDrawingBoard({ - width: 70, - height: 49, - rotate: 90 - }); - - // 缁樺埗浜岀淮鐮� - 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, - width: 24, - height: 24, - value: qrContent, - rotate: 0, - codeType: QrCodeType.QrCode, - }); - // getDrawLabelLine 锛坸鍧愭爣锛寉鍧愭爣锛岀嚎鏉″搴︼紝绾挎潯楂樺害锛屾棆杞搴︼紝绾挎潯绫诲瀷锛� - // 缁樺埗妯嚎 瀹炵嚎8鏉� - 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) // 绔栫嚎2 - // getDrawLabelText 锛�1.x鍧愭爣锛�2.y鍧愭爣锛�3.鏂囨湰妗嗗搴︼紝4.鏂囨湰妗嗛珮搴︼紝5.缁樺埗鏂囧瓧鍐呭锛�6.瀛椾綋澶у皬锛堥粯璁ら珮搴�4mm锛�,7.鏃嬭浆瑙掑害,8.鎹㈣鏂瑰紡,9.饩忛棿闅�,10.瀛楅棿闅�,11.鏂囧瓧姘村钩甯冨眬,12鏂囧瓧鍨傜洿甯冨眬) - // 鏍囬 - 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.5, 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() - let imageJsonObj111 = jcapi.generatePrintPreviewImage(imageJsonObj) - console.log('棰勮', imageJsonObj111) - // // 璁剧疆鎵撳嵃浠诲姟 - jcapi.startJob({ - totalCount: 1, - density: this.printDensity, - labelType: this.labelType, - printMode: this.printMode, - }, function(r) { - console.log('鎵撳嵃', r) - if (r.code == 0) { - // 鎵撳嵃鏁版嵁 - jcapi.printData(imageJsonObj, { - "printQuantity": 1, - }, function(r) { - if (r.code == 0) { - console.log("鎵撳嵃鎴愬姛") - uni.showToast({ - title: '鎵撳嵃鎴愬姛', - icon: 'success' - }) - } else { - console.log("鎵撳嵃澶辫触") - uni.showToast({ - title: '鎵撳嵃澶辫触: ' + (r.msg || '鏈煡閿欒'), - icon: 'none' - }) - } + return new Promise(async (resolve, reject) => { + console.log('item de shuju ', item) + // 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) + if (!res.data) { + this.$refs.uToast.show({ + title: '鏈煡璇㈠埌璇ユ爣绛句俊鎭紒', + type: 'warning ' }) - } else { - console.log("璁剧疆鎵撳嵃浠诲姟澶辫触") + reject(new Error('鏈煡璇㈠埌璇ユ爣绛句俊鎭�')); + return } - }) - } catch (error) { - console.log(error) - } + // 浠嶢PI鍝嶅簲涓彁鍙栨墍闇�鏁版嵁 + const { + ht, + lj, + ljms, + fh, + scdt, + scph, + fhdw, + shdw + } = res.data + + // 鍒濆鍖栫敾鏉� + jcapi.initDrawingBoard({ + width: 70, + height: 49, + rotate: 90 + }); + + // 缁樺埗浜岀淮鐮� + 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, + width: 24, + height: 24, + value: qrContent, + rotate: 0, + codeType: QrCodeType.QrCode, + }); + + // 缁樺埗妯嚎 + 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.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) + + // 鐢熸垚鎵撳嵃鏁版嵁 + let imageJsonObj = jcapi.generateLabelJson() + console.log('鎵撳嵃鐨勬暟鎹�',imageJsonObj) + + // 璁剧疆鎵撳嵃浠诲姟 + jcapi.startJob({ + totalCount: 1, + density: this.printDensity, + labelType: this.labelType, + printMode: this.printMode, + }, function(r) { + if (r.code == 0) { + // 鎵撳嵃鏁版嵁 + // 瀛樺偍鍘熷鎵撳嵃璁℃暟鍥炶皟 + const originalPrintCountCallback = jcapi.didReadPrintCountInfo._callback; + // 涓存椂鎵撳嵃璁℃暟鍥炶皟锛岀敤浜庣‘璁ゆ墦鍗板畬鎴� + const tempPrintCountCallback = (printResult) => { + console.log("鎵撳嵃璁℃暟鍥炶皟:", printResult); + // 鎭㈠鍘熷鍥炶皟 + jcapi.didReadPrintCountInfo(originalPrintCountCallback); + // 缁撴潫褰撳墠鎵撳嵃浠诲姟 + // 瑙f瀽Promise琛ㄧず鎵撳嵃瀹屾垚 + resolve(); + }; + // 璁剧疆涓存椂鍥炶皟 + jcapi.didReadPrintCountInfo(tempPrintCountCallback); + + // 娣诲姞鎵撳嵃瓒呮椂澶勭悊 + const printTimeout = setTimeout(() => { + jcapi.didReadPrintCountInfo(originalPrintCountCallback); + reject(new Error('鎵撳嵃瓒呮椂鏈搷搴�')); + }, 10000); + + jcapi.printData(imageJsonObj, { + "printQuantity": 1, + }, function(r) { + if (r.code != 0) { + console.log("鎵撳嵃澶辫触", r); + // 鎭㈠鍘熷鍥炶皟 + jcapi.didReadPrintCountInfo(originalPrintCountCallback); + // 缁撴潫褰撳墠鎵撳嵃浠诲姟 + reject(new Error(r.msg || '鎵撳嵃澶辫触')); + } + // 锟斤拷鍗版暟鎹彂閫佹垚鍔熷悗绛夊緟鎵撳嵃璁℃暟鍥炶皟纭瀹為檯鎵撳嵃瀹屾垚 + + }) + } else { + console.log("璁剧疆鎵撳嵃浠诲姟澶辫触", r) + reject(new Error(r.msg || '璁剧疆鎵撳嵃浠诲姟澶辫触')); + } + }) + } catch (error) { + console.log(error) + reject(error); + } + }); }, tapQuery(item) { this.maskShow = false // 杩炴帴鎵撳嵃鏈� let _this = this; console.log(item) + + // 璁剧疆涓鸿繛鎺ヤ腑鐘舵�� + this.connectionStatus = 'connecting'; + jcapi.openPrinterByDevice({ address: item.address, name: item.name, deviceType: 0 // 璁惧绫诲瀷锛�0-钃濈墮锛�1-缃戠粶 }, function(r) { - uni.showToast({ - title: (r.code == 0) ? "杩炴帴鎴愬姛" : "杩炴帴澶辫触", - duration: 2 * 1000 - }) if (r.code == 0) { _this.connectedDevice = item - // 娣诲姞鎵撳嵃鍒楄〃绌哄�兼鏌� - if (!_this.pritList || _this.pritList.length === 0) { - uni.showToast({ - title: '娌℃湁鍙墦鍗扮殑鏁版嵁', - icon: 'none' - }) - return + _this.connectionStatus = 'connected'; + uni.showToast({ + title: "杩炴帴鎴愬姛", + duration: 1500 + }) + // 寮�濮嬪鐞嗘墦鍗伴槦鍒� + console.log('鎵撳嵃闃熷垪',_this.printQueue) + if (_this.printQueue.length > 0) { + _this.processPrintQueue(); } - // 缁樻爣绛捐繘琛屾墦鍗� - _this.pritList.forEach(async item => { - await _this.printQrCode(item) + } else { + _this.connectionStatus = 'disconnected'; + uni.showToast({ + title: "杩炴帴澶辫触: " + (r.msg || '鏈煡閿欒'), + icon: 'none', + duration: 2000 }) } }) @@ -542,7 +639,7 @@ } }) }, - // 缁樺埗妯嚎 瀹炵嚎 + // 缁樺埗妯嚎 锟斤拷锟界嚎 getDrawLabelLine(x, y, width, height, rotate, lineType) { jcapi.drawLabelLine({ x: x, @@ -575,6 +672,28 @@ }, //鍒锋柊涓婁竴涓〉闈� + getConnectionStatusText() { + switch(this.connectionStatus) { + case 'connected': + return '钃濈墮宸茶繛鎺�'; + case 'connecting': + return '钃濈墮杩炴帴涓�...'; + default: + return '钃濈墮鏈繛鎺�'; + } + }, + getPrintStatusText() { + switch(this.printStatus) { + case 'printing': + const total = this.printQueue.length + 1; // 闃熷垪涓墿浣� + 褰撳墠姝e湪鎵撳嵃 + const current = total - this.printQueue.length; + return `鎵撳嵃涓�(${current}/${total})`; + case 'error': + return `鎵撳嵃閿欒: ${this.errorMessage}`; + default: + return '灏辩华'; + } + }, refreshLastPage(no) { // 鍛婄煡 A.vue 鏇存柊鏁版嵁 // 鑾峰彇椤甸潰鏍� @@ -731,4 +850,87 @@ line-height: 36rpx; margin-right: 32rpx; } + + /* 妯℃�佹鏍峰紡浼樺寲 */ + .u-modal { + --modal-width: 85% !important; + --modal-radius: 16rpx !important; + --modal-bg-color: #ffffff !important; + } + + /* 妯℃�佹鍐呭鍖哄煙 */ + .uni-scroll_box { + height: 500rpx !important; + padding: 20rpx; + } + + /* 璁惧鍒楄〃椤规牱寮� */ + .device-item { + background-color: #f5f9ff; + border-radius: 12rpx; + padding: 20rpx; + margin-bottom: 16rpx; + box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05); + } + + /* 璁惧鍚嶇О鏍峰紡 */ + .device-name { + font-size: 28rpx; + font-weight: 500; + color: #333333; + margin-bottom: 10rpx; + display: flex; + justify-content: space-between; + } + + /* UUID鏂囨湰鏍峰紡 */ + .device-uuid { + font-size: 24rpx; + color: #666666; + word-break: break-all; + } + + /* 妯℃�佹鏍囬 */ + .modal-title { + font-size: 32rpx; + font-weight: bold; + color: #333333; + text-align: center; + margin-bottom: 20rpx; + padding-bottom: 10rpx; + border-bottom: 1rpx solid #eeeeee; + } + + /* 绌虹姸鎬佹彁绀� */ + .empty-tip { + text-align: center; + padding: 100rpx 0; + color: #999999; + font-size: 28rpx; + } + + .status-indicator { + padding: 8rpx 16rpx; + font-size: 24rpx; + text-align: center; + color: #fff; + background-color: #666; + + &.connected { + background-color: #07c160; + } + + &.connecting { + background-color: #ff976a; + } + + &.disconnected { + background-color: #f53f3f; + } + + .print-status { + margin-left: 10rpx; + font-size: 22rpx; + } + } </style> \ No newline at end of file -- Gitblit v1.9.3