瀏覽代碼

1.测试环境的预上线版本 2.0.9
2.迁移了BLE.js 脚本函数到 store.js
3.调整了蓝牙触发事件时间

slambb 5 年之前
父節點
當前提交
acb6dddef8

+ 1 - 1
common/config.js

@@ -136,7 +136,7 @@ const URL = {
 
 //设置游戏列表的更新时间,超过这个时间,不显示出来
 //"2020-07-14"
-const endTime = "2021-01-18"
+const endTime = "2021-01-19"
 
 export default {
 	URL,

+ 2 - 2
manifest.json

@@ -2,8 +2,8 @@
     "name" : "哔蹦",
     "appid" : "__UNI__2635DF5",
     "description" : "",
-    "versionName" : "2.0.7",
-    "versionCode" : 21011802,
+    "versionName" : "2.0.9",
+    "versionCode" : 21012001,
     "transformPx" : false,
     /* 5+App特有相关 */
     "app-plus" : {

+ 66 - 64
pages/personal-page/devices-hardware/devices-hardware.vue

@@ -27,7 +27,7 @@
 				 mode="aspectFit" @tap="_onRadio(item,$event)"></image>
 			</view>
 		</view>
-		
+
 		<!-- <button class="margin" @click="onWriteBLEConnectionValue({value:'M'})">设备版本</button> -->
 		<!-- <button class="margin" @click="onWriteBLEConnectionValue({value:'4'})">加速计关</button> -->
 
@@ -47,7 +47,8 @@
 
 	export default {
 		computed: mapState(['bOpenBluetooth', 'bOpenSuccess', 'bListenAdapterStateChange', 'bListenDeviceFound',
-			'BLEConnectDevice', 'BLEGetServices', 'cIndex', 'bConnection', 'BLEInfoList', 'BLEDeviceShowList', 'finallyUseDevice'
+			'BLEConnectDevice', 'BLEGetServices', 'cIndex', 'bConnection', 'bVerifiedConnection', 'BLEInfoList',
+			'BLEDeviceShowList', 'finallyUseDevice'
 		]),
 		data() {
 			return {
@@ -64,11 +65,11 @@
 				//搜索提示定时器
 				searchMac: null,
 				//
-				getServicesTimeout:null,
-				writeMacTimeout:null,
+				getServicesTimeout: null,
+				writeMacTimeout: null,
 				//限制关闭连接
-				bLimitClose:false
-				
+				bLimitClose: false
+
 			}
 		},
 		onLoad(op) {
@@ -91,8 +92,8 @@
 			}
 			uni.$on('callbackCloseBLE', this.hardCallbackCloseBLE);
 			uni.$on('listenerBLE', this.onListenerBLE);
-			
-			this.getBondedDevices();
+
+			// this.getBondedDevices();
 		},
 		onUnload() {
 			uni.$off('callbackCloseBLE', this.hardCallbackCloseBLE);
@@ -102,11 +103,11 @@
 			this.onClearTimeout();
 		},
 		onShow() {
-			
+
 			this.bLimitClose = false;
 			// console.log(this.cIndex, this.BLEDeviceShowList, this.BLEConnectDevice,this.devicesList);
 			//this.bConnection &&
-			if (this.BLEConnectDevice) {
+			if (this.bVerifiedConnection && this.BLEConnectDevice) {
 				for (let i = 0; i < this.devicesList.length; i++) {
 					let eq = this.devicesList[i];
 					if (
@@ -125,8 +126,8 @@
 				}
 				// this.currentItem = null;
 			}
-			
-			
+
+
 		},
 		onHide() {},
 		methods: {
@@ -151,7 +152,7 @@
 					clearTimeout(this.writeMacTimeout);
 					this.writeMacTimeout = null;
 				}
-				
+
 				if (this.searchTimeOut) {
 					clearTimeout(this.searchTimeOut);
 					this.searchTimeOut = null;
@@ -159,7 +160,7 @@
 			},
 			//监听回调
 			onListenerBLE(res) {
-				console.log('onListenerBLE:',res);
+				console.log('onListenerBLE:', res);
 				if (res.type !== 'mac') return;
 				//如果mac 回调了不用提示
 				if (this.searchMac) {
@@ -173,7 +174,7 @@
 				//就判断一下是否
 				//测试
 				// mac="BB:34:24:22:77:88";
-				
+
 				reqUtil.requestData(config.URL.BLEFINDHASBIND, {
 					mac: mac,
 				}).then(
@@ -244,26 +245,28 @@
 					title: "连接设备成功!",
 					duration: 2000
 				})
-				if (this.BLEConnectDevice) {
-					for (let i = 0; i < this.devicesList.length; i++) {
-						let eq = this.devicesList[i];
-						if (
-							(eq.ename.indexOf("mobilePhoneBandage") > -1 && this.BLEConnectDevice.id == 0) ||
-							(eq.ename.indexOf("hotman") > -1 && this.BLEConnectDevice.id == 1) ||
-							(eq.ename.indexOf("BLEHandle") > -1 && this.BLEConnectDevice.id == 2)) {
-
-							eq.bRatio = true;
-							this.currentItem = eq;
-						}
+				for (let i = 0; i < this.devicesList.length; i++) {
+					let eq = this.devicesList[i];
+					if (
+						(eq.ename.indexOf("mobilePhoneBandage") > -1 && this.BLEConnectDevice.id == 0) ||
+						(eq.ename.indexOf("hotman") > -1 && this.BLEConnectDevice.id == 1) ||
+						(eq.ename.indexOf("BLEHandle") > -1 && this.BLEConnectDevice.id == 2)) {
+
+						eq.bRatio = true;
+						this.currentItem = eq;
+						/**
+						 * 已验证的连接设置true
+						 */
+						this.$store.state.bVerifiedConnection = true;
 					}
 				}
 			},
 			hardCallbackCloseBLE() {
 				//如果限制不走重连
-				if(this.bLimitClose)return;
-				
+				if (this.bLimitClose) return;
+
 				console.log(this.currentItem, this.oldItem);
-				if (this.oldItem &&this.currentItem&& this.currentItem.id == this.oldItem.id) {
+				if (this.oldItem && this.currentItem && this.currentItem.id == this.oldItem.id) {
 					// this.$store.state.bConnection = false;
 					if (this.currentItem.bRatio) {
 						uni.showToast({
@@ -276,13 +279,13 @@
 						this.oldItem = null;
 						this.currentItem = null;
 					}
-				}else if(this.bConnection && this.BLEConnectDevice){
+				} else if (this.bConnection && this.BLEConnectDevice) {
 					//假如匹配过程中断开连接
 					this.$store.state.BLEConnectDevice = null;
 					this.$store.state.bConnection = false;
 					uni.hideToast();
 				}
-				
+
 			},
 			/**
 			 * 开始查找设备
@@ -311,7 +314,7 @@
 
 							uni.showModal({
 								title: '连接提示!',
-								content: '检测到使用过旧手柄设备,是否使用旧设备切换新模式。否则继续搜索新手柄设备...',
+								content: "是否使用旧设备连接,取消则搜索'蓝灯闪烁'的新设备。",
 								success: (res) => {
 									if (res.confirm) {
 										//currentItem 是mode 页面选中的item
@@ -330,7 +333,6 @@
 										// 先直连,然后判断版本
 										_self._onConnectDevice(obj);
 									} else if (res.cancel) {
-
 										_self.onCanStart();
 									}
 								}
@@ -457,7 +459,7 @@
 					this.writeMacTimeout = null;
 				}
 				//如果已经连接,加上服务不存在,直接获取服务
-				if(this.bConnection &&this.BLEGetServices&& this.BLEGetServices.length == 0){
+				if (this.bConnection && this.BLEGetServices && this.BLEGetServices.length == 0) {
 					// console.log('onGetBLEDeviceServices');
 					console.log("***直接获取服务*******");
 					this.onGetBLEDeviceServices({
@@ -484,15 +486,15 @@
 									})
 									this.onOnlyCloseBLEConnection({
 										getSuccess: () => {
-											if(this.currentItem)
-											  this.currentItem.bRatio = false;
-											  
+											if (this.currentItem)
+												this.currentItem.bRatio = false;
+
 											this.currentItem = null;
 										}
 									});
-								}, 5000)
-							}, 1500)
-					
+								}, 6000)
+							}, 3000)
+
 						}
 					});
 					return;
@@ -506,7 +508,7 @@
 							this.onGetBLEDeviceServices({
 								item: item,
 								success: (res) => {
-									console.log("onGetBLEDeviceServices************",res);
+									console.log("onGetBLEDeviceServices************", res);
 									//连接成功了,设置旧的item
 									this.oldItem = this.currentItem;
 									// 初始化服务后,获取版本,判断
@@ -527,14 +529,14 @@
 											})
 											this.onOnlyCloseBLEConnection({
 												getSuccess: () => {
-													if(this.currentItem)
-													  this.currentItem.bRatio = false;
-													  
+													if (this.currentItem)
+														this.currentItem.bRatio = false;
+
 													this.currentItem = null;
 												}
 											});
-										}, 5000)
-									}, 1500)
+										}, 6000)
+									}, 3000)
 
 								}
 							});
@@ -589,28 +591,28 @@
 					})
 					return;
 				}
-				
+
 				this.bLimitClose = true;
 				uni.navigateTo({
 					url: "../devices-update/devices-update?deviceType=" + this.option.deviceType
 				})
 			},
-			
+
 			//获取手机已连接的设备
 			getBondedDevices() {
 				console.log("getBondedDevices ====>");
-			// 	uni.getBluetoothDevices({
-			// 		success(res) {
-			// 			console.log("getBluetoothDevices:", res)
-			// 		}
-			// 	})
-			
-			// 	uni.getConnectedBluetoothDevices({
-			// 		success(res) {
-			// 			console.log("getConnectedBluetoothDevices:", res)
-			// 		}
-			// 	})
-			
+				// 	uni.getBluetoothDevices({
+				// 		success(res) {
+				// 			console.log("getBluetoothDevices:", res)
+				// 		}
+				// 	})
+
+				// 	uni.getConnectedBluetoothDevices({
+				// 		success(res) {
+				// 			console.log("getConnectedBluetoothDevices:", res)
+				// 		}
+				// 	})
+
 				function bluetooth_list() {
 					var main = plus.android.runtimeMainActivity();
 					var BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter");
@@ -628,9 +630,9 @@
 						console.log(d.getName());
 						console.log(d.getAddress());
 					}
-			
+
 				}
-			
+
 				switch (plus.os.name) {
 					case "Android":
 						// Android平台: plus.android.*  
@@ -643,8 +645,8 @@
 						// 其它平台  
 						break;
 				}
-			
-			
+
+
 			}
 		}
 

+ 32 - 11
pages/personal-page/devices-update/devices-update.vue

@@ -293,9 +293,10 @@
 							}
 
 							this.sendFileHeaderTimeout = setTimeout(() => {
-								this.sendFileHeader();
+								let retryCount = 3;
+								this.sendFileHeader(retryCount);
 								// this.send_index = -1;
-							}, 2000)
+							}, 3000)
 
 							this.bStart = true;
 						}
@@ -325,7 +326,8 @@
 							_self.bListenValueChange = true;
 						}
 						if (characteristicId == _self.UUID_IDENTFY) {
-							_self.onGetDeviceVersion(context);
+							//重发3次
+							_self.onGetDeviceVersion(context,3);
 						}
 
 					},
@@ -340,7 +342,7 @@
 				})
 			},
 			
-			onGetDeviceVersion(context){
+			onGetDeviceVersion(context,retryCount){
 				let _self = this;
 				let {
 					deviceId,
@@ -353,6 +355,7 @@
 					_self.writeHeadTimeout = null;
 				}
 				_self.writeHeadTimeout = setTimeout(() => {
+					
 					// 向蓝牙设备发送一个0x00的16进制数据
 					let bufferDevice = new ArrayBuffer(1)
 					let dataViewDevice = new DataView(bufferDevice)
@@ -364,23 +367,32 @@
 						characteristicId: characteristicId,
 						value: bufferDevice,
 						success:(res) => {
-							console.log('获取版本:writeBLECharacteristicValue success', res.errMsg)
+							console.log('获取版本:writeBLECharacteristicValue success', res.errMsg ," == " ,retryCount)
 						},
 						fail:(fail)=>{
-							console.error('获取版本:writeBLECharacteristicValue fail', fail.errMsg)
+							console.error('获取版本:writeBLECharacteristicValue fail', fail.errMsg ," == " ,retryCount)
+							
+							if(retryCount>0){
+								retryCount--;
+								setTimeout(()=>{
+									_self.onGetDeviceVersion(context,retryCount);
+								},300);
+								return;
+							}
+							
 							
 							uni.showModal({
 								title:'获取固件版本',
 								content:'获取不成功,是否重新获取',
 								success: (resValue) => {
 									if(resValue.confirm){
-										_self.onGetDeviceVersion(context);
+										_self.onGetDeviceVersion(context,retryCount);
 									}
 								}
 							})
 						}
 					})
-				}, 1500)
+				}, 3000)
 			},
 			//监听低功耗蓝牙设备的特征值变化。必须先启用notify接口才能接收到设备推送的notification。
 			onBLECharacteristicValueChange() {
@@ -479,7 +491,7 @@
 			},
 
 			//发送文件头信息(配置信息)
-			sendFileHeader() {
+			sendFileHeader(retryCount) {
 				console.log('---------- sendFileHeader --------------')
 				let _self = this
 				let buffer = new ArrayBuffer(16)
@@ -508,13 +520,22 @@
 						// _self.SendBlePkg()
 					},
 					fail: function(err) {
-						console.log('read version fail! ' + JSON.stringify(err))
+						console.log('read version fail! ' + JSON.stringify(err)+retryCount)
+						
+						if(retryCount>0){
+							retryCount--;
+							setTimeout(()=>{
+								_self.sendFileHeader(retryCount);
+							},300);
+							return;
+						}
+						
 						uni.showModal({
 							title:'请求更新',
 							content:'请求更新失败,是否重新尝试继续。',
 							success: (resValue) => {
 								if(resValue.confirm){
-									_self.sendFileHeader();
+									_self.sendFileHeader(retryCount);
 								}else if(resValue.cancel){
 									_self.bStart = false;
 								}

+ 3 - 54
pages/personal-page/personal/personal.vue

@@ -448,7 +448,6 @@
 	import reqUtil from '@/util/util-js/requstUtil.js';
 	import config from '@/common/config.js';
 
-	import BLE from '@/util/util-js/BLE.js';
 	import uniCountDown from '@/components/uni-count-down/uni-count-down.vue'
 
 	import elect from "@/components/electAni/electAnimation.vue"
@@ -494,7 +493,7 @@
 			'bGuidePages',
 			'globalAcc', 'globalOri', 'DeviceBindingList', 'ConnectBindingDevice', 'cIndex', 'bNewGuide', 'localSportTime',
 			'currentModeIndex', 'oldArcbarProCalorie', 'oldArcbarAllCalorie', 'bOpenBluetooth', 'bOpenSuccess',
-			'bListenAdapterStateChange', 'bConnection', 'currentInstruction', 'instructionState', 'LocationGameUrl'
+			'bListenAdapterStateChange', 'bConnection', 'bVerifiedConnection', 'currentInstruction', 'instructionState', 'LocationGameUrl'
 		]),
 		components: {
 			uniNavBar,
@@ -880,7 +879,7 @@
 
 			// console.warn('this.BLEConnectDevice:',this.BLEConnectDevice);
 			//this.bConnection && 
-			if (this.BLEConnectDevice) {
+			if (this.bVerifiedConnection && this.BLEConnectDevice) {
 				// console.log('this.BLEConnectDevice:',this.BLEConnectDevice);
 				this.updateBLECIndex();
 			}
@@ -1477,7 +1476,7 @@
 				/**
 				 * 蓝牙部分操作,转全局变量操作
 				 * */
-				console.log("openDeviceList BLE.bOpenBluetooth", this.bOpenBluetooth);
+				console.log("openDeviceList bOpenBluetooth", this.bOpenBluetooth);
 				// #ifdef APP-PLUS
 				if (!this.bOpenBluetooth) {
 
@@ -2253,56 +2252,6 @@
 				}, 500)
 			},
 
-			// onGetDevices(context) {
-			// 	let {
-			// 		success
-			// 	} = context;
-
-			// 	let _self = this;
-
-			// 	// #ifdef APP-PLUS
-			// 	let deviceId = _self.BLEConnectDevice.deviceId;
-
-			// 	uni.getBLEDeviceRSSI({
-			// 		deviceId,
-			// 		success: res => {
-			// 			// console.log(res);
-			// 			//如果超过一定距离,则断开连接
-			// 			//66.78 / 16.56
-			// 			let _dis = Math.pow(Math.E, (Math.abs(res.RSSI) - 66.78) / 16.56);
-			// 			// console.log('当前的距离:', _dis,' == 限制距离:',BLE.BLEDIS);
-
-			// 			if (_dis > BLE.BLEDIS) {
-			// 				if (_self.cIndex != -1) {
-			// 					uni.showToast({
-			// 						title: '设备断开连接!',
-			// 						icon: 'none',
-			// 						duration: 2000,
-			// 						mask: true
-			// 					})
-			// 				}
-
-			// 				setTimeout(() => {
-			// 					BLE.closeBLEConnection(deviceId);
-			// 					_self.$store.state.cIndex = -1;
-			// 				}, 1000)
-
-			// 			} else {
-			// 				console.log("DIS~~~~~~~~~", _dis);
-			// 				if (success) {
-			// 					success({
-			// 						RSSI: res.RSSI,
-			// 						DIS: _dis
-			// 					});
-			// 				}
-			// 			}
-			// 		}
-			// 	})
-			// 	// #endif
-
-
-			// },
-
 			onGetAiRandom() {
 				let _self = this;
 

+ 17 - 7
util/util-js/BLE.js

@@ -137,6 +137,7 @@ function getBLEDeviceServices(item, callback,getServiceList) {
 		success: res => {
 			console.log("getBLEDeviceServices==", JSON.stringify(res), item);
 			serviceList = res.services;
+			// serviceList = [];
 			if(serviceList.length == 0){
 				uni.hideToast();
 				uni.showModal({
@@ -442,7 +443,6 @@ function hexToSignedInt(hex) {
 		return two;
 	}
 }
-
 //十六进制转ASCII码
 function hexCharCodeToStr(hexCharCodeStr) {
 	var trimedStr = hexCharCodeStr.trim();
@@ -596,17 +596,19 @@ function writeBLECharacteristicValue(value, retryCount, success, getFail) {
 			// })
 			if(retryCount>0){
 				console.log("writeBLECharacteristicValue Rewrite ===================>"+value+" == "+retryCount);
-				self.writeBLECharacteristicValue(value,retryCount,success,getFail);
 				retryCount--;
+				setTimeout(()=>{
+					self.writeBLECharacteristicValue(value,retryCount,success,getFail);
+				},300);
 			}
 			if(getFail){
 				getFail(fail);
 			}
-		},
-		complete: (completeRes) => {
-			
-			console.log(completeRes)
 		}
+		// ,
+		// complete: (completeRes) => {
+		// 	console.log(completeRes)
+		// }
 	})
 	
 	// uni.readBLECharacteristicValue({
@@ -677,6 +679,14 @@ export default {
 	//获取已经匹配的蓝牙
 	getBluetoothDevices,
 	//初始化this变量
-	initData
+	initData,
+	
+	ab2hext,
+	str2ab,
+	hex2int,
+	hexToSignedInt,
+	hexCharCodeToStr,
+	strToHexCharCode,
+	hexToString
 
 }

+ 548 - 129
util/util-js/store.js

@@ -139,7 +139,7 @@ const store = new Vuex.Store({
 		//选择连接的蓝牙设备
 		BLEConnectDevice: null,
 		//获取到的服务
-		BLEGetServices:null,
+		BLEGetServices: null,
 		//当前发送给蓝牙的指令,目前是只有蓝牙手柄
 		currentInstruction: '',
 
@@ -158,6 +158,10 @@ const store = new Vuex.Store({
 		cIndex: -1,
 		//当前是否连接
 		bConnection: false,
+		/**
+		 * 通过验证的连接,比如通过mac验证,或者说是首页直连,都设置这个参数,确保已经连上
+		 */
+		bVerifiedConnection: false,
 		//最近连接过的设备
 		finallyUseDevice: null,
 
@@ -237,8 +241,24 @@ const store = new Vuex.Store({
 
 		//快速打击对象
 		filter: null,
-		deviceMs: 1
+		deviceMs: 1,
 
+
+		/**
+		 * 蓝牙参数对象
+		 */
+
+		// 设备Id
+		deviceId: "",
+		// 服务Id
+		serviceId: "",
+		notifyCharacteristicId: "",
+		writeCharacteristicId: "",
+		currentInstruction: "",
+		showToast: false,
+		bListenerUpdate: false,
+		bListenerJson: false,
+		bListenerMac: false,
 	},
 	mutations: {
 
@@ -1074,7 +1094,7 @@ const store = new Vuex.Store({
 			state.ConnectBindingDevice = null;
 			//蓝牙设备
 			state.BLEConnectDevice = null;
-			
+
 			//蓝牙服务
 			state.BLEGetServices = null;
 
@@ -1215,20 +1235,15 @@ const store = new Vuex.Store({
 
 
 		initAdapter(state, callback) {
-
-			// if (state.bOpenBluetooth) return;
-
 			//初始化蓝牙模块
-			BLE.openBluetoothAdapter({
+			let params = {
 				success: (res) => {
 					state.bOpenSuccess = true;
 					state.bOpenBluetooth = true;
 					if (callback)
 						callback(res);
-
 					//监听断开事件
-					BLE.onBLEConnectionStateChange();
-
+					this.commit("B_OnBLEConnectionStateChange");
 				},
 				fail: (fail) => {
 					state.bOpenSuccess = false;
@@ -1253,9 +1268,10 @@ const store = new Vuex.Store({
 					})
 
 				}
-			});
+			};
+			this.commit("B_OpenBluetoothAdapter", params);
 		},
-
+		// todo 未使用到
 		onGetDevices(state, context) {
 			let {
 				success
@@ -1279,9 +1295,10 @@ const store = new Vuex.Store({
 						}
 
 						setTimeout(() => {
-							BLE.closeBLEConnection(deviceId);
+							this.commit("B_CloseBLEConnection",{deviceId:deviceId})
 							state.cIndex = -1;
 							state.bConnection = false;
+							state.bVerifiedConnection = false;
 						}, 1000)
 
 					} else {
@@ -1306,6 +1323,28 @@ const store = new Vuex.Store({
 				state.getBLEDeviceServicesTimeout = null;
 			}
 		},
+		
+		initBLEData(state) {
+			// 设备Id
+			state.deviceId = "";
+			// 服务Id
+			state.serviceId = "";
+		
+			state.notifyCharacteristicId = "";
+		
+			state.writeCharacteristicId = "";
+		
+			state.currentInstruction = "";
+		
+			state.showToast = false;
+		
+			state.bListenerUpdate = false;
+		
+			state.bListenerJson = false;
+		
+			state.bListenerMac = false;
+		
+		},
 		//连接蓝牙
 		onCreateBLEConnection(state, context) {
 			let {
@@ -1316,77 +1355,49 @@ const store = new Vuex.Store({
 				getinitAdapter = null
 			} = context;
 
-			BLE.createBLEConnection(item, success => {
+			let params = {
+				item:item,
+				success:(success) => {
 					state.bConnection = true;
 					if (state.getBLEDeviceServicesTimeout) {
 						clearTimeout(state.getBLEDeviceServicesTimeout);
 						state.getBLEDeviceServicesTimeout = null;
 					}
-					
-					state.getBLEDeviceServicesTimeout = setTimeout(function() {
-						BLE.getBLEDeviceServices(item, () => {
-							uni.showToast({
-								title: '连接成功',
-								icon: 'loading',
-								duration: 2000,
-								mask: true
-							})
-							//是否需要设置item,默认不设置
-							if (initItem) {
-								state.cIndex = index;
-								state.BLEConnectDevice = item;
+
+					state.getBLEDeviceServicesTimeout = setTimeout(() => {
+						this.commit("B_GetBLEDeviceServices", {
+							item:item,
+							callback:() => {
+								uni.showToast({
+									title: '连接成功',
+									icon: 'loading',
+									duration: 2000,
+									mask: true
+								})
+								//是否需要设置item,默认不设置
+								if (initItem) {
+									state.cIndex = index;
+									state.BLEConnectDevice = item;
+								}
+
+								/**
+								 * 直接连接过成功
+								 */
+								state.bVerifiedConnection = true;
+								if (getSuccess)
+									getSuccess();
+							},
+							getServiceList:(serviceList) => {
+								//搜索服务失败后
+								state.BLEGetServices = serviceList;
 							}
-							if (getSuccess)
-								getSuccess();
-						},(serviceList)=>{
-							//搜索服务失败后
-							state.BLEGetServices = serviceList;
 						});
+
 					}, 2000);
-					// this.commit('onGetDevices', {
-					// 	success: () => {
-
-					// 		if (state.getBLEDeviceServicesTimeout) {
-					// 			clearTimeout(state.getBLEDeviceServicesTimeout);
-					// 			state.getBLEDeviceServicesTimeout = null;
-					// 		}
-
-					// 		state.getBLEDeviceServicesTimeout = setTimeout(function() {
-					// 			BLE.getBLEDeviceServices(item, () => {
-					// 				uni.showToast({
-					// 					title: '连接成功',
-					// 					icon: 'loading',
-					// 					duration: 2000,
-					// 					mask: true
-					// 				})
-					// 				//是否需要设置item,默认不设置
-					// 				if (initItem) {
-					// 					state.cIndex = index;
-					// 					state.BLEConnectDevice = item;
-					// 				}
-					// 				state.bConnection = true;
-					// 				if (getSuccess)
-					// 					getSuccess();
-					// 			});
-					// 		}, 500);
-
-					// 		// uni.$emit('connectionSuccess');
-
-					// 		if (state.BLERSSIInterval) {
-					// 			clearInterval(state.BLERSSIInterval);
-					// 			state.BLERSSIInterval = null;
-					// 		}
-					// 		state.BLERSSIInterval = setInterval(() => {
-					// 			this.commit('onGetDevices', {
-					// 				success: () => {}
-					// 			});
-					// 		}, 1000)
-					// 	}
-					// })
 
 				},
-				fail => {
-					console.log("***fail:",fail);
+				fail:(fail) => {
+					console.log("***fail:", fail);
 					if (fail.errCode === 10012) {
 						console.log("连接超时,请重试!");
 						uni.showToast({
@@ -1430,39 +1441,26 @@ const store = new Vuex.Store({
 							mask: true
 						})
 					}
-				});
+				}
+			};
+			this.commit("B_CreateBLEConnection", params);
 		},
-		//直接处理成功
+		//devices hardware 连接后验证,这里不需要处理 bVerifiedConnection,通过mac 验证后处理
 		onCreateBLESuccess(state, context) {
 			let {
 				item,
 				getSuccess = null
 			} = context;
-
-			BLE.createBLEConnection(item, success => {
+			this.commit("B_CreateBLEConnection", {
+				item:item,
+				success:success => {
 					state.BLEConnectDevice = item;
 					state.bConnection = true;
 					if (getSuccess) {
 						getSuccess();
 					}
-
-					// if (state.BLERSSIInterval) {
-					// 	clearInterval(state.BLERSSIInterval);
-					// 	state.BLERSSIInterval = null;
-					// }
-					// state.BLERSSIInterval = setInterval(() => {
-					// 	this.commit('onGetDevices', {
-					// 		success: () => {}
-					// 	});
-					// }, 1000)
-
-					// uni.showToast({
-					// 	icon: "none",
-					// 	title: "连接设备成功!",
-					// 	duration: 2000
-					// })
 				},
-				fail => {
+				fail:fail => {
 					if (fail.errCode === 10012) {
 						console.log("连接超时,请重试!");
 						uni.showToast({
@@ -1500,7 +1498,8 @@ const store = new Vuex.Store({
 						// 	mask: true
 						// })
 					}
-				});
+				}
+			});
 		},
 		//获取蓝牙服务
 		onGetBLEDeviceServices(state, context) {
@@ -1508,9 +1507,13 @@ const store = new Vuex.Store({
 				item,
 				success = null,
 			} = context;
-			BLE.getBLEDeviceServices(item, success,(serviceList)=>{
-				state.BLEGetServices = serviceList;
-			});
+			this.commit("B_GetBLEDeviceServices", {
+				item:item,
+				callback:success,
+				getServiceList:(serviceList) => {
+					state.BLEGetServices = serviceList;
+				}
+			})
 		},
 		onCloseBLEConnection(state, context) {
 
@@ -1523,27 +1526,30 @@ const store = new Vuex.Store({
 				clearInterval(state.BLERSSIInterval);
 				state.BLERSSIInterval = null;
 			}
+			this.commit("B_CloseBLEConnection", {
+				deviceId:state.BLEConnectDevice.deviceId,
+				success:() => {
+					state.cIndex = -1;
+					state.BLEConnectDevice = null;
+					//蓝牙服务
+					state.BLEGetServices = null;
 
-			BLE.closeBLEConnection(state.BLEConnectDevice.deviceId, () => {
-				state.cIndex = -1;
-				state.BLEConnectDevice = null;
-				//蓝牙服务
-				state.BLEGetServices = null;
+					if (getSuccess) {
+						getSuccess();
+					}
+					state.bConnection = false;
+
+					state.bVerifiedConnection = false;
 
-				if (getSuccess) {
-					getSuccess();
+					uni.closeBluetoothAdapter({
+						success(res) {
+							console.log(res)
+							state.bOpenBluetooth = false;
+						}
+					})
 				}
-				state.bConnection = false;
-				
-				uni.closeBluetoothAdapter({
-					success(res) {
-						console.log(res)
-						state.bOpenBluetooth = false;
-					}
-				})
 			});
 
-			
 		},
 		//不关闭 adapter
 		onOnlyCloseBLEConnection(state, context) {
@@ -1556,24 +1562,28 @@ const store = new Vuex.Store({
 				state.BLERSSIInterval = null;
 			}
 
-			BLE.closeBLEConnection(state.BLEConnectDevice.deviceId, () => {
-				state.cIndex = -1;
-				state.BLEConnectDevice = null;
-				//蓝牙服务
-				state.BLEGetServices = null;
-				
-				if (getSuccess) {
-					getSuccess();
+			this.commit("B_CloseBLEConnection", {
+				deviceId: state.BLEConnectDevice.deviceId,
+				success:() => {
+					state.cIndex = -1;
+					state.BLEConnectDevice = null;
+					//蓝牙服务
+					state.BLEGetServices = null;
+					if (getSuccess) {
+						getSuccess();
+					}
+					state.bConnection = false;
+
+					state.bVerifiedConnection = false;
 				}
-				state.bConnection = false;
 			});
 
 		},
 		onWriteBLEConnectionValue(state, context) {
 			let {
 				getSuccess = null,
-				getFail = null,
-				value
+					getFail = null,
+					value
 			} = context;
 
 			if (!state.BLEConnectDevice && state.cIndex == -1) {
@@ -1598,9 +1608,8 @@ const store = new Vuex.Store({
 			} else if (value == "6") {
 				state.instructionState.bSteps = false;
 			}
-			let retryCount = 3;
-			
-			BLE.writeBLECharacteristicValue(value,retryCount,getSuccess,getFail);
+			let retryCount = 4;
+			this.commit("B_WriteBLECharacteristicValue",{value, retryCount, getSuccess, getFail});
 		},
 		//获取距离
 		onGetRSSITransDistance(state, context) {
@@ -1784,6 +1793,416 @@ const store = new Vuex.Store({
 
 		},
 
+
+		/**
+		 * 蓝牙BLE迁移到store.js
+		 */
+		// 初始化蓝牙模块适配器
+		B_OpenBluetoothAdapter(state, context) {
+			let {
+				success,
+				fail,
+				complete
+			} = context;
+			//#ifdef H5
+			console.warn('h5不加载蓝牙模块');
+			return;
+			//#endif
+			uni.openBluetoothAdapter({
+				success: res => {
+					if (success)
+						success(res);
+				},
+				fail: res => {
+					if (fail)
+						fail(res);
+				},
+				complete: res => {
+					if (complete)
+						complete(res);
+				}
+			})
+		},
+
+		/**
+		 * 关闭蓝牙模块适配器
+		 */
+		B_CloseBluetoothAdapter() {
+			//#ifdef H5
+			console.warn('h5不加载蓝牙模块');
+			return;
+			//#endif
+			uni.closeBluetoothAdapter({
+				success: res => {
+					console.log('断开蓝牙模块成功');
+					uni.showToast({
+						icon: "none",
+						title: "蓝牙已经断开!",
+						mask: false,
+						duration: 3000
+					});
+				}
+			});
+		},
+
+		B_OnBLEConnectionStateChange(state) {
+			//#ifdef H5
+			console.warn('h5不加载蓝牙模块');
+			return;
+			//#endif
+			uni.onBLEConnectionStateChange(res => {
+				// 该方法回调中可以用于处理连接意外断开等异常情况
+				console.log(`蓝牙连接状态 -------------------------->`, JSON.stringify(res));
+				if (!res.connected) {
+					uni.$emit('callbackCloseBLE');
+				}
+			});
+		},
+		/**
+		 * 连接低功耗蓝牙设备。
+		 * 若APP在之前已有搜索过某个蓝牙设备,并成功建立连接,可直接传入之前搜索获取的 deviceId 直接尝试连接该设备,无需进行搜索操作。
+		 */
+		B_CreateBLEConnection(state, context) {
+			let {
+				item,
+				success,
+				fail
+			} = context;
+			this.commit('initBLEData');
+			state.deviceId = item.deviceId;
+			let timeout = 10000;
+			uni.createBLEConnection({
+				// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
+				deviceId: state.deviceId,
+				timeout,
+				success: res => {
+					if (success) {
+						success(res);
+					}
+				},
+				fail: res => {
+					if (fail)
+						fail(res);
+				}
+			});
+		},
+
+
+		/**
+		 * 获取设备的服务ID
+		 */
+		B_GetBLEDeviceServices(state, context) {
+
+			let {
+				item,
+				callback,
+				getServiceList
+			} = context;
+			let serviceList = [];
+			let _self = this;
+			uni.getBLEDeviceServices({
+				deviceId: item.deviceId,
+				success: res => {
+					console.log("getBLEDeviceServices==", JSON.stringify(res), item);
+					serviceList = res.services;
+					if (serviceList.length == 0) {
+						uni.hideToast();
+						uni.showModal({
+							title: '失败',
+							content: '获取服务失败,请尝试重新连接对应的模式。'
+						})
+					}
+					if (getServiceList) {
+						getServiceList(serviceList);
+					}
+					for (let i = 0; i < serviceList.length; i++) {
+						let service = serviceList[i];
+						if (service.uuid.toLocaleLowerCase() === item.PRIMARY_SERVICE.toLocaleLowerCase()) {
+							state.serviceId = service.uuid;
+							//开始获取指定服务的特征值
+							_self.commit('B_GetBLEDeviceCharacteristics', {
+								item:item,
+								callback:callback
+							});
+							break;
+						}
+					}
+				},
+				fail: failRes => {
+					console.log('device services:', failRes.services)
+					uni.showModal({
+						title: '连接失败',
+						content: '未获取到相应服务,请继续尝试连接设备。'
+					})
+				}
+			});
+		},
+		/**
+		 * 获取指定服务的特征值
+		 */
+		B_GetBLEDeviceCharacteristics(state, context) {
+			let {
+				item,
+				callback
+			} = context;
+			let deviceId = state.deviceId;
+			let serviceId = state.serviceId;
+			let characteristicsList = [];
+			uni.getBLEDeviceCharacteristics({
+				deviceId,
+				serviceId,
+				success: res => {
+					if (item.PRIMARY_NOTIFY != '') {
+						state.notifyCharacteristicId = item.PRIMARY_NOTIFY;
+						this.commit('B_NotifyBLECharacteristicValueChange', {
+							callback:callback
+						});
+					}
+					if (item.PRIMARY_WRITE != '') {
+						state.writeCharacteristicId = item.PRIMARY_WRITE;
+					}
+				},
+				fail: res => {
+					console.log('device getBLEDeviceCharacteristics failed:', JSON.stringify(res))
+				}
+			})
+		},
+
+		//启用低功耗蓝牙设备特征值变化时的 notify 功能,订阅特征值。
+		//注意:必须设备的特征值支持notify或者indicate才可以成功调用,具体参照 characteristic 的 properties 属性
+		B_NotifyBLECharacteristicValueChange(state, context) {
+			let {
+				callback
+			} = context;
+			// 启用notify功能
+			// console.log("启用notify功能");
+			uni.notifyBLECharacteristicValueChange({
+				state: true,
+				deviceId: state.deviceId,
+				serviceId: state.serviceId,
+				characteristicId: state.notifyCharacteristicId,
+				success: (res) => {
+					this.commit('B_OnBLECharacteristicValueChange', {
+						callback:callback
+					});
+					// _self.onBLECharacteristicValueChange(callback); //监听特征值变化
+				},
+				fail: (res) => {
+					uni.showToast({
+						title: 'notify启动失败',
+						icon: "none",
+						mask: true
+					});
+
+				}
+			})
+		},
+		//监听低功耗蓝牙设备的特征值变化。必须先启用notify接口才能接收到设备推送的notification。
+		B_OnBLECharacteristicValueChange(state, context) {
+			let {
+				callback
+			} = context;
+			console.log("onBLECharacteristicValueChange success");
+			if (callback) {
+				callback({
+					notifyCharacteristicId: state.notifyCharacteristicId,
+					writeCharacteristicId: state.writeCharacteristicId
+				})
+			}
+			uni.onBLECharacteristicValueChange(function(res) {
+				let box = {};
+				var resValue = BLE.ab2hext(res.value); //16进制字符串
+				if (state.currentInstruction == "V" && state.showToast) {
+					var resValueStr = BLE.hexToString(resValue);
+					let _info = {
+						type: 'version',
+						instruction: 'V',
+						value: resValueStr.replace(/\{|}/g, '').trim()
+					}
+					uni.$emit('listenerBLE', _info);
+					state.currentInstruction = "";
+					state.showToast = false;
+					return;
+				} else if (state.currentInstruction == 'M' && state.bListenerMac) {
+					var resValueStr = BLE.hexToString(resValue);
+					let _info = {
+						type: 'mac',
+						instruction: 'M',
+						value: resValueStr.replace(/\{|}/g, '').trim()
+					}
+					uni.$emit('listenerBLE', _info);
+					state.currentInstruction = "";
+					state.bListenerMac = false;
+					return;
+				}
+				//步数数据解析
+				if (state.bListenerJson) {
+					var resValueStr = BLE.hexToString(resValue);
+					console.log(resValueStr);
+					box["Json"] = resValueStr;
+					uni.$emit('updateBLEDeviceJson', box);
+				}
+				//原始数据解析
+				if (state.bListenerUpdate) {
+					//R/L 左手还是右手
+					let handle = resValue.substr(6, 2);
+					let axStr = resValue.substr(8, 4);
+					let ayStr = resValue.substr(12, 4);
+					let azStr = resValue.substr(16, 4);
+					//一个字节最大只能表示265  2个字节可以表示65536  然后你这边做一下转换 例如00 3E   3*16+14=62 ----->0.03  g 
+					//(真实值= AD值 /32768  * 16)
+					//0.003 = 62 / 2768  * 16
+					let ax = BLE.hexToSignedInt(axStr) / 32768 * 16;
+					let ay = BLE.hexToSignedInt(ayStr) / 32768 * 16;
+					let az = BLE.hexToSignedInt(azStr) / 32768 * 16;
+
+					let gxStr = resValue.substr(20, 4);
+					let gyStr = resValue.substr(24, 4);
+					let gzStr = resValue.substr(28, 4);
+					//角速度(AD值/32768 * 2000) 角速度单位是 °/s  范围是 正负2000
+					let gx = BLE.hexToSignedInt(gxStr) / 32768 * 2000;
+					let gy = BLE.hexToSignedInt(gyStr) / 32768 * 2000;
+					let gz = BLE.hexToSignedInt(gzStr) / 32768 * 2000;
+					//毫秒
+					let ms = BLE.hex2int(resValue.substr(2, 4));
+					//分
+					let min = BLE.hex2int(resValue.substr(32, 2));
+					//秒
+					let s = BLE.hex2int(resValue.substr(34, 2));
+					box["handle"] = BLE.hexToString(handle);
+					box["acc"] = {
+						ax,
+						ay,
+						az
+					};
+					box["gyro"] = {
+						gx,
+						gy,
+						gz
+					};
+
+					box["min"] = min;
+					box["s"] = s;
+					box["ms"] = ms;
+
+					//更新数据给webview,在game-play-web||game-play-sub绑定
+					//后面更新数据都用此接口
+					uni.$emit('updateBLEDeviceData', box);
+				}
+
+
+			});
+		},
+
+
+		//向低功耗蓝牙设备特征值中写入二进制数据。注意:必须设备的特征值支持 write 才可以成功调用。
+		B_WriteBLECharacteristicValue(state, context) {
+			let {
+				value,
+				retryCount,
+				success,
+				getFail
+			} = context;
+			if (!value && value === '') {
+				uni.showToast({
+					title: "指令为空"
+				})
+				return;
+			}
+			//记录一下指令
+			state.currentInstruction = value;
+			//V 获取版本,M 获取mac 地址
+			if (value == "V")
+				state.showToast = true;
+
+			if (value == "M") {
+				state.showToast = true;
+				state.bListenerMac = true;
+			}
+			if (value == "4") {
+				state.bListenerUpdate = false;
+			}
+			if (value == "3") {
+				if (state.bListenerUpdate) {
+					uni.showToast({
+						title: "原始数据已开启"
+					})
+					return;
+				}
+				state.bListenerUpdate = true;
+			}
+
+			if (value == "6") {
+				state.bListenerJson = false;
+			}
+			if (value == "5") {
+				if (state.bListenerJson) {
+					uni.showToast({
+						title: "步数数据已开启"
+					})
+					return;
+				}
+				state.bListenerJson = true;
+			}
+
+
+			console.log("currentInstruction:", state.currentInstruction, value, state.bListenerUpdate, state.bListenerMac);
+			console.log("state.deviceId:", state.deviceId, state.serviceId, state.writeCharacteristicId);
+			uni.writeBLECharacteristicValue({
+				deviceId: state.deviceId,
+				serviceId: state.serviceId,
+				// 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
+				characteristicId: state.writeCharacteristicId,
+				// 这里的value是ArrayBuffer类型
+				value: BLE.str2ab(value),
+				success: (res) => {
+					console.log('writeBLECharacteristicValue success', res.errMsg, value, retryCount);
+					if (success) {
+						success(res);
+					}
+				},
+				fail: (fail) => {
+					console.log(fail)
+					//重新写入
+					if (retryCount > 0) {
+						console.log("writeBLECharacteristicValue Rewrite ===================>" + value + " == " + retryCount);
+						retryCount--;
+						setTimeout(() => {
+							this.commit("B_WriteBLECharacteristicValue", {
+								value,
+								retryCount,
+								success,
+								getFail
+							});
+						}, 300);
+					}
+					if (getFail) {
+						getFail(fail);
+					}
+				}
+			})
+
+		},
+
+		/**
+		 * 断开蓝牙连接
+		 */
+		B_CloseBLEConnection(state, context) {
+			let {
+				deviceId,
+				success = null
+			} = context;
+			uni.closeBLEConnection({
+				deviceId,
+				success: res => {
+					if (success)
+						success();
+				},
+				fail: (fail) => {
+					console.log("关闭蓝牙失败", fail);
+				}
+			});
+		}
 	}
 })