feat(supplement): 添加设备流程表单自动回填缓存数据并禁用编辑;payload 携带 SN

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
17792275749
2026-05-26 17:28:04 +08:00
co-authored by Claude Sonnet 4.6
parent 85402f2ec1
commit cc8dfb4f6e
4 changed files with 73 additions and 24 deletions
+8 -8
View File
@@ -6,13 +6,13 @@ App<IAppOption>({
onLaunch() {
// 已登录则跳过登录页
const userInfo = wx.getStorageSync('userInfo')
if (userInfo) {
const connectDeviceInfo = wx.getStorageSync('connectDeviceInfo')
const hasDevice = connectDeviceInfo && Object.keys(connectDeviceInfo).length > 0
wx.reLaunch({
url: hasDevice ? '/pages/home/home' : '/pages/connectedDevice/connectedDevice'
})
}
// const userInfo = wx.getStorageSync('userInfo')
// if (userInfo) {
// const connectDeviceInfo = wx.getStorageSync('connectDeviceInfo')
// const hasDevice = connectDeviceInfo && Object.keys(connectDeviceInfo).length > 0
// wx.reLaunch({
// url: hasDevice ? '/pages/home/home' : '/pages/connectedDevice/connectedDevice'
// })
// }
},
})
+1 -1
View File
@@ -168,7 +168,7 @@
justify-content: center;
background-color: #1385FA;
border-radius: 44rpx;
margin: 40rpx auto;
margin: 20rpx auto;
flex-shrink: 0;
.add-btn-icon {
@@ -80,7 +80,29 @@ Page({
/** 正在请求身份证查询接口 */
querying: false,
/** 接口返回的用户信息,提交时透传给更新接口 */
serverResult: null as UserInfoFromServer | null
serverResult: null as UserInfoFromServer | null,
/** 表单是否只读(从添加设备流程过来时为 true) */
readonly: false
},
onLoad() {
// 已有连接设备 → 从缓存 userInfo 回填表单并禁用编辑
const connectDeviceInfo = wx.getStorageSync('connectDeviceInfo')
if (!connectDeviceInfo || JSON.stringify(connectDeviceInfo) === '{}') return
const userInfo = wx.getStorageSync('userInfo') as Record<string, any> | null
if (!userInfo?.userId) return
const parsed = this.parseIdCard(userInfo.idCard ?? '')
this.setData({
readonly: true,
'form.name': userInfo.realname ?? '',
'form.idCard': userInfo.idCard ?? '',
'form.gender': parsed.gender || userInfo.sex_dictText || '',
'form.age': parsed.age || '',
'form.height': userInfo.height != null ? String(userInfo.height) : '',
'form.weight': userInfo.weight != null ? String(userInfo.weight) : '',
})
},
/**
@@ -235,10 +257,6 @@ Page({
wx.showToast({ title: '请填写体重', icon: 'none' })
return
}
if (!this.data.serverResult) {
wx.showToast({ title: '身份信息未验证,请检查姓名与身份证号', icon: 'none' })
return
}
const parsed = this.parseIdCard(idCard)
@@ -246,16 +264,43 @@ Page({
const connectDeviceInfoRaw = wx.getStorageSync('connectDeviceInfo')
const connectDeviceInfo: string = connectDeviceInfoRaw ? JSON.stringify(connectDeviceInfoRaw) : ''
const serverResult = this.data.serverResult as UserInfoFromServer
const payload: UpdateUserPayload = {
...serverResult,
idCard,
realname: name.trim(),
height: heightNum,
weight: weightNum,
sex: parsed.sex,
birthday: parsed.birthday,
connectDeviceInfo
let payload: UpdateUserPayload
if (this.data.readonly) {
// readonly 模式:从缓存 userInfo 构建 payload
const userInfo = wx.getStorageSync('userInfo') as Record<string, any>
const { connectDeviceInfo: _c, ...rest } = userInfo
payload = {
...rest,
idCard,
realname: name.trim(),
height: heightNum,
weight: weightNum,
sex: parsed.sex,
birthday: parsed.birthday,
sn: lefuService.deviceInfo?.serialNumber ?? '',
scaleDeviceId: lefuService.deviceInfo?.serialNumber ?? '',
connectDeviceInfo,
} as UpdateUserPayload
} else {
// 正常模式:需要 serverResult
if (!this.data.serverResult) {
wx.showToast({ title: '身份信息未验证,请检查姓名与身份证号', icon: 'none' })
return
}
const serverResult = this.data.serverResult as UserInfoFromServer
payload = {
...serverResult,
idCard,
realname: name.trim(),
height: heightNum,
weight: weightNum,
sex: parsed.sex,
birthday: parsed.birthday,
sn: lefuService.deviceInfo?.serialNumber ?? '',
scaleDeviceId: lefuService.deviceInfo?.serialNumber ?? '',
connectDeviceInfo,
}
}
put<UpdateUserPayload>('weighingScale/v3/update/user', payload)
@@ -23,6 +23,7 @@
placeholder="请填写真实姓名"
placeholder-class="form-placeholder"
value="{{ form.name }}"
disabled="{{ readonly }}"
bind:input="onNameInput" />
</view>
</view>
@@ -40,6 +41,7 @@
placeholder="请填写身份证号"
placeholder-class="form-placeholder"
value="{{ form.idCard }}"
disabled="{{ readonly }}"
bind:input="onIdCardInput" />
</view>
</view>
@@ -93,6 +95,7 @@
placeholder="请填写身高"
placeholder-class="form-placeholder"
value="{{ form.height }}"
disabled="{{ readonly }}"
bind:input="onHeightInput" />
<text class="form-suffix form-suffix-inside">cm</text>
</view>
@@ -113,6 +116,7 @@
placeholder="请填写体重"
placeholder-class="form-placeholder"
value="{{ form.weight }}"
disabled="{{ readonly }}"
bind:input="onWeightInput" />
<text class="form-suffix form-suffix-inside">kg</text>
</view>