Skip to content

Commit 13d22b7

Browse files
committed
fixBug:右上角的提醒通知优化 taskId:#4102
1 parent e84ba05 commit 13d22b7

File tree

2 files changed

+62
-11
lines changed

2 files changed

+62
-11
lines changed

app/components/Notification/actions.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import state from './state'
44
export const NOTIFY_TYPE = {
55
ERROR: 'error',
66
INFO: 'info',
7+
SUCCESS: 'success',
8+
WARNING: 'warning'
79
}
810

911
export const NOTIFICATION_REMOVE = 'NOTIFICATION_REMOVE'
@@ -13,12 +15,14 @@ export const removeNotification = registerAction.normal(NOTIFICATION_REMOVE, (no
1315
})
1416

1517
const NOTIFICATION_ADD = 'NOTIFICATION_ADD'
16-
export const addNotification = registerAction.normal(NOTIFICATION_ADD,
18+
export const addNotification = registerAction.normal(
19+
NOTIFICATION_ADD,
1720
(notification) => {
1821
const notifKey = Date.now()
1922
let defaultNotification = {
2023
message: '',
21-
action: 'Dismiss',
24+
action: '',
25+
notifyType: NOTIFY_TYPE.SUCCESS, // 默认弹出success弹窗
2226
key: notifKey,
2327
dismissAfter: 6000,
2428
onClick: () => removeNotification(notifKey)
@@ -28,7 +32,7 @@ export const addNotification = registerAction.normal(NOTIFICATION_ADD,
2832
defaultNotification = {
2933
...defaultNotification,
3034
barStyle: { backgroundColor: 'red' },
31-
actionStyle: { color: 'white' },
35+
actionStyle: { color: 'white' }
3236
}
3337
}
3438

app/components/Notification/index.jsx

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,87 @@ import { NotificationStack } from 'react-notification'
44
import * as actions from './actions'
55
import state from './state'
66

7-
const barStyleFactory = (index, style) => {
8-
return Object.assign({}, style, {
7+
const actionStyleFactory = (index, style) =>
8+
Object.assign({}, style, {
9+
color: '#ccc',
10+
right: '-100%',
11+
bottom: 'initial',
12+
top: `${2 + index * 4}rem`,
13+
zIndex: 20,
14+
fontSize: '12px',
15+
padding: '8px'
16+
})
17+
const barStyleFactory = (index, style) =>
18+
Object.assign({}, style, {
919
left: 'initial',
1020
right: '-100%',
1121
bottom: 'initial',
1222
top: `${2 + index * 4}rem`,
1323
zIndex: 20,
1424
fontSize: '12px',
15-
padding: '8px',
25+
padding: '8px'
1626
})
17-
}
1827

19-
const activeBarStyleFactory = (index, style) => {
20-
return Object.assign({}, style, {
28+
const activeBarStyleFactory = (index, style) =>
29+
Object.assign({}, style, {
2130
left: 'initial',
2231
right: '1rem',
2332
bottom: 'initial',
2433
top: `${2 + index * 4}rem`,
2534
fontSize: '12px',
26-
padding: '8px',
35+
padding: '8px'
2736
})
37+
38+
function notificationMessageFactory (notifyType, message) {
39+
let ClassName
40+
let Color
41+
switch (notifyType) {
42+
case 'error':
43+
ClassName = 'fa fa-times-circle'
44+
Color = 'red'
45+
break
46+
case 'success':
47+
ClassName = 'fa fa-check-circle'
48+
Color = 'green'
49+
break
50+
case 'warning':
51+
ClassName = 'fa fa-exclamation-triangle'
52+
Color = 'orange'
53+
break
54+
case 'info':
55+
ClassName = 'fa fa-info-circle'
56+
Color = 'blue'
57+
break
58+
default:
59+
}
60+
return (
61+
<span style={{ fontSize: 12 }}>
62+
<span style={{ color: Color }}>
63+
<i className={ClassName} aria-hidden='true' />
64+
</span>
65+
&nbsp;&nbsp;{message}
66+
</span>
67+
)
2868
}
2969

3070
class Notification extends Component {
3171
constructor (props) {
3272
super()
3373
}
74+
3475
render () {
35-
const { notifications } = this.props
76+
const notifications = this.props.notifications.map((v) => {
77+
v.action = <i className='fa fa-close' aria-hidden='true' />
78+
v.dismissAfter = false
79+
v.message = notificationMessageFactory(v.notifyType, v.message)
80+
return v
81+
})
3682
return (
3783
<NotificationStack
3884
notifications={notifications}
3985
onDismiss={notification => actions.removeNotification(notification.key)}
4086
barStyleFactory={barStyleFactory}
87+
actionStyleFactory={actionStyleFactory}
4188
activeBarStyleFactory={activeBarStyleFactory}
4289
/>
4390
)

0 commit comments

Comments
 (0)