Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivWeb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
CivWeb
Commits
c984c9d3
Commit
c984c9d3
authored
Nov 24, 2020
by
叶飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: notice
parent
0dddd61b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
61 deletions
+140
-61
NoticeIconView.js
src/components/GlobalHeader/NoticeIconView.js
+2
-5
NoticeList.js
src/components/NoticeIcon/NoticeList.js
+119
-46
index.js
src/components/NoticeIcon/Templates/Alarm/index.js
+14
-7
index.js
src/components/Notifier/index.js
+5
-3
No files found.
src/components/GlobalHeader/NoticeIconView.js
View file @
c984c9d3
import
React
,
{
Component
}
from
'react'
;
import
React
,
{
Component
}
from
'react'
;
import
{
message
,
Tag
,
notification
}
from
'antd'
;
import
moment
from
'moment'
;
import
{
connect
}
from
'react-redux'
;
import
{
connect
}
from
'react-redux'
;
import
NoticeIcon
from
'../NoticeIcon'
;
import
NoticeIcon
from
'../NoticeIcon'
;
import
styles
from
'./index.less'
;
import
styles
from
'./index.less'
;
import
Notifier
,
{
NEW_MESSAGE
}
from
'../Notifier'
;
import
Notifier
,
{
NEW_MESSAGE
}
from
'../Notifier'
;
...
@@ -34,7 +30,6 @@ class NoticeIconView extends Component {
...
@@ -34,7 +30,6 @@ class NoticeIconView extends Component {
})
})
};
};
render
()
{
render
()
{
return
(
return
(
<
NoticeIcon
<
NoticeIcon
...
@@ -47,6 +42,7 @@ class NoticeIconView extends Component {
...
@@ -47,6 +42,7 @@ class NoticeIconView extends Component {
title
=
"通知"
title
=
"通知"
emptyText
=
"你已查看所有通知"
emptyText
=
"你已查看所有通知"
confirmRead
=
{
this
.
notifier
.
confirmRead
}
confirmRead
=
{
this
.
notifier
.
confirmRead
}
loadMore
=
{
this
.
notifier
.
loadMore
}
/
>
/
>
<
/NoticeIcon
>
<
/NoticeIcon
>
);
);
...
@@ -58,6 +54,7 @@ const mapStateToProps = state => {
...
@@ -58,6 +54,7 @@ const mapStateToProps = state => {
global
:
state
.
getIn
([
'global'
,
'globalConfig'
]),
global
:
state
.
getIn
([
'global'
,
'globalConfig'
]),
};
};
};
};
export
default
connect
(
export
default
connect
(
mapStateToProps
,
mapStateToProps
,
null
,
null
,
...
...
src/components/NoticeIcon/NoticeList.js
View file @
c984c9d3
import
React
from
'react'
;
import
React
from
'react'
;
import
{
Avatar
,
List
}
from
'antd'
;
import
{
List
,
Spin
}
from
'antd'
;
import
classNames
from
'classnames'
;
import
classNames
from
'classnames'
;
import
styles
from
'./NoticeList.less'
;
import
styles
from
'./NoticeList.less'
;
import
Alarm
from
'./Templates/Alarm'
;
import
Alarm
from
'./Templates/Alarm'
;
...
@@ -18,52 +18,125 @@ const Empty = ({ emptyText }) => (
...
@@ -18,52 +18,125 @@ const Empty = ({ emptyText }) => (
<
/div
>
<
/div
>
);
);
const
NoticeList
=
({
data
=
[],
emptyText
,
confirmRead
})
=>
{
class
NoticeList
extends
React
.
Component
{
if
(
!
data
||
data
.
length
===
0
)
{
constructor
(
props
)
{
return
<
Empty
emptyText
=
{
emptyText
}
/>
;
super
(
props
);
this
.
data
=
props
.
data
;
this
.
emptyText
=
props
.
emptyText
;
this
.
confirmRead
=
props
.
confirmRead
;
this
.
loadMore
=
props
.
loadMore
;
this
.
container
=
React
.
createRef
();
this
.
state
=
{
isLoading
:
false
,
};
}
}
return
(
<
div
className
=
{
styles
.
container
}
>
componentDidMount
()
{
<
List
if
(
this
.
container
.
current
)
{
className
=
{
styles
.
list
}
this
.
container
.
current
.
addEventListener
(
dataSource
=
{
data
}
'scroll'
,
renderItem
=
{(
item
,
i
)
=>
{
this
.
throttle
(
this
.
handleScroll
.
bind
(
this
),
30
),
const
itemCls
=
classNames
(
styles
.
item
,
{
);
[
styles
.
read
]:
item
.
read
,
}
}
throttle
(
fn
,
wait
)
{
var
pre
=
Date
.
now
();
return
function
()
{
var
context
=
this
;
var
args
=
arguments
;
var
now
=
Date
.
now
();
if
(
now
-
pre
>=
wait
)
{
fn
.
apply
(
context
,
args
);
pre
=
Date
.
now
();
}
};
}
handleScroll
(
e
)
{
e
.
stopPropagation
();
if
(
!
this
.
container
.
current
)
return
;
let
current
=
this
.
container
.
current
;
if
(
current
.
scrollHeight
-
current
.
scrollTop
-
current
.
offsetHeight
<=
100
)
{
this
.
handleLoadMore
();
}
}
handleLoadMore
()
{
if
(
this
.
state
.
isLoading
)
return
;
this
.
setState
(
{
isLoading
:
true
,
},
()
=>
{
if
(
!
this
.
loadMore
)
return
;
this
.
loadMore
().
then
(
data
=>
{
this
.
setState
({
isLoading
:
false
,
});
});
let
messageTemplate
=
<><
/>
;
});
switch
(
item
.
infoType
)
{
},
case
'scadaType'
:
);
messageTemplate
=
(
}
<
Alarm
message
=
{
item
}
confirmRead
=
{
confirmRead
}
/
>
);
render
()
{
break
;
if
(
!
this
.
data
||
this
.
data
.
length
===
0
)
{
case
'caseType'
:
return
<
Empty
emptyText
=
{
this
.
emptyText
}
/>
;
messageTemplate
=
(
}
<
Case
message
=
{
item
}
confirmRead
=
{
confirmRead
}
/
>
return
(
);
<
div
className
=
{
styles
.
container
}
ref
=
{
this
.
container
}
>
break
;
<
List
case
'sysType'
:
className
=
{
styles
.
list
}
messageTemplate
=
(
dataSource
=
{
this
.
data
}
<
Notice
message
=
{
item
}
confirmRead
=
{
confirmRead
}
/
>
renderItem
=
{(
item
,
i
)
=>
{
);
const
itemCls
=
classNames
(
styles
.
item
,
{
break
;
[
styles
.
read
]:
item
.
read
,
default
:
});
messageTemplate
=
(
let
messageTemplate
=
<><
/>
;
<
Unknown
message
=
{
item
}
confirmRead
=
{
confirmRead
}
/
>
switch
(
item
.
infoType
)
{
);
case
'scadaType'
:
break
;
messageTemplate
=
(
}
<
Alarm
message
=
{
item
}
confirmRead
=
{
this
.
confirmRead
}
/
>
return
(
);
<
List
.
Item
className
=
{
itemCls
}
key
=
{
item
.
id
||
i
}
>
break
;
{
messageTemplate
}
case
'caseType'
:
<
/List.Item
>
messageTemplate
=
(
);
<
Case
message
=
{
item
}
confirmRead
=
{
this
.
confirmRead
}
/
>
}}
);
/
>
break
;
<
div
className
=
{
styles
.
bottomBar
}
>
下拉加载更多
<
/div
>
case
'sysType'
:
<
/div
>
messageTemplate
=
(
);
<
Notice
message
=
{
item
}
confirmRead
=
{
this
.
confirmRead
}
/
>
};
);
break
;
default
:
messageTemplate
=
(
<
Unknown
message
=
{
item
}
confirmRead
=
{
this
.
confirmRead
}
/
>
);
break
;
}
return
(
<
List
.
Item
className
=
{
itemCls
}
key
=
{
item
.
id
||
i
}
>
{
messageTemplate
}
<
/List.Item
>
);
}}
/
>
<
div
className
=
{
styles
.
bottomBar
}
>
{
this
.
state
.
isLoading
?
(
<>
<
Spin
/>
加载中
...
<
/
>
)
:
(
<
span
>
下拉加载更多
<
/span
>
)}
<
/div
>
<
/div
>
);
}
}
export
default
NoticeList
;
export
default
NoticeList
;
src/components/NoticeIcon/Templates/Alarm/index.js
View file @
c984c9d3
...
@@ -27,20 +27,27 @@ export class AlarmContent {
...
@@ -27,20 +27,27 @@ export class AlarmContent {
const
Alarm
=
({
message
,
confirmRead
})
=>
{
const
Alarm
=
({
message
,
confirmRead
})
=>
{
let
alarmContent
=
message
.
infoContent
;
let
alarmContent
=
message
.
infoContent
;
const
history
=
useHistory
();
const
history
=
useHistory
();
const
goPath
=
(
item
)
=>
{
const
goPath
=
item
=>
{
confirmRead
(
false
,[
message
.
id
]);
confirmRead
(
false
,
[
message
.
id
]);
let
path
=
item
.
webPath
?
`/civweb4/
${
item
.
webPath
}
`
:
`/civweb4/product/scada/AlertMonitoring/AlertMonitoring`
let
path
=
item
.
webPath
?
`/civweb4/
${
item
.
webPath
}
`
:
`/civweb4/product/scada/AlertMonitoring/AlertMonitoring`
;
history
.
push
(
path
);
history
.
push
(
path
);
}
}
;
return
(
return
(
<
div
className
=
{
classNames
(
styles
.
scada
,
commonStyles
.
messageContainer
)
}
title
=
"点击查看详情"
onClick
=
{()
=>
goPath
(
message
)}
>
<
div
className
=
{
classNames
(
styles
.
scada
,
commonStyles
.
messageContainer
)}
title
=
"点击查看详情"
onClick
=
{()
=>
goPath
(
message
)}
>
<
div
className
=
{
commonStyles
.
title
}
>
<
div
className
=
{
commonStyles
.
title
}
>
<
span
>
消息
<
/span
>
<
span
>
消息
<
/span
>
<
img
<
img
className
=
{
commonStyles
.
confirm
}
className
=
{
commonStyles
.
confirm
}
title
=
"点击标为已读"
title
=
"点击标为已读"
onClick
=
{()
=>
{
onClick
=
{
e
=>
{
confirmRead
(
false
,[
message
.
id
]);
e
.
stopPropagation
();
confirmRead
(
false
,
[
message
.
id
]);
}}
}}
src
=
"https://panda-water.cn/Web4/assets/images/message/%E5%8B%BE%E6%B5%85.png"
src
=
"https://panda-water.cn/Web4/assets/images/message/%E5%8B%BE%E6%B5%85.png"
/>
/>
...
...
src/components/Notifier/index.js
View file @
c984c9d3
...
@@ -53,6 +53,8 @@ class Notifier {
...
@@ -53,6 +53,8 @@ class Notifier {
this
.
MQTTClient
=
null
;
this
.
MQTTClient
=
null
;
this
.
MQTTOptions
=
{};
this
.
MQTTOptions
=
{};
this
.
IsNeedReconnect
=
true
;
this
.
IsNeedReconnect
=
true
;
this
.
pageIndex
=
1
;
this
.
pageSize
=
10
;
// 对外接口处理this指向问题
// 对外接口处理this指向问题
this
.
start
=
this
.
start
.
bind
(
this
);
this
.
start
=
this
.
start
.
bind
(
this
);
...
@@ -60,6 +62,7 @@ class Notifier {
...
@@ -60,6 +62,7 @@ class Notifier {
this
.
subscribe
=
this
.
subscribe
.
bind
(
this
);
this
.
subscribe
=
this
.
subscribe
.
bind
(
this
);
this
.
unsubscribe
=
this
.
unsubscribe
.
bind
(
this
);
this
.
unsubscribe
=
this
.
unsubscribe
.
bind
(
this
);
this
.
confirmRead
=
this
.
confirmRead
.
bind
(
this
);
this
.
confirmRead
=
this
.
confirmRead
.
bind
(
this
);
this
.
loadMore
=
this
.
loadHisMessages
.
bind
(
this
);
}
}
// 对外接口
// 对外接口
...
@@ -72,7 +75,6 @@ class Notifier {
...
@@ -72,7 +75,6 @@ class Notifier {
stop
()
{
stop
()
{
this
.
disconnectMQTTServer
();
this
.
disconnectMQTTServer
();
}
}
subscribe
(
type
,
handler
)
{
subscribe
(
type
,
handler
)
{
if
(
!
(
type
in
this
.
_subscribers
))
{
if
(
!
(
type
in
this
.
_subscribers
))
{
this
.
_subscribers
[
type
]
=
[];
this
.
_subscribers
[
type
]
=
[];
...
@@ -108,7 +110,6 @@ class Notifier {
...
@@ -108,7 +110,6 @@ class Notifier {
}
}
});
});
}
}
confirmRead
(
isAll
=
false
,
hisIDs
=
[])
{
confirmRead
(
isAll
=
false
,
hisIDs
=
[])
{
let
list
=
[];
let
list
=
[];
if
(
if
(
...
@@ -279,7 +280,8 @@ class Notifier {
...
@@ -279,7 +280,8 @@ class Notifier {
}
}
// 工具类
// 工具类
async
loadHisMessages
({
userID
,
pageIndex
=
1
,
pageSize
=
10
})
{
async
loadHisMessages
({
userID
,
pageIndex
=
this
.
pageIndex
,
pageSize
=
this
.
pageSize
})
{
debugger
;
let
me
=
this
;
let
me
=
this
;
return
Http
.
getInformationInfo
({
return
Http
.
getInformationInfo
({
userID
,
userID
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment