[AI Generated]: feat(device): 配网/绑定后下发主用户到设备并兜底超时
- configWifi 加 20s 超时与 settled 互锁,避免回调不触发导致 loading 死转 - supplementPersonal 提交后、connectedWifi 二次配网确认后均下发主用户 - 设备成员唯一标识从 idCard 切换为 userId,清理 MemberDisplay.idCard Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
e4404a6b0c
commit
ea52c495f6
@@ -1,5 +1,25 @@
|
||||
import { lefuService } from '../../lefu/index'
|
||||
import type { LeFuWifiItem } from '../../lefu/index'
|
||||
import type { LeFuWifiItem, DeviceMember } from '../../lefu/index'
|
||||
|
||||
/** 本地 userInfo 关键字段,用于下发主用户到新设备 */
|
||||
interface StoredUserInfo {
|
||||
userId: string
|
||||
realname: string
|
||||
sex: number
|
||||
height: number
|
||||
birthday: string
|
||||
}
|
||||
|
||||
/** 从生日字符串(YYYY-MM-DD)计算周岁 */
|
||||
const calcAge = (birthday: string): number => {
|
||||
if (!birthday) return 0
|
||||
const [y, m, d] = birthday.split('-').map(Number)
|
||||
if (!y || !m || !d) return 0
|
||||
const now = new Date()
|
||||
let age = now.getFullYear() - y
|
||||
if (now.getMonth() + 1 < m || (now.getMonth() + 1 === m && now.getDate() < d)) age -= 1
|
||||
return Math.max(0, age)
|
||||
}
|
||||
|
||||
interface WifiItem {
|
||||
ssid: string
|
||||
@@ -126,6 +146,29 @@ Page({
|
||||
|
||||
onConfirm() {
|
||||
if (!this.data.hasConnected) return
|
||||
// 已有 userInfo 表示是从首页/设备页添加新设备,需把主用户下发到新设备后回首页
|
||||
const userInfo = wx.getStorageSync('userInfo') as StoredUserInfo | null
|
||||
if (userInfo) {
|
||||
const mainUser: DeviceMember = {
|
||||
id: userInfo.userId,
|
||||
name: userInfo.realname,
|
||||
gender: userInfo.sex === 1 ? 1 : 0,
|
||||
age: calcAge(userInfo.birthday),
|
||||
height: userInfo.height,
|
||||
isSelf: true,
|
||||
}
|
||||
wx.showLoading({ title: '正在下发主用户...', mask: true })
|
||||
lefuService.syncMembersToDevice([mainUser])
|
||||
.then(() => {
|
||||
wx.hideLoading()
|
||||
wx.switchTab({ url: '/pages/home/home' })
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: err.message || '主用户下发失败', icon: 'none' })
|
||||
})
|
||||
return
|
||||
}
|
||||
wx.navigateTo({ url: '/pages/supplementPersonal/supplementPersonal' })
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user