Просмотр исходного кода

测试数据没有问题,等待真实数据测试

Changpeng Duan 5 лет назад
Родитель
Сommit
6337808036
6 измененных файлов с 155 добавлено и 90 удалено
  1. 3 0
      online/src/Mock/index.js
  2. 120 59
      online/src/page/mainpage.vue
  3. 10 10
      pc/src/api/Navs.js
  4. 0 2
      pc/src/libs/rem.js
  5. 12 13
      pc/src/views/courseEdit.vue
  6. 10 6
      pc/src/views/online.vue

+ 3 - 0
online/src/Mock/index.js

@@ -139,6 +139,9 @@ if (t == 1) {
     Mock.mock('/api/testSelect', 'post', testSelect());
     Mock.mock('/api/testSelect', 'post', testSelect());
     Mock.mock(headapi + 'v1/Auth/testTable', 'post', testTable());
     Mock.mock(headapi + 'v1/Auth/testTable', 'post', testTable());
     Mock.mock(headapi + 'v1/Auth/PhoneSignIn', 'post', PhoneSignIn());//用户登录
     Mock.mock(headapi + 'v1/Auth/PhoneSignIn', 'post', PhoneSignIn());//用户登录
+
+    // Mock.mock(headapi + 'v1/Auth/PhoneSignIn', 'post', HrSensorsUpdate());//
+    // Mock.mock(headapi + 'v1/Auth/PhoneSignIn', 'post', GetDuInfoAndUserInfoByUserMd5());//
 }
 }
 
 
 
 

+ 120 - 59
online/src/page/mainpage.vue

@@ -57,7 +57,7 @@
                 <em>心率带未连接</em>
                 <em>心率带未连接</em>
                 <button>点击连接</button>
                 <button>点击连接</button>
             </div>
             </div>
-            <div class="classInfo" v-if="InClass == 1">
+            <div class="classInfo" v-if="InClass == 1 && watchState">
                 <em><span>课程名称</span>:{{DpName}}</em>
                 <em><span>课程名称</span>:{{DpName}}</em>
             </div>
             </div>
         </div>
         </div>
