|
|
@@ -279,7 +279,12 @@ const store = new Vuex.Store({
|
|
|
BluetoothAdapter: null,
|
|
|
|
|
|
//版本状态,用于区分部分特定的环境
|
|
|
- versionCodeState: null
|
|
|
+ versionCodeState: null,
|
|
|
+
|
|
|
+ //显示蓝牙是否断开连接Modal
|
|
|
+ bShowBLEConnectModal: false,
|
|
|
+ bGamePlaying:false,
|
|
|
+
|
|
|
},
|
|
|
mutations: {
|
|
|
|
|
|
@@ -1058,12 +1063,12 @@ const store = new Vuex.Store({
|
|
|
// cityCode: 12345
|
|
|
// }
|
|
|
// });
|
|
|
-
|
|
|
+
|
|
|
//进入此页面先设置平台参数
|
|
|
- if(state.platform == "ios"){
|
|
|
- uni.setStorageSync("platform",1);
|
|
|
- }else if(state.platform == "android"){
|
|
|
- uni.setStorageSync("platform",0);
|
|
|
+ if (state.platform == "ios") {
|
|
|
+ uni.setStorageSync("platform", 1);
|
|
|
+ } else if (state.platform == "android") {
|
|
|
+ uni.setStorageSync("platform", 0);
|
|
|
}
|
|
|
//获取版本信息
|
|
|
this.commit('getVersionCode');
|
|
|
@@ -1388,24 +1393,17 @@ const store = new Vuex.Store({
|
|
|
getSuccess = null,
|
|
|
getinitAdapter = null
|
|
|
} = context;
|
|
|
-
|
|
|
+
|
|
|
+ uni.showToast({
|
|
|
+ title: '连接设备中...',
|
|
|
+ icon: 'loading',
|
|
|
+ duration: 10000,
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
+
|
|
|
let params = {
|
|
|
item: item,
|
|
|
success: (success) => {
|
|
|
-
|
|
|
- // uni.getBluetoothDevices({
|
|
|
- // success(res) {
|
|
|
- // console.log("getBluetoothDevices:", res)
|
|
|
- // }
|
|
|
- // })
|
|
|
-
|
|
|
- // uni.getConnectedBluetoothDevices({
|
|
|
- // success(res) {
|
|
|
- // console.log("getConnectedBluetoothDevices:", res)
|
|
|
- // }
|
|
|
- // })
|
|
|
-
|
|
|
-
|
|
|
state.bConnection = true;
|
|
|
if (state.getBLEDeviceServicesTimeout) {
|
|
|
clearTimeout(state.getBLEDeviceServicesTimeout);
|
|
|
@@ -1430,7 +1428,6 @@ const store = new Vuex.Store({
|
|
|
state.BLEConnectDevice = item;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
if (getSuccess)
|
|
|
getSuccess();
|
|
|
|
|
|
@@ -1448,9 +1445,10 @@ const store = new Vuex.Store({
|
|
|
this.commit("B_CloseBLEConnection", {
|
|
|
deviceId: item.deviceId
|
|
|
})
|
|
|
- state.cIndex = -1;
|
|
|
- state.bConnection = false;
|
|
|
- state.bVerifiedConnection = false;
|
|
|
+ // state.cIndex = -1;
|
|
|
+ // state.bConnection = false;
|
|
|
+ // state.bVerifiedConnection = false;
|
|
|
+ this.commit("onResetBLEConnection");
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -1462,7 +1460,7 @@ const store = new Vuex.Store({
|
|
|
if (fail.errCode === 10012) {
|
|
|
console.log("连接超时,请重试!");
|
|
|
uni.showToast({
|
|
|
- title: '连接失败,设备无响应,请重试。',
|
|
|
+ title: '连接失败,开启设备后尝试重新连接!',
|
|
|
icon: 'none',
|
|
|
duration: 3000,
|
|
|
mask: true
|
|
|
@@ -1476,27 +1474,16 @@ const store = new Vuex.Store({
|
|
|
mask: true
|
|
|
})
|
|
|
} else if (fail.errCode === 10000) {
|
|
|
- // console.log("连接失败,初始化 uni.openBluetoothAdapter 调用之后使用");
|
|
|
- // uni.showToast({
|
|
|
- // title: '连接失败,检查手机蓝牙是否开启',
|
|
|
- // icon: 'none',
|
|
|
- // duration: 2000,
|
|
|
- // mask: true
|
|
|
- // })
|
|
|
-
|
|
|
this.commit('initAdapter', () => {
|
|
|
if (getinitAdapter) {
|
|
|
getinitAdapter();
|
|
|
}
|
|
|
})
|
|
|
- // this.initAdapter(() => {
|
|
|
- // this.onDevice(item, e);
|
|
|
- // });
|
|
|
} else {
|
|
|
// err.errCode10003原因多种:蓝牙设备未开启或异常导致无法连接;蓝牙设备被占用或者上次蓝牙连接未断开导致无法连接
|
|
|
- console.log("连接失败,请重试!");
|
|
|
+ console.log("连接失败,请重试!",state.BLEConnectDevice);
|
|
|
uni.showToast({
|
|
|
- title: '设备未开启或被占用异常导致无法连接。',
|
|
|
+ title: '请尝试开启设备和重启app。',
|
|
|
icon: 'none',
|
|
|
duration: 2000,
|
|
|
mask: true
|
|
|
@@ -1576,9 +1563,23 @@ const store = new Vuex.Store({
|
|
|
getServiceList: (serviceList) => {
|
|
|
state.BLEGetServices = serviceList;
|
|
|
},
|
|
|
- getFail: () => {}
|
|
|
+ getFail: () => {
|
|
|
+ this.commit("B_CloseBLEConnection", {
|
|
|
+ deviceId: item.deviceId
|
|
|
+ })
|
|
|
+ this.commit("onResetBLEConnection");
|
|
|
+ }
|
|
|
})
|
|
|
},
|
|
|
+ //重置蓝牙连接参数
|
|
|
+ onResetBLEConnection(state) {
|
|
|
+ state.cIndex = -1;
|
|
|
+ state.BLEConnectDevice = null;
|
|
|
+ //蓝牙服务
|
|
|
+ state.BLEGetServices = null;
|
|
|
+ state.bConnection = false;
|
|
|
+ state.bVerifiedConnection = false;
|
|
|
+ },
|
|
|
onCloseBLEConnection(state, context) {
|
|
|
|
|
|
console.log("onCloseBLEConnection", state.BLEConnectDevice);
|
|
|
@@ -1751,7 +1752,7 @@ const store = new Vuex.Store({
|
|
|
gz
|
|
|
} = data.gyro;
|
|
|
|
|
|
- state.filter.Update(new o0.Vector3(ax, ay, az), msGap, new o0.Vector3(gx, gy, gz) , callback); //我自己的更新acc的函数
|
|
|
+ state.filter.Update(new o0.Vector3(ax, ay, az), msGap, new o0.Vector3(gx, gy, gz), callback); //我自己的更新acc的函数
|
|
|
},
|
|
|
/**
|
|
|
* 限制开始游戏
|
|
|
@@ -1921,6 +1922,7 @@ const store = new Vuex.Store({
|
|
|
},
|
|
|
|
|
|
B_OnBLEConnectionStateChange(state) {
|
|
|
+ let _self = this;
|
|
|
//#ifdef H5
|
|
|
console.warn('h5不加载蓝牙模块');
|
|
|
return;
|
|
|
@@ -1929,6 +1931,38 @@ const store = new Vuex.Store({
|
|
|
// 该方法回调中可以用于处理连接意外断开等异常情况
|
|
|
console.log(`蓝牙连接状态 -------------------------->`, JSON.stringify(res));
|
|
|
if (!res.connected) {
|
|
|
+
|
|
|
+ //要在连接的状态下 ,并且获取过匹配列表有参数的情况下,才提示重连
|
|
|
+ if (!state.bShowBLEConnectModal && state.bVerifiedConnection && state.bPhoneMatched) {
|
|
|
+ state.bShowBLEConnectModal = true;
|
|
|
+ let _connectItem = Object.assign({},state.BLEConnectDevice);
|
|
|
+ let _cIndex = state.cIndex;
|
|
|
+ //断开连接后reset一下参数
|
|
|
+ _self.commit("onResetBLEConnection");
|
|
|
+
|
|
|
+ let _tip = state.bGamePlaying? "蓝牙已断开是否重新连接蓝牙?重连需要重启游戏!":"蓝牙已断开是否重新连接蓝牙";
|
|
|
+ uni.showModal({
|
|
|
+ title: _tip,
|
|
|
+ success: (sRes) => {
|
|
|
+ state.bShowBLEConnectModal = false;
|
|
|
+ if (sRes.confirm) {
|
|
|
+ console.log("重连的_cIndex:",_cIndex);
|
|
|
+ _self.commit("onCreateBLEConnection", {
|
|
|
+ item: _connectItem,
|
|
|
+ index: _cIndex,
|
|
|
+ initItem: true,
|
|
|
+ getSuccess: () => {
|
|
|
+ //此处不检查外部设备
|
|
|
+ uni.$emit('retryConnectBLESuccess');
|
|
|
+ },
|
|
|
+ getinitAdapter: () => {}
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
uni.$emit('callbackCloseBLE');
|
|
|
}
|
|
|
});
|
|
|
@@ -2024,6 +2058,9 @@ const store = new Vuex.Store({
|
|
|
title: '连接错误',
|
|
|
content: '请尝试重新连接设备。'
|
|
|
})
|
|
|
+ if (getFail) {
|
|
|
+ getFail();
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
},
|