Refine child management entry points

This commit is contained in:
stu2not
2026-07-02 10:37:46 +08:00
parent 429d96a9b3
commit 998401f8c9
2 changed files with 35 additions and 63 deletions

View File

@@ -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;

View File

@@ -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<number | null>(null)
const [editingCard, setEditingCard] = useState<BindingCardItem | null>(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() {
>
<View className='device-switch-head'>
<Text className='device-switch-id'>{item.child_name}</Text>
{isActive && <Text className='device-switch-tag'></Text>}
<View className='device-switch-tags'>
{isActive && <Text className='device-switch-tag'></Text>}
{isActive && (
<Text
className='device-switch-edit'
onClick={(event) => {
event.stopPropagation()
handleOpenChildNameModal(item)
}}
>
</Text>
)}
</View>
</View>
<Text className='device-switch-name'>{itemBinding?.device_id || '未绑定设备'}</Text>
</View>
@@ -1328,11 +1316,6 @@ export default function Sleep() {
})}
</View>
)}
<View className='device-switch-footer'>
<Text className='device-switch-add' onClick={handleOpenAddChildFromSwitch}>
+
</Text>
</View>
<View className='modal-actions'>
<Text className='modal-action cancel' onClick={() => setShowChildModal(false)}>
@@ -1414,11 +1397,6 @@ export default function Sleep() {
))}
</View>
)}
<View className='device-switch-footer'>
<Text className='device-switch-add' onClick={handleOpenAddChildFromSwitch}>
+
</Text>
</View>
<View className='modal-actions'>
<Text className='modal-action cancel' onClick={() => setShowAssignDeviceModal(false)}>
@@ -1431,7 +1409,7 @@ export default function Sleep() {
{showModal && (
<View className='modal-mask'>
<View className='modal-card'>
<Text className='modal-title'>{modalType === 'add' ? '新建儿童资料' : '修改儿童昵称'}</Text>
<Text className='modal-title'></Text>
<View className='modal-input-wrap'>
<Input
className='modal-input'