Ver código fonte

Merge branch 'master' of git.beswell.com:duanchangpeng/flyLong

# Conflicts:
#	hbuild/online/unpackage/res/icons/1024x1024.png
#	hbuild/online/unpackage/res/icons/120x120.png
#	hbuild/online/unpackage/res/icons/144x144.png
#	hbuild/online/unpackage/res/icons/152x152.png
#	hbuild/online/unpackage/res/icons/167x167.png
#	hbuild/online/unpackage/res/icons/180x180.png
#	hbuild/online/unpackage/res/icons/192x192.png
#	hbuild/online/unpackage/res/icons/20x20.png
#	hbuild/online/unpackage/res/icons/29x29.png
#	hbuild/online/unpackage/res/icons/40x40.png
#	hbuild/online/unpackage/res/icons/58x58.png
#	hbuild/online/unpackage/res/icons/60x60.png
#	hbuild/online/unpackage/res/icons/72x72.png
#	hbuild/online/unpackage/res/icons/76x76.png
#	hbuild/online/unpackage/res/icons/80x80.png
#	hbuild/online/unpackage/res/icons/87x87.png
#	hbuild/online/unpackage/res/icons/96x96.png
Changpeng Duan 5 anos atrás
pai
commit
ca7ff153b9
1 arquivos alterados com 46 adições e 17 exclusões
  1. 46 17
      online/src/page/mainpage.vue

+ 46 - 17
online/src/page/mainpage.vue

@@ -98,15 +98,16 @@
                             {'slowJump':activeLevel < 30},
                             ]">{{heartRate}}</em>
         </div>
-        <mu-dialog title="" width="600" max-width="80%" :esc-press-close="false"
-                   :overlay-close="false" :open.sync="openAlert">
-            <p v-if="!watchs">
+        <mu-dialog title="" width="600" max-width="80%" :esc-press-close="true"
+                   :overlay-close="true" :open.sync="openAlert">
+            <p v-if="!watchListState">
                 没有任何设备
             </p>
             <div class="watchList" v-else>
                 <p>请选择设备</p>
                 <ul>
-                    <li v-for="w in watchs" @click="choiceWatch">{{w.name}} <em>信号:{{w.level}}</em></li>
+                    <li v-for="w in watchs" @click="choiceWatch(w)">{{w.localName}} <em>信号:{{w.RSSI |parseLevel}}</em>
+                    </li>
                 </ul>
             </div>
             <br>
@@ -153,11 +154,6 @@
         },
         mounted() {
             this.getBodyInfo();
-            this.activeLevel = 0;
-            this.watchs = [
-                // {name: 'CL831-0022750', id: 1, rssi: -90, level: '强'},
-                // {name: 'CL831-0022767', id: 2, rssi: -30, level: '弱'},
-            ]
         },
         watch: {
             activeLevel(val) {
@@ -194,12 +190,12 @@
         methods: {
             connectWatch() {
                 // 打开蓝牙适配器
-                this.Toast('蓝牙适配器打开成功!');
                 let that = this;
                 plus.bluetooth.openBluetoothAdapter({
                     success: function (e) {
                         that.Toast('蓝牙适配器打开成功!');
                         that.openAlert = true;
+                        that.searchWatch();
                         return e
                     },
                     fail: function (e) {
@@ -210,21 +206,54 @@
             closeAlertDialog() {
                 this.openAlert = false;
             },
+            // 监听搜索到新设备
             searchWatch() {
-                // test
-                this.watchs = [
-                    {name: 'CL831-0022750', id: 1, rssi: -90, level: '强'},
-                    {name: 'CL831-0022767', id: 2, rssi: -30, level: '弱'},
-                ];
-                this.watchListState = true;
+                let that = this;
+                plus.bluetooth.startBluetoothDevicesDiscovery({
+                    // services: ['heart_rate'],//ios不支持
+                    success: function (e) {
+                        that.Toast('开始搜索成功!');
+                        plus.bluetooth.onBluetoothDeviceFound(function (e) {
+                            let devices = e.devices;
+                            for (let i in devices) {
+                                let device = devices[i];
+                                console.log(JSON.stringify(device));
+                                // localName CL831
+                                if (device.localName.includes('CL831')) {
+                                    that.watchs.push(device)
+                                }
+                            }
+                            that.watchListState = true;
+                        });
+                    },
+                    fail: function (e) {
+                        that.Toast('开始搜索失败! ' + JSON.stringify(e));
+                    }
+                });
             },
-            choiceWatch() {
+            choiceWatch(w) {
+                let that = this;
+                that.Toast('连接心率带' + w.localName + '中...');
+
             },
             // 获取基础身体数据
             getBodyInfo() {
 
             }
         },
+        filters: {
+            parseLevel: function (value) {
+                if (!value) {
+                    return '无'
+                } else {
+                    if (value < -90) {
+                        return '强'
+                    } else {
+                        return '弱'
+                    }
+                }
+            }
+        },
         components: {
             LineExample
         }