diff --git a/miniprogram/pages/supplementPersonal/supplementPersonal.ts b/miniprogram/pages/supplementPersonal/supplementPersonal.ts
index 9312de9..628fc8e 100644
--- a/miniprogram/pages/supplementPersonal/supplementPersonal.ts
+++ b/miniprogram/pages/supplementPersonal/supplementPersonal.ts
@@ -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
}
diff --git a/miniprogram/pages/supplementPersonal/supplementPersonal.wxml b/miniprogram/pages/supplementPersonal/supplementPersonal.wxml
index 8bde356..5a793bd 100644
--- a/miniprogram/pages/supplementPersonal/supplementPersonal.wxml
+++ b/miniprogram/pages/supplementPersonal/supplementPersonal.wxml
@@ -80,7 +80,8 @@
placeholder-class="form-placeholder"
value="{{ height }}"
disabled="{{ readonly }}"
- bind:input="onHeightInput" />
+ bind:input="onHeightInput"
+ bind:blur="onHeightBlur" />
cm
@@ -99,7 +100,8 @@
placeholder-class="form-placeholder"
value="{{ weight }}"
disabled="{{ readonly }}"
- bind:input="onWeightInput" />
+ bind:input="onWeightInput"
+ bind:blur="onWeightBlur" />
kg