From 1dfda24645185107f6667366637effce59f48711 Mon Sep 17 00:00:00 2001 From: 17792275749 <812100002@qq.com> Date: Wed, 2 Sep 2026 19:44:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(addUser):=20=E7=94=9F=E6=97=A5=E4=B8=8D?= =?UTF-8?q?=E8=B6=85=E4=BB=8A=E5=A4=A9=E3=80=81=E8=BA=AB=E9=AB=98=E4=BD=93?= =?UTF-8?q?=E9=87=8D=E8=8C=83=E5=9B=B4=E6=A0=A1=E9=AA=8C=E5=B9=B6=E5=A4=B1?= =?UTF-8?q?=E7=84=A6=E6=B8=85=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 出生年月 picker 限制到今天 - 身高 50-250cm、体重 20-300kg - 失焦时越界值清空并提示 Co-Authored-By: Claude Opus 4.7 --- miniprogram/pages/addUser/addUser.ts | 45 ++++++++++++++++++++------ miniprogram/pages/addUser/addUser.wxml | 10 +++--- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/miniprogram/pages/addUser/addUser.ts b/miniprogram/pages/addUser/addUser.ts index 1a3b2d2..3055bb1 100644 --- a/miniprogram/pages/addUser/addUser.ts +++ b/miniprogram/pages/addUser/addUser.ts @@ -55,13 +55,16 @@ Page({ rawUser: null as Record | null, isEdit: false, queryError: false, + today: '', }, onLoad(options: Record) { targetSn = decodeURIComponent(options.sn || '') console.log(targetSn); editId = decodeURIComponent(options.id || '') - this.setData({ isEdit: !!editId }) + const now = new Date() + const today = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}` + this.setData({ isEdit: !!editId, today }) if (editId) { this._loadEditUser(editId) } @@ -295,6 +298,28 @@ Page({ this.setData({ 'form.weight': e.detail.value }) }, + /** 身高失焦校验:不在 50-250 则清空 */ + onHeightBlur() { + const height = this.data.form.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({ 'form.height': '' }) + } + }, + + /** 体重失焦校验:不在 20-300 则清空 */ + onWeightBlur() { + const weight = this.data.form.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({ 'form.weight': '' }) + } + }, + /** 复用已有信息:关弹框直接提交 */ onConfirmModalConfirm() { this.setData({ showConfirmModal: false }) @@ -329,10 +354,6 @@ Page({ wx.showToast({ title: '请先查询员工信息', icon: 'none' }) return } - if (!height || isNaN(heightNum) || heightNum <= 0) { - wx.showToast({ title: '请填写身高', icon: 'none' }) - return - } } else { if (!name.trim()) { wx.showToast({ title: '请填写昵称', icon: 'none' }) @@ -346,10 +367,16 @@ Page({ wx.showToast({ title: '请填写出生年月', icon: 'none' }) return } - if (!height || isNaN(heightNum) || heightNum <= 0) { - wx.showToast({ title: '请填写身高', icon: 'none' }) - return - } + } + + // 身高体重范围校验(员工/家庭用户共用) + 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/addUser/addUser.wxml b/miniprogram/pages/addUser/addUser.wxml index 208e877..0e45f4c 100644 --- a/miniprogram/pages/addUser/addUser.wxml +++ b/miniprogram/pages/addUser/addUser.wxml @@ -78,7 +78,7 @@ - + cm @@ -87,7 +87,7 @@ 体重 - + kg @@ -142,7 +142,7 @@ * - + {{ birthday || '请选择出生年月' }} @@ -157,7 +157,7 @@ - + cm @@ -166,7 +166,7 @@ 体重 - + kg