Эх сурвалжийг харах

整理修改首页代码,添加测试方向跳。

slambb 4 жил өмнө
parent
commit
3894d8ed91

+ 304 - 0
components/modal/action-jump/action-jump.vue

@@ -0,0 +1,304 @@
+<template>
+	<view>
+		<view style="display: flex;justify-content: space-between;">
+			<button  @click="startJumpGame">startGame</button>
+			<button  @click="onClear">onClear</button>
+		</view>
+
+		<view style="display: flex;justify-content: space-between;" class="margin-top margin-bottom">
+			<button @click="onJumpType(0)">jump</button>
+			<button @click="onJumpType(1)">left</button>
+			<button @click="onJumpType(2)">right</button>
+			<button @click="onJumpType(3)">rLeft</button>
+			<button @click="onJumpType(4)">rRight</button>
+		</view>
+		
+		<view style="display: flex;justify-content: space-around;">
+			<view style="font-size: 14px;">t:{{countdown}}</view>
+			<view style="font-size: 14px;">e:{{eliminationCount}}</view>
+			<view style="font-size: 14px;">f:{{faultCount}}</view>
+		</view>
+		
+		<view class="action-jump-parent margin-top margin-bottom">
+			<view class="action-jump-container">
+				<canvas canvas-id="actionJumpCanvas" style="width: 375px;height: 50px; background-color: #1CBBB4;"></canvas>
+			</view>
+		</view>
+	</view>
+
+</template>
+
+<script>
+	export default {
+		data() {
+			return {
+				directionJump: null,
+				midJump: null,
+				rotateJump: null,
+				jumpTypeArray: [{
+					jumpName: 'NORMAL',
+					jumpCode: 0,
+					icon: 'midJump',
+					scaleX: 1,
+					bTrigger: false,
+				}, {
+					jumpName: 'LEFT',
+					jumpCode: 1,
+					icon: 'directionJump',
+					scaleX: -1,
+					bTrigger: false,
+				}, {
+					jumpName: 'RIGHT',
+					jumpCode: 2,
+					icon: 'directionJump',
+					scaleX: 1,
+					bTrigger: false,
+				}, {
+					jumpName: 'LEFT_ROTATE',
+					jumpCode: 3,
+					icon: 'rotateJump',
+					scaleX: 1,
+					bTrigger: false,
+				}, {
+					jumpName: 'RIGHT_ROTATE',
+					jumpCode: 4,
+					icon: 'rotateJump',
+					scaleX: -1,
+					bTrigger: false,
+				}],
+				spawnArray: [],
+
+				//下一个生成是相反的方向
+				bNextSpawnRightDirection: false,
+				bNextSpawnRightRotateDirection: false,
+
+				level: 3,
+				countdown: 60,
+				countdownInterval: null,
+				
+				faultCount:0,
+				eliminationCount:0,
+			}
+		},
+		created() {
+			let _self = this;
+			uni.getImageInfo({
+				src: "../../../static/modal/action-jump/directionJump.png",
+				success: function(image) {
+					_self.directionJump = image;
+				}
+			});
+			uni.getImageInfo({
+				src: "../../../static/modal/action-jump/midJump.png",
+				success: function(image) {
+					_self.midJump = image;
+					console.log("==============", image);
+				}
+			});
+			uni.getImageInfo({
+				src: "../../../static/modal/action-jump/rotateJump.png",
+				success: function(image) {
+					_self.rotateJump = image;
+				}
+			});
+			this.actionJumpCanvas = uni.createCanvasContext("actionJumpCanvas", this);
+			console.log("this.actionJumpCanvas:", this.actionJumpCanvas);
+
+		},
+		methods: {
+			/**
+			 * 重置生成数组,重置倒计时
+			 */
+			resetJumpGame() {
+
+				this.spawnArray = [];
+				if (this.countdownInterval) {
+					clearInterval(this.countdownInterval);
+					this.countdownInterval = null;
+				}
+
+				this.resetCountdown(60);
+			},
+			startJumpGame() {
+				this.resetJumpGame();
+				//开始游戏
+
+				this.index = 0;
+				// this.levelLabel.string = '关卡' + this.level;
+				if (this.level == 1) {
+					for (let i = 0; i < 2; i++) {
+						this.spawnJumpPrefabs(i);
+					}
+					// this.buttonLabel.string = '下一关';
+
+				} else if (this.level == 2) {
+					for (let i = 0; i < 4; i++) {
+						this.spawnJumpPrefabs(i);
+					}
+					// this.buttonLabel.string = '下一关';
+				} else if (this.level == 3) {
+					for (let i = 0; i < 6; i++) {
+						this.spawnJumpPrefabs(i);
+					}
+					// this.buttonLabel.string = '最后一关';
+					//todo 暂时给循环
+					this.level = 0;
+				}
+
+				this.level++;
+
+				//倒计时
+				this.countdownInterval = setInterval(() => {
+					if (this.countdown <= 0) {
+						clearInterval(this.countdownInterval);
+						this.countdownInterval = null;
+						//处理下一个关卡
+						// console.warn('时间到,处理下一个关卡');
+						this.startJumpGame();
+						return;
+					}
+					this.setCountdown(1);
+				}, 1000);
+				
+				this.onDraw();
+			},
+			spawnJumpPrefabs(index) {
+
+				let ran = Math.floor(Math.random() * 5);
+				//todo 生成的节点,后面再处理节奏问题。比如生成顺序
+				let _jumpPrefab = Object.assign({},this.jumpTypeArray[ran]);
+				//这里处理相反方向,比如生成了一个左旋转,下一个右旋转
+
+				if (_jumpPrefab.jumpName == 'LEFT') {
+					if (this.bNextSpawnRightDirection) {
+						//如果是对应的需要记录一个对应的准确值
+						this.bNextSpawnRightDirection = false;
+					} else {
+						ran = 2; //RIGHT;
+						this.bNextSpawnRightDirection = true;
+					}
+
+				} else if (_jumpPrefab.jumpName == 'RIGHT') {
+
+					if (this.bNextSpawnRightDirection) {
+						ran = 1; //LEFT;
+						this.bNextSpawnRightDirection = false;
+
+					} else {
+						this.bNextSpawnRightDirection = true;
+					}
+				}
+				if (_jumpPrefab.jumpName == 'LEFT_ROTATE') {
+					if (this.bNextSpawnRightRotateDirection) {
+						//如果是对应的需要记录一个对应的准确值
+						this.bNextSpawnRightRotateDirection = false;
+					} else {
+						ran = 4; //RIGHT_ROTATE;
+						this.bNextSpawnRightRotateDirection = true;
+					}
+					// console.log('l==rotate', ran);
+				} else if (_jumpPrefab.jumpName == 'RIGHT_ROTATE') {
+					if (this.bNextSpawnRightRotateDirection) {
+						ran = 3; //LEFT_ROTATE;
+						this.bNextSpawnRightRotateDirection = false;
+					} else {
+						//如果是对应的需要记录一个对应的准确值
+						this.bNextSpawnRightRotateDirection = true;
+					}
+				}
+				this.spawnArray.push(_jumpPrefab);
+			},
+			onDraw() {
+				this.actionJumpCanvas.clearRect(0, 0, 375, 50);
+				for (let i = 0; i < this.spawnArray.length; i++) {
+					//默认 mid 图标
+					let _temp = this.midJump;
+					if (this.spawnArray[i].icon == 'directionJump') {
+						_temp = this.directionJump;
+					} else if (this.spawnArray[i].icon == 'rotateJump') {
+						_temp = this.rotateJump;
+					}
+					this.actionJumpCanvas.save();
+					this.actionJumpCanvas.globalAlpha = this.spawnArray[i].bTrigger ? 0.5 : 1;
+					this.actionJumpCanvas.scale(this.spawnArray[i].scaleX, 1);
+					//如果是相反绘制,需要加多一个自身位置偏移
+					let _pos = this.spawnArray[i].scaleX < 0 ? i + 1 : i;
+					this.actionJumpCanvas.drawImage(_temp.path, (_pos * 50 + 20) * this.spawnArray[i].scaleX, 0, 50, 50);
+					this.actionJumpCanvas.restore();
+				}
+				// console.log('draw');
+				this.actionJumpCanvas.draw();
+			},
+			onClear() {
+				this.resetJumpGame();
+				
+				this.onDraw();
+			},
+
+			onJumpType(event) {
+				// console.log("onJumpType:", event);
+				this.eliminateJumpPrefab(event);
+			},
+
+			// update (dt) {}
+
+			eliminateJumpPrefab(_jumpType) {
+				//如果消除完,需要重新生成
+				if (this.index >= this.spawnArray.length) return;
+				let _temp = this.spawnArray[this.index];
+				_temp.bTrigger = true;
+				this.index++;
+				//绘制新触发状态
+				this.onDraw();
+				//如果当前的跳类型和预制目标一样
+				if (_jumpType == _temp.jumpCode) {
+					//成功
+					this.setEliminationCount(1);
+				} else {
+					//失误
+					this.setFaultCount(1);
+				}
+
+			},
+
+			//设置倒计时
+			setCountdown(value) {
+				this.countdown -= value;
+				// this.countdownLabel.string = '倒计时:' + this.countdown;
+			},
+			resetCountdown(value) {
+				this.countdown = value;
+				// this.countdownLabel.string = '倒计时:' + this.countdown;
+			},
+			//设置ui信息
+			setEliminationCount(value) {
+				this.eliminationCount += value;
+				// this.eliminationLabel.string = '消除数量:' + this.eliminationCount.toString();
+			},
+			setFaultCount(value) {
+				this.faultCount += value;
+				// this.faultLabel.string = '失误:' + this.faultCount;
+			}
+		}
+	}
+</script>
+
+<style lang="scss">
+	.action-jump-parent {
+		border: 1rpx solid #ffaa7f;
+		position: relative;
+		display: flex;
+		justify-content: center;
+		overflow: hidden;
+		top: 0;
+		width: 750rpx;
+	}
+
+	.action-jump-container {
+		width: 100%;
+		height: 50px;
+		border: 1rpx solid #000000;
+		position: relative;
+		// display: flex;
+	}
+</style>

