import React, { useState, useEffect, useRef } from "react"; import { Tabs, Badge, Spin, List, Avatar, Tag, Popover, notification } from "antd"; import { BellOutlined, LoadingOutlined } from "@ant-design/icons"; // svg 转组件 import { ReactComponent as NoticeSvg } from '../../../public/icons/notice.svg'; import type { NotificationPlacement } from 'antd/es/notification/interface'; // import { getallnotices, getUidNotices } from "@/api/caravan/User"; import styles from "./index.module.less"; import { useNavigate } from "react-router-dom"; enum EventStatus { todo = "rgba(255,255,255,1)", urgent = "#f5222d", doing = "#faad14", processing = "#1890ff" } const antIcon = ; const { TabPane} = Tabs; const Context = React.createContext({ name: 'Default' }); const Notice: React.FC = () => { const [visible, setVisible] = useState(false); const [noticeList, setNoticeList] = useState([]); const [loading, setLoading] = useState(false); const noticeCount = 10; const intervalHandle: any = useRef(null); const [noticeNum, setNoticeNum] = useState(0); const noticeListFilter = (type: T) => { return noticeList.filter(notice => notice.type === type) as any[]; }; const navigate = useNavigate(); const toManagePage = () => { navigate("/notice"); }; const getNotice = async () => { //查看我是否有新消息 无论如何 // setLoading(true); //无论如何,清掉定时器,使用了 ref,肯定能拿到指针。 //并且启动一个定时器,定时刷新我的消息 clearTimeout(intervalHandle.current); intervalHandle.current = setTimeout(() => { setNoticeNum(Math.ceil(Math.random() * 1000)); }, 1000 * 60 * 60); // getUidNotices() // .then(result => { // setLoading(false); // if (result.status && result.data && Array.isArray(result.data.data)) { // setNoticeList(result.data.data); // } // }) // .catch(() => { // setLoading(false); // }); // getallnotices(); }; // const [api, contextHolder] = notification.useNotification(); // const openNotification = (placement: NotificationPlacement) => { // api.info({ // message: `Notification ${placement}`, // description: {({ name }) => `Hello, ${name}!`}, // placement, // }); // }; useEffect(() => { getNotice(); }, [noticeNum]); // const ws = new WebSocket("ws://localhost:3000/"); // useEffect(() => { // console.log(ws); // // ws.onopen = function () { // // setInterval(function () { // // ws.send("客户端消息"); // // }, 2000); // // }; // ws.onmessage = function (e) { // console.log(e.data); // openNotification('topRight') // } // }, []); useEffect(() => { return () => { clearTimeout(intervalHandle.current); }; }, []); const onClear = () => { // ws.send("客户端消息"); }; const onViewMore = () => {}; const tabsData = [ { title: 'Ant Design Title 1', time: '刚刚' }, { title: 'Ant Design Title 2Ant Design Title 2Ant Design Title 2Ant Design Title 2Ant Design Title 2Ant Design Title 2Ant Design Title 2', time: '刚刚' }, { title: 'Ant Design Title 3', time: '刚刚' }, { title: 'Ant Design Title 4', time: '刚刚' }, ]; const tabs = (
( toManagePage()} style={{ cursor: "pointer" }}>
系统消息 紧急
{item.title}
{item.time}
} /> )} /> ); return (
{/* {contextHolder} */} setVisible(v)} arrow={{pointAtCenter: true}} overlayStyle={{ width: 396, }} > {/* */} {/* */} {/* */}
); }; export default Notice;