king
2025-05-14 e8ef7263819e847d55cd35e006aa02635fd7b82e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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