import React, { Component } from 'react'
|
import { notification } from 'antd'
|
import moment from 'moment'
|
|
import Api from '@/api'
|
import MKEmitter from '@/utils/events.js'
|
import url from './msg.png'
|
|
class SysIcon extends Component {
|
state = {
|
notices: null
|
}
|
|
componentDidMount () {
|
setTimeout(() => {
|
this.getMsgList()
|
}, 2000)
|
}
|
|
getMsgList = () => {
|
let param = {
|
func: 's_get_unread_oa_mail_v1'
|
}
|
|
Api.genericInterface(param).then(result => {
|
if (result.status) {
|
let notices = result.data || []
|
notices.forEach(item => {
|
let time = new Date(item.submitdate).getTime()
|
let _val = item.submitdate
|
if (!isNaN(time)) {
|
time = parseInt(time / 60000) // 时间值
|
let now = parseInt(new Date().getTime() / 60000) // 当前时间值
|
let start = new Date(new Date().toDateString()).getTime() / 60000 // 今天零点时间值
|
let split = now - time
|
|
if (split < 0) { // 时间值在当前时间之后
|
_val = moment(_val).format('MM月DD日 HH:mm')
|
} else if (split < 3) {
|
_val = '刚刚'
|
} else if (split < 5) {
|
_val = '3分钟前'
|
} else if (split < 10) {
|
_val = '5分钟前'
|
} else if (split < 20) {
|
_val = '10分钟前'
|
} else if (split < 30) {
|
_val = '20分钟前'
|
} else if (split < 60) {
|
_val = '30分钟前'
|
} else if (split < 420 || time > start) { // 7小时内或时间值在今天零点后
|
_val = parseInt(split / 60) + '小时前'
|
} else { // 时间值在今天零点之前
|
let _day = parseInt((start - time) / (24 * 60)) + 1
|
if (_day === 1) {
|
_val = '昨天'
|
} else if (_day <= 30) {
|
_val = _day + '天前'
|
} else {
|
_val = moment(_val).format('MM月DD日 HH:mm')
|
}
|
}
|
}
|
item.time = _val
|
})
|
|
this.setState({ notices })
|
|
MKEmitter.emit('sysMessageChange', notices.slice(0, 5))
|
|
if (notices.length > 0) {
|
setTimeout(() => {
|
MKEmitter.emit('sysMessageOpen')
|
}, 50)
|
}
|
|
setTimeout(() => {
|
this.getMsgList()
|
}, 600000)
|
} else {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
|
open = () => {
|
const { notices } = this.state
|
|
if (notices.length === 0) {
|
this.toMenu()
|
} else {
|
MKEmitter.emit('sysMessageOpen')
|
}
|
}
|
|
toMenu = () => {
|
let menu = {
|
MenuID: '1731250110643ivgpv9gdgiif5lggh4e',
|
MenuName: '内部邮箱',
|
type: 'CustomPage',
|
param: {$BID: ''}
|
}
|
|
if (window.GLOB.mkThdMenus.has(menu.MenuID)) {
|
menu.MenuName = window.GLOB.mkThdMenus.get(menu.MenuID).MenuName
|
}
|
|
MKEmitter.emit('modifyTabs', menu)
|
}
|
|
render() {
|
const { notices } = this.state
|
|
if (!notices) return null
|
|
return (
|
<span className="mk-msg-icon" onClick={this.open}>
|
<img src={url} alt=""/>
|
<span>{notices.length ? notices.length : ''}</span>
|
</span>
|
)
|
}
|
}
|
|
export default SysIcon
|