@@ -137,6 +137,9 @@
     export default {
     export default {
         data() {
         data() {
             return {
             return {
+                runMode: '',//'' 为正常模式 mock 为模拟操作模式
+                isClassTime: 5000,//上课状态检测频率
+                isAddHeartTime: 1000,//心率上报检测频率
                 dataLabels: [],
                 dataLabels: [],
                 dataDatasets: [],
                 dataDatasets: [],
                 watchText: '',
                 watchText: '',
@@ -169,24 +172,50 @@
                 watchs: [],
                 watchs: [],
                 begin: null,
                 begin: null,
                 heartLine: [],
                 heartLine: [],
-                dataLabels: [],
                 InClass: 0,//是否上课
                 InClass: 0,//是否上课
                 DpName: '1234',//课程名称
                 DpName: '1234',//课程名称
                 HrId: '',//心率带
                 HrId: '',//心率带
-                duId:'',
-                sn:'',
+                duId: '',
+                sn: '',
             }
             }
         },
         },
         mounted() {
         mounted() {
             this.getBodyInfo();
             this.getBodyInfo();
             this.init();
             this.init();
-            clearInterval(this.timer);
-            this.timer = setInterval(() => {
+
+            // 获取上课状态
+            clearInterval(this.timerisClass);
+            this.timerisClass = setInterval(() => {
                 this.isClass();
                 this.isClass();
-            }, 3000);
+            }, this.isClassTime);
+
+            // 上报心率信息
+            clearInterval(this.timerAutoAddAppHeartRate);
+            this.timerAutoAddAppHeartRate = setInterval(() => {
+                // 上课中,且已连接心率带
+                if (this.InClass == 1 && this.watchState) {
+                    // 上课就自动上报
+                    this.AutoAddAppHeartRate();
+                } else {
+                    // 不上课就不报
+                    console.log('下课中,不汇报');
+                }
+
+                // if (this.runMode == 'mock') {
+                //     this.InClass = 1;
+                //     this.duId = 775;
+                //     this.sn = '22735';
+                //     this.HrId = 87;
+                //     this.AutoAddAppHeartRate();
+                // } else {
+                //     // 不上课就不报
+                //     console.log('下课中,不汇报test');
+                // }
+            }, this.isAddHeartTime);
         },
         },
         beforeDestroy() {
         beforeDestroy() {
-            clearInterval(this.timer);
+            clearInterval(this.timerisClass);
+            clearInterval(this.timerAutoAddAppHeartRate);
         },
         },
         watch: {
         watch: {
             activeLevel(val) {
             activeLevel(val) {
@@ -222,36 +251,66 @@
         methods: {
         methods: {
             init() {
             init() {
                 let that = this;
                 let that = this;
-                // 页面初始化操作
-                document.addEventListener('plusready', function (e) {
-                    plus.bluetooth.onBLECharacteristicValueChange(function (e) {
-                        if (e.characteristicId == '00002A19-0000-1000-8000-00805F9B34FB') {
-                            // 获取电量
-                            var value = that.buffer2hexPower(e.value);
-                            that.battery = value + '%';
-                        } else {
-                            // 成功获取心跳
-                            that.heartRate = parseInt(that.parseHeartRate(e.value).heartRate);
-                            that.watchText = '心率带已连接';
-                            that.activeState = true;
-                            // 运动强度计算
-                            that.calcActLevel(that.heartRate);
-                            that.openAlert = false;//关闭弹窗
-                            that.watchState = true;//关闭连接按钮
-                            // 卡路里计算
-                            that.calcCalorie(that.heartRate);
-                            if (that.heartLine.length > 30) {
-                                that.heartLine.unshift();
-                                that.dataLabels.unshift();
+                if (this.runMode == 'mock') {
+                    that.mockCreateDate();
+                } else {
+                    // 页面初始化操作
+                    document.addEventListener('plusready', function (e) {
+                        plus.bluetooth.onBLECharacteristicValueChange(function (e) {
+                            if (e.characteristicId == '00002A19-0000-1000-8000-00805F9B34FB') {
+                                // 获取电量
+                                var value = that.buffer2hexPower(e.value);
+                                that.battery = value + '%';
                             } else {
                             } else {
-                                that.heartLine.push(that.heartRate);
-                                that.dataLabels.push('');
+                                // 成功获取心跳
+                                that.heartRate = parseInt(that.parseHeartRate(e.value).heartRate);
+                                that.watchText = '心率带已连接';
+                                that.activeState = true;
+                                // 运动强度计算
+                                that.calcActLevel(that.heartRate);
+                                that.openAlert = false;//关闭弹窗
+                                that.watchState = true;//关闭连接按钮并显示当前课程名
+                                // 卡路里计算
+                                that.calcCalorie(that.heartRate);
+                                if (that.heartLine.length > 30) {
+                                    that.heartLine.unshift();
+                                    that.dataLabels.unshift();
+                                } else {
+                                    that.heartLine.push(that.heartRate);
+                                    that.dataLabels.push('');
+                                }
+                                that.DrawHeartLine(that.heartLine, that.dataLabels);
+                                // that.AutoAddAppHeartRate();
                             }
                             }
-                            that.DrawHeartLine(that.heartLine, that.dataLabels);
-                            // that.AutoAddAppHeartRate();
-                        }
+                        });
                     });
                     });
-                });
+                }
+            },
+            // 生成心率数据
+            mockCreateDate() {
+                let that = this;
+                clearInterval(this.timermockCreateDate);
+                this.timermockCreateDate = setInterval(() => {
+                    that.battery =  '85%';
+                    // 成功获取心跳
+                    that.heartRate = parseInt(Math.random() * 100 + 90);
+                    that.watchText = '心率带已连接';
+                    that.activeState = true;
+                    // 运动强度计算
+                    that.calcActLevel(that.heartRate);
+                    that.openAlert = false;//关闭弹窗
+                    that.watchState = true;//关闭连接按钮
+                    // 卡路里计算
+                    that.calcCalorie(that.heartRate);
+                    if (that.heartLine.length > 30) {
+                        that.heartLine.shift();
+                        that.dataLabels.shift();
+                    } else {
+                        that.heartLine.push(that.heartRate);
+                        that.dataLabels.push('');
+                    }
+                    that.DrawHeartLine(that.heartLine, that.dataLabels);
+                }, 1000);
             },
             },
             // 是否正在上课
             // 是否正在上课
             isClass() {
             isClass() {
@@ -264,16 +323,8 @@
                     let json = res;
                     let json = res;
                     if (json.Code == 0) {
                     if (json.Code == 0) {
                         that.InClass = json.InClass;//0下课,1上课
                         that.InClass = json.InClass;//0下课,1上课
-                        if (that.InClass == 1) {
-                            // 记录duid
-                            that.duid = json.DuInfo.DuId;
-                            // 上课就上报
-                            that.AutoAddAppHeartRate();
-                        } else {
-                            // 不上课就不报
-                            console.log('下课中,不汇报');
-                            return false
-                        }
+                        // 记录duid
+                        that.duid = json.DuInfo.DuId;
                     } else {
                     } else {
                         that.$message.error(json.Memo);
                         that.$message.error(json.Memo);
                     }
                     }
@@ -295,6 +346,10 @@
             connectWatch() {
             connectWatch() {
                 // 打开蓝牙适配器
                 // 打开蓝牙适配器
                 let that = this;
                 let that = this;
+                if(typeof plus == 'undefined'){
+                    that.Toast('当前设备不支持蓝牙心率带', 'error');
+                    return false
+                }
                 plus.bluetooth.openBluetoothAdapter({
                 plus.bluetooth.openBluetoothAdapter({
                     success: function (e) {
                     success: function (e) {
                         that.Toast('蓝牙适配器打开成功!', 'success');
                         that.Toast('蓝牙适配器打开成功!', 'success');
@@ -356,7 +411,7 @@
                         }, 2000);
                         }, 2000);
                     },
                     },
                     fail: function (e) {
                     fail: function (e) {
-                        that.Toast('连接失败! ' + JSON.stringify(e));
+                        that.Toast('连接失败! 请重新连接' + JSON.stringify(e));
                     }
                     }
                 });
                 });
             },
             },
@@ -366,7 +421,7 @@
                 plus.bluetooth.getBLEDeviceServices({
                 plus.bluetooth.getBLEDeviceServices({
                     deviceId: w.deviceId,
                     deviceId: w.deviceId,
                     success: function (e) {
                     success: function (e) {
-                        that.Toast('获取服务成功!', 'success');
+                        that.Toast('获取蓝牙服务成功!', 'success');
                         // 获取服务的特征值
                         // 获取服务的特征值
                         // console.log('服务的特征值' + w.advertisServiceUUIDs[0]);
                         // console.log('服务的特征值' + w.advertisServiceUUIDs[0]);
                         var HEARTuuid = "0000180D-0000-1000-8000-00805F9B34FB";//HEART RATE
                         var HEARTuuid = "0000180D-0000-1000-8000-00805F9B34FB";//HEART RATE
@@ -380,7 +435,7 @@
                     },
                     },
                     fail: function (e) {
                     fail: function (e) {
                         console.log('获取服务失败! ' + JSON.stringify(e));
                         console.log('获取服务失败! ' + JSON.stringify(e));
-                        that.Toast('获取服务失败! ' + JSON.stringify(e));
+                        that.Toast('获取服务失败!请重试 ' + JSON.stringify(e));
                     }
                     }
                 });
                 });
             },
             },
@@ -408,13 +463,13 @@
                                 //that.onValuesChange();
                                 //that.onValuesChange();
                             },
                             },
                             fail: function (e) {
                             fail: function (e) {
-                                that.Toast('notifyBLECharacteristicValueChange failed! ' + JSON.stringify(e));
+                                that.Toast('获取特征值失败!重启APP后再次尝试 ' + JSON.stringify(e));
                             }
                             }
                         });
                         });
                     },
                     },
                     fail: function (e) {
                     fail: function (e) {
                         console.log('获取特征值失败! ' + JSON.stringify(e));
                         console.log('获取特征值失败! ' + JSON.stringify(e));
-                        that.Toast('获取特征值失败! ' + JSON.stringify(e));
+                        that.Toast('获取特征值失败!重启APP后再次尝试 ' + JSON.stringify(e));
                     }
                     }
                 })
                 })
             },
             },