+ 34 - 354
pages/personal-page/personal/personal.vue

@@ -109,6 +109,10 @@
 								 @closeBoxingControl="onCloseBoxingHit"></boxing-hit>
 
 							</view>
+							
+							<view id='actionJumpID' v-if="true" class="charts-pring-bottom">
+								<action-jump ref = "actionJumpRef"></action-jump>
+							</view>
 							<!-- <button @tap="onTestAddLocalCalorie">11</button> -->
 						</view>
 
@@ -470,6 +474,8 @@
 	import boxingPost from "@/components/modal/boxing-post/boxing-post.vue"
 
 	import boxingHit from "@/components/modal/boxing-hit/boxing-hit.vue"
+	
+	import actionJump from "@/components/modal/action-jump/action-jump.vue"
 
 	import AccAndOri from "@/util/util-js/AccAndOri.js"
 
@@ -527,7 +533,9 @@
 			HitEffect,
 			HitFistEffect,
 			ModalTip,
-			keyboardListener
+			keyboardListener,
+			
+			actionJump
 		},
 
 		data() {
@@ -540,159 +548,29 @@
 				cHeightArcbar: '', //圆弧进度图
 				arcbarWidth: '', //圆弧进度图,进度条宽度,此设置可使各端宽度一致
 				pixelRatio: 1,
-				textarea: '',
-				arcbarImagePath: '/static/logo.png',
+				// textarea: '',
+				// arcbarImagePath: '/static/logo.png',
 				cWidth: '',
 				cHeight: '',
 				scrollviewHight: '',
 				// 顶部区域部分
 				topScrollHight: '',
-
 				// 选择器
 				pickerObj: {},
-				lineAImagePath: '/static/logo.png',
-
-				// value: [9999, month - 1, day - 1],
-				visible: true,
-				indicatorStyle: `height: ${Math.round(uni.getSystemInfoSync().screenWidth / (750 / 100))}px;`,
-
+				// lineAImagePath: '/static/logo.png',
+				// visible: true,
+				// indicatorStyle: `height: ${Math.round(uni.getSystemInfoSync().screenWidth / (750 / 100))}px;`,
 				//设备列表
 				deviceList: [{
 					name: '蹦床',
 					icon: '/static/trampoline.png'
 				}],
-
-				//体重列表
-				weightLigt: [],
-
-				// cIndex: -1,
 				cState: 1,
-
 				//游戏列表
 				gameList: [],
-
 				//视频列表,现在视频是和游戏一起管理
 				videoList: [],
-
-				//运动模式
-				planModeList: [{
-						id: 0,
-						image: '/static/plan-ranzhi.png',
-						name: '燃脂模式'
-					},
-					{
-						id: 1,
-						image: '/static/plan-qixing.png',
-						name: '骑行模式'
-					},
-					{
-						id: 2,
-						image: '/static/plan-jianfei.png',
-						name: '减肥塑身'
-					},
-					{
-						id: 3,
-						image: '/static/plan-youyang.png',
-						name: '有氧恢复'
-					},
-					{
-						id: 4,
-						image: '/static/plan-saidao.png',
-						name: '赛道模式'
-					},
-					{
-						id: 5,
-						image: '/static/plan-shandi.png',
-						name: '山地模式'
-					},
-					{
-						id: 6,
-						image: '/static/plan-dianbo.png',
-						name: '颠簸模式'
-					},
-					{
-						id: 7,
-						image: '/static/plan-yueye.png',
-						name: '越野模式'
-					},
-					{
-						id: 8,
-						image: '/static/plan-jianxie.png',
-						name: '间歇模式'
-					}
-				],
-				planModeSelectId: 7,
-				planModeSelectName: '越野模式',
-				planModeSelectIcon: '/static/plan-yueye.png',
-
-				showPlanMode: true,
-
-				showRunMode: true,
-				showPlayMode: true,
-
-				// 模式名称
-				modelList: [{
-						id: 0,
-						name: '拳击模式'
-					},
-					{
-						id: 1,
-						name: '心电图模式'
-					}
-				],
-
-				//新增心电图部分
-				//步骤点
-				basicsList: [{
-					cuIcon: 'radioboxfill',
-					name: '1'
-				}, {
-					cuIcon: 'radioboxfill',
-					name: '2'
-				}, {
-					cuIcon: 'radioboxfill',
-					name: '3'
-				}, {
-					cuIcon: 'radioboxfill',
-					name: '4'
-				}, {
-					cuIcon: 'radioboxfill',
-					name: '5'
-				}, {
-					cuIcon: 'radioboxfill',
-					name: '6'
-				}, {
-					cuIcon: 'radioboxfill',
-					name: '7'
-				}],
-				basics: 0,
-				// 默认不运行
-				bElectRun: false,
-				// 是否是第一运行
-				bFirstRun: true,
-				//心电图定义,数据
-				electro: {
-					oldData: [], //心电图旧的数据
-					oldLine: {},
-					bCanDelete: false,
-					mValue: 60, //绘制时候中间值的数据
-					curCount: 6,
-					dataLenght: 6,
-					curElectData: null,
-					duration: 2000, //整个心电图运行的时间
-					speed: 100, //心电图运行的速度,执行setInterval的间隔
-					frequencyTime: 20, //_self.electro.frequencyTime*_self.electro.speed 心电图生成的频率间隔
-
-					type: [{
-						data: [10, -20, 80, -70, 10, -10],
-						name: "心电图形状1",
-					}, {
-						data: [-30, 80, -70, 10, -5, 5],
-						name: "心电图形状2"
-					}]
-				},
-				bCanDelete: false,
-
+				//运动数据
 				sportData: {
 					calorie: 0,
 					hit: 0,
@@ -702,22 +580,6 @@
 					allData: 0
 				},
 
-				//里程
-				currMileage: 0,
-				// 计算速度的临时里程
-				tempMileage: 0,
-				// 速度
-				currSpeed: 0,
-
-				// 心电图 的图片地址
-				electUrl: '',
-
-				// 心电图部分图片切换
-				bRoundJump: true,
-				bVolume: true,
-
-
-
 				//设置滚动栏高度
 				scrollTop: 0,
 				//scroll view 跳转到对应的组件上
@@ -751,8 +613,6 @@
 					'您今天的目标还没完成,是否结束训练.'
 				],
 				planTipIndex: 0,
