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() { onLaunch() {
// 已登录则跳过登录页 // 已登录则跳过登录页
const userInfo = wx.getStorageSync('userInfo') // const userInfo = wx.getStorageSync('userInfo')
if (userInfo) { // if (userInfo) {
const connectDeviceInfo = wx.getStorageSync('connectDeviceInfo') // const connectDeviceInfo = wx.getStorageSync('connectDeviceInfo')
const hasDevice = connectDeviceInfo && Object.keys(connectDeviceInfo).length > 0 // const hasDevice = connectDeviceInfo && Object.keys(connectDeviceInfo).length > 0
wx.reLaunch({ // wx.reLaunch({
url: hasDevice ? '/pages/home/home' : '/pages/connectedDevice/connectedDevice' // url: hasDevice ? '/pages/home/home' : '/pages/connectedDevice/connectedDevice'
}) // })
} // }
}, },
}) })
+1 -1
View File
@@ -168,7 +168,7 @@
justify-content: center; justify-content: center;
background-color: #1385FA; background-color: #1385FA;
border-radius: 44rpx; border-radius: 44rpx;
margin: 40rpx auto; margin: 20rpx auto;
flex-shrink: 0; flex-shrink: 0;
.add-btn-icon { .add-btn-icon {
@@ -80,7 +80,29 @@ Page({
/** 正在请求身份证查询接口 */ /** 正在请求身份证查询接口 */
querying: false, 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' }) wx.showToast({ title: '请填写体重', icon: 'none' })
return return
} }
if (!this.data.serverResult) {
wx.showToast({ title: '身份信息未验证,请检查姓名与身份证号', icon: 'none' })
return
}
const parsed = this.parseIdCard(idCard) const parsed = this.parseIdCard(idCard)
@@ -246,8 +264,32 @@ Page({
const connectDeviceInfoRaw = wx.getStorageSync('connectDeviceInfo') const connectDeviceInfoRaw = wx.getStorageSync('connectDeviceInfo')
const connectDeviceInfo: string = connectDeviceInfoRaw ? JSON.stringify(connectDeviceInfoRaw) : '' const connectDeviceInfo: string = connectDeviceInfoRaw ? JSON.stringify(connectDeviceInfoRaw) : ''
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 const serverResult = this.data.serverResult as UserInfoFromServer
const payload: UpdateUserPayload = { payload = {
...serverResult, ...serverResult,
idCard, idCard,
realname: name.trim(), realname: name.trim(),
@@ -255,7 +297,10 @@ Page({
weight: weightNum, weight: weightNum,
sex: parsed.sex, sex: parsed.sex,
birthday: parsed.birthday, birthday: parsed.birthday,
connectDeviceInfo sn: lefuService.deviceInfo?.serialNumber ?? '',
scaleDeviceId: lefuService.deviceInfo?.serialNumber ?? '',
connectDeviceInfo,
}
} }
put<UpdateUserPayload>('weighingScale/v3/update/user', payload) put<UpdateUserPayload>('weighingScale/v3/update/user', payload)
@@ -23,6 +23,7 @@
placeholder="请填写真实姓名" placeholder="请填写真实姓名"
placeholder-class="form-placeholder" placeholder-class="form-placeholder"
value="{{ form.name }}" value="{{ form.name }}"
disabled="{{ readonly }}"
bind:input="onNameInput" /> bind:input="onNameInput" />
</view> </view>
</view> </view>
@@ -40,6 +41,7 @@
placeholder="请填写身份证号" placeholder="请填写身份证号"
placeholder-class="form-placeholder" placeholder-class="form-placeholder"
value="{{ form.idCard }}" value="{{ form.idCard }}"
disabled="{{ readonly }}"
bind:input="onIdCardInput" /> bind:input="onIdCardInput" />
</view> </view>
</view> </view>
@@ -93,6 +95,7 @@
placeholder="请填写身高" placeholder="请填写身高"
placeholder-class="form-placeholder" placeholder-class="form-placeholder"
value="{{ form.height }}" value="{{ form.height }}"
disabled="{{ readonly }}"
bind:input="onHeightInput" /> bind:input="onHeightInput" />
<text class="form-suffix form-suffix-inside">cm</text> <text class="form-suffix form-suffix-inside">cm</text>
</view> </view>
@@ -113,6 +116,7 @@
placeholder="请填写体重" placeholder="请填写体重"
placeholder-class="form-placeholder" placeholder-class="form-placeholder"
value="{{ form.weight }}" value="{{ form.weight }}"
disabled="{{ readonly }}"
bind:input="onWeightInput" /> bind:input="onWeightInput" />
<text class="form-suffix form-suffix-inside">kg</text> <text class="form-suffix form-suffix-inside">kg</text>
</view> </view>