@@ -445,7 +500,7 @@
                     },
                     },
                     fail: function (e) {
                     fail: function (e) {
                         console.log('获取特征值失败! ' + JSON.stringify(e));
                         console.log('获取特征值失败! ' + JSON.stringify(e));
-                        that.Toast('获取特征值失败! ' + JSON.stringify(e));
+                        that.Toast('获取特征值失败!重启APP后再次尝试 ' + JSON.stringify(e));
                     }
                     }
                 })
                 })
             },
             },
@@ -459,7 +514,7 @@
                         console.log("读取电量数据成功" + JSON.stringify(e));
                         console.log("读取电量数据成功" + JSON.stringify(e));
                     },
                     },
                     fail: function (e) {
                     fail: function (e) {
-                        that.Toast('读取电量数据失败! ' + JSON.stringify(e));
+                        that.Toast('读取电量数据失败!重启APP后再次尝试 ' + JSON.stringify(e));
                     }
                     }
                 });
                 });
             },
             },
@@ -536,19 +591,23 @@
             // 活动强度计算公式
             // 活动强度计算公式
             calcActLevel(heartRate) {
             calcActLevel(heartRate) {
                 let sum = 170 - this.age;
                 let sum = 170 - this.age;
-                this.activeLevel = parseInt((heartRate / sum) * 100);
+                let actLevel = parseInt((heartRate / sum) * 100) > 100 ? 100 : parseInt((heartRate / sum) * 100);
+                this.activeLevel = actLevel;
             },
             },
             // 持续时间
             // 持续时间
             calcHoldTime(curTime) {
             calcHoldTime(curTime) {
-                let res = parseInt(curTime.getTime() - this.begin.getTime()) / 1000;
-                return parseInt(res)
+                if (this.runMode == 'mock') {
+                    return 1
+                } else {
+                    let res = parseInt(curTime.getTime() - this.begin.getTime()) / 1000;
+                    return parseInt(res)
+                }
             },
             },
             // 计算卡路里
             // 计算卡路里
             calcCalorie(heartRate) {
             calcCalorie(heartRate) {
                 let that = this;
                 let that = this;
                 let calorieNoVo2 = 0;
                 let calorieNoVo2 = 0;
                 let curTime = that.calcHoldTime(new Date());
                 let curTime = that.calcHoldTime(new Date());
-                console.log(curTime);
                 // 男
                 // 男
                 if (that.sex == 1) {
                 if (that.sex == 1) {
                     calorieNoVo2 = ((-55.0969 + (0.6309 * heartRate) + (0.1988 * that.weight) + (0.2017 * that.age)) / 4.184) / 60 * 1;
                     calorieNoVo2 = ((-55.0969 + (0.6309 * heartRate) + (0.1988 * that.weight) + (0.2017 * that.age)) / 4.184) / 60 * 1;
@@ -568,6 +627,7 @@
             },
             },
             // 计算运动卡路里
             // 计算运动卡路里
             calcSportCal(calorieNoVo2) {
             calcSportCal(calorieNoVo2) {
+                let that = this;
                 let bmrMSjDaily = (10.00 * this.weight) + (6.25 * this.height) - (5.00 * this.age) + 5.00;
                 let bmrMSjDaily = (10.00 * this.weight) + (6.25 * this.height) - (5.00 * this.age) + 5.00;
                 let BmrMSjRmrcb = parseFloat((bmrMSjDaily * 1.1) / 24);
                 let BmrMSjRmrcb = parseFloat((bmrMSjDaily * 1.1) / 24);
                 let calorieNoVo2Pure = (calorieNoVo2 - BmrMSjRmrcb / 3600 * 1);
                 let calorieNoVo2Pure = (calorieNoVo2 - BmrMSjRmrcb / 3600 * 1);
@@ -605,16 +665,17 @@
                     hrId: that.HrId,
                     hrId: that.HrId,
                     heartRate: that.heartRate,
                     heartRate: that.heartRate,
                     rcvTime: new Date().getTime(),
                     rcvTime: new Date().getTime(),
-                    calories: that.addCalories,
-                    pureCalories: that.addPureCalories,
+                    calories: parseInt(that.addCalories * 1000), //卡
+                    pureCalories: parseInt(that.addPureCalories * 1000), //卡
                 };
                 };
                 let postdata = qs.stringify(param);
                 let postdata = qs.stringify(param);
                 AddAppHeartRate(postdata).then(res => {
                 AddAppHeartRate(postdata).then(res => {
                     let json = res;
                     let json = res;
                     if (json.Code == 0) {
                     if (json.Code == 0) {
+                        that.InClass = json.InClass;
                         console.log('心率数据上传成功!');
                         console.log('心率数据上传成功!');
                     } else {
                     } else {
-                        that.Toast(json.Memo);
+                        that.Toast( '心率数据上传失败' + json.Memo);
                     }
                     }
                 })
                 })
             },
             },

