king
2024-12-24 2998f413a5e196e99df887787aa4b250cd9f3b78
src/components/header/sysmessage/icon.jsx
@@ -1,13 +1,14 @@
import React, { Component } from 'react'
import { notification } from 'antd'
import { MessageFilled } from '@ant-design/icons'
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: []
    notices: null
  }
  componentDidMount () {
@@ -18,15 +19,60 @@
  getMsgList = () => {
    let param = {
      func: 's_get_kei'
      func: 's_get_unread_oa_mail_v1'
    }
    Api.getSystemConfig(param).then(result => {
    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)
        MKEmitter.emit('sysMessageChange', notices.slice(0, 5))
        if (notices.length > 0) {
          setTimeout(() => {
            MKEmitter.emit('sysMessageOpen')
          }, 50)
        }
        setTimeout(() => {
          this.getMsgList()
@@ -42,14 +88,40 @@
  }
  open = () => {
    MKEmitter.emit('sysMessageOpen')
    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 (
      <MessageFilled className="mk-msg-icon" data-title={notices.length ? notices.length : ''} onClick={this.open} />
      <span className="mk-msg-icon" onClick={this.open}>
        <img src={url} alt=""/>
        <span>{notices.length ? notices.length : ''}</span>
      </span>
    )
  }
}