Handle unassigned device after child deletion
This commit is contained in:
@@ -126,6 +126,7 @@ function getAlarmLocationHint(alarm: DeviceAlarmItem | null): string {
|
||||
export default function Device() {
|
||||
const systemBanner = useSystemBanner()
|
||||
const [binding, setBinding] = useState<Binding | null>(null)
|
||||
const [pendingBinding, setPendingBinding] = useState<Binding | null>(null)
|
||||
const [child, setChild] = useState<Child | null>(null)
|
||||
const [deviceStatus, setDeviceStatus] = useState<DeviceStatus | null>(null)
|
||||
const [deviceAlarms, setDeviceAlarms] = useState<DeviceAlarmItem[]>([])
|
||||
@@ -144,6 +145,7 @@ export default function Device() {
|
||||
const loadDeviceInfo = async () => {
|
||||
if (!getToken()) {
|
||||
setBinding(null)
|
||||
setPendingBinding(null)
|
||||
setChild(null)
|
||||
setDeviceStatus(null)
|
||||
setDeviceAlarms([])
|
||||
@@ -159,6 +161,7 @@ export default function Device() {
|
||||
const context = await loadCurrentChildBindingContext()
|
||||
setChild(context.currentChild)
|
||||
setBinding(context.currentBinding)
|
||||
setPendingBinding(context.pendingBinding)
|
||||
|
||||
if (context.currentBinding?.device_id) {
|
||||
const [nextStatus, nextAlarms] = await Promise.all([
|
||||
@@ -324,6 +327,7 @@ export default function Device() {
|
||||
}
|
||||
|
||||
if (!child) {
|
||||
const hasPendingDevice = Boolean(pendingBinding?.device_id)
|
||||
return (
|
||||
<View className='device-page'>
|
||||
<View className='page-header'>
|
||||
@@ -334,10 +338,14 @@ export default function Device() {
|
||||
<View className='empty-robot'>
|
||||
<Image className='robot-img' src={require('../../assets/tab-icons/robot.png')} mode='aspectFit' />
|
||||
</View>
|
||||
<Text className='empty-title'>先绑定一台伴伴设备</Text>
|
||||
<Text className='empty-subtitle'>绑定时可以选择已有孩子,或直接新建孩子昵称</Text>
|
||||
<View className='empty-btn' onClick={() => Taro.navigateTo({ url: '/pages/bind/index' })}>
|
||||
<Text className='empty-btn-text'>添加设备</Text>
|
||||
<Text className='empty-title'>{hasPendingDevice ? '设备已绑定,待关联孩子' : '先绑定一台伴伴设备'}</Text>
|
||||
<Text className='empty-subtitle'>
|
||||
{hasPendingDevice
|
||||
? '这台设备还没有关联孩子,关联后即可查看定位、聊天和设备状态'
|
||||
: '绑定时可以选择已有孩子,或直接新建孩子昵称'}
|
||||
</Text>
|
||||
<View className='empty-btn' onClick={() => Taro.navigateTo({ url: hasPendingDevice ? '/pages/bind/index?mode=assign' : '/pages/bind/index' })}>
|
||||
<Text className='empty-btn-text'>{hasPendingDevice ? '关联孩子' : '添加设备'}</Text>
|
||||
</View>
|
||||
</View>
|
||||
{systemBanner}
|
||||
@@ -346,6 +354,7 @@ export default function Device() {
|
||||
}
|
||||
|
||||
if (!binding) {
|
||||
const hasPendingDevice = Boolean(pendingBinding?.device_id)
|
||||
return (
|
||||
<View className='device-page'>
|
||||
<View className='page-header'>
|
||||
@@ -366,10 +375,14 @@ export default function Device() {
|
||||
<View className='empty-robot'>
|
||||
<Image className='robot-img' src={require('../../assets/tab-icons/robot.png')} mode='aspectFit' />
|
||||
</View>
|
||||
<Text className='empty-title'>给当前孩子绑定一台设备</Text>
|
||||
<Text className='empty-subtitle'>绑定后,这个孩子的聊天记录、定位和设备状态都会显示在首页</Text>
|
||||
<View className='empty-btn' onClick={() => Taro.navigateTo({ url: '/pages/bind/index' })}>
|
||||
<Text className='empty-btn-text'>去绑定设备</Text>
|
||||
<Text className='empty-title'>{hasPendingDevice ? '有设备待关联' : '给当前孩子绑定一台设备'}</Text>
|
||||
<Text className='empty-subtitle'>
|
||||
{hasPendingDevice
|
||||
? `设备 ${pendingBinding?.device_id} 还没有关联孩子,可以关联到当前孩子`
|
||||
: '绑定后,这个孩子的聊天记录、定位和设备状态都会显示在首页'}
|
||||
</Text>
|
||||
<View className='empty-btn' onClick={() => Taro.navigateTo({ url: hasPendingDevice ? '/pages/bind/index?mode=assign' : '/pages/bind/index' })}>
|
||||
<Text className='empty-btn-text'>{hasPendingDevice ? '关联到当前孩子' : '去绑定设备'}</Text>
|
||||
</View>
|
||||
</View>
|
||||
{systemBanner}
|
||||
|
||||
Reference in New Issue
Block a user