Refine child management entry points
This commit is contained in:
@@ -677,22 +677,6 @@
|
|||||||
overflow-y: auto;
|
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 {
|
.device-switch-item {
|
||||||
padding: 24px;
|
padding: 24px;
|
||||||
border-radius: 18px;
|
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 {
|
.device-switch-name {
|
||||||
font-size: 26px;
|
font-size: 26px;
|
||||||
color: #666666;
|
color: #666666;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
updateBindingCardName,
|
updateBindingCardName,
|
||||||
unbindDevice,
|
unbindDevice,
|
||||||
} from '@/services/binding'
|
} from '@/services/binding'
|
||||||
import { Child, clearSelectedChildId, createChild, deleteChild, setSelectedChildId, updateChild } from '@/services/child'
|
import { Child, clearSelectedChildId, deleteChild, setSelectedChildId, updateChild } from '@/services/child'
|
||||||
import {
|
import {
|
||||||
createFamilyInvitation,
|
createFamilyInvitation,
|
||||||
FamilyMember,
|
FamilyMember,
|
||||||
@@ -96,7 +96,6 @@ export default function Sleep() {
|
|||||||
const [showFamilyNameModal, setShowFamilyNameModal] = useState(false)
|
const [showFamilyNameModal, setShowFamilyNameModal] = useState(false)
|
||||||
const [showAssignDeviceModal, setShowAssignDeviceModal] = useState(false)
|
const [showAssignDeviceModal, setShowAssignDeviceModal] = useState(false)
|
||||||
const [showCardNameModal, setShowCardNameModal] = useState(false)
|
const [showCardNameModal, setShowCardNameModal] = useState(false)
|
||||||
const [modalType, setModalType] = useState<'add' | 'edit'>('add')
|
|
||||||
const [childName, setChildName] = useState('')
|
const [childName, setChildName] = useState('')
|
||||||
const [editingChildId, setEditingChildId] = useState<number | null>(null)
|
const [editingChildId, setEditingChildId] = useState<number | null>(null)
|
||||||
const [editingCard, setEditingCard] = useState<BindingCardItem | null>(null)
|
const [editingCard, setEditingCard] = useState<BindingCardItem | null>(null)
|
||||||
@@ -539,10 +538,10 @@ export default function Sleep() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOpenModal = (type: 'add' | 'edit', child?: Child) => {
|
const handleOpenChildNameModal = (child: Child) => {
|
||||||
setModalType(type)
|
setChildName(child.child_name || '')
|
||||||
setChildName(child?.child_name || '')
|
setEditingChildId(child.child_id)
|
||||||
setEditingChildId(child?.child_id || null)
|
setShowChildModal(false)
|
||||||
setShowModal(true)
|
setShowModal(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -573,12 +572,6 @@ export default function Sleep() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOpenAddChildFromSwitch = () => {
|
|
||||||
setShowChildModal(false)
|
|
||||||
setShowAssignDeviceModal(false)
|
|
||||||
handleOpenModal('add')
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleOpenCardNameModal = (card: BindingCardItem) => {
|
const handleOpenCardNameModal = (card: BindingCardItem) => {
|
||||||
setEditingCard(card)
|
setEditingCard(card)
|
||||||
setCardName(card.card_name || '')
|
setCardName(card.card_name || '')
|
||||||
@@ -636,15 +629,13 @@ export default function Sleep() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (modalType === 'add') {
|
if (!editingChildId) {
|
||||||
const createdChild = await createChild({ child_name: normalizedName })
|
Taro.showToast({ title: '当前没有可修改的孩子', icon: 'none' })
|
||||||
setSelectedChildId(createdChild.child_id)
|
return
|
||||||
Taro.showToast({ title: '创建成功', icon: 'success' })
|
|
||||||
} else if (editingChildId) {
|
|
||||||
await updateChild(editingChildId, { child_name: normalizedName })
|
|
||||||
Taro.showToast({ title: '修改成功', icon: 'success' })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await updateChild(editingChildId, { child_name: normalizedName })
|
||||||
|
Taro.showToast({ title: '修改成功', icon: 'success' })
|
||||||
handleCloseModal()
|
handleCloseModal()
|
||||||
await loadData()
|
await loadData()
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -899,15 +890,6 @@ export default function Sleep() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.name === '编辑当前孩子') {
|
|
||||||
if (currentChild) {
|
|
||||||
handleOpenModal('edit', currentChild)
|
|
||||||
} else {
|
|
||||||
handleOpenModal('add')
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.name === '删除孩子') {
|
if (item.name === '删除孩子') {
|
||||||
setShowDeleteChildModal(true)
|
setShowDeleteChildModal(true)
|
||||||
return
|
return
|
||||||
@@ -1070,13 +1052,6 @@ export default function Sleep() {
|
|||||||
value: currentChildName,
|
value: currentChildName,
|
||||||
arrow: true,
|
arrow: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
icon: require('../../assets/tab-icons/orange-robot.png'),
|
|
||||||
iconBgClass: 'orange',
|
|
||||||
name: '编辑当前孩子',
|
|
||||||
value: '',
|
|
||||||
arrow: true,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
icon: require('../../assets/tab-icons/broken-rings.png'),
|
icon: require('../../assets/tab-icons/broken-rings.png'),
|
||||||
iconBgClass: 'red',
|
iconBgClass: 'red',
|
||||||
@@ -1320,7 +1295,20 @@ export default function Sleep() {
|
|||||||
>
|
>
|
||||||
<View className='device-switch-head'>
|
<View className='device-switch-head'>
|
||||||
<Text className='device-switch-id'>{item.child_name}</Text>
|
<Text className='device-switch-id'>{item.child_name}</Text>
|
||||||
|
<View className='device-switch-tags'>
|
||||||
{isActive && <Text className='device-switch-tag'>当前</Text>}
|
{isActive && <Text className='device-switch-tag'>当前</Text>}
|
||||||
|
{isActive && (
|
||||||
|
<Text
|
||||||
|
className='device-switch-edit'
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation()
|
||||||
|
handleOpenChildNameModal(item)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
修改
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<Text className='device-switch-name'>{itemBinding?.device_id || '未绑定设备'}</Text>
|
<Text className='device-switch-name'>{itemBinding?.device_id || '未绑定设备'}</Text>
|
||||||
</View>
|
</View>
|
||||||
@@ -1328,11 +1316,6 @@ export default function Sleep() {
|
|||||||
})}
|
})}
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
<View className='device-switch-footer'>
|
|
||||||
<Text className='device-switch-add' onClick={handleOpenAddChildFromSwitch}>
|
|
||||||
+ 新增孩子
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
<View className='modal-actions'>
|
<View className='modal-actions'>
|
||||||
<Text className='modal-action cancel' onClick={() => setShowChildModal(false)}>
|
<Text className='modal-action cancel' onClick={() => setShowChildModal(false)}>
|
||||||
关闭
|
关闭
|
||||||
@@ -1414,11 +1397,6 @@ export default function Sleep() {
|
|||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
<View className='device-switch-footer'>
|
|
||||||
<Text className='device-switch-add' onClick={handleOpenAddChildFromSwitch}>
|
|
||||||
+ 新增孩子
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
<View className='modal-actions'>
|
<View className='modal-actions'>
|
||||||
<Text className='modal-action cancel' onClick={() => setShowAssignDeviceModal(false)}>
|
<Text className='modal-action cancel' onClick={() => setShowAssignDeviceModal(false)}>
|
||||||
关闭
|
关闭
|
||||||
@@ -1431,7 +1409,7 @@ export default function Sleep() {
|
|||||||
{showModal && (
|
{showModal && (
|
||||||
<View className='modal-mask'>
|
<View className='modal-mask'>
|
||||||
<View className='modal-card'>
|
<View className='modal-card'>
|
||||||
<Text className='modal-title'>{modalType === 'add' ? '新建儿童资料' : '修改儿童昵称'}</Text>
|
<Text className='modal-title'>修改儿童昵称</Text>
|
||||||
<View className='modal-input-wrap'>
|
<View className='modal-input-wrap'>
|
||||||
<Input
|
<Input
|
||||||
className='modal-input'
|
className='modal-input'
|
||||||
|
|||||||
Reference in New Issue
Block a user