-				//蓝牙对象
-				BLERSSIInterval: null,
 
 				//匹配的ai信息
 				aiObj: {
@@ -929,24 +789,24 @@
 			this.bLimitReconnection = false;
 
 			//测试环境检测,给个modal提示 active
-			if (config.active == 'dev') {
-				function thanDate(date2) {
-					var oDate1 = new Date();
-					console.log("检测日期", oDate1);
-					var oDate2 = new Date(date2);
-					if (oDate1.getTime() > oDate2.getTime()) {
-						return true;
-					} else {
-						return false;
-					}
-				}
-				if (thanDate('2021-05-31 13:10:36')) {
-					uni.showModal({
-						title: "提示",
-						content: "此版本为测试版本,有需要请和开发者联系。微信 sweetdontcry"
-					})
-				}
-			}
+			// if (config.active == 'dev') {
+			// 	function thanDate(date2) {
+			// 		var oDate1 = new Date();
+			// 		console.log("检测日期", oDate1);
+			// 		var oDate2 = new Date(date2);
+			// 		if (oDate1.getTime() > oDate2.getTime()) {
+			// 			return true;
+			// 		} else {
+			// 			return false;
+			// 		}
+			// 	}
+			// 	if (thanDate('2021-05-31 13:10:36')) {
+			// 		uni.showModal({
+			// 			title: "提示",
+			// 			content: "此版本为测试版本,有需要请和开发者联系。微信 sweetdontcry"
+			// 		})
+			// 	}
+			// }
 
 		},
 		onReady() {
@@ -994,7 +854,6 @@
 		onHide() {
 			_self.bHide = true;
 			console.log("personal ******* onHide *******");
-			_self.bElectRun = false;
 			//时间暂停 ,隐藏了 需要判断是否为空
 			if (_self.$refs.countDownObj)
 				_self.$refs.countDownObj.timePause('pause');
@@ -1128,7 +987,6 @@
 				let _add = (10 * 1.875) / (4 * 30);
 				console.log(_add);
 				this.onUpdateCaloriePlane(10);
-				// this.onDeleteOnce();
 			},
 			// 进度条数据
 			arcbarData(_planData) {
@@ -1792,39 +1650,7 @@
 					url: '../../game-page/game/game?type=' + e.currentTarget.dataset.type
 				});
 			},
