[AI Generated]: feat(device): 扫描命中缓存设备自动连接(不跳转),整卡点击按状态跳转/连接
- connectedDevice:扫描列表与 connectDeviceInfo 缓存按 deviceId 实时比对,命中后一次性自动连,仅刷状态/缓存不跳页 - connectedDevice:新增 onTapCard,整卡点击 → 已连接跳 connectedWifi,未连接走 onConnect;按钮改 catch:tap 防冒泡 - connectedWifi:移除 onConfirm 中下发主用户与 calcAge/StoredUserInfo 残留,统一跳 supplementPersonal Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
b94ffb7995
commit
b979771650
@@ -1,25 +1,5 @@
|
||||
import { lefuService } 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)
|
||||
}
|
||||
import type { LeFuWifiItem } from '../../lefu/index'
|
||||
|
||||
interface WifiItem {
|
||||
ssid: string
|
||||
@@ -146,29 +126,6 @@ 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