king
2024-10-18 b1fc0a89ce16dd14a6dff98c228a308e85a53828
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
import { Component } from 'react'
import { notification } from 'antd'
import moment from 'moment'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import MKEmitter from '@/utils/events.js'
 
/**
 * @description 操作记录,每隔10分钟更新一次
 */
class QueryLog extends Component {
  state = {
    logs: []
  }
 
  componentDidMount () {
    MKEmitter.addListener('queryTrigger', this.queryTrigger)
    setTimeout(() => {
      this.sendLog()
    }, 600000)
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('queryTrigger', this.queryTrigger)
  }
 
  sendLog = () => {
    const { logs } = this.state
 
    let logMap = new Map()
 
    logs.forEach(item => {
      if (logMap.has(item.menuId)) {
        let _item = logMap.get(item.menuId)
        _item.times++
        logMap.set(item.menuId, _item)
      } else {
        item.times = 1
        logMap.set(item.menuId, item)
      }
    })
 
    let userid = sessionStorage.getItem('UserID') || ''
    let LText = [...logMap.values()].map(item => `select '${item.menuId}','${item.times}','${item.name || ''}','${window.GLOB.appkey}','${userid}'`)
 
    if (LText.length === 0) {
      setTimeout(() => {
        this.sendLog()
      }, 600000)
      return
    }
 
    // {func: 's_get_local_users_operation_log'} 本地接口 返回 long_param 传入 sso 的 s_get_users_operation_log
 
    let param = {
      func: 's_get_users_operation_log',
      exec_type: window.GLOB.execType || 'y',
      LText: LText.join(' union all '),
      long_param: ''
    }
 
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt('', param.timestamp)
    param.LText = Utils.formatOptions(param.LText, param.exec_type)
 
    Api.getSystemConfig(param).then(result => {
      if (!result.status) {
        notification.warning({
          top: 92,
          message: result.message,
          duration: 3
        })
        return
      }
 
      setTimeout(() => {
        this.sendLog()
      }, 600000)
      this.setState({logs: []})
    })
  }
 
  queryTrigger = (item) => {
    this.setState({logs: [...this.state.logs, item]})
  }
 
  render () {
    return null
  }
}
 
export default QueryLog