feat: support assigning child to existing device
This commit is contained in:
@@ -68,6 +68,7 @@ export default function Sleep() {
|
||||
const [showDeleteChildModal, setShowDeleteChildModal] = useState(false)
|
||||
const [showRoleModal, setShowRoleModal] = useState(false)
|
||||
const [showFamilyModal, setShowFamilyModal] = useState(false)
|
||||
const [showAssignDeviceModal, setShowAssignDeviceModal] = useState(false)
|
||||
const [modalType, setModalType] = useState<'add' | 'edit'>('add')
|
||||
const [childName, setChildName] = useState('')
|
||||
const [editingChildId, setEditingChildId] = useState<number | null>(null)
|
||||
@@ -334,9 +335,17 @@ export default function Sleep() {
|
||||
|
||||
const handleOpenAddChildFromSwitch = () => {
|
||||
setShowChildModal(false)
|
||||
setShowAssignDeviceModal(false)
|
||||
handleOpenModal('add')
|
||||
}
|
||||
|
||||
const handleAssignExistingDevice = (targetBinding: BindingListItem) => {
|
||||
if (!targetBinding?.device_id) return
|
||||
setSelectedBindingDeviceId(targetBinding.device_id)
|
||||
setShowAssignDeviceModal(false)
|
||||
Taro.navigateTo({ url: '/pages/bind/index' })
|
||||
}
|
||||
|
||||
const handleSubmitModal = async () => {
|
||||
const normalizedName = childName.trim()
|
||||
if (!normalizedName) {
|
||||
@@ -544,6 +553,11 @@ export default function Sleep() {
|
||||
return
|
||||
}
|
||||
|
||||
if (item.name === '关联现有设备') {
|
||||
setShowAssignDeviceModal(true)
|
||||
return
|
||||
}
|
||||
|
||||
if (item.name === '绑定设备') {
|
||||
if (!currentChild) {
|
||||
handleOpenModal('add')
|
||||
@@ -584,6 +598,7 @@ export default function Sleep() {
|
||||
}
|
||||
|
||||
const parentDisplayName = parentInfo.nickname?.trim() || '家长'
|
||||
const unassignedBindings = bindings.filter((item) => item.device_id && item.child_id === null)
|
||||
const currentFirmwareLabel = firmwareStatus?.current_version || '--'
|
||||
const latestFirmwareLabel = firmwareStatus?.latest_version || '--'
|
||||
const currentUserId = getCurrentUserId()
|
||||
@@ -637,6 +652,15 @@ export default function Sleep() {
|
||||
arrow: true,
|
||||
disabled: children.length === 0,
|
||||
},
|
||||
...(unassignedBindings.length > 0
|
||||
? [{
|
||||
icon: require('../../assets/tab-icons/rings.png'),
|
||||
iconBgClass: 'green',
|
||||
name: '关联现有设备',
|
||||
value: `${unassignedBindings.length} 台待关联`,
|
||||
arrow: true,
|
||||
}]
|
||||
: []),
|
||||
{
|
||||
icon: require('../../assets/tab-icons/rings.png'),
|
||||
iconBgClass: 'green',
|
||||
@@ -856,6 +880,48 @@ export default function Sleep() {
|
||||
</View>
|
||||
)}
|
||||
|
||||
{showAssignDeviceModal && (
|
||||
<View className='modal-mask' onClick={() => setShowAssignDeviceModal(false)}>
|
||||
<View
|
||||
className='modal-card device-switch-card'
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
}}
|
||||
>
|
||||
<Text className='modal-title'>关联现有设备</Text>
|
||||
{unassignedBindings.length === 0 ? (
|
||||
<Text className='device-switch-empty'>当前没有待关联设备</Text>
|
||||
) : (
|
||||
<View className='device-switch-list'>
|
||||
{unassignedBindings.map((item) => (
|
||||
<View
|
||||
key={item.device_id}
|
||||
className='device-switch-item'
|
||||
onClick={() => handleAssignExistingDevice(item)}
|
||||
>
|
||||
<View className='device-switch-head'>
|
||||
<Text className='device-switch-id'>{item.device_id}</Text>
|
||||
<Text className='device-switch-tag'>待关联</Text>
|
||||
</View>
|
||||
<Text className='device-switch-name'>未关联孩子</Text>
|
||||
</View>
|
||||
))}
|
||||
</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)}>
|
||||
关闭
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
|
||||
{showModal && (
|
||||
<View className='modal-mask'>
|
||||
<View className='modal-card'>
|
||||
|
||||
Reference in New Issue
Block a user