+ 10 - 10
pc/src/api/Navs.js

@@ -29,16 +29,16 @@ let navs = [
         "grouplist": "2,5",
         "grouplist": "2,5",
         "icon": "el-icon-user-solid",
         "icon": "el-icon-user-solid",
     }
     }
-    // , {
-    //     "clmid": "3",
-    //     "clmcode": "region",
-    //     "clmname": "在线上课",
-    //     "clmurl": "/online",
-    //     "prname": "",
-    //     "show": 3,//2
-    //     "grouplist": "2,5",
-    //     "icon": "el-icon-video-camera",
-    // }
+    , {
+        "clmid": "3",
+        "clmcode": "region",
+        "clmname": "在线上课",
+        "clmurl": "/online",
+        "prname": "",
+        "show": 3,//2
+        "grouplist": "2,5",
+        "icon": "el-icon-video-camera",
+    }
     ,
     ,
     {
     {
         "clmid": "13",
         "clmid": "13",

+ 0 - 2
pc/src/libs/rem.js

@@ -4,8 +4,6 @@ function setRem() {
     // 320 默认大小16px; 320px = 20rem ;每个元素px基础上/16
     // 320 默认大小16px; 320px = 20rem ;每个元素px基础上/16
     let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
     let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
 
 
-    console.log('htmlWidth:' + htmlWidth);
-
     //得到html的Dom元素
     //得到html的Dom元素
     let htmlDom = document.getElementsByTagName('html')[0];
     let htmlDom = document.getElementsByTagName('html')[0];
     //设置根元素字体大小
     //设置根元素字体大小

+ 12 - 13
pc/src/views/courseEdit.vue

@@ -216,18 +216,18 @@
                         </div>
                         </div>
                     </template>
                     </template>
                 </el-table-column>
                 </el-table-column>
-                <!--<el-table-column-->
-                        <!--prop="isOnline"-->
-                        <!--label="是否网课"-->
-                        <!--type="selection"-->
-                        <!--width="120"-->
-                        <!--sortable-->
-                <!--&gt;-->
-                    <!--&lt;!&ndash;<template slot-scope="scope">&ndash;&gt;-->
-                    <!--&lt;!&ndash;<el-checkbox label="网课" v-model="scope.row.isOnline" name="type"&ndash;&gt;-->
-                    <!--&lt;!&ndash;@change="showOrDiss(scope.row)"></el-checkbox>&ndash;&gt;-->
-                    <!--&lt;!&ndash;</template>&ndash;&gt;-->
-                <!--</el-table-column>-->
+                <el-table-column
+                        prop="isOnline"
+                        label="是否网课"
+                        type="selection"
+                        width="120"
+                        sortable
+                >
+                    <!--<template slot-scope="scope">-->
+                    <!--<el-checkbox label="网课" v-model="scope.row.isOnline" name="type"-->
+                    <!--@change="showOrDiss(scope.row)"></el-checkbox>-->
+                    <!--</template>-->
+                </el-table-column>
                 <el-table-column
                 <el-table-column
                         prop="Status"
                         prop="Status"
                         label="状态"
                         label="状态"
@@ -284,7 +284,6 @@
                                 </el-button>
                                 </el-button>
                             </span>
                             </span>
                         </div>
                         </div>
-
                     </template>
                     </template>
                 </el-table-column>
                 </el-table-column>
             </el-table>
             </el-table>

+ 10 - 6
pc/src/views/online.vue

@@ -7,10 +7,14 @@
                 <em>(在线:{{classInfo.online}}人 离线:{{classInfo.offline}}人) </em>
                 <em>(在线:{{classInfo.online}}人 离线:{{classInfo.offline}}人) </em>
                 <em>当前时间:{{classInfo.time}} </em>
                 <em>当前时间:{{classInfo.time}} </em>
             </div>
             </div>
+            <div class="region">
+                <!--拿到eqsn才能获取数据-->
+
+            </div>
             <el-button @click="full_screen" v-if="!screen_full" icon="el-icon-full-screen" type="primary">全屏</el-button>
             <el-button @click="full_screen" v-if="!screen_full" icon="el-icon-full-screen" type="primary">全屏</el-button>
             <el-button @click="cancle_screen" v-else icon="el-icon-full-screen" type="primary">缩小</el-button>
             <el-button @click="cancle_screen" v-else icon="el-icon-full-screen" type="primary">缩小</el-button>
-            <el-button v-if="classState == 0" @click="" type="success">上课</el-button>
-            <el-button v-else @click="" type="danger">下课</el-button>
+            <!--<el-button v-if="classState == 0" @click="" type="success">上课</el-button>-->
+            <!--<el-button v-else @click="" type="danger">下课</el-button>-->
             <el-button @click="showRank" type="warning">排行榜</el-button>
             <el-button @click="showRank" type="warning">排行榜</el-button>
             <!--<el-button @click="">隐藏信息 todo</el-button>-->
             <!--<el-button @click="">隐藏信息 todo</el-button>-->
         </div>
         </div>
@@ -114,7 +118,6 @@
     import levelIcon from '@/components/levelIcon'
     import levelIcon from '@/components/levelIcon'
     import power from '@/components/power'
     import power from '@/components/power'
     import userRank from '@/components/userRank'
     import userRank from '@/components/userRank'
-
     export default {
     export default {
         data() {
         data() {
             return {
             return {
@@ -136,7 +139,7 @@
             };
             };
         },
         },
         mounted() {
         mounted() {
-            this.getList(26);
+            // this.getList(26);
         },
         },
         watch: {
         watch: {
             $route(to) {
             $route(to) {
@@ -150,6 +153,8 @@
         },
         },
         methods: {
         methods: {
             clearRem() {
             clearRem() {
+                // 320 默认大小16px; 320px = 20rem ;每个元素px基础上/16
+                let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
                 //得到html的Dom元素
                 //得到html的Dom元素
                 let htmlDom = document.getElementsByTagName('html')[0];
                 let htmlDom = document.getElementsByTagName('html')[0];
                 htmlDom.style.fontSize = '14px'
                 htmlDom.style.fontSize = '14px'
@@ -160,7 +165,7 @@
                 //得到html的Dom元素
                 //得到html的Dom元素
                 let htmlDom = document.getElementsByTagName('html')[0];
                 let htmlDom = document.getElementsByTagName('html')[0];
                 //设置根元素字体大小
                 //设置根元素字体大小
-                htmlDom.style.fontSize = htmlWidth / 20 + 'px';
+                htmlDom.style.fontSize = htmlWidth / 120 + 'px';
             },
             },
             // 全屏显示
             // 全屏显示
             full_screen() {
             full_screen() {
@@ -398,7 +403,6 @@
         background: #EDEDED;
         background: #EDEDED;
     }
     }
 
 
-
     .panel /deep/ h5 {
     .panel /deep/ h5 {
         margin: 0;
         margin: 0;
         text-align: left;
         text-align: left;