diff --git a/banban-mini/src/pages/sleep/index.scss b/banban-mini/src/pages/sleep/index.scss index e9acbe3..22cf3bd 100644 --- a/banban-mini/src/pages/sleep/index.scss +++ b/banban-mini/src/pages/sleep/index.scss @@ -677,22 +677,6 @@ overflow-y: auto; } -.device-switch-footer { - margin-top: 20px; -} - -.device-switch-add { - display: flex; - align-items: center; - justify-content: center; - height: 84px; - border-radius: 18px; - background: #FFF2E7; - font-size: 28px; - color: #FF8C42; - font-weight: 600; -} - .device-switch-item { padding: 24px; border-radius: 18px; @@ -796,6 +780,16 @@ } } +.device-switch-edit { + padding: 6px 14px; + border-radius: 999px; + background: #FFFFFF; + border: 2px solid #FF8C42; + font-size: 22px; + color: #FF8C42; + flex-shrink: 0; +} + .device-switch-name { font-size: 26px; color: #666666; diff --git a/banban-mini/src/pages/sleep/index.tsx b/banban-mini/src/pages/sleep/index.tsx index 05d1372..2ed8c1c 100644 --- a/banban-mini/src/pages/sleep/index.tsx +++ b/banban-mini/src/pages/sleep/index.tsx @@ -15,7 +15,7 @@ import { updateBindingCardName, unbindDevice, } from '@/services/binding' -import { Child, clearSelectedChildId, createChild, deleteChild, setSelectedChildId, updateChild } from '@/services/child' +import { Child, clearSelectedChildId, deleteChild, setSelectedChildId, updateChild } from '@/services/child' import { createFamilyInvitation, FamilyMember, @@ -96,7 +96,6 @@ export default function Sleep() { const [showFamilyNameModal, setShowFamilyNameModal] = useState(false) const [showAssignDeviceModal, setShowAssignDeviceModal] = useState(false) const [showCardNameModal, setShowCardNameModal] = useState(false) - const [modalType, setModalType] = useState<'add' | 'edit'>('add') const [childName, setChildName] = useState('') const [editingChildId, setEditingChildId] = useState(null) const [editingCard, setEditingCard] = useState(null) @@ -539,10 +538,10 @@ export default function Sleep() { }) } - const handleOpenModal = (type: 'add' | 'edit', child?: Child) => { - setModalType(type) - setChildName(child?.child_name || '') - setEditingChildId(child?.child_id || null) + const handleOpenChildNameModal = (child: Child) => { + setChildName(child.child_name || '') + setEditingChildId(child.child_id) + setShowChildModal(false) setShowModal(true) } @@ -573,12 +572,6 @@ export default function Sleep() { }) } - const handleOpenAddChildFromSwitch = () => { - setShowChildModal(false) - setShowAssignDeviceModal(false) - handleOpenModal('add') - } - const handleOpenCardNameModal = (card: BindingCardItem) => { setEditingCard(card) setCardName(card.card_name || '') @@ -636,15 +629,13 @@ export default function Sleep() { } try { - if (modalType === 'add') { - const createdChild = await createChild({ child_name: normalizedName }) - setSelectedChildId(createdChild.child_id) - Taro.showToast({ title: '创建成功', icon: 'success' }) - } else if (editingChildId) { - await updateChild(editingChildId, { child_name: normalizedName }) - Taro.showToast({ title: '修改成功', icon: 'success' }) + if (!editingChildId) { + Taro.showToast({ title: '当前没有可修改的孩子', icon: 'none' }) + return } + await updateChild(editingChildId, { child_name: normalizedName }) + Taro.showToast({ title: '修改成功', icon: 'success' }) handleCloseModal() await loadData() } catch (error: any) { @@ -899,15 +890,6 @@ export default function Sleep() { return } - if (item.name === '编辑当前孩子') { - if (currentChild) { - handleOpenModal('edit', currentChild) - } else { - handleOpenModal('add') - } - return - } - if (item.name === '删除孩子') { setShowDeleteChildModal(true) return @@ -1070,13 +1052,6 @@ export default function Sleep() { value: currentChildName, arrow: true, }, - { - icon: require('../../assets/tab-icons/orange-robot.png'), - iconBgClass: 'orange', - name: '编辑当前孩子', - value: '', - arrow: true, - }, { icon: require('../../assets/tab-icons/broken-rings.png'), iconBgClass: 'red', @@ -1320,7 +1295,20 @@ export default function Sleep() { > {item.child_name} - {isActive && 当前} + + {isActive && 当前} + {isActive && ( + { + event.stopPropagation() + handleOpenChildNameModal(item) + }} + > + 修改 + + )} + {itemBinding?.device_id || '未绑定设备'} @@ -1328,11 +1316,6 @@ export default function Sleep() { })} )} - - - + 新增孩子 - - setShowChildModal(false)}> 关闭 @@ -1414,11 +1397,6 @@ export default function Sleep() { ))} )} - - - + 新增孩子 - - setShowAssignDeviceModal(false)}> 关闭 @@ -1431,7 +1409,7 @@ export default function Sleep() { {showModal && ( - {modalType === 'add' ? '新建儿童资料' : '修改儿童昵称'} + 修改儿童昵称