feat: add loading animation on reconnect button, 5s timeout
这个提交包含在:
@@ -4,7 +4,8 @@ Page({
|
|||||||
data: {
|
data: {
|
||||||
statusBarHeight: 44,
|
statusBarHeight: 44,
|
||||||
battery: 0,
|
battery: 0,
|
||||||
connected: false
|
connected: false,
|
||||||
|
reconnecting: false
|
||||||
},
|
},
|
||||||
|
|
||||||
onBack: function () {
|
onBack: function () {
|
||||||
@@ -37,29 +38,32 @@ Page({
|
|||||||
|
|
||||||
onRetry: function () {
|
onRetry: function () {
|
||||||
var self = this
|
var self = this
|
||||||
|
if (self.data.reconnecting) return
|
||||||
if (ble.isConnected()) {
|
if (ble.isConnected()) {
|
||||||
self.setData({ connected: true })
|
self.setData({ connected: true })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.setData({ connected: false })
|
self.setData({ connected: false, reconnecting: true })
|
||||||
ble.disconnect()
|
ble.disconnect()
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
ble.startScan({
|
ble.startScan({
|
||||||
onFound: function () {},
|
onFound: function () {},
|
||||||
onConnected: function () {
|
onConnected: function () {
|
||||||
clearTimeout(self._reconnectTimer)
|
clearTimeout(self._reconnectTimer)
|
||||||
self.setData({ connected: true })
|
self.setData({ connected: true, reconnecting: false })
|
||||||
wx.showToast({ title: '连接成功', icon: 'success' })
|
wx.showToast({ title: '连接成功', icon: 'success' })
|
||||||
},
|
},
|
||||||
onError: function (err) {
|
onError: function (err) {
|
||||||
clearTimeout(self._reconnectTimer)
|
clearTimeout(self._reconnectTimer)
|
||||||
|
self.setData({ reconnecting: false })
|
||||||
wx.showToast({ title: err.msg || '连接失败', icon: 'none' })
|
wx.showToast({ title: err.msg || '连接失败', icon: 'none' })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
self._reconnectTimer = setTimeout(function () {
|
self._reconnectTimer = setTimeout(function () {
|
||||||
ble.stopScan()
|
ble.stopScan()
|
||||||
|
self.setData({ reconnecting: false })
|
||||||
wx.showToast({ title: '搜索超时', icon: 'none' })
|
wx.showToast({ title: '搜索超时', icon: 'none' })
|
||||||
}, 15000)
|
}, 5000)
|
||||||
}, 500)
|
}, 500)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,6 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<button class="btn-primary" wx:if="{{connected}}" bindtap="onNext">确认已佩戴,开始检测</button>
|
<button class="btn-primary" wx:if="{{connected}}" bindtap="onNext">确认已佩戴,开始检测</button>
|
||||||
<button class="btn-secondary" wx:if="{{!connected}}" bindtap="onRetry">重新连接</button>
|
<button class="btn-secondary" wx:if="{{!connected}}" bindtap="onRetry" disabled="{{reconnecting}}" loading="{{reconnecting}}">{{reconnecting ? '正在连接...' : '重新连接'}}</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户