diff --git a/src/components/NoticeModal/NoticeModal.tsx b/src/components/NoticeModal/NoticeModal.tsx index f3c4cb4..6f6dff3 100644 --- a/src/components/NoticeModal/NoticeModal.tsx +++ b/src/components/NoticeModal/NoticeModal.tsx @@ -1,28 +1,21 @@ import { useEffect, useState } from 'react' import './noticeModal.css' -import { get, put,del } from '../../util/AjaxUtils' +import { get, put, del } from '../../util/AjaxUtils' import { Table, - // Pagination, Select, Button, Input, message, Spin } from 'antd'; -import type { TableColumnsType } from 'antd'; +import type { TableColumnsType} from 'antd'; import { MailOutlined, MailFilled } from '@ant-design/icons'; const { Search } = Input; interface DataType { - // key: React.Key; - // title: string; - // time: string; - // type: string; - // orderId: number; - // status: boolean content: string; gmtCreate: string; title: string; @@ -38,17 +31,13 @@ export default function NoticeModal() { dataIndex: 'index', align: 'center', width: 80, - render: (_text, _record, index) =>(page - 1)*10 + index + 1, // 显示序号,从1开始 + render: (_text, _record, index) => (page - 1) * 10 + index + 1, // 显示序号,从1开始 }, { - title:
站内信
, + title:
站内信
, dataIndex: 'content', - // align: 'center', render: (text: string, record: DataType) =>
{ // alert('一度') @@ -79,7 +68,7 @@ export default function NoticeModal() { {text}
, }, - + { title: '消息类型', dataIndex: 'title', @@ -105,34 +94,12 @@ export default function NoticeModal() { // 数据总数 const [total, setTotal] = useState(0) // 被选中的消息数组 - const [selectArray, setSelectArray] = useState([]) + // const [selectArray, setSelectArray] = useState([]) // 被选中的消息id数组 const [ids, setIds] = useState([]) const [selectedRowKeys, setSelectedRowKeys] = useState([]); // 选中的行键 - const [data, setData] = useState([ - // { - // orderId: 111, - // title: '消息1', - // time: '2024-08-12 12:56:35', - // type: '类型1', - // status: true - // }, - // { - // orderId: 222, - // title: '消息2', - // time: '2024-08-12 12:56:35', - // type: '类型2', - // status: false - - // }, - // { - // orderId: 333, - // title: '消息3嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻', - // time: '2024-08-12 12:56:35', - // type: '类型3', - // status: false - // }, - ]) + // const [totalSelectedKeys, setTotalSelectedKeys] = useState([]); // 存储跨页选中项 + const [data, setData] = useState([]) // 获取消息列表 const getNoticeData = () => { get({ @@ -140,8 +107,8 @@ export default function NoticeModal() { url: '/api/user-msg/listpage-simple/self', config: { params: { - page: page, - rows: 10, + // page: page, + // rows: 10, isRead: isRead ? isRead : '', keywords: keywords ? keywords : '' } @@ -160,35 +127,12 @@ export default function NoticeModal() { } }) } - // const data: DataType[] = [ - // { - // orderId: 111, - // title: '消息1', - // time: '2024-08-12 12:56:35', - // type: '类型1', - // status: true - // }, - // { - // orderId: 222, - // title: '消息2', - // time: '2024-08-12 12:56:35', - // type: '类型2', - // status: false - - // }, - // { - // orderId: 333, - // title: '消息3', - // time: '2024-08-12 12:56:35', - // type: '类型3', - // status: false - // }, - // ]; - // const isButtonDisabled = !data.some(item => item.status == false); // 输入关键字搜索 const handleSearch = (value: string) => { // console.log(value); setKeywords(value) + // init() + setPage(1) } // 当删除所有关键字时 const handleChange = (e: any) => { @@ -197,6 +141,8 @@ export default function NoticeModal() { // 如果删除所有发起请求重新取列表 // alert('重新获取') setKeywords('') + // init() + setPage(1) } } // 点击删除按钮 @@ -204,7 +150,7 @@ export default function NoticeModal() { // const deleteIds:any = ids.join('/') del({ messageApi, - url: `api/user-msg/remove/self/${ ids.join('_')}`, + url: `api/user-msg/remove/self/${ids.join('_')}`, onSuccess() { messageApi.open({ type: 'success', @@ -218,7 +164,6 @@ export default function NoticeModal() { //恢复无内容被选中状态 const init = () => { setSelectedRowKeys([]); - setSelectArray([]) setIds([]) } // 标记为已读 @@ -244,9 +189,6 @@ export default function NoticeModal() { } // 全部已读 const ReadAll = () => { - // setData(data.map(item => ({ ...item, status: true }))); //将所有false改为true - // console.log(data.map(item => item.orderId)); //所有的id数组 - // console.log(data.filter(item => !item.status).map(item => item.orderId)); //未读的id数组 put({ messageApi, url: `/api/user-msg/update-read-all/self`, @@ -269,18 +211,14 @@ export default function NoticeModal() { // 选择(多选)项目 const rowSelection = { selectedRowKeys, - onChange: (selectedRowKeys: React.Key[], selectedRows: DataType[]) => { - console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows); + onChange: (newselectedRowKeys: React.Key[], selectedRows: DataType[]) => { + setSelectedRowKeys(newselectedRowKeys); const selectedOrderIds = selectedRows.map(row => row.userMsgId); - // Array.isArray() - // console.log(Array.isArray(selectedOrderIds)); - setSelectedRowKeys(selectedRowKeys); - setSelectArray(selectedRowKeys); - console.log(`selectedOrderIds: ${selectedOrderIds}`); setIds(selectedOrderIds) - setSelectArray(selectedRows) }, }; + + useEffect(() => { getNoticeData() }, [page, isRead, keywords]) @@ -294,6 +232,8 @@ export default function NoticeModal() { style={{ height: '31px', width: '70px' }} onChange={(value: string) => { // console.log(value); + // init() + setPage(1) setIsRead(value) }} options={[ @@ -305,10 +245,10 @@ export default function NoticeModal() { // placeholder='选择类型' />
- -
{ setPage(currentPage); + // init() }, - showSizeChanger: false + showSizeChanger: false, + current: page } } - scroll={{ y: 500 }} bordered key="dataTable" rowKey="userMsgId" + scroll={{ y: 500 }} bordered rowKey="userMsgId" /> - {/* defaultCurrent: 默认当前页数 total:数据总数 defaultPageSize:'页面显示几条' */} - {/*
- { - console.log(page) - }} /> -
*/} + )