Răsfoiți Sursa

1.修改一个 uni.reLaunch 替换 uni.switchTab
2.添加一个脸部识别功能

slambb 1 săptămână în urmă
părinte
comite
b598adc8e1

+ 4 - 1
pages/Loading-page/Loading/Loading.vue

@@ -77,7 +77,10 @@
 					})
 				} else if (navType == "personal") {
 					// uni.redirectTo({
-					uni.switchTab({
+					// uni.switchTab({
+					// 	url: "../../personal-page/personal/personal"
+					// })
+					uni.reLaunch({
 						url: "../../personal-page/personal/personal"
 					})
 				} else {

+ 459 - 341
pages/game-page/game-play-sub/subGame/subGame.nvue

@@ -98,7 +98,10 @@
 				 */
 				//跳绳数据判断对象
 				actionJumpObj: null,
-				BLEAccIndex: 0
+				BLEAccIndex: 0,
+
+				//定义事件映射表
+				handlers: new Map()
 			}
 		},
 		onLoad() {
@@ -150,10 +153,14 @@
 				if (_self.bMyAttitudeListen) {
 					_self.gStopSimulateBLEUpdate();
 				}
-
+				
+				//停止脸部检测
+				_self.handleFaceStopDetect();
+				
 				// console.log(_self.BLEConnectDevice);
 				//如果连接了蓝牙设备是手柄
-				if (_self.BLEConnectDevice && ( _self.BLEConnectDevice.deviceType == "BLEHandle" || _self.BLEConnectDevice.deviceType == "BLEIntelligent")) {
+				if (_self.BLEConnectDevice && (_self.BLEConnectDevice.deviceType == "BLEHandle" || _self
+						.BLEConnectDevice.deviceType == "BLEIntelligent")) {
 					//开启设备回调 3/4关闭
 					_self.onWriteBLEConnectionValue({
 						value: "4"
@@ -169,7 +176,7 @@
 						//拳击柱
 						_self.uploadUserData_hitCount();
 					}
-
+					
 				} //关闭跳绳模式指令
 				else if (_self.BLEConnectDevice && _self.BLEConnectDevice.deviceType == "BLERope") {
 					console.warn("还没设置关闭跳绳模式")
@@ -197,6 +204,9 @@
 
 			//设置store状态
 			_self.$store.state.bGamePlaying = true;
+
+			// 注册事件
+			_self.registerHandlers();
 		},
 		onUnload() {
 			this.$store.state.bGamePlaying = false;
@@ -213,11 +223,17 @@
 			uni.$emit("game-unload");
 		},
 		methods: {
-			...mapMutations(['addlocalCalorie', 'syncRequestEvent', 'onWriteBLEConnectionValue', 'B_WriteHexToBLECharacteristic',
+			...mapMutations(['addlocalCalorie', 'syncRequestEvent', 'onWriteBLEConnectionValue',
+				'B_WriteHexToBLECharacteristic',
 				'gCreateFilterObj', 'gUpdateFilter', 'B_OpenRopeSkipping', 'B_CloseRopeSkipping',
-				'gStopSimulateBLEUpdate', 'gStartSimulateBLEUpdate', 'gIntelligentUpdateSandbagAlgorithm', 'gUpdateSandbagAlgorithm',
-				'gCreateSandbagAlgorithm','gIntelligentCreateSandbagAlgorithm', 'onConvertDeviceData', 'addSandbagHitCount', 'uploadUserData_hitCount',
-				'jumpIdenModule_onJump6AxisDataUpdate'
+				'gStopSimulateBLEUpdate', 'gStartSimulateBLEUpdate', 'gIntelligentUpdateSandbagAlgorithm',
+				'gUpdateSandbagAlgorithm',
+				'gCreateSandbagAlgorithm', 'gIntelligentCreateSandbagAlgorithm', 'onConvertDeviceData',
+				'addSandbagHitCount', 'uploadUserData_hitCount',
+				'jumpIdenModule_onJump6AxisDataUpdate',
+				//面部识别START
+				'faceModule_startDetect', 'faceModule_stopDetect', 'faceModule_setPreview'
+				//面部识别END
 			]),
 			navBack() {
 
@@ -364,7 +380,8 @@
 						avatarBase64Url: toBase64Url,
 						userName: this.userName,
 						gender: this.gender,
-						caloriUnit: 10,
+						caloriUnit: 10,//废弃字段
+						calorieUnit: 10,
 						calorieParams: calorieParams,
 						//蓝牙连接的设备
 						device: device,
@@ -414,364 +431,465 @@
 				});
 
 			},
-			handlePostMessage: function(postData) {
-				console.log("handlePostMessage得到参数", postData.detail);
-				let temp = postData.detail.data[0];
-				let gameData = temp.gameData;
-				if (temp.funName == "uploadInfo") {
-
-					//TODO:写入排行榜分数,后面需要在游戏完结里面调用
-					//TODO: 后面游戏时间,卡路里的需要写入数据库,目前只是处理了分数
-					// let num = Math.round(Math.random() * 10000);
-					//1. gameScore 处理上传的分数
-					// let _temp = {
-					// 	gameId: '1595755153789139696',
-					// 	score: 1230,
-					// 	cityCode: '110101',
-					// };
-					//2. calorieBurned 处理卡路里
-					// 记录卡路里到本地
-					this.addlocalCalorie(gameData.calorieBurned);
-					console.log("gameData.calorieBurned", gameData.calorieBurned);
-					//然后更新上服务器
-					this.syncRequestEvent({
-						success: () => {
-							// uni.$emit('updateArcbarData', '');
-
-							let _temp = {
-								//假如排行id 为空,排行榜就是游戏自己的id
-								gameId: this.decodeItem.gameRankingId == null ? this.decodeItem
-									.gameId : this.decodeItem.gameRankingId,
-								score: gameData.gameScore,
-								cityCode: this.city.cityCode,
-								bMaxLimit: true
-							}
-							console.log('_temp =====', _temp);
-
-							reqUtil.requestData(config.URL.UPLOADRANKING, _temp, "POST").then(res => {
-									console.log('UPLOADRANKING =====', res);
-									if (res.code == 0) {
-										//TODO 后续游戏数据处理
-										this.sendMessage("onUploadInfo", {
-											code: 0,
-											msg: '上传成功'
-										});
-									} else {
-										//TODO 后续游戏数据处理
-										this.sendMessage("onUploadInfo", {
-											code: 400,
-											msg: '上传失败'
-										});
-									}
-
-								},
-								e => {
-									console.log(e)
-								});
-						},
-						fail: () => {
-							this.sendMessage("onUploadInfo", {
-								code: 400,
-								msg: '上传失败'
-							});
+			// 注册所有事件
+			registerHandlers() {
+				this.handlers.set("uploadInfo", (gameData) => this.handleUploadInfo(gameData)); //上传分数
+				this.handlers.set("gameInit", () => this.sendGameInit()); //获取游戏信息
+				this.handlers.set("aiRandomInfo", (gameData) => this.handleAiRandomInfo(gameData));
+				this.handlers.set("fruitInfo", (gameData) => this.handleFruitInfo(gameData));
+				this.handlers.set("urlToBase64", (gameData) => this.handleUrlToBase64(gameData));
+				this.handlers.set("openAccelerometer", () => this.handleOpenAccelerometer());
+				this.handlers.set("closeAccelerometer", () => this.handleCloseAccelerometer());
+				this.handlers.set("openOrientation", () => this.handleOpenOrientation());
+				this.handlers.set("closeOrientation", () => this.handleCloseOrientation());
+				
+				this.handlers.set("bindBoxingPost", () => this.handleBindBoxingPost());
+				this.handlers.set("unbindBoxingPost", () => this.handleUnbindBoxingPost());
+				this.handlers.set("setAngleRatio", (gameData) => this.handleSetAngleRatio(gameData));
+				this.handlers.set("bindHitBoxingPost", () => this.handleBindHitBoxingPost());
+				this.handlers.set("unbindHitBoxingPost", () => this.handleUnbindHitBoxingPost());
+				
+				this.handlers.set("closeGame", () => this.handleCloseGame());
+				this.handlers.set("addQuitModal", () => this.handleAddQuitModal());
+				this.handlers.set("removeQuitModal", () => this.handleRemoveQuitModal());
+				this.handlers.set("writeBLEConnectionValue", (gameData) => this.handleWriteBLEConnectionValue(gameData));
+				this.handlers.set("writeHexToBLEDevice", (gameData) => this.handleWriteHexToBLEDevice(gameData));
+				this.handlers.set("log", (gameData) => console.log(gameData));
+				this.handlers.set("addDeviceUpdateListener", () => this.handleAddDeviceUpdateListener());
+				this.handlers.set("closeDeviceUpdateListener", () => this.handleCloseDeviceUpdateListener());
+				this.handlers.set("addDeviceJsonUpdateListener", () => this.handleAddDeviceJsonUpdateListener());
+				this.handlers.set("closeDeviceJsonUpdateListener", () => this.handleCloseDeviceJsonUpdateListener());
+				//用手机的加速计和陀螺仪触发onBoxingPostHit?
+				this.handlers.set("onStartAccAndGyro", () => this.handleStartAccAndGyro());
+				this.handlers.set("onStopAccAndGyro", () => this.handleStopAccAndGyro());
+				//检测脸部函数
+				this.handlers.set("faceStartDetect", (gameData) => this.handleFaceStartDetect(gameData));
+				this.handlers.set("faceStopDetect", () => this.handleFaceStopDetect());
+				this.handlers.set("faceSetPreview", (gameData) => this.handleFaceSetPreview(gameData));
+			},
+			handleUploadInfo(gameData) {
+				//TODO:写入排行榜分数,后面需要在游戏完结里面调用
+				//TODO: 后面游戏时间,卡路里的需要写入数据库,目前只是处理了分数
+				// let num = Math.round(Math.random() * 10000);
+				//1. gameScore 处理上传的分数
+				// let _temp = {
+				// 	gameId: '1595755153789139696',
+				// 	score: 1230,
+				// 	cityCode: '110101',
+				// };
+				//2. calorieBurned 处理卡路里
+				// 记录卡路里到本地
+				this.addlocalCalorie(gameData.calorieBurned);
+				console.log("gameData.calorieBurned", gameData.calorieBurned);
+				//然后更新上服务器
+				this.syncRequestEvent({
+					success: () => {
+						// uni.$emit('updateArcbarData', '');
+
+						let _temp = {
+							//假如排行id 为空,排行榜就是游戏自己的id
+							gameId: this.decodeItem.gameRankingId == null ? this.decodeItem
+								.gameId : this.decodeItem.gameRankingId,
+							score: gameData.gameScore,
+							cityCode: this.city.cityCode,
+							bMaxLimit: true
 						}
-					});
-
-					//3. gameTime 游戏时间 
-					//TODO 后面处理游戏时长
-
-
-				} else if (temp.funName == "gameInit") {
-					// 获取游戏信息
-					this.sendGameInit();
-				} else if (temp.funName == "aiRandomInfo") {
-					// 获取aiRandomInfo
-					reqUtil.requestData(config.URL.AIRANDOMINFO, {}).then(res => {
-							console.log('AIRANDOMINFO =====', res);
-							if (res.code == 0) {
-								let data = res.data;
-								this.urlToBase64(data.aiAvatar, (toBase64Url) => {
-									let sendData = {
-										aiId: data.aiId,
-										aiName: data.aiName,
-										aiGender: data.aiGender,
-										aiType: data.aiType,
-										aiAvatarBase64Url: toBase64Url
-									}
-									this.sendMessage("onAiRandomInfo", sendData);
-								})
-							}
+						console.log('_temp =====', _temp);
+
+						reqUtil.requestData(config.URL.UPLOADRANKING, _temp, "POST").then(res => {
+								console.log('UPLOADRANKING =====', res);
+								if (res.code == 0) {
+									//TODO 后续游戏数据处理
+									this.sendMessage("onUploadInfo", {
+										code: 0,
+										msg: '上传成功'
+									});
+								} else {
+									//TODO 后续游戏数据处理
+									this.sendMessage("onUploadInfo", {
+										code: 400,
+										msg: '上传失败'
+									});
+								}
 
-						},
-						e => {
-							console.log(e)
+							},
+							e => {
+								console.log(e)
+							});
+					},
+					fail: () => {
+						this.sendMessage("onUploadInfo", {
+							code: 400,
+							msg: '上传失败'
 						});
-				} else if (temp.funName == "fruitInfo") {
-					let fruitIndexArray = [0, 0, 0];
-					if (gameData.hasOwnProperty("calorie")) {
-						fruitIndexArray = fruit.getFruitIndex(gameData.calorie);
 					}
+				});
 
-					this.urlToBase64("https://bbeng-bucket.oss-cn-beijing.aliyuncs.com/cocos/fruitMachine.png", (
-						toBase64Url) => {
-						this.sendMessage("onFruitInfo", {
-							// 水果雪碧图
-							fruitBase64Url: toBase64Url,
-							// 雪碧图 单张图片宽高
-							unitWidth: 100,
-							unitHeight: 100,
-							unit: "px",
-							imageStartPosY: 0,
-							imageEndPosY: -1200,
-							fruitIndexArray: fruitIndexArray
-						});
-					})
+				//3. gameTime 游戏时间 
+				//TODO 后面处理游戏时长	
+			},
+			handleAiRandomInfo(gameData) {
+				// 获取aiRandomInfo
+				reqUtil.requestData(config.URL.AIRANDOMINFO, {}).then(res => {
+						console.log('AIRANDOMINFO =====', res);
+						if (res.code == 0) {
+							let data = res.data;
+							this.urlToBase64(data.aiAvatar, (toBase64Url) => {
+								let sendData = {
+									aiId: data.aiId,
+									aiName: data.aiName,
+									aiGender: data.aiGender,
+									aiType: data.aiType,
+									aiAvatarBase64Url: toBase64Url
+								}
+								this.sendMessage("onAiRandomInfo", sendData);
+							})
+						}
 
+					},
+					e => {
+						console.log(e)
+					});
+			},
+			handleFruitInfo(gameData) {
+				let fruitIndexArray = [0, 0, 0];
+				if (gameData.hasOwnProperty("calorie")) {
+					fruitIndexArray = fruit.getFruitIndex(gameData.calorie);
+				}
 
+				this.urlToBase64("https://bbeng-bucket.oss-cn-beijing.aliyuncs.com/cocos/fruitMachine.png", (
+					toBase64Url) => {
+					this.sendMessage("onFruitInfo", {
+						// 水果雪碧图
+						fruitBase64Url: toBase64Url,
+						// 雪碧图 单张图片宽高
+						unitWidth: 100,
+						unitHeight: 100,
+						unit: "px",
+						imageStartPosY: 0,
+						imageEndPosY: -1200,
+						fruitIndexArray: fruitIndexArray
+					});
+				})
 
-				} else if (temp.funName == "urlToBase64") {
-					if (gameData.url) {
-						this.urlToBase64(gameData.url, (toBase64Url) => {
-							this.sendMessage("onUrlToBase64", {
-								base64: toBase64Url,
-							});
-						})
-					} else {
+			},
+			handleUrlToBase64(gameData) {
+				if (gameData.url) {
+					this.urlToBase64(gameData.url, (toBase64Url) => {
 						this.sendMessage("onUrlToBase64", {
-							base64: {},
+							base64: toBase64Url,
 						});
-					}
-
-				} else if (temp.funName == "openAccelerometer") {
-					if (this.globalAcc) {
-						uni.$off('watchAcceleration', this.gWatchAcceleration);
-						uni.$on('watchAcceleration', this.gWatchAcceleration);
-					} else {
-						uni.$emit("bindAcc", {
-							callback: (accId) => {
-								console.log("开启的:globalAcc=", accId);
-								this.bGameOpenListen = true;
-								this.$store.state.globalAcc = accId;
-								uni.$off('watchAcceleration', this.gWatchAcceleration);
-								uni.$on('watchAcceleration', this.gWatchAcceleration);
-							}
-						});
-					}
+					})
+				} else {
+					this.sendMessage("onUrlToBase64", {
+						base64: {},
+					});
+				}
+			},
+			handleOpenAccelerometer() {
+				if (this.globalAcc) {
+					uni.$off('watchAcceleration', this.gWatchAcceleration);
+					uni.$on('watchAcceleration', this.gWatchAcceleration);
+				} else {
+					uni.$emit("bindAcc", {
+						callback: (accId) => {
+							console.log("开启的:globalAcc=", accId);
+							this.bGameOpenListen = true;
+							this.$store.state.globalAcc = accId;
+							uni.$off('watchAcceleration', this.gWatchAcceleration);
+							uni.$on('watchAcceleration', this.gWatchAcceleration);
+						}
+					});
+				}
+			},
+			handleCloseAccelerometer() {
+				uni.$off('watchAcceleration', this.gWatchAcceleration);
+				uni.$emit("unBindAcc", this.globalAcc);
+				this.$store.state.globalAcc = null;
+			},
+			handleOpenOrientation() {
+				//打开陀螺仪
+				if (this.globalOri) {
+					uni.$off('watchOrientation', this.gWatchOrientation);
+					uni.$on('watchOrientation', this.gWatchOrientation);
+			s	} else {
+					uni.$emit("bindOri", {
+						callback: (oriId) => {
+							console.log("开启的:globalOri=", oriId);
+							this.bGameOpenListen = true;
+							this.$store.state.globalOri = oriId;
+							uni.$off('watchOrientation', this.gWatchOrientation);
+							uni.$on('watchOrientation', this.gWatchOrientation);
+						}
+					});
+				}
+			},
+			handleCloseOrientation() {
+				uni.$off('watchOrientation', this.gWatchOrientation);
+				uni.$emit("unBindOri", this.globalOri);
+				this.$store.state.globalOri = null;
+			},
+			handleBindBoxingPost() {
+				if (this.globalAcc) {
+					uni.$off('watchAcceleration', this.gWatchBoxingAcc);
+					uni.$on('watchAcceleration', this.gWatchBoxingAcc);
+				} else {
+					uni.$emit("bindAcc", {
+						callback: (accId) => {
+							console.log("bindBoxingPost开启的:globalAcc=", accId);
+							this.bGameOpenListen = true;
+							this.$store.state.globalAcc = accId;
+							uni.$off('watchAcceleration', this.gWatchBoxingAcc);
+							uni.$on('watchAcceleration', this.gWatchBoxingAcc);
+						}
+					});
+				}
+			},
+			handleUnbindBoxingPost() {
+				uni.$off('watchAcceleration', this.gWatchBoxingAcc);
+				uni.$emit("unBindAcc", this.globalAcc);
+				this.$store.state.globalAcc = null;
+			},
+			handleSetAngleRatio(gameData) {
+				if (gameData) {
+					this.angleRatio = Number(gameData.angleRatio);
+					console.log("this.angleRatio:", this.angleRatio);
+					this.sendMessage("onSetAngleRatio", {
+						angleRatio: this.angleRatio
+					});
+				}
+			},
+			handleBindHitBoxingPost() {
+				/**
+				 * 返回拳击柱的绑定状态
+				 */
+				console.log("bindHitBoxingPost");
+				if (this.ConnectBindingDevice) {
+					uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
+					uni.$on('updateBLEDeviceData', this.gWatchBLEUpdate);
+					//hotman 沙袋情景
+					this.gCreateSandbagAlgorithm();
+					this.gStartSimulateBLEUpdate();
+					return;
+				}
 
+				if (!this.BLEConnectDevice) return;
+				//用设备来区分,开启什么加速计;
+				if (this.BLEConnectDevice.deviceType == "BLEHandle" || this.BLEConnectDevice.deviceType ==
+					"BLEIntelligent") {
+					//处理蓝牙设备情况下
+					//开启设备回调 3/4关闭
+					this.onWriteBLEConnectionValue({
+						value: "3"
+					});
+					// setTimeout(() => {
+					// 	//设置加速计b:20ms a:10ms
+					// 	this.onWriteBLEConnectionValue({
+					// 		value: config.refreshRate
+					// 	});
 
-				} else if (temp.funName == "closeAccelerometer") {
-					uni.$off('watchAcceleration', this.gWatchAcceleration);
-					uni.$emit("unBindAcc", this.globalAcc);
-					this.$store.state.globalAcc = null;
+					// }, 2000)
+					uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
+					uni.$on('updateBLEDeviceData', this.gWatchBLEUpdate);
 
-				} else if (temp.funName == "openOrientation") {
-					//打开陀螺仪
-					if (this.globalOri) {
-						uni.$off('watchOrientation', this.gWatchOrientation);
-						uni.$on('watchOrientation', this.gWatchOrientation);
-					} else {
-						uni.$emit("bindOri", {
-							callback: (oriId) => {
-								console.log("开启的:globalOri=", oriId);
-								this.bGameOpenListen = true;
-								this.$store.state.globalOri = oriId;
-								uni.$off('watchOrientation', this.gWatchOrientation);
-								uni.$on('watchOrientation', this.gWatchOrientation);
-							}
-						});
+					if (this.BLEConnectDevice.usageMode == "phone" || this.BLEConnectDevice.usageMode ==
+						"general") {
+						//手机情景或者自由模式
+						this._createEquipmentBasedOnBoxingPostHit();
+					} else if (this.BLEConnectDevice.usageMode == "hotman") {
+						//hotman 沙袋情景  
+						// this.gCreateSandbagAlgorithm();
+						if (this.BLEConnectDevice.deviceType == "BLEIntelligent") {
+							this.gIntelligentCreateSandbagAlgorithm();
+						} else {
+							this.gCreateSandbagAlgorithm();
+						}
 					}
-				} else if (temp.funName == "closeOrientation") {
-					uni.$off('watchOrientation', this.gWatchOrientation);
-					uni.$emit("unBindOri", this.globalOri);
-					this.$store.state.globalOri = null;
-
-				} else if (temp.funName == "bindBoxingPost") {
+				} else if (this.BLEConnectDevice.deviceType == "mySelf") {
+					//处理手机本身情况下
 					if (this.globalAcc) {
-						uni.$off('watchAcceleration', this.gWatchBoxingAcc);
-						uni.$on('watchAcceleration', this.gWatchBoxingAcc);
+						uni.$off('watchAcceleration', this.gWatchHitBoxingAcc);
+						uni.$on('watchAcceleration', this.gWatchHitBoxingAcc);
 					} else {
+						//开启手机加速计
 						uni.$emit("bindAcc", {
 							callback: (accId) => {
-								console.log("bindBoxingPost开启的:globalAcc=", accId);
+								console.log("bindHitBoxingPost开启的:globalAcc=", accId);
 								this.bGameOpenListen = true;
 								this.$store.state.globalAcc = accId;
-								uni.$off('watchAcceleration', this.gWatchBoxingAcc);
-								uni.$on('watchAcceleration', this.gWatchBoxingAcc);
+								uni.$off('watchAcceleration', this.gWatchHitBoxingAcc);
+								uni.$on('watchAcceleration', this.gWatchHitBoxingAcc);
+								if (this.BLEConnectDevice.usageMode == "phone" || this.BLEConnectDevice
+									.usageMode == "general") {
+									//手机情景或者自由模式
+									this._createEquipmentBasedOnBoxingPostHit();
+								} else if (this.BLEConnectDevice.usageMode == "hotman") {
+									//hotman 沙袋情景 todo
+									console.warn("没有处理手机加速计的 gCreateFilterObj");
+									// this.gCreateFilterObj();
+								}
 							}
 						});
 					}
-				} else if (temp.funName == "unbindBoxingPost") {
-					uni.$off('watchAcceleration', this.gWatchBoxingAcc);
+				} else if (this.BLEConnectDevice.deviceType == "BLERope") {
+					//todo 开启跳绳模式
+					this.B_OpenRopeSkipping();
+					// this._createActionJumpOnBoxingPostHit();
+					//监听蓝牙回调
+					uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
+					uni.$on('updateBLEDeviceData', this.gWatchBLEUpdate);
+				}
+
+			},
+			handleUnbindHitBoxingPost() {
+				/**
+				 * 解绑拳击柱的绑定状态
+				 */
+				if (this.ConnectBindingDevice) {
+					uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
+					this.gStopSimulateBLEUpdate();
+					return;
+				}
+
+				if (this.BLEConnectDevice && (this.BLEConnectDevice.deviceType == "BLEHandle" || this
+						.BLEConnectDevice.deviceType == "BLEIntelligent")) {
+					//开启设备回调 3/4关闭
+					this.onWriteBLEConnectionValue({
+						value: "4"
+					});
+					uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
+				} else if (this.BLEConnectDevice && this.BLEConnectDevice.deviceType == "BLERope") {
+					console.warn("unbindHitBoxingPost 还没设置关闭跳绳模式")
+					this.onClearData();
+					this.B_CloseRopeSkipping();
+					uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
+				} else {
+					uni.$off('watchAcceleration', this.gWatchHitBoxingAcc);
 					uni.$emit("unBindAcc", this.globalAcc);
 					this.$store.state.globalAcc = null;
+				}
+			},
+			handleCloseGame() {
+				uni.getCurrentSubNVue().hide('auto');
+			},
+			handleAddQuitModal() {
+				this.gameQuitListener = true;
+				this.sendMessage("onQuitModalListener", {
+					bListener: this.gameQuitListener
+				});
+			},
+			handleRemoveQuitModal() {
+				this.gameQuitListener = false;
+				this.sendMessage("onQuitModalListener", {
+					bListener: this.gameQuitListener
+				});
+			},
+			handleWriteBLEConnectionValue(gameData) {
+				if (!gameData.value || gameData.value == "") return;
 
-				} else if (temp.funName == "setAngleRatio") {
-					if (gameData) {
-						this.angleRatio = Number(gameData.angleRatio);
-						console.log("this.angleRatio:", this.angleRatio);
-						this.sendMessage("onSetAngleRatio", {
-							angleRatio: this.angleRatio
-						});
-					}
-				} else if (temp.funName == "bindHitBoxingPost") {
-					/**
-					 * 返回拳击柱的绑定状态
-					 */
-					console.log("bindHitBoxingPost");
-					if (this.ConnectBindingDevice) {
-						uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
-						uni.$on('updateBLEDeviceData', this.gWatchBLEUpdate);
-						//hotman 沙袋情景
-						this.gCreateSandbagAlgorithm();
-						this.gStartSimulateBLEUpdate();
-						return;
-					}
+				if (!this.BLEConnectDevice) return;
+				//蓝牙写入数据
+				this.onWriteBLEConnectionValue(gameData);
+			},
+			handleWriteHexToBLEDevice(gameData) {
+				if (!gameData.value || gameData.value == "") return;
 
-					if (!this.BLEConnectDevice) return;
-					//用设备来区分,开启什么加速计;
-					if (this.BLEConnectDevice.deviceType == "BLEHandle" || this.BLEConnectDevice.deviceType ==
-						"BLEIntelligent") {
-						//处理蓝牙设备情况下
-						//开启设备回调 3/4关闭
-						this.onWriteBLEConnectionValue({
-							value: "3"
-						});
-						// setTimeout(() => {
-						// 	//设置加速计b:20ms a:10ms
-						// 	this.onWriteBLEConnectionValue({
-						// 		value: config.refreshRate
-						// 	});
-
-						// }, 2000)
-						uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
-						uni.$on('updateBLEDeviceData', this.gWatchBLEUpdate);
-
-						if (this.BLEConnectDevice.usageMode == "phone" || this.BLEConnectDevice.usageMode ==
-							"general") {
-							//手机情景或者自由模式
-							this._createEquipmentBasedOnBoxingPostHit();
-						} else if (this.BLEConnectDevice.usageMode == "hotman") {
-							//hotman 沙袋情景  
-							// this.gCreateSandbagAlgorithm();
-							if (this.BLEConnectDevice.deviceType == "BLEIntelligent") {
-								this.gIntelligentCreateSandbagAlgorithm();
-							} else {
-								this.gCreateSandbagAlgorithm();
-							}
-						}
-					} else if (this.BLEConnectDevice.deviceType == "mySelf") {
-						//处理手机本身情况下
-						if (this.globalAcc) {
-							uni.$off('watchAcceleration', this.gWatchHitBoxingAcc);
-							uni.$on('watchAcceleration', this.gWatchHitBoxingAcc);
-						} else {
-							//开启手机加速计
-							uni.$emit("bindAcc", {
-								callback: (accId) => {
-									console.log("bindHitBoxingPost开启的:globalAcc=", accId);
-									this.bGameOpenListen = true;
-									this.$store.state.globalAcc = accId;
-									uni.$off('watchAcceleration', this.gWatchHitBoxingAcc);
-									uni.$on('watchAcceleration', this.gWatchHitBoxingAcc);
-									if (this.BLEConnectDevice.usageMode == "phone" || this.BLEConnectDevice
-										.usageMode == "general") {
-										//手机情景或者自由模式
-										this._createEquipmentBasedOnBoxingPostHit();
-									} else if (this.BLEConnectDevice.usageMode == "hotman") {
-										//hotman 沙袋情景 todo
-										console.warn("没有处理手机加速计的 gCreateFilterObj");
-										// this.gCreateFilterObj();
-									}
-								}
-							});
-						}
-					} else if (this.BLEConnectDevice.deviceType == "BLERope") {
-						//todo 开启跳绳模式
-						this.B_OpenRopeSkipping();
-						// this._createActionJumpOnBoxingPostHit();
-						//监听蓝牙回调
-						uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
-						uni.$on('updateBLEDeviceData', this.gWatchBLEUpdate);
+				if (!this.BLEConnectDevice) return;
+				//蓝牙写入数据
+				this.B_WriteHexToBLECharacteristic(gameData);
+			},
+			handleAddDeviceUpdateListener() {
+				uni.$off('updateBLEDeviceData', this.BLECallback);
+				uni.$on('updateBLEDeviceData', this.BLECallback);
+			},
+			handleCloseDeviceUpdateListener() {
+				uni.$off('updateBLEDeviceData', this.BLECallback);
+			},
+			handleAddDeviceJsonUpdateListener() {
+				uni.$off('updateBLEDeviceJson', this.BLEJsonCallback);
+				uni.$on('updateBLEDeviceJson', this.BLEJsonCallback);
+			},
+			handleCloseDeviceJsonUpdateListener() {
+				uni.$off('updateBLEDeviceJson', this.BLEJsonCallback);
+			},
+			//获取手机原始陀螺仪和加速计数据
+			handleStartAccAndGyro() {
+				this.bMyAttitudeListen = true;
+				this.gStartSimulateBLEUpdate();
+				//监听蓝牙回调
+				uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
+				uni.$on('updateBLEDeviceData', this.gWatchBLEUpdate);
+			},
+			handleStopAccAndGyro() {
+				this.bMyAttitudeListen = false;
+				this.gStopSimulateBLEUpdate();
+				//监听蓝牙回调
+				uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
+			},
+			handleFaceStartDetect(gameData) {
+				this.faceModule_startDetect({
+					options: gameData,
+					callback: (data) => {
+						//回调识别数据
+						this.sendMessage("onFaceDetectUpdate", data);
 					}
+				});
+			},
+			handleFaceStopDetect() {
+				this.faceModule_stopDetect();
+			},
+			handleFaceSetPreview(gameData) {
+				// 提取配置,提供默认值
+				const {
+					preview = true,
+					overlay = true,
+					closeButton = true
+				} = gameData;
+				this.faceModule_setPreview({
+					preview,
+					overlay,
+					closeButton
+				})
+			},
 
+			handlePostMessage: function(postData) {
+				console.log("handlePostMessage得到参数", postData.detail);
+				let temp = postData.detail.data[0];
+				let gameData = temp.gameData;
 
-				} else if (temp.funName == "unbindHitBoxingPost") {
-					/**
-					 * 解绑拳击柱的绑定状态
-					 */
-					if (this.ConnectBindingDevice) {
-						uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
-						this.gStopSimulateBLEUpdate();
-						return;
-					}
-
-					if (this.BLEConnectDevice && (this.BLEConnectDevice.deviceType == "BLEHandle" || this
-							.BLEConnectDevice.deviceType == "BLEIntelligent")) {
-						//开启设备回调 3/4关闭
-						this.onWriteBLEConnectionValue({
-							value: "4"
-						});
-						uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
-					} else if (this.BLEConnectDevice && this.BLEConnectDevice.deviceType == "BLERope") {
-						console.warn("unbindHitBoxingPost 还没设置关闭跳绳模式")
-						this.onClearData();
-						this.B_CloseRopeSkipping();
-						uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
-					} else {
-						uni.$off('watchAcceleration', this.gWatchHitBoxingAcc);
-						uni.$emit("unBindAcc", this.globalAcc);
-						this.$store.state.globalAcc = null;
-					}
-				} else if (temp.funName == "closeGame") {
-					uni.getCurrentSubNVue().hide('auto');
-				} else if (temp.funName == "addQuitModal") {
-					this.gameQuitListener = true;
-					this.sendMessage("onQuitModalListener", {
-						bListener: this.gameQuitListener
-					});
-				} else if (temp.funName == "removeQuitModal") {
-					this.gameQuitListener = false;
-					this.sendMessage("onQuitModalListener", {
-						bListener: this.gameQuitListener
-					});
-				} else if (temp.funName == "writeBLEConnectionValue") {
-					if (!gameData.value || gameData.value == "") return;
-
-					if (!this.BLEConnectDevice) return;
-					//蓝牙写入数据
-					this.onWriteBLEConnectionValue(gameData);
-				} else if(temp.funName == "writeHexToBLEDevice"){
-					if (!gameData.value || gameData.value == "") return;
-					
-					if (!this.BLEConnectDevice) return;
-					//蓝牙写入数据
-					this.B_WriteHexToBLECharacteristic(gameData);
-				} else if (temp.funName == "log") {
-					console.log(gameData);
-				} else if (temp.funName == "addDeviceUpdateListener") {
-					uni.$off('updateBLEDeviceData', this.BLECallback);
-					uni.$on('updateBLEDeviceData', this.BLECallback);
-				} else if (temp.funName == "closeDeviceUpdateListener") {
-					uni.$off('updateBLEDeviceData', this.BLECallback);
-				} else if (temp.funName == "addDeviceJsonUpdateListener") {
-					uni.$off('updateBLEDeviceJson', this.BLEJsonCallback);
-					uni.$on('updateBLEDeviceJson', this.BLEJsonCallback);
-				} else if (temp.funName == "closeDeviceJsonUpdateListener") {
-					uni.$off('updateBLEDeviceJson', this.BLEJsonCallback);
-				}
-				//获取手机原始陀螺仪和加速计数据
-				else if (temp.funName == "onStartAccAndGyro") {
-					this.bMyAttitudeListen = true;
-					this.gStartSimulateBLEUpdate();
-					//监听蓝牙回调
-					uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
-					uni.$on('updateBLEDeviceData', this.gWatchBLEUpdate);
-				} else if (temp.funName == "onStopAccAndGyro") {
-					this.bMyAttitudeListen = false;
-					this.gStopSimulateBLEUpdate();
-					//监听蓝牙回调
-					uni.$off('updateBLEDeviceData', this.gWatchBLEUpdate);
+				let handler = this.handlers.get(temp.funName);
+				if (handler) {
+					handler(gameData);
+				} else {
+					console.warn("未知的 funName:", temp.funName);
 				}
+
+				// if (temp.funName == "uploadInfo") {} 
+				// else if (temp.funName == "gameInit") {} 
+				// else if (temp.funName == "aiRandomInfo") {} 
+				// else if (temp.funName == "fruitInfo") {} 
+				// else if (temp.funName == "urlToBase64") {} 
+				// else if (temp.funName == "openAccelerometer") {} 
+				// else if (temp.funName == "closeAccelerometer") {} 
+				// else if (temp.funName == "openOrientation") {} 
+				// else if (temp.funName == "closeOrientation") {} 
+				// else if (temp.funName == "bindBoxingPost") {} 
+				// else if (temp.funName == "unbindBoxingPost") {} 
+				// else if (temp.funName == "setAngleRatio") {} 
+				// else if (temp.funName == "bindHitBoxingPost") {} 
+				// else if (temp.funName == "unbindHitBoxingPost") {} 
+				// else if (temp.funName == "closeGame") {} 
+				// else if (temp.funName == "addQuitModal") {} 
+				// else if (temp.funName == "removeQuitModal") {} 
+				// else if (temp.funName == "writeBLEConnectionValue") {} 
+				// else if (temp.funName == "writeHexToBLEDevice") {} 
+				// else if (temp.funName == "log") {} 
+				// else if (temp.funName == "addDeviceUpdateListener") {} 
+				// else if (temp.funName == "closeDeviceUpdateListener") {} 
+				// else if (temp.funName == "addDeviceJsonUpdateListener") {} 
+				// else if (temp.funName == "closeDeviceJsonUpdateListener") {}
+				// else if (temp.funName == "onStartAccAndGyro") {} 
+				// else if (temp.funName == "onStopAccAndGyro") {}
 			},
 			onPageStart: function(e) {
 				// 监听页面加载成功
@@ -898,8 +1016,8 @@
 						bLimitRebound: false
 					})
 				} else if (this.BLEConnectDevice.usageMode == "hotman") {
-					
-					if(this.BLEConnectDevice.deviceType == "BLEIntelligent"){
+
+					if (this.BLEConnectDevice.deviceType == "BLEIntelligent") {
 						//智能hotman 沙袋情景
 						this.gIntelligentUpdateSandbagAlgorithm({
 							data: data,
@@ -927,7 +1045,7 @@
 								}
 							}
 						});
-					}else{
+					} else {
 						//hotman 沙袋情景 todo
 						this.gUpdateSandbagAlgorithm({
 							data: data,
@@ -956,7 +1074,7 @@
 							}
 						});
 					}
-					
+
 				} else if (this.BLEConnectDevice.usageMode == "ropeSkipping") {
 					//跳绳蓝牙反馈
 					this.onBLERopeUpdate(data);
@@ -1287,4 +1405,4 @@
 		justify-content: center;
 		align-items: center;
 	}
-</style>
+</style>

+ 4 - 1
pages/my-page/firstPlan/firstPlan.vue

@@ -299,7 +299,10 @@
 								// console.log("updateArcbarData==setTimeout");
 								that.addlocalCalorie(0);
 								
-								uni.switchTab({
+								// uni.switchTab({
+								// 	url: "../../personal-page/personal/personal"
+								// })
+								uni.reLaunch({
 									url: "../../personal-page/personal/personal"
 								})
 							}, 500);

+ 15 - 7
pages/personal-page/personal/personal.vue

@@ -1034,7 +1034,9 @@
 			plus.globalEvent.addEventListener("onTestModuleUpdate", this.onTestModuleUpdateCallback);
 			//初始化一个android数据
 			this.jumpIdenModule_onJumpInit();
-
+			
+			//初始化脸部识别
+			this.faceModule_initDetect();
 			//
 			this.onGetReadBLELight();
 			
@@ -1201,7 +1203,11 @@
 				'jumpIdenModule_onTestUpdate',
 				'jumpIdenModule_onTestJump6AxisDataUpdate',
 				//算法相关END
-
+				
+				//面部识别START
+				'faceModule_initDetect',
+				'faceModule_startDetect',
+				//面部识别END
 				//灯光
 				'onHitOpenBLELight',
 				'onHitOpenBLELightNew',
@@ -3065,11 +3071,13 @@
 													}
 
 												} else if (res.code === 802 || res.code === 805) {
-													uni.showToast({
-														title: res.msg,
-														icon: 'none',
-														duration: 2000
-													})
+													if (res && res.msg) {
+														uni.showToast({
+															title: res.msg,
+															icon: 'none',
+															duration: 2000
+														});
+													}
 												}
 											},
 											e => {

+ 76 - 6
util/util-js/store.js

@@ -15,7 +15,7 @@ import deviceData from "@/util/util-js/devices.js"
 
 // 加载算法插件 JumpIdentificationModule
 var jumpIdenModule = uni.requireNativePlugin("JumpIdentificationModule")
-
+var faceModule = uni.requireNativePlugin("FaceModule")
 
 Vue.use(Vuex)
 
@@ -255,7 +255,7 @@ const store = new Vuex.Store({
 		platform: '', // 平台
 		appName: '',
 		version: '1.6.3', //软件版本
-		versionCode: '21120701', //app.vue 自动获取.目前是h5 设置给了一个默认值
+		versionCode: '23050901', //app.vue 自动获取.目前是h5 设置给了一个默认值
 		showEndTime: config.endTime, //游戏显示时间字段,后台返回对应此时间之前的数据
 
 		//现在游戏显示在对应的平台
@@ -2974,16 +2974,16 @@ const store = new Vuex.Store({
 					//忽略偶数帧
 					if (state.bIgnore) {
 						state.LastMS++;
-						if (state.LastMS % 2 != 0){
+						if (state.LastMS % 2 != 0) {
 							uni.$emit('updateBLEDeviceData', box);
 						}
-						if (state.LastMS >= 1000){
+						if (state.LastMS >= 1000) {
 							state.LastMS = 0;
 						}
 					} else {
 						uni.$emit('updateBLEDeviceData', box);
 					}
-					
+
 				}
 
 				//todo 解析跳绳模式
@@ -3574,6 +3574,8 @@ const store = new Vuex.Store({
 							index: 3,
 							visible: state.versionCodeState.showVideo
 						})
+
+						console.log('获取版本控制信息 =====' + state.versionCodeState.showGame);
 					}
 				},
 				e => {
@@ -4190,7 +4192,75 @@ const store = new Vuex.Store({
 		onSaveHotmanIntelligentData(state) {
 			uni.setStorageSync('hotmanIntelligentData', state.hotmanIntelligentData);
 		},
+
+		//faceModule 头像识别
+		/**
+		 * 初始化识别头像
+		 */
+		faceModule_initDetect(state) {
+			if (uni.getSystemInfoSync().platform == "ios") {
+				return;
+			}
+			let res = faceModule.initDetect();
+			uni.showToast({
+				title: '' + res.code,
+				icon: 'none',
+				duration: 1000,
+				mask: true
+			})
+		},
+		/**
+		 * 开启头像识别
+		 */
+		faceModule_startDetect(state,context) {
+			if (uni.getSystemInfoSync().platform == "ios") {
+				console.log('iOS 平台暂不支持 faceModule');
+				return;
+			}
+			let {
+				options = {},
+				callback = null
+			} = context;
+			// 合并默认参数
+			const params = Object.assign({
+				showFaceView: false,
+			}, options);
+			faceModule.startDetect(params, (data) => {
+				if (callback) {
+					callback(data);
+				}
+			});
+		},
+		/**
+		 * 停止头像识别
+		 */
+		faceModule_stopDetect(state) {
+			if (uni.getSystemInfoSync().platform == "ios") {
+				return;
+			}
+			faceModule.stopDetect();
+		},
+
+		/**
+		 * 显示和隐藏对应摄像头预览
+		 * @param {Object} options - 可选参数
+		 * 例如:{ preview:true, overlay:true, closeButton:true }
+		 */
+		faceModule_setPreview(state, options = {}) {
+			if (uni.getSystemInfoSync().platform === 'ios') {
+				console.log('iOS 平台暂不支持 faceModule');
+				return;
+			}
+			// 合并默认参数
+			const params = Object.assign({
+				preview: true,
+				overlay: true,
+				closeButton: true
+			}, options);
+			faceModule.setPreview(params);
+		}
+		//faceModule
 	}
 })
 
-export default store
+export default store