king
2019-09-23 cec9290f6cd8e3e7e881f4d38d43de307645a08a
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
// import { is, fromJS } from 'immutable'
import { Button, Affix, Modal } from 'antd'
import './index.scss'
 
const { confirm } = Modal
 
class MainAction extends Component {
  static propTpyes = {
    actions: PropTypes.array, // 搜索条件列表
    dict: PropTypes.object, // 字典项
    fixed: PropTypes.any
  }
 
  state = {
 
  }
 
  actionTrigger = (item) => {
    if (item.Action === 'Prompt' || item.Action === 'Delete') {
      confirm({
        title: this.props.dict['main.action.confirm.tip'],
        // content: 'Some descriptions',
        onOk() {
          return new Promise((resolve, reject) => {
            setTimeout(Math.random() > 0.5 ? resolve : reject, 1000)
          }).catch(() => console.log('Oops errors!'))
        },
        onCancel() {
          console.log('Cancel')
        }
      })
    }
  }
 
  UNSAFE_componentWillMount () {
 
  }
 
  // shouldComponentUpdate (nextProps, nextState) {
  //   console.log(!is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)))
  //   return true
  // }
 
  render() {
    if (this.props.fixed) { // 按钮是否固定在头部
      return (
        <Affix offsetTop={48}>
          <div className="button-list">
            {this.props.actions.map((item, index) => {
              return (
                <Button
                  className={'mk-btn ' + item.CssClass}
                  icon={item.Icon}
                  key={'action' + index}
                  onClick={() => {this.actionTrigger(item)}}
                >{item.MenuName}</Button>
              )
            })}
          </div>
        </Affix>
      )
    }
    return (
      <div className="button-list">
        {this.props.actions.map((item, index) => {
          return (
            <Button
              className={'mk-btn ' + item.CssClass}
              icon={item.Icon}
              key={'action' + index}
              onClick={() => {this.actionTrigger(item)}}
            >{item.MenuName}</Button>
          )
        })}
      </div>
    )
  }
}
 
export default MainAction