-			onChooseMode(item) {
-				console.log(item);
-				this.planModeSelectId = item.id;
-				this.planModeSelectName = item.name;
-				this.planModeSelectIcon = item.image;
-			},
-			changeRunMode() {
-				this.showRunMode = !this.showRunMode;
-			},
-			changePlayMode() {
-				this.showPlayMode = !this.showPlayMode;
-			},
-			//操作心电图
-			onSetBasics(index) {
-				// if (!this.bElectRun) return;
-				this.basics = index;
-
-				this.electro.duration = 2000 - (this.basics + 1) * 150;
-				this.$refs.electRef.changeDuration(this.electro.duration);
-
-			},
-			onElect(direRight) {
-				// if (!this.bElectRun) return;
-				if (direRight) {
-					this.basics = this.basics == this.basicsList.length - 1 ? 0 : this.basics + 1;
-				} else {
-					this.basics = this.basics == 0 ? 6 : this.basics - 1;
-				}
-				this.electro.duration = 2000 - (this.basics + 1) * 150;
-				this.$refs.electRef.changeDuration(this.electro.duration);
-
-			},
-
+			
 			//判断是否有其他限制
 			onStartCheck() {
 				//#ifdef H5
@@ -2029,126 +1855,6 @@
 				this.setLocalSportTime(res);
 			},
 
