import React from "react"; import {Panel} from "../../components/panel"; import {AppList} from "../../components/AppList"; import {AppModel, EventDataModel, EventModel} from "../../../model"; import {appList, appEventList, appEventDataList} from "../../service/api.app"; import './style.scss' import {Space, Table} from "@douyinfe/semi-ui"; import {formatDate} from "../../../utils/date"; import {useInterval} from "ahooks"; export const DashboardIndex: React.FC = () => { // 数据 const [apps, setApps] = React.useState([]); const [currentAppID, setCurrentAppID] = React.useState(0); const [events, setEvents] = React.useState([]); const [eventDataList, setEventDataList] = React.useState([]); const [page, setPage] = React.useState(1); const [dataTotal, setDataTotal] = React.useState(0); const eventDataColumns = [ { title: '编号', dataIndex: 'id', width: 60 }, { title: '事件', dataIndex: 'title', width: 80 }, { title: '路径', dataIndex: 'path', width: 120 }, { title: '访问者浏览器', ellipsis: true, dataIndex: 'browser' }, { title: '来源', dataIndex: 'ip', width: 80 }, { title: '分辨率', dataIndex: 'resolution', width: 120 }, { title: '日期', dataIndex: 'create_time', render: (text: string) => formatDate(text), width: 180 }, ] // 加载应用所有的事件 const getAppEvents = () => { appEventList(currentAppID).then(list => setEvents(list)) } // 加载引用所有事件上报的数据 const loadAppEventsAndDataList = (page = 1) => { if (currentAppID < 1) return; appEventDataList({ appId: currentAppID, pageSize: 10, page }).then(list => { setEventDataList(list) setPage(page) }) } const getAppEventAndData = () => { if (currentAppID > 0) { getAppEvents() loadAppEventsAndDataList() } } // 10s 自动刷新 useInterval(loadAppEventsAndDataList, 10000) React.useEffect(() => { appList().then(list => setApps(list)) }, []) React.useEffect(getAppEventAndData, [currentAppID]) return (

Dashboard

setCurrentAppID(it.id)} /> {currentAppID > 0 && <>
{events.map(it => (
{it.id} {it.title} 查看
))}
} ); };