feat(mini): add child delete picker in manage page
This commit is contained in:
@@ -480,15 +480,24 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
gap: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.device-switch-id {
|
.device-switch-id {
|
||||||
|
min-width: 0;
|
||||||
font-size: 28px;
|
font-size: 28px;
|
||||||
color: #1A1A1A;
|
color: #1A1A1A;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.device-switch-tags {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.device-switch-tag {
|
.device-switch-tag {
|
||||||
margin-left: 16px;
|
margin-left: 16px;
|
||||||
padding: 6px 14px;
|
padding: 6px 14px;
|
||||||
@@ -497,6 +506,14 @@
|
|||||||
font-size: 22px;
|
font-size: 22px;
|
||||||
color: #FFFFFF;
|
color: #FFFFFF;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
|
|
||||||
|
.device-switch-tags & {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.danger {
|
||||||
|
background: #E5484D;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.device-switch-name {
|
.device-switch-name {
|
||||||
@@ -504,6 +521,15 @@
|
|||||||
color: #666666;
|
color: #666666;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.delete-child-item {
|
||||||
|
border: 2px solid transparent;
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background: #FFF1F2;
|
||||||
|
border-color: #FDA4AF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.loading {
|
.loading {
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
setSelectedBindingDeviceId,
|
setSelectedBindingDeviceId,
|
||||||
unbindDevice,
|
unbindDevice,
|
||||||
} from '@/services/binding'
|
} from '@/services/binding'
|
||||||
import { Child, clearSelectedChildId, createChild, setSelectedChildId, updateChild } from '@/services/child'
|
import { Child, clearSelectedChildId, createChild, deleteChild, setSelectedChildId, updateChild } from '@/services/child'
|
||||||
import {
|
import {
|
||||||
DeviceCurrentRole,
|
DeviceCurrentRole,
|
||||||
DeviceFirmwareStatus,
|
DeviceFirmwareStatus,
|
||||||
@@ -48,6 +48,7 @@ export default function Sleep() {
|
|||||||
const [isUpdatingRole, setIsUpdatingRole] = useState(false)
|
const [isUpdatingRole, setIsUpdatingRole] = useState(false)
|
||||||
const [showModal, setShowModal] = useState(false)
|
const [showModal, setShowModal] = useState(false)
|
||||||
const [showChildModal, setShowChildModal] = useState(false)
|
const [showChildModal, setShowChildModal] = useState(false)
|
||||||
|
const [showDeleteChildModal, setShowDeleteChildModal] = useState(false)
|
||||||
const [showRoleModal, setShowRoleModal] = useState(false)
|
const [showRoleModal, setShowRoleModal] = useState(false)
|
||||||
const [modalType, setModalType] = useState<'add' | 'edit'>('add')
|
const [modalType, setModalType] = useState<'add' | 'edit'>('add')
|
||||||
const [childName, setChildName] = useState('')
|
const [childName, setChildName] = useState('')
|
||||||
@@ -207,6 +208,43 @@ export default function Sleep() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleDeleteChild = (child: Child) => {
|
||||||
|
const childBinding = bindings.find((item) => item.child_id === child.child_id) || null
|
||||||
|
const isCurrentChild = currentChild?.child_id === child.child_id
|
||||||
|
const content = childBinding?.device_id
|
||||||
|
? '删除后,' + child.child_name + ' 将不再显示,设备 ' + childBinding.device_id + ' 会保留但不再分配给该孩子。确定删除吗?'
|
||||||
|
: '删除后,' + child.child_name + ' 将不再显示。确定删除吗?'
|
||||||
|
|
||||||
|
Taro.showModal({
|
||||||
|
title: '删除孩子',
|
||||||
|
content,
|
||||||
|
confirmText: '删除',
|
||||||
|
confirmColor: '#E5484D',
|
||||||
|
success: async (result) => {
|
||||||
|
if (!result.confirm) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
await deleteChild(child.child_id)
|
||||||
|
if (isCurrentChild) {
|
||||||
|
clearSelectedChildId()
|
||||||
|
}
|
||||||
|
if (isCurrentChild && childBinding?.device_id && binding?.device_id === childBinding.device_id) {
|
||||||
|
clearSelectedBindingDeviceId()
|
||||||
|
}
|
||||||
|
setShowDeleteChildModal(false)
|
||||||
|
Taro.showToast({ title: '已删除', icon: 'success' })
|
||||||
|
await loadData()
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[manage] delete child failed:', error)
|
||||||
|
Taro.showToast({
|
||||||
|
title: error?.message || '删除失败,请重试',
|
||||||
|
icon: 'none',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const handleStartFirmwareUpdate = () => {
|
const handleStartFirmwareUpdate = () => {
|
||||||
if (!binding?.device_id || !firmwareStatus?.can_update || isLoadingFirmware || isUpdatingFirmware) return
|
if (!binding?.device_id || !firmwareStatus?.can_update || isLoadingFirmware || isUpdatingFirmware) return
|
||||||
|
|
||||||
@@ -332,6 +370,11 @@ export default function Sleep() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (item.name === '删除孩子') {
|
||||||
|
setShowDeleteChildModal(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (item.name === '绑定设备') {
|
if (item.name === '绑定设备') {
|
||||||
if (!currentChild) {
|
if (!currentChild) {
|
||||||
handleOpenModal('add')
|
handleOpenModal('add')
|
||||||
@@ -405,6 +448,14 @@ export default function Sleep() {
|
|||||||
value: '',
|
value: '',
|
||||||
arrow: true,
|
arrow: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
icon: require('../../assets/tab-icons/broken-rings.png'),
|
||||||
|
iconBgClass: 'red',
|
||||||
|
name: '删除孩子',
|
||||||
|
value: children.length > 0 ? `${children.length} 个可选` : '未添加',
|
||||||
|
arrow: true,
|
||||||
|
disabled: children.length === 0,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
icon: require('../../assets/tab-icons/rings.png'),
|
icon: require('../../assets/tab-icons/rings.png'),
|
||||||
iconBgClass: 'green',
|
iconBgClass: 'green',
|
||||||
@@ -572,6 +623,50 @@ export default function Sleep() {
|
|||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{showDeleteChildModal && (
|
||||||
|
<View className='modal-mask' onClick={() => setShowDeleteChildModal(false)}>
|
||||||
|
<View
|
||||||
|
className='modal-card device-switch-card'
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation()
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text className='modal-title'>选择要删除的孩子</Text>
|
||||||
|
{children.length === 0 ? (
|
||||||
|
<Text className='device-switch-empty'>当前还没有儿童资料</Text>
|
||||||
|
) : (
|
||||||
|
<View className='device-switch-list'>
|
||||||
|
{children.map((item) => {
|
||||||
|
const isActive = currentChild?.child_id === item.child_id
|
||||||
|
const itemBinding = bindings.find((bindingItem) => bindingItem.child_id === item.child_id) || null
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
key={item.child_id}
|
||||||
|
className='device-switch-item delete-child-item'
|
||||||
|
onClick={() => handleDeleteChild(item)}
|
||||||
|
>
|
||||||
|
<View className='device-switch-head'>
|
||||||
|
<Text className='device-switch-id'>{item.child_name}</Text>
|
||||||
|
<View className='device-switch-tags'>
|
||||||
|
{isActive && <Text className='device-switch-tag'>当前</Text>}
|
||||||
|
<Text className='device-switch-tag danger'>删除</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
<Text className='device-switch-name'>{itemBinding?.device_id || '未绑定设备'}</Text>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<View className='modal-actions'>
|
||||||
|
<Text className='modal-action cancel' onClick={() => setShowDeleteChildModal(false)}>
|
||||||
|
关闭
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
|
||||||
{showModal && (
|
{showModal && (
|
||||||
<View className='modal-mask'>
|
<View className='modal-mask'>
|
||||||
<View className='modal-card'>
|
<View className='modal-card'>
|
||||||
|
|||||||
Reference in New Issue
Block a user