import React, { useState, useEffect } from 'react'; import { PageContainer } from '@ant-design/pro-layout'; import { Button, Card, Row, Col, Input, Table, Tooltip, Space, Popconfirm, message, Divider, } from 'antd'; import { getNotice, deleteNotice } from '@/services/notice'; import NoticeModal from './modal'; import DetailModal from './detailModal'; import { filterTimestamp } from '@/filters/index'; import { connect, Dispatch } from 'umi'; import type { ConnectState } from '@/models/connect'; import type { Role } from '@/models/user'; interface IProps { dispatch: Dispatch; roleList: Role[]; } const Notice: React.FC = ({ dispatch, roleList }) => { const [label, setLabel] = useState(''); const [curPage, setCurpage] = useState(1); const [total, setTotal] = useState(0); const [noticeList, setNoticeList] = useState([]); const [loading, setLoading] = useState(false); const [type, setType] = useState(0); const [visible, setVisible] = useState(false); const [curNoticeData, setCurNoticeData] = useState({}); const [DetailModalVisible, setDetailModalVisible] = useState(false); const [id, setId] = useState(''); // 获取公告列表 const GetNotice = async (): Promise => { const $par = { curPage, label, type: 'ANN', }; setLoading(true); const { code, data } = await getNotice($par); setLoading(false); if (code === 0) { console.log(data); const { records, total: Total } = data; setTotal(Total); setNoticeList(records); } }; useEffect(() => { GetNotice(); }, [label, curPage]); // 打开弹窗 const openModal = (value: number, record: Record) => { console.log(record, '打开弹窗 '); setType(value); setVisible(true); setCurNoticeData(record); }; // 删除公告 const DeleteNotice = async (value: string): Promise => { const { code, data } = await deleteNotice(value); if (code === 0) { console.log(data); message.success('删除成功'); } GetNotice(); }; // 关闭弹窗 const closeModal = (): void => setVisible(false); // 搜索 const onSearch = (value: string): void => setLabel(value); // 分页 const changePagination = (page: number): void => setCurpage(page); return ( ) => ( {record.label} )} >) => ( { setDetailModalVisible(true); setId(record.id); }} > {' '} 查看公告内容{' '} )} /> 管理员} > {filterTimestamp(text)}} > ) => ( { setDetailModalVisible(true); setId(record.id); }} > 查看 openModal(1, record as Record)}>编辑 DeleteNotice(record.id)} okText="Yes" cancelText="No" > 删除 )} >
{visible && ( )} {/* 详情弹窗 */} {DetailModalVisible && ( setDetailModalVisible(false)} /> )}
); }; export default connect(({ user }: ConnectState) => ({ roleList: user.roleList, }))(Notice);