Remove all fitting detection logic (setParams, fitting event listener, timeout). User manually confirms wearing, then proceeds to detection page. No BLE commands sent on this page.
73 行
1.7 KiB
JavaScript
73 行
1.7 KiB
JavaScript
var ble = require('../../services/ble')
|
|
|
|
Page({
|
|
data: {
|
|
statusBarHeight: 44,
|
|
battery: 0,
|
|
connected: false,
|
|
regions: 0x1F
|
|
},
|
|
|
|
onBack: function () {
|
|
wx.navigateBack({
|
|
fail: function () {
|
|
wx.reLaunch({ url: '/pages/index/index' })
|
|
}
|
|
})
|
|
},
|
|
|
|
onLoad: function (options) {
|
|
var app = getApp()
|
|
this.setData({
|
|
statusBarHeight: app.globalData.statusBarHeight,
|
|
connected: ble.isConnected(),
|
|
regions: parseInt(options.regions) || 0x1F
|
|
})
|
|
var device = app.globalData.currentDevice || {}
|
|
this.setData({ battery: device.battery || 0 })
|
|
},
|
|
|
|
onNext: function () {
|
|
if (!ble.isConnected()) {
|
|
wx.showToast({ title: '设备未连接', icon: 'none' })
|
|
return
|
|
}
|
|
wx.redirectTo({
|
|
url: '/pages/auto-scan/auto-scan?regions=' + this.data.regions
|
|
})
|
|
},
|
|
|
|
onRetry: function () {
|
|
var self = this
|
|
if (ble.isConnected()) {
|
|
self.setData({ connected: true })
|
|
return
|
|
}
|
|
self.setData({ connected: false })
|
|
ble.disconnect()
|
|
setTimeout(function () {
|
|
ble.startScan({
|
|
onFound: function () {},
|
|
onConnected: function () {
|
|
clearTimeout(self._reconnectTimer)
|
|
self.setData({ connected: true })
|
|
wx.showToast({ title: '连接成功', icon: 'success' })
|
|
},
|
|
onError: function (err) {
|
|
clearTimeout(self._reconnectTimer)
|
|
wx.showToast({ title: err.msg || '连接失败', icon: 'none' })
|
|
}
|
|
})
|
|
self._reconnectTimer = setTimeout(function () {
|
|
ble.stopScan()
|
|
wx.showToast({ title: '搜索超时', icon: 'none' })
|
|
}, 15000)
|
|
}, 500)
|
|
},
|
|
|
|
onUnload: function () {
|
|
clearTimeout(this._reconnectTimer)
|
|
ble.stopScan()
|
|
}
|
|
})
|