我的通知

This commit is contained in:
谢思 2021-09-14 16:02:22 +08:00
parent c5bb61cb9a
commit 7fbd76630c
3 changed files with 141 additions and 152 deletions

View File

@ -1,7 +1,7 @@
import React , { Component } from 'react';
import nodata from './Images/nodata.png';
import './css/index.scss';
class Nodata extends Component{
render(){
const { _html , small } = this.props;

View File

@ -1,142 +1,95 @@
import React, { useState, useEffect } from 'react';
import { Badge, Button, Checkbox, Menu } from 'antd';
import { Badge, Button, Checkbox, Menu, Pagination } from 'antd';
import './Index.scss';
import '../manager/Index.scss'
import DelModal from '../../../Wiki/components/ModalFun';
import axios from 'axios';
import { Link } from 'react-router-dom';
import NoneData from '../../../Nodata.js';
function MyNotice(props) {
let current_user = props.current_user;
let pageSize = 20;
const [noticeType, setNoticeType] = useState("2");//tab
const [selectedNum, setSelectedNum] = useState(0);//@
const [isBatchDelete, setIsBatchDelete] = useState(false);//@
const [batchDeleteCheckedAll, setBatchDeleteCheckAll] = useState(false);//@--
const [batchDeleteList, setBatchDeleteList] = useState([]);//@--
const [atmeIds, setAtmeIds] = useState([]);
const [noticeUnreadCount, setNoticeUnreadCount] = useState();//
const [letterUnreadCount, setLetterUnreadCount] = useState(0);//
const [atUnreadCount, setAtUnreadCount] = useState(2);//@
const [messageList, setMessageList] = useState([
{
"id": 1,
"status": 1,
"content": "Atme Message Content 1",
"notification_url": "http://www.baidu.com",
"source": "PullRequestAtme",
"time_ago": "1天前",
"type": "atme",
"sender": {
"id": 5,
"type": "User",
"name": "testforge2",
"login": "testforge2",
"image_url": "system/lets/letter_avatars/2/T/236_177_85/120.png"
}
},
{
"id": 2,
"status": 0,
"content": "Atme Message Content 2",
"notification_url": "http://www.baidu.com",
"source": "IssueAtme",
"time_ago": "1天前",
"type": "atme",
"sender": {
"id": 4,
"type": "User",
"name": "testforge1",
"login": "testforge1",
"image_url": "system/lets/letter_avatars/2/T/19_237_174/120.png"
}
},
{
"id": 3,
"status": 1,
"content": "Notification Message Content 1",
"notification_url": "http://www.baidu.com",
"source": "IssueDelete",
"time_ago": "1天前",
"type": "notification"
},
{
"id": 4,
"status": 0,
"content": "Notification Message Content 2",
"notification_url": "http://www.baidu.com",
"source": "IssueChanged",
"time_ago": "1天前",
"type": "notification"
},
{
"id": 5,
"status": 0,
"content": "Notification Message Content 3",
"notification_url": "http://www.baidu.com",
"source": "ProjectJoined",
"time_ago": "1天前",
"type": "notification"
}
]);
// const [letterUnreadCount, setLetterUnreadCount] = useState(0);//
const [atUnreadCount, setAtUnreadCount] = useState();//@
const [messageList, setMessageList] = useState([]);
const [messTotalCount, setMessTotalCount] = useState();//
const [currentPage, setCurrentPage] = useState(1);//
const [onlyUnread, setOnlyUnread] = useState();
const noticeType = {
const noticeSourceType = {
//
IssueAssigned:1, //
IssueAssignerExpire:1, //
IssueAtme:1, // @
IssueChanged:1, //
IssueCreatorExpire:1, //
IssueDeleted:1, //
IssueJournal:1, //
IssueAssigned:"icon-yixiuicon1", //
IssueAssignerExpire:"icon-yixiuicon1", //
IssueAtme:"icon-yixiuicon1", // @
IssueChanged:"icon-yixiuicon1", //
IssueCreatorExpire:"icon-yixiuicon1", //
IssueDelete:"icon-yixiuicon1", //
IssueDeleted:"icon-yixiuicon1", //
IssueJournal:"icon-yixiuicon1", //
//
LoginIpTip:2, //
LoginIpTip:"icon-xitongtongzhiicon", //
//
OrganizationJoined:3, //
OrganizationLeft:3, //
rganizationRole:3, //
ProjectJoined:3, //
ProjectLeft:3, //
ProjectRole:3, //
OrganizationJoined:"icon-xiaoxi2", //
OrganizationLeft:"icon-xiaoxi2", //
rganizationRole:"icon-xiaoxi2", //
ProjectJoined:"icon-xiaoxi2", //
ProjectLeft:"icon-xiaoxi2", //
ProjectRole:"icon-xiaoxi2", //
//
ProjectDelete:4, //
ProjectFollowed:4, //
ProjectForked:4, //
ProjectIssue:4, // /
ProjectSettingChanged:4, //
ProjectTransfer:4, //
ProjectVersion:4, //
ProjectDelete:"icon-daimakuicon1", //
ProjectFollowed:"icon-daimakuicon1", //
ProjectForked:"icon-daimakuicon1", //
ProjectIssue:"icon-daimakuicon1", // /
ProjectSettingChanged:"icon-daimakuicon1", //
ProjectTransfer:"icon-daimakuicon1", //
ProjectVersion:"icon-daimakuicon1", //
ProjectMemberJoined:"icon-daimakuicon1", //
ProjectMemberLeft:"icon-daimakuicon1", //
ProjectPraised:"icon-daimakuicon1", //
//
ProjectPullRequest:5, // /
PullRequestAssigned:5, //
PullReuqestAtme:5, // @
PullRequestChanged:5, //
PullRequestJournal:5, //
ProjectPullRequest:"icon-hebingqingqiuicon", // /
PullRequestAssigned:"icon-hebingqingqiuicon", //
PullRequestAtme:"icon-hebingqingqiuicon", // @
PullRequestChanged:"icon-hebingqingqiuicon", //
PullRequestJournal:"icon-hebingqingqiuicon", //
//
ProjectMilestone:6, //
ProjectMilestone:"icon-lichengbeiicon", //
};
// useEffect(() => {
// const params = {
// type: noticeType === "0" ? "notification" : noticeType === "2" ? "atme" : "",
// status: onlyUnread ? onlyUnread : "",
// limit: 20,
// page: 0,
// }
// getMessageList(params);
// }, [noticeType, onlyUnread])
useEffect(() => {
// const params = {
// type: noticeType === "0" ? "notification" : noticeType === "2" ? "atme" : "",
// status: onlyUnread ? onlyUnread : "",
// limit: pageSize,
// page: currentPage,
// }
getMessageList();
}, [noticeType, onlyUnread, currentPage])
function getMessageList(params) {
axios.get(`/users/yystopf/messages.json`, {
function getMessageList() {
const params = {
type: noticeType === "0" ? "notification" : noticeType === "2" ? "atme" : "",
status: onlyUnread ? onlyUnread : "",
limit: pageSize,
page: currentPage,
};
axios.get(`/users/${current_user.login}/messages.json`, {
params: params,
}).then((response) => {
setNoticeUnreadCount(response.data.unread_notification);
setAtUnreadCount(response.data.unread_atme);
setMessageList(response.data.messages);
})
console.log(messageList);
//@ids
const atmeIds = new Array();
if(response && response.data){
setNoticeUnreadCount(response.data.unread_notification);
setAtUnreadCount(response.data.unread_atme);
setMessageList(response.data.messages);
setMessTotalCount(response.data.total_count);
}
});
}
function readNotice(id){
@ -145,17 +98,15 @@ function MyNotice(props) {
type: noticeType === "0" ? "notification" : noticeType === "2" ? "atme" : "",
ids:id,
};
console.log(params);
axios.post(`/users/yystopf/messages/read.json`,{
params:params,
}).then((response)=>{
console.log(response);
})
axios.post(`/users/${current_user.login}/messages/read.json`,params);
getMessageList;
}
}
function handleClick(e) {
setNoticeType(e.key);
setCurrentPage(1);
setOnlyUnread();
if (e.key != "2") {
setIsBatchDelete(false);
}
@ -172,7 +123,7 @@ function MyNotice(props) {
});
setMessageList(messageListNew);
setSelectedNum(checkboxNum);
setBatchDeleteCheckAll(checkboxNum === atUnreadCount);
setBatchDeleteCheckAll(checkboxNum === messageList.length);
}
@ -187,29 +138,36 @@ function MyNotice(props) {
}
function deleteNotice(id) {
console.log(id);
const ids = new Array();
if(id[0] == 0){
messageList.map((item)=>{
item.bacheckedBatch ? ids.push(item.id):"";
})
}
console.log(ids);
if(id){
DelModal({
title: noticeType === "1" ? '删除私信' : '删除与我相关',
contentTitle: noticeType === "1" ? '您确定要删除与 xxx 的聊天吗?' : id[0] != -1 ? '您确定要删除这条@我消息吗?' : '您确定要删除选中的' + selectedNum + '条消息吗?',
content: noticeType === "1" ? '此操作将删除与xxx的聊天框和xxx的所有聊天记录请进行确认以防数据的丢失' : id[0] != -1 ? '此操作将删除这条消息,请进行确认以防数据的丢失' : '此操作将删除选中的' + selectedNum + '条消息,请进行确认以防数据的丢失',
contentTitle: noticeType === "1" ? '您确定要删除与 xxx 的聊天吗?' : id[0] != 0 ? '您确定要删除这条@我消息吗?' : '您确定要删除选中的' + selectedNum + '条消息吗?',
content: noticeType === "1" ? '此操作将删除与xxx的聊天框和xxx的所有聊天记录请进行确认以防数据的丢失' : id[0] != 0 ? '此操作将删除这条消息,请进行确认以防数据的丢失' : '此操作将删除选中的' + selectedNum + '条消息,请进行确认以防数据的丢失',
onOk: () => {
const params = {
type: noticeType === "0" ? "notification" : noticeType === "2" ? "atme" : "",
ids:id,
ids:id[0]===0?ids:id,
};
// console.log(params);
axios.delete(`/users/yystopf/messages.json`,{
console.log(params);
axios.delete(`/users/${current_user.login}/messages.json`,{
data:params,
}).then((response)=>{
// console.log(response);
})
console.log(response);
});
getMessageList();
}
});
}
}
return (
<div className="notice01">
<div className="sshHead">
@ -223,12 +181,14 @@ function MyNotice(props) {
<div className={isBatchDelete ? "invisible " : "visible"}>
<div className="vertical-center-style">
<Checkbox onChange={(e) => e.target.checked ? setOnlyUnread(1) : setOnlyUnread(2)}>仅看未读{noticeType === "1" ? `私信12` : noticeType === "0" ? `消息(${noticeUnreadCount}` : `消息(${atUnreadCount}`}</Checkbox>
<Checkbox checked={onlyUnread === 1?true:false} onChange={(e) => e.target.checked ? setOnlyUnread(1) : setOnlyUnread()}>仅看未读{noticeType === "1" ? `私信12` : noticeType === "0" ? `消息(${noticeUnreadCount}` : `消息(${atUnreadCount}`}</Checkbox>
</div>
{noticeType === "2" ? <button onClick={() => { setIsBatchDelete(true); }}>批量删除</button> : ""}
{noticeType === "2" && messageList.length > 0 ? <button onClick={() => { setIsBatchDelete(true); }}>批量删除</button> : ""}
</div>
<div className={isBatchDelete ? 'visible' : 'invisible'}>
{messageList.length===0 ? <NoneData _html="暂无相关消息"/>:""}
{messageList && messageList.length>0 && <div className={isBatchDelete ? 'visible' : 'invisible'}>
<div className="vertical-center-style">
{/* <input type="checkbox" id="checkAll" onChange={onChangeAll} />&nbsp; */}
<Checkbox onChange={onChangeAll} checked={batchDeleteCheckedAll}>全选</Checkbox>
@ -236,21 +196,20 @@ function MyNotice(props) {
</div>
<div>
<button onClick={() => { setIsBatchDelete(false); setSelectedNum(0); }}>取消</button>&nbsp;&nbsp;&nbsp;&nbsp;
<button className="deleteBut" onClick={selectedNum > 0 ? ()=>deleteNotice([-1]) : () => { }}>删除</button>
<button className="deleteBut" onClick={selectedNum > 0 ? ()=>deleteNotice([0]) : () => { }}>删除</button>
</div>
</div>
</div>}
{messageList.map(item => {
//
//
// const iconName = item.source.startsWith("Issue")?"icon-yixiuicon1":item.source.startsWith("Project")?"icon-daimakuicon1":item.source.startsWith("Project")?"icon-daimakuicon1":
if (noticeType === "0" && item.type === "notification") {
if (noticeType === "0") {
//
return (
<div className="mynotice-content vertical-center-style" key={item.id}>
<div className="mynotice-cont vertical-center-style">
<div className="mynotice-cont stretch-style">
{item.status === 1 ? <Badge color="#FA2020" /> : <span className="system-notice-blank"></span>}
<i className="iconfont icon-yixiuicon1"></i>
<span className="sysNotice-length highlightSpan" onClick={() => window.location.href = (`${item.notification_url}`)}>{item.content}</span>
<i className={"iconfont "+noticeSourceType[item.source]}></i>
<span className="sysNotice-length highlightSpan" onClick={() => window.open("https://"+`${item.notification_url}`)}>{item.content}</span>
</div>
<div className="mynotice-cont vertical-center-style float-left-little">
<span className={item.status === 1?"timeSpan":""}>{item.time_ago}</span>
@ -258,29 +217,41 @@ function MyNotice(props) {
</div>
</div>
)
} else if (noticeType === "2" && item.type === "atme") {
} else if (noticeType === "2") {
//@
return (
<div className="mynotice-content vertical-center-style" key={item.id}>
<div className="mynotice-cont vertical-center-style">
{/* <input type="checkbox" className={isBatchDelete ? 'atme-checkbox' : 'invisible'} onChange={onChange} /> */}
<Checkbox value={item.id} className={isBatchDelete ? 'visible-checkbox' : 'invisible-checkbox'} onChange={onChange} checked={item.checkedBatch}></Checkbox>
<img src={`https://testforgeplus.trustie.net//${item.sender.image_url}`} className="currentImg" />
<span className="at-length highlightSpan">
{item.status === 1 ? <Badge color="#FA2020" className="at-badge" /> : <span className="system-notice-blank"></span>}
{item.content}
</span>
{item.sender && <img src={`https://testforgeplus.trustie.net//${item.sender.image_url}`} className="currentImg" />}
<div className="atme-notice-text">
<div className="at-badge">{item.status === 1 ? <Badge color="#FA2020" /> : <span className="system-notice-blank"></span>}</div>
<div className="highlightSpan">{item.content}</div>
</div>
</div>
<div className="mynotice-cont vertical-center-style">
<span className={item.status === 1?"timeSpan":""}>{item.time_ago}</span>
{item.status === 1 && <span className="invisable-read" onClick={()=>readNotice([item.id])}>标记为已读</span>}&nbsp;&nbsp;&nbsp;
<span className="invisable-read" onClick={()=>deleteNotice([item.id])}>删除</span>
<span className="invisable-read float-left-little" onClick={()=>deleteNotice([item.id])}>删除</span>
</div>
</div>
)
}
})}
{/* 分页 */}
<div className="paging">
<Pagination
simple
current = {currentPage}
pageSize={pageSize}
onChange={(page)=>{setCurrentPage(page)}}
total = {messTotalCount}
hideOnSinglePage
></Pagination>
</div>
{/* 私信 */}
{/* <div className="mynotice-content vertical-center-style">
<Badge count={95}><img src="https://testforgeplus.trustie.net//system/lets/letter_avatars/2/D/208_124_118/120.png" className="currentImg private-letter-img" /></Badge>

View File

@ -82,7 +82,6 @@ button:active {
padding: 15px 0 15px 10px;
border-bottom: 1px solid #EEEEEE;
color: #333333;
&:hover{
background: #F3F4F6;
}
@ -135,6 +134,18 @@ button:active {
& .invisible-checkbox{
display: none;
}
.atme-notice-text{
position: relative;
margin-left: 12px;
max-width: 48rem;
& .at-badge{
position:absolute;
}
& .highlightSpan{
margin-left: 12px;
}
}
}
& .ant-badge-count, .ant-badge-dot, .ant-badge .ant-scroll-number-custom-component {
@ -198,10 +209,7 @@ button:active {
max-width: 52rem;
}
.at-length{
max-width: 48rem;
margin-left: 12px;
}
#numberSpan{
color: #466AFF;
}
@ -211,10 +219,20 @@ button:active {
align-items: center;
}
.stretch-style{
display: flex;
align-items: baseline;
}
.float-left-little{
margin-right: 10px;
}
.paging{
float: right;
margin: 12px;
}
// .invisible_checkGroup{
// & .ant-checkbox-inner{
// display: none;