feat(supplement): 添加设备流程表单自动回填缓存数据并禁用编辑;payload 携带 SN
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
85402f2ec1
commit
cc8dfb4f6e
+8
-8
@@ -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'
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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,16 +264,43 @@ 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) : ''
|
||||||
|
|
||||||
const serverResult = this.data.serverResult as UserInfoFromServer
|
let payload: UpdateUserPayload
|
||||||
const payload: UpdateUserPayload = {
|
|
||||||
...serverResult,
|
if (this.data.readonly) {
|
||||||
idCard,
|
// readonly 模式:从缓存 userInfo 构建 payload
|
||||||
realname: name.trim(),
|
const userInfo = wx.getStorageSync('userInfo') as Record<string, any>
|
||||||
height: heightNum,
|
const { connectDeviceInfo: _c, ...rest } = userInfo
|
||||||
weight: weightNum,
|
payload = {
|
||||||
sex: parsed.sex,
|
...rest,
|
||||||
birthday: parsed.birthday,
|
idCard,
|
||||||
connectDeviceInfo
|
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)
|
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>
|
||||||
|
|||||||
Reference in New Issue
Block a user