-			//运行心电图
-			onPauseElect() {
-				//1.检测一下计划日期
-				console.log(this.remainingDays);
-				if (this.planData.startTime > this.planData.endTime || this.remainingDays == 0) {
-					if (!this.$store.state.bPlanExpired) {
-						this.$store.state.bPlanExpired = true;
-						setTimeout(() => {
-							this.$store.state.bPlanExpired = false;
-						}, 3000)
-						uni.showToast({
-							title: "计划到期,请制定计划。",
-							icon: 'none'
-						})
-					}
-
-					this.$store.state.bGuidePages = true;
-					setTimeout(() => {
-						this.$refs.codeElfGuide.setCurrent(0);
-					}, 0)
-					this.toView = "projectButtonView";
-					return;
-				}
-				//2.检测是否有设备
-				// if (this.BLEDeviceShowList.length == 0) {
-				// 	this.$store.state.bGuidePages = true;
-				// 	this.guideCurrent = 1;
-				// 	this.toView = "addDeviceView";
-				// 	return;
-				// }
-				//2.检测是否连接设备
-				//隐藏功能
-				// if (this.cIndex == -1) {
-				// 	//没有连接设备,提示去连接设备
-
-				// 	uni.showModal({
-				// 		title: '提示',
-				// 		content: '还没有连接设备,是否跳转到设备处?',
-				// 		success: (res) => {
-				// 			if (res.confirm) {
-				// 				this.toView = "addDeviceView";
-				// 			}
-				// 		}
-				// 	})
-				// 	return;
-				// }
-
-
-				// 如果是第一次运行,设置最低速度
-				if (this.bFirstRun) {
-					this.bFirstRun = false;
-					this.onSetBasics(0);
-				}
-
-				if (this.bElectRun) {
-					if (sportSpeedInterval) {
-						clearInterval(sportSpeedInterval);
-						sportSpeedInterval = null;
-					}
-
-					this.bElectRun = false;
-					//时间暂停
-					this.$refs.countDownObj.timePause('pause');
-					this.$refs.electRef.pausedElect();
-				} else {
-					this.bElectRun = true;
-
-					sportSpeedInterval = setInterval(() => {
-						// 每秒检测,相当于m/s
-						this.currSpeed = this.tempMileage;
-						// 累计跑了多远
-						this.currMileage += this.tempMileage;
-						this.tempMileage = 0;
-					}, 1000);
-
-					//时间暂停
-					this.$refs.countDownObj.timePlay('play');
-					this.$refs.electRef.playElect(true);
-
-
-					//播放跳的动画
-					this.modalName = "jumpAnimation";
-					setTimeout(() => {
-						this.modalName = null;
-					}, 4000)
-
-				}
-			},
-
-			BasicsSteps() {
-				this.basics = this.basics == this.basicsList.length - 1 ? 0 : this.basics + 1;
-
-			},
-			//计划时间到, 心电图运行处理这里流程
-			onEndElect() {
-
-				clearInterval(sportSpeedInterval);
-				this.$refs.electRef.pausedElect(true);
-				this.bElectRun = false;
-				this.bFirstRun = true;
-				this.modalName = "sportCompletion";
-				this.sportData.time = this.planData.sportTime;
-				// 1. 计算miss 的个数
-				// this.sportData.miss = this.sportData.allData - this.sportData.hit;
-
-				// 1.计算 总量
-				this.sportData.allData = this.sportData.miss + this.sportData.hit;
-				// 2. 计算击中 的个数
-				if (this.sportData.hit != 0) {
-					let num = this.sportData.hit / this.sportData.allData;
-					this.sportData.percent = num.toFixed(2) * 100;
-				}
-				//TODO 运动的卡路里暂时是*10 57公斤(125磅) 300大卡 30分钟
-				//大概 跳的次数 /2
-				let hitCalorie = this.sportData.hit / 2;
-				this.sportData.calorie = hitCalorie.toFixed(0);
-
-				this.onUpdateCaloriePlane(this.sportData.calorie);
-
-			},
 			//更新运动数据
 			onUpdateCaloriePlane(data) {
 
@@ -2158,32 +1864,6 @@
 				this.updateArcbarData();
 			},
 
