From 9c03b75ea7dfdc210568fae90927060ffc7a85c3 Mon Sep 17 00:00:00 2001 From: whycq <10027870+whycq@user.noreply.gitee.com> Date: 星期四, 04 五月 2023 16:44:46 +0800 Subject: [PATCH] # --- pages/print/printUNI.vue | 820 ++++++++-------------------------------------------------- 1 files changed, 114 insertions(+), 706 deletions(-) diff --git a/pages/print/printUNI.vue b/pages/print/printUNI.vue index d9bc4da..75b8835 100644 --- a/pages/print/printUNI.vue +++ b/pages/print/printUNI.vue @@ -1,723 +1,131 @@ <template> - <view> - <page-head :title="title"></page-head> - <view class="uni-padding-wrap uni-common-mt"> - <view> - 鏈摑鐗欏崗璁彧鏀寔浣庡姛鑰楄摑鐗欏崗璁産le銆傚鏋滄兂杩炴帴闈瀊le钃濈墮璁惧锛岃鍦ㄧぞ鍖烘悳绱� Native.js 钃濈墮銆� + <view class="content"> + <view> + <view class="bluetoothConnected"> + <view class="bluetoothList" v-for="(item,index) in GET_CONNECTBLEDATA" :key="index" @tap="confirm_bluetooth(item)"> + <view class="bluetoothList-name">鍚嶇О:{{item.name}}</view> + <view class="bluetoothList-mac">鍦板潃:{{item.mac}}</view> + </view> </view> - <view class="uni-btn-v"> - <button type="primary" :disabled="disabled[0]" @click="openBluetoothAdapter"> - 鍒濆鍖栬摑鐗欐ā鍧� - </button> - <view v-if="!adapterState.available"> - {{ '钃濈墮閫傞厤鍣ㄤ笉鍙敤,璇峰垵濮嬪寲钃濈墮妯″潡' }} + <button type="default" @click="search_bluetooth">鎼滅储钃濈墮</button> + <button @click="senBleLabel">鎵撳嵃</button> + <view class="bluetoothItem" v-if="GET_INFODATA"> + <view class="bluetoothList" v-for="(item,index) in GET_INFODATA" :key="index" @tap="confirm_bluetooth(item)"> + <view class="bluetoothList-name">鍚嶇О:{{item.name}}</view> + <view class="bluetoothList-mac">鍦板潃:{{item.mac}}</view> </view> - <button - type="primary" - :loading="searchLoad" - :disabled="disabled[1]" - @click="startBluetoothDevicesDiscovery" - > - 寮�濮嬫悳绱㈣摑鐗欒澶� - </button> - <button - type="primary" - :disabled="disabled[2]" - @click="stopBluetoothDevicesDiscovery(false)" - > - 鍋滄鎼滅储钃濈墮璁惧 - </button> - <button - type="primary" - :loading="newDeviceLoad" - :disabled="disabled[3]" - @click="queryDevices" - > - 閫夋嫨璁惧 - </button> - <view v-if="equipment.length > 0"> - {{ - (connected ? '宸茶繛鎺ヨ澶�' : '宸查�夋嫨璁惧') + - ' : ' + - equipment[0].name + - ' (' + - equipment[0].deviceId + - ')' - }} - </view> - <button type="primary" :disabled="disabled[4]" @click="createBLEConnection"> - 杩炴帴钃濈墮璁惧 - </button> - <button type="primary" :disabled="disabled[5]" @click="getBLEDeviceServices"> - 閫夋嫨璁惧鏈嶅姟 - </button> - <view v-if="servicesData.length > 0">宸查�夋湇鍔uid锛歿{ servicesData[0].uuid }}</view> - <button type="primary" :disabled="disabled[6]" @click="getBLEDeviceCharacteristics"> - 鑾峰彇鏈嶅姟鐨勭壒寰佸�� - </button> - <view v-if="characteristicsData.length > 0"> - <view class="uni-list_name">uuid:{{ characteristicsData[0].uuid }}</view> - <view class="uni-list_item"> - 鏄惁鏀寔 read 鎿嶄綔:{{ characteristicsData[0].properties.read }} - </view> - <view class="uni-list_item"> - 鏄惁鏀寔 write 鎿嶄綔:{{ characteristicsData[0].properties.write }} - </view> - <view class="uni-list_item"> - 鏄惁鏀寔 notify 鎿嶄綔:{{ characteristicsData[0].properties.notify }} - </view> - <view class="uni-list_item"> - 鏄惁鏀寔 indicate 鎿嶄綔:{{ characteristicsData[0].properties.indicate }} - </view> - </view> - <!-- <button type="primary" :disabled="disabled[7]" @click="readBLECharacteristicValue"> - 璇诲彇鐗瑰緛鍊兼暟鎹� - </button> - <view v-if="valueChangeData.serviceId"> - <view class="list-name"> - 鐗瑰緛鍊兼渶鏂扮殑鍊�:{{ valueChangeData.value || '杩樻病鏈夋渶鏂板��' }} - </view> - </view> --> - <!-- <button type="primary" :disabled="disabled[8]" @click="w">鍐欏叆鐗瑰緛鍊兼暟鎹�</button> --> - <button type="primary" :disabled="disabled[9]" @click="closeBLEConnection"> - 鏂紑钃濈墮璁惧 - </button> - <button type="primary" :disabled="disabled[10]" @click="closeBluetoothAdapter"> - 鍏抽棴钃濈墮妯″潡 - </button> </view> - </view> - <!-- 閬僵 --> - <view v-if="maskShow" class="uni-mask" @touchmove.stop.prevent="moveHandle" @click="maskclose"> - <scroll-view class="uni-scroll_box" scroll-y @touchmove.stop.prevent="moveHandle" @click.stop="moveHandle"> - <view class="uni-title"> - 宸茬粡鍙戠幇{{ list.length }}{{ showMaskType === 'device' ? '鍙拌澶�' : '涓湇鍔�' }}: - </view> - <view - class="uni-list-box" - v-for="(item, index) in list" - :key="index" - @click="tapQuery(item)" - > - <view v-if="showMaskType === 'device'"> - <view class="uni-list_name">{{ item.name || item.localName }}</view> - <view class="uni-list_item">淇″彿寮哄害:{{ item.RSSI }}dBm</view> - <view class="uni-list_item">UUID:{{ item.deviceId }}</view> - <!-- <view class="list-item" v-if="showMaskType === 'device'"> - Service鏁伴噺:{{ item.advertisServiceUUIDs.length }} - </view> --> - </view> - <view v-if="showMaskType === 'service'"> - <view class="uni-list_item" style="line-height:2.2;"> - UUID: {{ item.uuid }} - <text v-if="showMaskType === 'service'"> - {{ item.isPrimary ? '锛堜富鏈嶅姟锛�' : '' }} - </text> - </view> - </view> - <view v-if="showMaskType === 'characteristics'"> - <view class="uni-list_name">uuid:{{ item.uuid }}</view> - <view class="uni-list_item">鏄惁鏀寔 read 鎿嶄綔:{{ item.properties.read }}</view> - <view class="uni-list_item"> - 鏄惁鏀寔 write 鎿嶄綔:{{ item.properties.write }} - </view> - <view class="uni-list_item"> - 鏄惁鏀寔 notify 鎿嶄綔:{{ item.properties.notify }} - </view> - <view class="uni-list_item"> - 鏄惁鏀寔 indicate 鎿嶄綔:{{ item.properties.indicate }} - </view> - </view> - </view> - </scroll-view> </view> </view> </template> + <script> -export default { - data() { - return { - title: 'bluetooth', - disabled: [false, true, true, true, true, true, true, true, true, true, true], - newDeviceLoad: false, - searchLoad: false, - maskShow: false, - equipment: [], - adapterState: { - discovering: false, - available: false + import printConnect from "@/common/print.js"; //寮曞叆鎵撳嵃鏈烘ā鏉挎枃浠� + let _this = null; + import { + mapGetters, + mapActions + } from 'vuex'; + import { + GET_INFODATA, + GET_CONNECTBLEDATA + } from "@/store/gettersType.js"; + import { + SET_CONNECTBLEDATA + } from '@/store/actionsType.js'; + // #ifdef APP-PLUS + const HanyinPlugin = uni.requireNativePlugin('Hanyin-Plugin'); //姹夊嵃 + // #endif + let print; + export default { + data() { + return { + bArray: [], //鐢ㄤ簬鎼滅储钃濈墮鍘婚噸鐢ㄧ殑 + no_match_list: [], //娌℃湁閰嶅鐨勮摑鐗欏垪琛� + match_list: "", //宸茶繛鎺ヨ摑鐗欐墦鍗版満 + val: "", + dateTimer: "", + valArr: [], + // 宸存灙鍙傛暟 + // broadcase_actions: "com.android.receive_scan_action", + // broadcast_flag: "data" + }; + }, + computed: { + ...mapGetters([GET_INFODATA, GET_CONNECTBLEDATA]) + }, + onShow() { + uni.hideLoading(); + //妫�鏌ユ槸鍚﹀凡杩炴帴钃濈墮 + // this.$check_bluetooth_connect(); + console.log('onShow'); + }, + onHide() { + console.log('onHide'); + }, + onUnload() { + console.log('onUnload'); + }, + onLoad(options) { + _this = this; + this.$init_bluetooth(); + }, + methods: { + ...mapActions([SET_CONNECTBLEDATA]), + senBleLabel() { + // console.log(this.$Mock.order_data); + if(!print) return; + print.startPrint(this.$Mock.order_data); }, - connected: false, - showMaskType: 'device', - servicesData: [], - characteristicsData: [], - valueChangeData: {}, - isStop:true , - list: [] - }; - }, - onLoad() { - this.onBLEConnectionStateChange(); - }, - methods: { - moveHandle() {}, - /** - * 鍏抽棴閬僵 - */ - maskclose(){ - this.maskShow = false; - }, - /** - * 閫夋嫨璁惧 - */ - queryDevices() { - // this.newDeviceLoad = true; - this.showMaskType = 'device'; - this.maskShow = true; - }, - tapQuery(item) { - if (this.showMaskType === 'device') { - this.$set(this.disabled, 4, false); - if (this.equipment.length > 0) { - this.equipment[0] = item; - } else { - this.equipment.push(item); - } - this.newDeviceLoad = false; - } - if (this.showMaskType === 'service') { - this.$set(this.disabled, 6, false); - if (this.servicesData.length > 0) { - this.servicesData[0] = item; - } else { - this.servicesData.push(item); - } - } - if (this.showMaskType === 'characteristics') { - this.$set(this.disabled, 7, false); - if (this.characteristicsData.length > 0) { - this.characteristicsData[0] = item; - } else { - this.characteristicsData.push(item); - } - } - this.maskShow = false; - }, - /** - * 鍒濆鍖栬摑鐗欒澶� - */ - openBluetoothAdapter() { - uni.openBluetoothAdapter({ - success: e => { - console.log('鍒濆鍖栬摑鐗欐垚鍔�:' + e.errMsg); - console.log(JSON.stringify(e)); - this.isStop = false ; - this.$set(this.disabled, 0, true); - this.$set(this.disabled, 1, false); - this.$set(this.disabled, 10, false); - this.getBluetoothAdapterState(); - }, - fail: e => { - console.log(e) - console.log('鍒濆鍖栬摑鐗欏け璐ワ紝閿欒鐮侊細' + (e.errCode || e.errMsg)); - if (e.errCode !== 0) { - initTypes(e.errCode,e.errMsg); - } - } - }); - }, - /** - * 寮�濮嬫悳绱㈣摑鐗欒澶� - */ - startBluetoothDevicesDiscovery() { - uni.startBluetoothDevicesDiscovery({ - success: e => { - console.log('寮�濮嬫悳绱㈣摑鐗欒澶�:' + e.errMsg); - this.searchLoad = true; - this.$set(this.disabled, 1, true); - this.$set(this.disabled, 2, false); - this.$set(this.disabled, 3, false); - this.onBluetoothDeviceFound(); - }, - fail: e => { - console.log('鎼滅储钃濈墮璁惧澶辫触锛岄敊璇爜锛�' + e.errCode); - if (e.errCode !== 0) { - initTypes(e.errCode); - } - } - }); - }, - /** - * 鍋滄鎼滅储钃濈墮璁惧 - */ - stopBluetoothDevicesDiscovery(types) { - uni.stopBluetoothDevicesDiscovery({ - success: e => { - console.log('鍋滄鎼滅储钃濈墮璁惧:' + e.errMsg); - if (types) { - this.$set(this.disabled, 1, true); - } else { - this.$set(this.disabled, 1, false); - } - this.$set(this.disabled, 2, true); - // this.$set(this.disabled, 3, true); - this.searchLoad = false; - }, - fail: e => { - console.log('鍋滄鎼滅储钃濈墮璁惧澶辫触锛岄敊璇爜锛�' + e.errCode); - if (e.errCode !== 0) { - initTypes(e.errCode); - } - } - }); - }, - /** - * 鍙戠幇澶栧洿璁惧 - */ - onBluetoothDeviceFound() { - uni.onBluetoothDeviceFound(devices => { - console.log('寮�濮嬬洃鍚鎵惧埌鏂拌澶囩殑浜嬩欢'); - // this.$set(this.disabled, 3, false); - this.getBluetoothDevices(); - }); - }, - /** - * 鑾峰彇鍦ㄨ摑鐗欐ā鍧楃敓鏁堟湡闂存墍鏈夊凡鍙戠幇鐨勮摑鐗欒澶囥�傚寘鎷凡缁忓拰鏈満澶勪簬杩炴帴鐘舵�佺殑璁惧銆� - */ - getBluetoothDevices() { - uni.getBluetoothDevices({ - success: res => { - this.newDeviceLoad = false; - console.log('鑾峰彇钃濈墮璁惧鎴愬姛:' + res.errMsg); - // console.log(JSON.stringify(res)) - this.list = res.devices; - }, - fail: e => { - console.log('鑾峰彇钃濈墮璁惧閿欒锛岄敊璇爜锛�' + e.errCode); - if (e.errCode !== 0) { - initTypes(e.errCode); - } - } - }); - }, - /** - * 鑾峰彇鏈満钃濈墮閫傞厤鍣ㄧ姸鎬� - */ - getBluetoothAdapterState() { - console.log('--->'); - uni.getBluetoothAdapterState({ - success: res => { - console.log(JSON.stringify(res)); - this.adapterState = res; - }, - fail: e => { - console.log('鑾峰彇鏈満钃濈墮閫傞厤鍣ㄧ姸鎬佸け璐ワ紝閿欒鐮侊細' + e.errCode); - if (e.errCode !== 0) { - initTypes(e.errCode); - } - } - }); - }, - /** - * 杩炴帴浣庡姛鑰楄摑鐗� - */ - createBLEConnection() { - let deviceId = this.equipment[0].deviceId; - uni.showToast({ - title: '杩炴帴钃濈墮...', - icon: 'loading', - duration: 99999 - }); - uni.createBLEConnection({ - // 杩欓噷鐨� deviceId 闇�瑕佸凡缁忛�氳繃 createBLEConnection 涓庡搴旇澶囧缓绔嬮摼鎺� - deviceId, - success: res => { + // 杩炴帴鎵撳嵃鏈� + confirm_bluetooth(item) { + let { + name, + mac + } = item; + //鍒ゆ柇钃濈墮鏄惁鎵撳紑 + this.$check_bluetooth_open().then(res => { console.log(res); - console.log('杩炴帴钃濈墮鎴愬姛:' + res.errMsg); - // 杩炴帴璁惧鍚庢柇寮�鎼滅储 骞朵笖涓嶈兘鎼滅储璁惧 - this.stopBluetoothDevicesDiscovery(true); - uni.hideToast(); - uni.showToast({ - title: '杩炴帴鎴愬姛', - icon: 'success', - duration: 2000 - }); - this.$set(this.disabled, 3, true); - this.$set(this.disabled, 4, true); - this.$set(this.disabled, 5, false); - this.$set(this.disabled, 9, false); - this.connected = true; - }, - fail: e => { - console.log('杩炴帴浣庡姛鑰楄摑鐗欏け璐ワ紝閿欒鐮侊細' + e.errCode); - if (e.errCode !== 0) { - initTypes(e.errCode); + //杩涜鎵撳嵃鏈鸿繛鎺� + if (res) { + print =new printConnect(item); //鎵撳嵃鏈鸿繛鎺� } - } - }); - }, - /** - * 鏂紑涓庝綆鍔熻�楄摑鐗欒澶囩殑杩炴帴 - */ - closeBLEConnection() { - let deviceId = this.equipment[0].deviceId; - uni.closeBLEConnection({ - deviceId, - success: res => { - console.log(res); - console.log('鏂紑浣庡姛鑰楄摑鐗欐垚鍔�:' + res.errMsg); - this.$set(this.disabled, 1, false); - this.$set(this.disabled, 3, true); - this.$set(this.disabled, 4, true); - this.$set(this.disabled, 5, true); - this.$set(this.disabled, 6, true); - this.$set(this.disabled, 7, true); - this.$set(this.disabled, 8, true); - this.$set(this.disabled, 9, true); - this.equipment = []; - this.servicesData = []; - this.characteristicsData = []; - }, - fail: e => { - console.log('鏂紑浣庡姛鑰楄摑鐗欐垚鍔燂紝閿欒鐮侊細' + e.errCode); - if (e.errCode !== 0) { - initTypes(e.errCode); + }) + }, + //鎼滅储娌″尮閰嶇殑钃濈墮璁惧 + search_bluetooth(address) { + let _this = this; + //妫�鏌ヨ摑鐗欐槸鍚﹀紑鍚� + this.$check_bluetooth_open().then(ores => { + if (ores) { + console.log(ores); + //鎼滅储钃濈墮 + _this.$search_bluetooth().then(bres => { + console.log(bres); + if (bres.code) { + _this.$search_pipei().then(pres => { + console.log(pres); + }) + } + }) } - } - }); - }, - /** - * 鑾峰彇鎵�鏈夋湇鍔� - */ - getBLEDeviceServices() { - let deviceId = this.equipment[0].deviceId; - console.log('鑾峰彇鎵�鏈夋湇鍔$殑 uuid:' + deviceId); - - uni.getBLEDeviceServices({ - // 杩欓噷鐨� deviceId 闇�瑕佸凡缁忛�氳繃 createBLEConnection 涓庡搴旇澶囧缓绔嬮摼鎺� - deviceId, - success: res => { - console.log(JSON.stringify(res.services)); - console.log('鑾峰彇璁惧鏈嶅姟鎴愬姛:' + res.errMsg); - this.$set(this.disabled, 7, true); - this.$set(this.disabled, 8, true); - this.showMaskType = 'service'; - this.list = res.services; - - this.characteristicsData = []; - if (this.list.length <= 0) { - toast('鑾峰彇鏈嶅姟澶辫触锛岃閲嶈瘯!'); - return; - } - this.maskShow = true; - }, - fail: e => { - console.log('鑾峰彇璁惧鏈嶅姟澶辫触锛岄敊璇爜锛�' + e.errCode); - if (e.errCode !== 0) { - initTypes(e.errCode); - } - } - }); - }, - /** - * 鑾峰彇鏌愪釜鏈嶅姟涓嬬殑鎵�鏈夌壒寰佸�� - */ - getBLEDeviceCharacteristics() { - let deviceId = this.equipment[0].deviceId; - let serviceId = this.servicesData[0].uuid; - console.log(deviceId); - console.log(serviceId); - uni.getBLEDeviceCharacteristics({ - // 杩欓噷鐨� deviceId 闇�瑕佸凡缁忛�氳繃 createBLEConnection 涓庡搴旇澶囧缓绔嬮摼鎺� - deviceId, - // 杩欓噷鐨� serviceId 闇�瑕佸湪 getBLEDeviceServices 鎺ュ彛涓幏鍙� - serviceId, - success: res => { - console.log(JSON.stringify(res)); - console.log('鑾峰彇鐗瑰緛鍊兼垚鍔�:' + res.errMsg); - this.$set(this.disabled, 7, true); - this.valueChangeData = {}; - this.showMaskType = 'characteristics'; - this.list = res.characteristics; - if (this.list.length <= 0) { - toast('鑾峰彇鐗瑰緛鍊煎け璐ワ紝璇烽噸璇�!'); - return; - } - this.maskShow = true; - }, - fail: e => { - console.log('鑾峰彇鐗瑰緛鍊煎け璐ワ紝閿欒鐮侊細' + e.errCode); - if (e.errCode !== 0) { - initTypes(e.errCode); - } - } - }); - }, - /** - * 鐩戝惉浣庡姛鑰楄摑鐗欒繛鎺ョ姸鎬佺殑鏀瑰彉浜嬩欢銆傚寘鎷紑鍙戣�呬富鍔ㄨ繛鎺ユ垨鏂紑杩炴帴锛岃澶囦涪澶憋紝杩炴帴寮傚父鏂紑绛夌瓑 - */ - onBLEConnectionStateChange() { - uni.onBLEConnectionStateChange(res => { - // 璇ユ柟娉曞洖璋冧腑鍙互鐢ㄤ簬澶勭悊杩炴帴鎰忓鏂紑绛夊紓甯告儏鍐� - console.log(`钃濈墮杩炴帴鐘舵�� -------------------------->`); - console.log(JSON.stringify(res)); - if (!res.connected) { - if(this.isStop) return ; - console.log('鏂紑浣庡姛鑰楄摑鐗欐垚鍔�:'); - this.$set(this.disabled, 1, false); - this.$set(this.disabled, 3, true); - this.$set(this.disabled, 4, true); - this.$set(this.disabled, 5, true); - this.$set(this.disabled, 6, true); - this.$set(this.disabled, 7, true); - this.$set(this.disabled, 8, true); - this.$set(this.disabled, 9, true); - this.searchLoad = false; - this.equipment = []; - this.servicesData = []; - this.characteristicsData = []; - this.valueChangeData = {}; - toast('宸茬粡鏂紑褰撳墠钃濈墮杩炴帴'); - } - }); - }, - /** - * 璇诲彇浣庡姛鑰楄摑鐗欒澶囩殑鐗瑰緛鍊肩殑浜岃繘鍒舵暟鎹�笺�傛敞鎰忥細蹇呴』璁惧鐨勭壒寰佸�兼敮鎸� read 鎵嶅彲浠ユ垚鍔熻皟鐢� - */ - readBLECharacteristicValue() { - let deviceId = this.equipment[0].deviceId; - let serviceId = this.servicesData[0].uuid; - let characteristicId = this.characteristicsData[0].uuid; - console.log(deviceId); - console.log(serviceId); - console.log(characteristicId); - uni.readBLECharacteristicValue({ - // 杩欓噷鐨� deviceId 闇�瑕佸凡缁忛�氳繃 createBLEConnection 涓庡搴旇澶囧缓绔嬮摼鎺� - deviceId, - // 杩欓噷鐨� serviceId 闇�瑕佸湪 getBLEDeviceServices 鎺ュ彛涓幏鍙� - serviceId, - // 杩欓噷鐨� characteristicId 闇�瑕佸湪 getBLEDeviceCharacteristics 鎺ュ彛涓幏鍙� - characteristicId, - success: res => { - console.log('璇诲彇璁惧鏁版嵁鍊兼垚鍔�'); - console.log(JSON.stringify(res)); - this.notifyBLECharacteristicValueChange(); - }, - fail(e) { - console.log('璇诲彇璁惧鏁版嵁鍊煎け璐ワ紝閿欒鐮侊細' + e.errCode); - if (e.errCode !== 0) { - initTypes(e.errCode); - } - } - }); - this.onBLECharacteristicValueChange(); - }, - /** - * 鐩戝惉浣庡姛鑰楄摑鐗欒澶囩殑鐗瑰緛鍊煎彉鍖栦簨浠躲�傚繀椤诲厛鍚敤 notifyBLECharacteristicValueChange 鎺ュ彛鎵嶈兘鎺ユ敹鍒拌澶囨帹閫佺殑 notification銆� - */ - onBLECharacteristicValueChange() { - // 蹇呴』鍦ㄨ繖閲岀殑鍥炶皟鎵嶈兘鑾峰彇 - uni.onBLECharacteristicValueChange(characteristic => { - console.log('鐩戝惉浣庡姛鑰楄摑鐗欒澶囩殑鐗瑰緛鍊煎彉鍖栦簨浠舵垚鍔�'); - console.log(JSON.stringify(characteristic)); - this.valueChangeData = characteristic; - }); - }, - /** - * 璁㈤槄鎿嶄綔鎴愬姛鍚庨渶瑕佽澶囦富鍔ㄦ洿鏂扮壒寰佸�肩殑 value锛屾墠浼氳Е鍙� uni.onBLECharacteristicValueChange 鍥炶皟銆� - */ - notifyBLECharacteristicValueChange() { - let deviceId = this.equipment[0].deviceId; - let serviceId = this.servicesData[0].uuid; - let characteristicId = this.characteristicsData[0].uuid; - let notify = this.characteristicsData[0].properties.notify; - console.log(deviceId); - console.log(serviceId); - console.log(characteristicId); - console.log(notify); - uni.notifyBLECharacteristicValueChange({ - state: true, // 鍚敤 notify 鍔熻兘 - // 杩欓噷鐨� deviceId 闇�瑕佸凡缁忛�氳繃 createBLEConnection 涓庡搴旇澶囧缓绔嬮摼鎺� - deviceId, - // 杩欓噷鐨� serviceId 闇�瑕佸湪 getBLEDeviceServices 鎺ュ彛涓幏鍙� - serviceId, - // 杩欓噷鐨� characteristicId 闇�瑕佸湪 getBLEDeviceCharacteristics 鎺ュ彛涓幏鍙� - characteristicId, - success(res) { - console.log('notifyBLECharacteristicValueChange success:' + res.errMsg); - console.log(JSON.stringify(res)); - } - }); - }, - /** - * 鏂紑钃濈墮妯″潡 - */ - closeBluetoothAdapter(OBJECT) { - uni.closeBluetoothAdapter({ - success: res => { - console.log('鏂紑钃濈墮妯″潡鎴愬姛'); - this.isStop = true ; - this.$set(this.disabled, 0, false); - this.$set(this.disabled, 1, true); - this.$set(this.disabled, 2, true); - this.$set(this.disabled, 3, true); - this.$set(this.disabled, 4, true); - this.$set(this.disabled, 5, true); - this.$set(this.disabled, 6, true); - this.$set(this.disabled, 7, true); - this.$set(this.disabled, 8, true); - this.$set(this.disabled, 9, true); - this.$set(this.disabled, 10, true); - this.equipment = []; - this.servicesData = []; - this.characteristicsData = []; - this.valueChangeData = {}; - this.adapterState = []; - this.searchLoad =false; - toast('鏂紑钃濈墮妯″潡'); - } - }); + }) + } } } -}; - -/** - * 鍒ゆ柇鍒濆鍖栬摑鐗欑姸鎬� - */ -function initTypes(code, errMsg) { - switch (code) { - case 10000: - toast('鏈垵濮嬪寲钃濈墮閫傞厤鍣�'); - break; - case 10001: - toast('鏈娴嬪埌钃濈墮锛岃鎵撳紑钃濈墮閲嶈瘯锛�'); - break; - case 10002: - toast('娌℃湁鎵惧埌鎸囧畾璁惧'); - break; - case 10003: - toast('杩炴帴澶辫触'); - break; - case 10004: - toast('娌℃湁鎵惧埌鎸囧畾鏈嶅姟'); - break; - case 10005: - toast('娌℃湁鎵惧埌鎸囧畾鐗瑰緛鍊�'); - break; - case 10006: - toast('褰撳墠杩炴帴宸叉柇寮�'); - break; - case 10007: - toast('褰撳墠鐗瑰緛鍊间笉鏀寔姝ゆ搷浣�'); - break; - case 10008: - toast('鍏朵綑鎵�鏈夌郴缁熶笂鎶ョ殑寮傚父'); - break; - case 10009: - toast('Android 绯荤粺鐗规湁锛岀郴缁熺増鏈綆浜� 4.3 涓嶆敮鎸� BLE'); - break; - default: - toast(errMsg); - } -} - -/** - * 寮瑰嚭妗嗗皝瑁� - */ -function toast(content, showCancel = false) { - uni.showModal({ - title: '鎻愮ず', - content, - showCancel - }); -} </script> -<style> - -.uni-title { - /* width: 100%; */ - /* height: 80rpx; */ - text-align: center; -} - -.uni-mask { - position: fixed; - top: 0; - left: 0; - bottom: 0; - display: flex; - align-items: center; - width: 100%; - background: rgba(0, 0, 0, 0.6); - padding: 0 30rpx; - box-sizing: border-box; -} - -.uni-scroll_box { - height: 70%; - background: #fff; - border-radius: 20rpx; -} -.uni-list-box { - margin: 0 20rpx; - padding: 15rpx 0; - border-bottom: 1px #f5f5f5 solid; - box-sizing: border-box; -} -.uni-list:last-child { - border: none; -} -.uni-list_name { - font-size: 30rpx; - color: #333; -} -.uni-list_item { - font-size: 24rpx; - color: #555; - line-height: 1.5; -} - -.uni-success_box { - position: absolute; - left: 0; - bottom: 0; - min-height: 100rpx; - width: 100%; - background: #fff; - box-sizing: border-box; - border-top: 1px #eee solid; -} -.uni-success_sub { - /* width: 100%%; */ - height: 100rpx; - display: flex; - justify-content: space-between; - align-items: center; - padding: 0 30rpx; -} -.uni-close_button { - padding: 0 20rpx; - height: 60rpx; - line-height: 60rpx; - background: #ce3c39; - color: #ffffff; - border-radius: 10rpx; -} -.uni-success_content { - height: 600rpx; - margin: 30rpx; - margin-top: 0; - border: 1px #eee solid; - padding: 30rpx; -} -.uni-content_list { - padding-bottom: 10rpx; - border-bottom: 1px #f5f5f5 solid; -} -.uni-tips { - text-align: center; - font-size: 24rpx; - color: #666; -} +<style lang="scss"> + .bluetoothItem { + width: 100%; + height: 100%; + + .bluetoothList { + display: flex; + flex-direction: column; + padding: 20rpx; + border-bottom: 1rpx solid #BEBEBE; + font-size: 18rpx; + } + } </style> -- Gitblit v1.9.1