feat: add loading animation on reconnect button, 5s timeout

这个提交包含在:
Guoguo
2026-07-02 06:06:11 -07:00
父节点 dae50a74fd
当前提交 5775568cd6
修改 2 个文件,包含 9 行新增5 行删除
+8 -4
查看文件
@@ -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)
}, },
+1 -1
查看文件
@@ -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>