-			//跳中心电图部分
-			onDeleteOnce() {
-				if (this.bElectRun) {
-					this.$refs.electRef.jumpElect();
-					this.tempMileage++;
-				}
-
-			},
-
-			onSetVolume() {
-				if (this.bVolume) {
-					this.bVolume = false;
-					this.$refs.electRef.setVolume(0);
-				} else {
-					this.bVolume = true;
-					this.$refs.electRef.setVolume(1);
-				}
-			},
-
-			onMiss() {
-				this.sportData.miss++;
-			},
-			onAdd() {
-				this.sportData.hit++;
-			},
-
 			onRoundTrigger(data) {
 				// console.log("onRoundTrigger==", data);
 				// return;

BIN
static/modal/action-jump/directionJump.png


BIN
static/modal/action-jump/midJump.png


BIN
static/modal/action-jump/rotateJump.png


+ 288 - 0
util/util-js/action/jump.js

@@ -0,0 +1,288 @@
+/**
+ * 跳判断相关脚本代码
+ */
+
+let assign = function (target, ...varArgs) {
+	if (target == null) {
+		throw new TypeError('Cannot convert undefined or null to object');
+	}
+	if (!varArgs || varArgs.length <= 0) {
+		return target;
+	}
+	// 深度合并对象
+	function deepAssign(obj1, obj2) {
+		for (let key in obj2) {
+			obj1[key] = obj1[key] && obj1[key].toString() === "[object Object]" ?
+				deepAssign(obj1[key], obj2[key]) : obj1[key] = obj2[key];
+		}
+		return obj1;
+	}
+
+	varArgs.forEach(val => {
+		target = deepAssign(target, val);
+	});
+	return target;
+};
+
+function Event() {
+	this.events = {};
+}
+Event.prototype.addEventListener = function (type, listener) {
+	this.events[type] = this.events[type] || [];
+	this.events[type].push(listener);
+};
+Event.prototype.trigger = function () {
+	for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
+		args[_key] = arguments[_key];
+	}
+
+	var type = args[0];
+	var params = args.slice(1);
+	if (!!this.events[type]) {
+		// console.log("type:",type);
+		this.events[type].forEach(function (listener) {
+			try {
+				listener.apply(null, params);
+			} catch (e) {
+				console.error(e);
+			}
+		});
+	}
+};
+
+var ActionJump = function ActionJump() {
+
+
+	let jumpOpts = {
+		//是否上升的标志位
+		isDirectionUp: false,
+		//持续上升次数
+		continueUpCount: 0,
+		//上一点的持续上升的次数,为了记录波峰的上升次数
+		continueUpFormerCount: 0,
+
+		continueDownCount: 0,
+		continueDownFormerCount: 0,
+
+		//上一点的状态,上升还是下降
+		lastStatus: false,
+		//波峰值
+		peakOfWave: 0,
+		//波谷值
+		valleyOfWave: 0,
+		//检测到极快的波动的次数
+		timeOfPeakCount: 0,
+		//停止跳
+		bStopJump: false,
+		//上次传感器的值
+		gravityOld: 0,
+
+		bUpState: false,
+	}
+	this.jumpOpts = jumpOpts;
+	//其他波峰波谷参数相关数组记录
+	this.peakOfWaveArray = [];
+	this.peakOfWaveMaxValue = 0;
+	this.valleyOfWaveArray = [];
+	this.valleyOfWaveMinValue = 0;
+	this.highestCount = 0;
+	//陀螺仪
+	this.oriGyroYArray = [];
+
+	this.event = new Event();
+
+}
+ActionJump.prototype.addEventListener = function (type, listener) {
+	this.event.addEventListener(type, listener);
+};
+
+
+ActionJump.prototype.updateJump = function () {
+	let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
+	//使用三个轴的数据,计算重力轴的加速度。最后减去重力的加速度值
+	//********加速计********
+	let { lAccX, lAccY, lAccZ } = data.linearAcc;
+	let { oAccX, oAccY, oAccZ } = data.oriAcc;
+	let { oGyroX, oGyroY, oGyroZ } = data.oriGyro;
+	this.detectorNewStep(data.resultant, lAccX, lAccY, lAccZ, oAccX, oAccY, oAccZ, data.runIndex, oGyroY);
+};
+
+
+
+/*
+ * 检测步子,并开始计步
+ * 1.传入数据
+ * 2.如果检测到了波峰,并且符合时间差以及阈值的条件,则判定为1步
+ * 3.符合时间差条件,波峰波谷差值大于initialValue,则将该差值纳入阈值的计算中
+ * */
+ActionJump.prototype.detectorNewStep = function (resultant, linearX, linearY, linearZ, oriX, oriY, oriZ, _runIndex, _oGyroY) {
+	let bUpdate = true;
+	let _judgmentValue = oriZ;
+	if (this.jumpOpts.gravityOld == 0) {
+		this.jumpOpts.gravityOld = _judgmentValue;
+	} else {
+
+		if (!this.jumpOpts.bStopJump) {
+			let { bState, bType, value } = this.detectorPeakOfWaveAndValleyOfWave(_judgmentValue, this.jumpOpts.gravityOld);
+			if (bState) {
+				this.jumpOpts.bUpState = true;
+				let _temp = {
+					type: bType,
+					oldValue: value,
+					value: resultant,
+					lastIndex: _runIndex - 1
+				};
+				this.event.trigger('resultant', _temp);
+				bUpdate = false;
+				//记录最高点和最低点数组
+				if (bType == 'peakOfWave') {
+					this.peakOfWaveArray.push(_temp);
+					if (value > this.peakOfWaveMaxValue)
+						this.peakOfWaveMaxValue = value;
+				} else if (bType == 'valleyOfWave') {
+					this.valleyOfWaveArray.push(_temp);
+					if (value < this.valleyOfWaveMinValue)
+						this.valleyOfWaveMinValue = value;
+				}
+				this.highestCount = 0;
+				//陀螺仪部分
+				this.oriGyroYArray = [];
+			}
+
+			if (this.jumpOpts.bUpState) {
+				this.oriGyroYArray.push(_oGyroY);
+				//出现极值后
+				if (Math.abs(linearZ) < 4 && Math.abs(resultant) < 6) {
+					this.highestCount++;
+					if (this.highestCount >= 2) {
+						//达到最高点,
+						this.jumpOpts.bStopJump = true;
+
+						let _currentMaxValue = 0;
+						if (Math.abs(this.peakOfWaveMaxValue) > Math.abs(this.valleyOfWaveMinValue)) {
+							_currentMaxValue = this.peakOfWaveMaxValue;
+						} else {
+							_currentMaxValue = this.valleyOfWaveMinValue;
+						}
+
+						let allOGyroValue = 0;
+						for (let i = 0; i < this.oriGyroYArray.length; i++) {
+							allOGyroValue += this.oriGyroYArray[i];
+						}
+						allOGyroValue /= this.oriGyroYArray.length;
+
+						//目前测试预大于100 为旋转跳动
+						// if (allOGyroValue > 0) {
+						// 	console.log('right:', allOGyroValue);
+
+						// } else {
+						// 	console.log('left:', allOGyroValue);
+						// }
+
+						this.event.trigger('resultant', {
+							type: "jump",
+							acc: _currentMaxValue,
+							value: resultant
+						});
+
+						this.event.trigger('resultant', {
+							type: "curAngle",
+							value: _currentMaxValue,
+							resultant: resultant
+						});
+
+						this.event.trigger('resultant', {
+							type: "rotate",
+							value: allOGyroValue,
+							resultant: resultant
+						});
+						//如果_currentMaxValue小于30判断原地跳
+						// console.log("_currentMaxValue:", _currentMaxValue,allOGyroValue);
+
+						//后面通用使用这个类型传输数据
+						this.event.trigger('resultant', {
+							type: "stateDataOfJump",
+							currentMaxValue: _currentMaxValue,
+							oGyroValue: allOGyroValue,
+							resultant: resultant
+						});
+
+						// bUpdate = false;
+						this.jumpOpts.bUpState = false;
+						this.resetAll();
+					}
+
+				}
+			}
+		} else {
+			this.jumpOpts.timeOfPeakCount++;
+			if (this.jumpOpts.timeOfPeakCount >= 30) {
+				this.jumpOpts.timeOfPeakCount = 0;
+				this.jumpOpts.bStopJump = false;
+				this.event.trigger('resultant', {
+					type: "stop"
+				});
+
+				this.resetAll();
+			}
+		}
+		// 		let result = Math.atan2(averX, averZ) * 180 / (Math.PI);
+		// 		result = Math.round(result);
+		// 		let curAngle = result > 0 ? result : (360 + result);
+		// 		console.log("curAngle:", curAngle);
+		this.event.trigger('resultant', {
+			type: "bUpdateDraw",
+			linearX: linearX,
+			linearZ: linearZ,
+			linearY: linearY,
+			oriX: oriX,
+			oriY: oriY,
+			oriZ: oriZ
+		});
+		this.jumpOpts.gravityOld = _judgmentValue;
+	}
+}
+
+
+ActionJump.prototype.detectorPeakOfWaveAndValleyOfWave = function (newValue, oldValue) {
+	this.jumpOpts.lastStatus = this.jumpOpts.isDirectionUp;
+	if (newValue >= oldValue) {
+		this.jumpOpts.continueDownFormerCount = this.jumpOpts.continueDownCount;
+		this.jumpOpts.continueDownCount = 0;
+		this.jumpOpts.isDirectionUp = true;
+		this.jumpOpts.continueUpCount++;
+	} else {
+		this.jumpOpts.continueUpFormerCount = this.jumpOpts.continueUpCount;
+		this.jumpOpts.continueUpCount = 0;
+		this.jumpOpts.isDirectionUp = false;
+		this.jumpOpts.continueDownCount++;
+	}
+	if (!this.jumpOpts.isDirectionUp && this.jumpOpts.lastStatus && this.jumpOpts.continueUpFormerCount >= 2 && Math.abs(oldValue) >= 5) {
+		this.jumpOpts.peakOfWave = oldValue;
+		return { value: oldValue, bType: 'peakOfWave', bState: true };
+	} else if (!this.jumpOpts.lastStatus && this.jumpOpts.isDirectionUp && this.jumpOpts.continueDownFormerCount >= 2 && Math.abs(oldValue) >= 5) {
+		this.jumpOpts.valleyOfWave = oldValue;
+		return { value: oldValue, bType: 'valleyOfWave', bState: true };
+	} else {
+		return { value: oldValue, bType: 'None', bState: false };
+	}
+}
+//重置对应的参数
+ActionJump.prototype.resetAll = function () {
+
+	this.peakOfWaveArray = [];
+	this.peakOfWaveMaxValue = 0;
+	this.valleyOfWaveArray = [];
+	this.valleyOfWaveMinValue = 0;
+	this.highestCount = 0;
+
+
+	this.jumpOpts.continueDownFormerCount = 0;
+	this.jumpOpts.continueDownCount = 0;
+	this.jumpOpts.continueUpFormerCount = 0;
+	this.jumpOpts.continueUpCount = 0;
+}
+
+if (typeof module === "object" && typeof module.exports === "object") {
+	module.exports = ActionJump;
+}

+ 1 - 1
util/util-js/store.js

@@ -246,7 +246,7 @@ const store = new Vuex.Store({
 		globalMyAttitude: null,
 
 		//当前显示的模式下标
-		currentModeIndex: 0,
+		currentModeIndex: 1,
 
 		//蓝牙变量操作
 		/**