From 37ff907815e5b7532750b0778a0f758b6ebc9663 Mon Sep 17 00:00:00 2001 From: iven Date: Fri, 24 Apr 2026 12:50:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(miniprogram):=20=E7=94=A8=E8=8D=AF?= =?UTF-8?q?=E6=8F=90=E9=86=92=E6=97=B6=E9=97=B4=E9=80=89=E6=8B=A9=E5=99=A8?= =?UTF-8?q?=20+=20=E5=AE=B6=E4=BA=BA=E7=BC=96=E8=BE=91=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 用药提醒页:时间输入改为 Taro TimePicker 原生选择器 - 家人列表页:每个就诊人增加编辑按钮入口 - 家人添加页:支持编辑模式(URL 传 id + Storage 传数据 + updatePatient API) --- .../src/pages/profile/family-add/index.tsx | 60 ++++++++++++------- .../src/pages/profile/family/index.scss | 9 +++ .../src/pages/profile/family/index.tsx | 6 ++ .../src/pages/profile/medication/index.tsx | 15 +++-- 4 files changed, 64 insertions(+), 26 deletions(-) diff --git a/apps/miniprogram/src/pages/profile/family-add/index.tsx b/apps/miniprogram/src/pages/profile/family-add/index.tsx index 02c352d..44ee07c 100644 --- a/apps/miniprogram/src/pages/profile/family-add/index.tsx +++ b/apps/miniprogram/src/pages/profile/family-add/index.tsx @@ -1,19 +1,31 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { View, Text, Input, Picker } from '@tarojs/components'; -import Taro from '@tarojs/taro'; -import { createPatient } from '../../../services/patient'; +import Taro, { useRouter } from '@tarojs/taro'; +import { createPatient, updatePatient, Patient } from '../../../services/patient'; import './index.scss'; const RELATION_OPTIONS = ['本人', '配偶', '父母', '子女', '其他']; const GENDER_OPTIONS = ['男', '女']; export default function FamilyAdd() { - const [name, setName] = useState(''); - const [relationIdx, setRelationIdx] = useState(0); - const [genderIdx, setGenderIdx] = useState(0); - const [birthDate, setBirthDate] = useState(''); + const router = useRouter(); + const editId = router.params.id || ''; + const editData = Taro.getStorageSync('edit_patient') as Patient | null; + + const [name, setName] = useState(editData?.name || ''); + const [relationIdx, setRelationIdx] = useState( + editData?.relation ? RELATION_OPTIONS.indexOf(editData.relation) : 0 + ); + const [genderIdx, setGenderIdx] = useState( + editData?.gender === 'female' ? 1 : 0 + ); + const [birthDate, setBirthDate] = useState(editData?.birthday || ''); const [submitting, setSubmitting] = useState(false); + useEffect(() => { + return () => { Taro.removeStorageSync('edit_patient'); }; + }, []); + const handleSubmit = async () => { if (!name.trim()) { Taro.showToast({ title: '请输入姓名', icon: 'none' }); @@ -21,17 +33,25 @@ export default function FamilyAdd() { } setSubmitting(true); try { - await createPatient({ - name: name.trim(), - gender: GENDER_OPTIONS[genderIdx] === '男' ? 'male' : 'female', - birthday: birthDate || undefined, - }); - Taro.showToast({ title: '添加成功', icon: 'success' }); - setTimeout(() => { - Taro.navigateBack(); - }, 1000); + if (editId && editData) { + await updatePatient(editId, { + name: name.trim(), + gender: GENDER_OPTIONS[genderIdx] === '男' ? 'male' : 'female', + birthday: birthDate || undefined, + relation: RELATION_OPTIONS[relationIdx], + }, editData.version); + Taro.showToast({ title: '修改成功', icon: 'success' }); + } else { + await createPatient({ + name: name.trim(), + gender: GENDER_OPTIONS[genderIdx] === '男' ? 'male' : 'female', + birthday: birthDate || undefined, + }); + Taro.showToast({ title: '添加成功', icon: 'success' }); + } + setTimeout(() => Taro.navigateBack(), 1000); } catch { - Taro.showToast({ title: '添加失败', icon: 'none' }); + Taro.showToast({ title: editId ? '修改失败' : '添加失败', icon: 'none' }); } finally { setSubmitting(false); } @@ -40,7 +60,6 @@ export default function FamilyAdd() { return ( - {/* 姓名 */} 姓名 - {/* 关系 */} 关系 - {/* 性别 */} 性别 - {/* 出生日期 */} 出生日期 - {submitting ? '提交中...' : '确认添加'} + {submitting ? '提交中...' : editId ? '保存修改' : '确认添加'} ); diff --git a/apps/miniprogram/src/pages/profile/family/index.scss b/apps/miniprogram/src/pages/profile/family/index.scss index e75a26b..16ad4b0 100644 --- a/apps/miniprogram/src/pages/profile/family/index.scss +++ b/apps/miniprogram/src/pages/profile/family/index.scss @@ -68,6 +68,15 @@ font-weight: bold; } +.family-edit { + font-size: 24px; + color: $pri; + margin-left: 16px; + padding: 6px 16px; + border: 1px solid $pri; + border-radius: 16px; +} + .empty-state { display: flex; justify-content: center; diff --git a/apps/miniprogram/src/pages/profile/family/index.tsx b/apps/miniprogram/src/pages/profile/family/index.tsx index 671245e..d49ae09 100644 --- a/apps/miniprogram/src/pages/profile/family/index.tsx +++ b/apps/miniprogram/src/pages/profile/family/index.tsx @@ -42,6 +42,11 @@ export default function FamilyList() { Taro.navigateTo({ url: '/pages/profile/family-add/index' }); }; + const goToEdit = (patient: Patient) => { + Taro.setStorageSync('edit_patient', patient); + Taro.navigateTo({ url: `/pages/profile/family-add/index?id=${patient.id}` }); + }; + const genderText = (g?: string) => { if (g === 'male') return '男'; if (g === 'female') return '女'; @@ -67,6 +72,7 @@ export default function FamilyList() { {isActive && 当前} + { e.stopPropagation(); goToEdit(p); }}>编辑 ); })} diff --git a/apps/miniprogram/src/pages/profile/medication/index.tsx b/apps/miniprogram/src/pages/profile/medication/index.tsx index 9145049..95948fe 100644 --- a/apps/miniprogram/src/pages/profile/medication/index.tsx +++ b/apps/miniprogram/src/pages/profile/medication/index.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react'; -import { View, Text, Input } from '@tarojs/components'; +import { View, Text, Input, Picker } from '@tarojs/components'; import Taro from '@tarojs/taro'; import EmptyState from '../../../components/EmptyState'; import './index.scss'; @@ -132,9 +132,16 @@ export default function MedicationReminder() { 提醒时间 - - {formTime} - + setFormTime(e.detail.value)} + > + + {formTime} + 修改 + + setShowForm(false)}>