mirror of https://github.com/openspug/spug
U 系统通知将显示已读的历史记录
parent
78702006c7
commit
887cf8c01f
|
@ -8,7 +8,7 @@ from libs import json_response, JsonParser, Argument
|
||||||
|
|
||||||
class NotifyView(View):
|
class NotifyView(View):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
notifies = Notify.objects.filter(unread=True)
|
notifies = Notify.objects.all()
|
||||||
return json_response(notifies)
|
return json_response(notifies)
|
||||||
|
|
||||||
def patch(self, request):
|
def patch(self, request):
|
||||||
|
|
|
@ -56,8 +56,8 @@ export default function () {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
http.get('/api/notify/')
|
http.get('/api/notify/')
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
setReads(res.filter(x => !x.unread).map(x => x.id))
|
||||||
setNotifies(res);
|
setNotifies(res);
|
||||||
setReads([])
|
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false))
|
.finally(() => setLoading(false))
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,7 @@ export default function () {
|
||||||
ws = new WebSocket(`${protocol}//${window.location.host}/api/ws/notify/?x-token=${X_TOKEN}`);
|
ws = new WebSocket(`${protocol}//${window.location.host}/api/ws/notify/?x-token=${X_TOKEN}`);
|
||||||
ws.onopen = () => ws.send('ok');
|
ws.onopen = () => ws.send('ok');
|
||||||
ws.onmessage = e => {
|
ws.onmessage = e => {
|
||||||
if (e.data === 'pong') {
|
if (e.data !== 'pong') {
|
||||||
} else {
|
|
||||||
fetch();
|
fetch();
|
||||||
const {title, content} = JSON.parse(e.data);
|
const {title, content} = JSON.parse(e.data);
|
||||||
const key = `open${Date.now()}`;
|
const key = `open${Date.now()}`;
|
||||||
|
@ -80,6 +79,12 @@ export default function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleVisible(visible) {
|
||||||
|
if (visible) {
|
||||||
|
fetch()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleRead(e, item) {
|
function handleRead(e, item) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (reads.indexOf(item.id) === -1) {
|
if (reads.indexOf(item.id) === -1) {
|
||||||
|
@ -95,9 +100,10 @@ export default function () {
|
||||||
http.patch('/api/notify/', {ids})
|
http.patch('/api/notify/', {ids})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const count = notifies.length - reads.length;
|
||||||
return (
|
return (
|
||||||
<div className={styles.right}>
|
<div className={styles.right}>
|
||||||
<Dropdown trigger={['click']} overlay={(
|
<Dropdown trigger={['click']} onVisibleChange={handleVisible} overlay={(
|
||||||
<Menu className={styles.notify}>
|
<Menu className={styles.notify}>
|
||||||
<Menu.Item style={{padding: 0, whiteSpace: 'unset'}}>
|
<Menu.Item style={{padding: 0, whiteSpace: 'unset'}}>
|
||||||
<List
|
<List
|
||||||
|
@ -112,7 +118,7 @@ export default function () {
|
||||||
avatar={<Icon type={item.source}/>}
|
avatar={<Icon type={item.source}/>}
|
||||||
title={<span style={{fontWeight: 400, color: '#404040'}}>{item.title}</span>}
|
title={<span style={{fontWeight: 400, color: '#404040'}}>{item.title}</span>}
|
||||||
description={[
|
description={[
|
||||||
<div key="1" style={{fontSize: 12}}>{item.content}</div>,
|
<div key="1" style={{fontSize: 12, overflowWrap: 'anywhere'}}>{item.content}</div>,
|
||||||
<div key="2" style={{fontSize: 12}}>{moment(item['created_at']).fromNow()}</div>
|
<div key="2" style={{fontSize: 12}}>{moment(item['created_at']).fromNow()}</div>
|
||||||
]}/>
|
]}/>
|
||||||
</List.Item>
|
</List.Item>
|
||||||
|
@ -124,7 +130,7 @@ export default function () {
|
||||||
</Menu>
|
</Menu>
|
||||||
)}>
|
)}>
|
||||||
<span className={styles.trigger}>
|
<span className={styles.trigger}>
|
||||||
<Badge count={notifies.length - reads.length}>
|
<Badge count={count > 0 ? count : 0}>
|
||||||
<NotificationOutlined style={{fontSize: 16}}/>
|
<NotificationOutlined style={{fontSize: 16}}/>
|
||||||
</Badge>
|
</Badge>
|
||||||
</span>
|
</span>
|
||||||
|
|
Loading…
Reference in New Issue