import { useState, useCallback, useMemo } from 'react' import { useDidShow } from '@tarojs/taro' import { View, Text } from '@tarojs/components' import { Navbar } from '@/components/navbar' import { Loading } from '@/components/loading' import { Empty } from '@/components/empty' import { getEventList, type EventItem } from '@/api/event' import { ROUTES } from '@/constants/routes' import { navigateTo } from '@/utils/navigation' import { showToast } from '@/utils/toast' import { splitAlerts } from './splitAlerts' import styles from './index.module.scss' export default function Index() { const [alertList, setAlertList] = useState([]) const [loading, setLoading] = useState(true) const [loadError, setLoadError] = useState(false) // 每次进入页面重拉全量告警(与事件页"全部"筛选同参数) const loadAlerts = useCallback(async () => { setLoading(true) setLoadError(false) try { const list = await getEventList({ sceneId: 0, status: 0, startDate: '', endDate: '' }) setAlertList(list) } catch { setLoadError(true) } finally { setLoading(false) } }, []) useDidShow(() => { loadAlerts() }) const { unhandled, messages } = useMemo(() => splitAlerts(alertList), [alertList]) const goFamily = () => navigateTo(ROUTES.FAMILY) const goAlertDetail = () => showToast('告警详情即将上线') return ( {loading ? ( ) : loadError ? ( 重试 ) : ( <> {unhandled.length > 0 && ( )} {messages.length > 0 && ( {messages.map((alert) => ( ))} )} {unhandled.length === 0 && messages.length === 0 && ( )} )} ) } function FamilyEntry({ onClick }: { onClick: () => void }) { return ( 👨‍👩‍👧 家庭圈 ) } function UnhandledAlert({ alert, onClick }: { alert: EventItem; onClick: () => void }) { return ( 未处理 {alert.deviceName || '未知设备'} {alert.sceneName && ( 家庭圈: {alert.sceneName} )} {alert.time && ( 时间: {alert.time} )} ) } function AlertMessageItem({ alert, onClick }: { alert: EventItem; onClick: () => void }) { return ( 告警消息 {alert.time && {alert.time}} ) }