¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <view class="mui-content"> |
| | | <view class="mui-input-row"> |
| | | <label>PDAå°å:</label> |
| | | <input v-model="pdaMac" type="text" class="mui-input-clear" placeholder="请è¾å
¥PDAçMACå°å" /> |
| | | </view> |
| | | <view class="mui-input-row"> |
| | | <label>æå°å°å:</label> |
| | | <input v-model="printMac" type="text" class="mui-input-clear" placeholder="请è¾å
¥æå°æºMACå°å" /> |
| | | </view> |
| | | </form> |
| | | <view class="mui-table-view ulcss"> |
| | | <view class="mui-table-view-cell acss" @tap="saveSettings" style="background-color: rgb(93, 204, 201);"> |
| | | <text>ä¿å</text> |
| | | </view> |
| | | </view> |
| | | <view class="mui-table-view ulcss"> |
| | | <view class="mui-table-view-cell acss" @tap="doPrint2" style="background-color: rgb(153, 204, 153);"> |
| | | <text>æå°æµè¯</text> |
| | | </view> |
| | | </view> |
| | | <view class="mui-table-view ulcss"> |
| | | <view class="mui-table-view-cell acss" @tap="getSettings" style="background-color: rgb(153, 204, 153);"> |
| | | <text>å·æ°</text> |
| | | </view> |
| | | </view> |
| | | </view> |
| | | </template> |
| | | |
| | | <script> |
| | | export default { |
| | | data() { |
| | | return { |
| | | pdaMac: '', |
| | | printMac:'',// '00:01:78:24:28:32', |
| | | }; |
| | | }, |
| | | created() { |
| | | this.getSettings(); |
| | | }, |
| | | methods: { |
| | | //读åpda macå°å |
| | | getSettings() { |
| | | var mac = ""; |
| | | if (plus.os.name == "Android") { |
| | | //è·åææºMACå°å |
| | | var Context = plus.android.importClass("android.content.Context"); |
| | | var WifiManager = plus.android.importClass("android.net.wifi.WifiManager"); |
| | | var wifiManager = plus.android.runtimeMainActivity().getSystemService(Context.WIFI_SERVICE); |
| | | var WifiInfo = plus.android.importClass("android.net.wifi.WifiInfo"); |
| | | var wifiInfo = wifiManager.getConnectionInfo(); |
| | | mac = wifiInfo.getMacAddress(); |
| | | //妿mac为â02:00:00:00:00:00âï¼åå¯è½æ¯å®å6.0以ä¸çæ¬ï¼å使ç¨å¦ä¸ç§æ¹æ³è·åmacå°å |
| | | if (mac == "02:00:00:00:00:00") { |
| | | var str = ""; |
| | | try { |
| | | if (plus.os.name == "Android") { |
| | | var NetworkInterface = plus.android.importClass("java.net.NetworkInterface"); |
| | | var networkInterface = NetworkInterface.getByName("wlan0"); |
| | | var bytes = networkInterface.getHardwareAddress(); |
| | | //å°byte[] è½¬æ¢æ String |
| | | for (var i = 0; i < bytes.length; i++) { |
| | | var tmp = ""; |
| | | var num = bytes[i]; |
| | | if (num < 0) { |
| | | tmp = (255 + num + 1).toString(16); |
| | | } else { |
| | | tmp = num.toString(16); |
| | | } |
| | | if (tmp.length == 1) { |
| | | tmp = "0" + tmp; |
| | | } |
| | | str += (i == 0) ? (tmp) : (":" + tmp); |
| | | } |
| | | } |
| | | } catch (err) { |
| | | str = "02:00:00:00:00:00"; |
| | | } |
| | | mac = str; |
| | | } |
| | | //妿macä½¿ç¨æ°æ¹æ³ä¾ç¶æ¯â02:00:00:00:00:00âåä¸è¿è¡ä¿å |
| | | if (mac == "02:00:00:00:00:00") { |
| | | return; |
| | | } |
| | | uni.setStorageSync('pdaMac', mac); |
| | | console.log(mac); |
| | | this.pdaMac=mac; |
| | | this.printMac= uni.getStorageSync('printMac'); |
| | | } |
| | | }, |
| | | //ä¿åå°å |
| | | saveSettings() { |
| | | if (!this.pdaMac) { |
| | | uni.showToast({ |
| | | title: 'PDAå°åä¸è½ä¸ºç©º', |
| | | icon: 'none', |
| | | }); |
| | | return; |
| | | } |
| | | if (!this.printMac) { |
| | | uni.showToast({ |
| | | title: 'æå°æºå°åä¸è½ä¸ºç©º', |
| | | icon: 'none', |
| | | }); |
| | | return; |
| | | } |
| | | uni.setStorageSync('pdaMac', this.pdaMac); |
| | | uni.setStorageSync('printMac', this.printMac); |
| | | //å
ä¿åå¨ç¼åä¸ï¼è¥è¦ä¿åè³æ°æ®åºï¼å¨è¿épost |
| | | }, |
| | | //æå°æµè¯ |
| | | doPrint2() { |
| | | var mac_address = uni.getStorageSync('printMac'); |
| | | console.log('æå°å¼å§:'+mac_address) |
| | | var device = null, |
| | | BAdapter = null, |
| | | BluetoothAdapter = null, |
| | | uuid = null, |
| | | main = null, |
| | | bluetoothSocket = null; |
| | | if (!mac_address) { |
| | | this.$showMessage('è¯·éæ©èçæå°æº'); |
| | | return false; |
| | | } |
| | | main = plus.android.runtimeMainActivity(); |
| | | BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"); |
| | | let UUID = plus.android.importClass("java.util.UUID"); |
| | | uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); |
| | | BAdapter = BluetoothAdapter.getDefaultAdapter(); |
| | | device = BAdapter.getRemoteDevice(mac_address); |
| | | plus.android.importClass(device); |
| | | bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); |
| | | plus.android.importClass(bluetoothSocket); |
| | | if (!bluetoothSocket.isConnected()) { |
| | | console.log('æ£æµå°è®¾å¤æªè¿æ¥ï¼å°è¯è¿æ¥....'); |
| | | bluetoothSocket.connect(); |
| | | } |
| | | console.log('设å¤å·²è¿æ¥'); |
| | | if (bluetoothSocket.isConnected()) { |
| | | var outputStream = bluetoothSocket.getOutputStream(); |
| | | plus.android.importClass(outputStream); |
| | | let printStr = |
| | | "! 0 200 200 230 1\n" + |
| | | "PW 848\n" + |
| | | "TONE 0\n" + |
| | | "SPEED 0\n" + |
| | | "GAP-SENSE\n" + |
| | | "NO-PACE\n" + |
| | | "POSTFEED 0\n" + |
| | | "LEFT\n" + |
| | | "T 65 1 20 2 ç©æç¼ç ï¼\n" + |
| | | "SETBOLD 2\n" + |
| | | "T 65 1 140 1 {0}\n" + |
| | | "SETBOLD 0\n" + |
| | | "T 65 1 300 1 {11}\n" + |
| | | "T 65 1 20 25 ç©æè§æ ¼ï¼{1}\n" + |
| | | "T 65 1 20 50 {2}\n" + |
| | | "T 65 0 20 75 ä¾åºåï¼\n" + |
| | | "T 65 0 20 100 æææï¼\n" + |
| | | "T 65 0 20 125 æ£éªåï¼\n" + |
| | | "T 65 0 20 150 æ ¡éªæ¥æï¼\n" + |
| | | "T 55 0 120 80 {3}\n" + |
| | | "T 55 0 120 105 {4}\n" + |
| | | "T 55 0 120 130 {6}\n" + |
| | | "T 55 0 140 155 {5}\n" + |
| | | "SETBOLD 2\n" + |
| | | "SETBOLD 0\n" + |
| | | "SETMAG 0 0\n" + |
| | | "T 65 1 440 75 æ°éï¼\n" + |
| | | "SETBOLD 2\n" + |
| | | "T 65 1 500 75 {9}\n" + |
| | | "SETBOLD 0\n" + |
| | | "B QR 600 2 M 2 U 4\n" + |
| | | "MA,{10}\n" + |
| | | "ENDQR\n" + |
| | | "B 128 1 0 50 320 100 {10}\n" + |
| | | "T 65 1 385 155 {10}\n" + |
| | | "FORM\n" + |
| | | "PRINT\n"; |
| | | var bytes = plus.android.invoke(printStr, 'getBytes', 'gbk'); |
| | | outputStream.write(bytes); |
| | | outputStream.flush(); |
| | | device = null //è¿éå
³é® |
| | | bluetoothSocket.close(); //å¿
é¡»å
³éèçè¿æ¥å¦åæå¤æå¼çè¯æå°é误 |
| | | //this.$showMessage('OK'); |
| | | console.log("æå°æºè¿æ¥ç¶æï¼111"); |
| | | return true; |
| | | } else { |
| | | //this.$showMessage('NG'); |
| | | console.log("æå°æºè¿æ¥ç¶æï¼222"); |
| | | return false; |
| | | } |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |
| | | <style scoped> |
| | | .mui-content { |
| | | margin-top:80px;padding:10px; |
| | | } |
| | | .ulcss { |
| | | margin-top: 0.625rem;padding:2px; |
| | | } |
| | | |
| | | </style> |