feat(supplementPersonal): 身高体重范围校验并失焦清空
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
1dfda24645
commit
e0f201f15c
@@ -123,6 +123,28 @@ Page({
|
||||
this.setData({ weight: e.detail.value })
|
||||
},
|
||||
|
||||
/** 身高失焦校验:不在 50-250 则清空 */
|
||||
onHeightBlur() {
|
||||
const height = this.data.height.trim()
|
||||
if (!height) return
|
||||
const h = parseFloat(height)
|
||||
if (isNaN(h) || h < 50 || h > 250) {
|
||||
wx.showToast({ title: '身高需在50-250cm之间', icon: 'none' })
|
||||
this.setData({ height: '' })
|
||||
}
|
||||
},
|
||||
|
||||
/** 体重失焦校验:不在 20-300 则清空 */
|
||||
onWeightBlur() {
|
||||
const weight = this.data.weight.trim()
|
||||
if (!weight) return
|
||||
const w = parseFloat(weight)
|
||||
if (isNaN(w) || w < 20 || w > 300) {
|
||||
wx.showToast({ title: '体重需在20-300kg之间', icon: 'none' })
|
||||
this.setData({ weight: '' })
|
||||
}
|
||||
},
|
||||
|
||||
async onSubmit() {
|
||||
const { name, idCard, height, weight } = this.data
|
||||
const heightNum = parseFloat(height)
|
||||
@@ -136,8 +158,12 @@ Page({
|
||||
wx.showToast({ title: '请填写正确的身份证号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!height || isNaN(heightNum) || heightNum <= 0) {
|
||||
wx.showToast({ title: '请填写身高', icon: 'none' })
|
||||
if (!height || isNaN(heightNum) || heightNum < 50 || heightNum > 250) {
|
||||
wx.showToast({ title: '身高需在50-250cm之间', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (weight && (isNaN(weightNum) || weightNum < 20 || weightNum > 300)) {
|
||||
wx.showToast({ title: '体重需在20-300kg之间', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,8 @@
|
||||
placeholder-class="form-placeholder"
|
||||
value="{{ height }}"
|
||||
disabled="{{ readonly }}"
|
||||
bind:input="onHeightInput" />
|
||||
bind:input="onHeightInput"
|
||||
bind:blur="onHeightBlur" />
|
||||
<text class="form-suffix form-suffix-inside">cm</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -99,7 +100,8 @@
|
||||
placeholder-class="form-placeholder"
|
||||
value="{{ weight }}"
|
||||
disabled="{{ readonly }}"
|
||||
bind:input="onWeightInput" />
|
||||
bind:input="onWeightInput"
|
||||
bind:blur="onWeightBlur" />
|
||||
<text class="form-suffix form-suffix-inside">kg</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user