| | |
| | | <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"> |
| | | <view class="navbar-right" slot="right" @click="goPrintAll"> |
| | | å
¨é¨æå° |
| | | <u-navbar |
| | | title="" |
| | | :background="background" |
| | | :border-bottom="false" |
| | | :title-bold="true" |
| | | title-color="#000" |
| | | back-icon-color="#000" |
| | | > |
| | | <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"> |
| | | <!-- è¿æ¥åæå°ç¶ææç¤ºå¨ --> |
| | | <view class="status-indicator" :class="{ |
| | | <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> |
| | | <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)"> |
| | | <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">{{ list.length - index }}</view> |
| | | <view class="content-header-title">{{ |
| | | list.length - index |
| | | }}</view> |
| | | </view> |
| | | <view class="content-body"> |
| | | <view class="row-list"> |
| | |
| | | </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"> |
| | | <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> |
| | |
| | | </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: "", |
| | |
| | | this.verificationNo = JSON.parse( |
| | | decodeURIComponent(options.verificationNo) |
| | | ); |
| | | |
| | | bluetooth.init(); |
| | | |
| | | bluetooth.onChange(({ connectedDevice, connectionStatus }) => { |
| | | this.connectedDevice = connectedDevice; |
| | | this.connectionStatus = connectionStatus; |
| | | }); |
| | | |
| | | this.getlist(); |
| | | // åå§åSDK |
| | | jcapi.initSDK(); |
| | | }, |
| | | |
| | | // å°è¯æ¢å¤ä¹åçèçè¿æ¥ç¶æ |
| | | this.restoreBluetoothConnection(); |
| | | |
| | | // çå¬é¡µç åè° |
| | | jcapi.didReadPrintCountInfo(function(r) { |
| | | console.log("页ç ", r); |
| | | }); |
| | | |
| | | // çå¬é误åè° |
| | | jcapi.didReadPrintErrorInfo((r) => { |
| | | console.log("é误", r); |
| | | if (r.code == 23) { |
| | | // æå°æºæå¼è¿æ¥ |
| | | this.connectedDevice = null; |
| | | // æ¸
餿¬å°åå¨çè¿æ¥ä¿¡æ¯ |
| | | uni.removeStorageSync("bluetoothConnection"); |
| | | uni.showToast({ |
| | | icon: "none", |
| | | title: "æå°æºè¿æ¥å·²æå¼ï¼è¯·éæ°è¿æ¥", |
| | | duration: 2 * 1000, |
| | | }); |
| | | } else { |
| | | uni.showToast({ |
| | | icon: "none", |
| | | title: JSON.stringify(r), |
| | | duration: 2 * 1000, |
| | | }); |
| | | } |
| | | }); |
| | | // 页é¢å¸è½½æ¶ä¸ä¸»å¨æå¼èçè¿æ¥ï¼ä¿æè¿æ¥ç¶æ |
| | | onUnload() { |
| | | // 䏿§è¡æå¼è¿æ¥æä½ï¼ä¿æèçè¿æ¥ |
| | | }, |
| | | methods: { |
| | | restoreBluetoothConnection() { |
| | | try { |
| | | // 仿¬å°åå¨è·åä¹åä¿åçè¿æ¥ä¿¡æ¯ |
| | | const savedConnection = uni.getStorageSync("bluetoothConnection"); |
| | | if (savedConnection && savedConnection.address) { |
| | | console.log("å°è¯æ¢å¤èçè¿æ¥:", savedConnection); |
| | | // è®¾ç½®ä¸ºè¿æ¥ä¸ç¶æ |
| | | this.connectionStatus = "connecting"; |
| | | // restoreBluetoothConnection() { |
| | | // try { |
| | | // // 仿¬å°åå¨è·åä¹åä¿åçè¿æ¥ä¿¡æ¯ |
| | | // const savedConnection = uni.getStorageSync("bluetoothConnection"); |
| | | // if (savedConnection && savedConnection.address) { |
| | | // console.log("å°è¯æ¢å¤èçè¿æ¥:", savedConnection); |
| | | // // ç´æ¥è®¾ç½®ä¸ºå·²è¿æ¥ç¶æï¼é¿å
ä¸å¿
è¦çéè¿ |
| | | // // å®é
è¿æ¥ç¶æä¼éè¿SDKçåè°èªå¨æ´æ° |
| | | // this.connectedDevice = savedConnection; |
| | | // this.connectionStatus = "connected"; |
| | | // console.log("èçè¿æ¥ç¶æå·²æ¢å¤"); |
| | | |
| | | // å°è¯éæ°è¿æ¥ |
| | | jcapi.openPrinterByDevice({ |
| | | address: savedConnection.address, |
| | | name: savedConnection.name, |
| | | deviceType: 0, // 设å¤ç±»åï¼0-èçï¼1-ç½ç» |
| | | }, |
| | | (r) => { |
| | | if (r.code == 0) { |
| | | this.connectedDevice = savedConnection; |
| | | this.connectionStatus = "connected"; |
| | | console.log("èçè¿æ¥å·²æ¢å¤"); |
| | | } else { |
| | | this.connectionStatus = "disconnected"; |
| | | // 妿éè¿å¤±è´¥ï¼æ¸
é¤ä¿åçè¿æ¥ä¿¡æ¯ |
| | | uni.removeStorageSync("bluetoothConnection"); |
| | | console.log("èçéè¿å¤±è´¥:", r); |
| | | } |
| | | } |
| | | ); |
| | | } |
| | | } catch (e) { |
| | | console.error("æ¢å¤èçè¿æ¥å¤±è´¥:", e); |
| | | } |
| | | }, |
| | | // // éªè¯è¿æ¥æ¯å¦ççææï¼éè¿åéä¸ä¸ªç®åçå½ä»¤ææ£æ¥ç¶æ |
| | | // // è¿é䏿§è¡å®é
çéè¿æä½ï¼èæ¯ä¾èµSDKçè¿æ¥ç¶æåè° |
| | | // // å¦æè¿æ¥å·²æå¼ï¼SDKä¼éè¿didReadPrintErrorInfoåè°éç¥æä»¬ |
| | | // } |
| | | // } catch (e) { |
| | | // console.error("æ¢å¤èçè¿æ¥å¤±è´¥:", e); |
| | | // this.connectionStatus = "disconnected"; |
| | | // } |
| | | // }, |
| | | getmoreList() { |
| | | if (this.pageSize >= this.total) { |
| | | this.status = "nomore"; |
| | |
| | | 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); |
| | | } |
| | | }, |
| | | }); |
| | |
| | | let imageJsonObj = jcapi.generateLabelJson(); |
| | | |
| | | // 设置æå°ä»»å¡ |
| | | jcapi.startJob({ |
| | | jcapi.startJob( |
| | | { |
| | | totalCount: 1, |
| | | density: this.printDensity, |
| | | labelType: this.labelType, |
| | |
| | | }, 20000); |
| | | |
| | | jcapi.printData( |
| | | imageJsonObj, { |
| | | imageJsonObj, |
| | | { |
| | | printQuantity: 1, |
| | | }, |
| | | function(r) { |
| | | if (r.code != 0) { |
| | | // æ¢å¤åå§åè° |
| | | jcapi.didReadPrintCountInfo( |
| | | originalPrintCountCallback); |
| | | jcapi.didReadPrintCountInfo(originalPrintCountCallback); |
| | | // ç»æå½åæå°ä»»å¡ |
| | | reject(new Error(r.msg || "æå°å¤±è´¥")); |
| | | } |
| | |
| | | } |
| | | }); |
| | | }, |
| | | 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) { |
| | | // å¨tapQueryæ¹æ³ä¸ï¼è¿æ¥æåæ¶æ·»å ä¿åè¿æ¥ä¿¡æ¯ç代ç |
| | | if (r.code == 0) { |
| | | _this.connectedDevice = item; |
| | | _this.connectionStatus = "connected"; |
| | | // ä¿åè¿æ¥ä¿¡æ¯å°æ¬å°åå¨ |
| | | uni.setStorageSync("bluetoothConnection", item); |
| | | uni.showToast({ |
| | | title: "è¿æ¥æå", |
| | | duration: 1500, |
| | | }); |
| | | // å¼å§å¤çæå°éå |
| | | if (_this.printQueue.length > 0) { |
| | | _this.processPrintQueue(); |
| | | // 妿ææå°ä»»å¡ï¼ç»§ç»æå° |
| | | if (this.printQueue.length) { |
| | | this.processPrintQueue(); |
| | | } |
| | | } else { |
| | | _this.connectionStatus = "disconnected"; |
| | | } catch (e) { |
| | | uni.showToast({ |
| | | title: "è¿æ¥å¤±è´¥: " + (r.msg || "æªç¥é误"), |
| | | icon: "none", |
| | | duration: 2000, |
| | | title: "è¿æ¥å¤±è´¥", |
| | | }); |
| | | } |
| | | } |
| | | ); |
| | | }, |
| | | |
| | | //æå°ç¸å
³ |
| | | searchDevice() { |
| | | let _this = this; |
| | | uni.openBluetoothAdapter({ |
| | | // 确认èçæ¯å¦æå¼ |
| | | success(r) { |
| | | uni.showLoading({ |
| | | title: "æç´¢ä¸...", |
| | | }); |
| | | // æªæäºèçç¸å
³æéåæªæå¼ææºå®ä½ä¼æç´¢ä¸å°è®¾å¤ |
| | | jcapi.getBluetoothDevices(function(r) { |
| | | console.log("device:" + JSON.stringify(r)); |
| | | // æç´¢å°è®¾å¤åè° |
| | | async searchDevice() { |
| | | try { |
| | | uni.showLoading({ title: "æç´¢ä¸..." }); |
| | | const devices = await bluetooth.searchDevices(); |
| | | 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) { |
| | | |
| | | this.listDevice = devices; |
| | | this.maskShow = true; |
| | | } catch (e) { |
| | | uni.hideLoading(); |
| | | uni.showModal({ |
| | | title: "æç¤º", |
| | | content: "æå¼èç失败ï¼è¯·æ£æ¥èçæ¯å¦å¼å¯", |
| | | content: "请确认èçåå®ä½å·²å¼å¯", |
| | | showCancel: false, |
| | | }); |
| | | console.log("å¼å¯èç设å¤å¤±è´¥" + e); |
| | | } |
| | | }, |
| | | }); |
| | | }, |
| | | |
| | | // ç»å¶æ¨ªçº¿ |
| | | getDrawLabelLine(x, y, width, height, rotate, lineType) { |
| | | jcapi.drawLabelLine({ |