feat(lefu): 切后台挂起连接、回前台自动重连

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
17792275749
2026-08-25 20:57:00 +08:00
co-authored by Claude Opus 4.7
parent 3dea0382f7
commit e95d28a87b
2 changed files with 73 additions and 7 deletions
+22 -2
View File
@@ -1,6 +1,9 @@
App<IAppOption>({
import { leFuService } from './lefu/index'
App<IAppOption>({
globalData: {
operationsEngineer: false
operationsEngineer: false,
wasConnected: false
},
onLaunch() {
@@ -15,6 +18,23 @@
}
},
onHide() {
// 切后台:记录连接状态,挂起(断开但保留缓存设备,回前台可重连)
const wasConnected = leFuService.isConnected
this.globalData.wasConnected = wasConnected
if (wasConnected) {
leFuService.suspend()
}
},
onShow() {
// 回前台:如果之前连接过,自动重连
if (this.globalData.wasConnected) {
this.globalData.wasConnected = false
leFuService.autoConnect()
}
},
getWxLoginCode(): Promise<string> {
return new Promise((resolve, reject) => {
wx.login({