|
|
@@ -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
|
|
|
}
|