king
2020-08-17 df565b506ddb2bed918befceefddcd529eb58782
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Affix } from 'antd'
 
import asyncComponent from './asyncButtonComponent'
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
import './index.scss'
 
const NormalButton = asyncComponent(() => import('./normalbutton'))
const ExcelInButton = asyncComponent(() => import('./excelInbutton'))
const ExcelOutButton = asyncComponent(() => import('./exceloutbutton'))
const PopupButton = asyncComponent(() => import('./popupbutton'))
const TabButton = asyncComponent(() => import('./tabbutton'))
const NewPageButton = asyncComponent(() => import('./newpagebutton'))
const ChangeUserButton = asyncComponent(() => import('./changeuserbutton'))
const PrintButton = asyncComponent(() => import('./printbutton'))
 
class ActionList extends Component {
  static propTpyes = {
    BID: PropTypes.any,               // 主表ID
    BData: PropTypes.any,             // 主表数据
    selectedData: PropTypes.any,      // 子表中选择数据
    Tab: PropTypes.any,               // 如果当前元素为标签时,tab为标签信息
    MenuID: PropTypes.string,         // 菜单ID
    actions: PropTypes.array,         // 按钮组
    operations: PropTypes.array,      // 表格中按钮组
    logcolumns: PropTypes.array,      // 显示列
    setting: PropTypes.any,           // 页面通用设置
    ContainerId: PropTypes.any,       // tab页面ID,用于弹窗控制
    refreshdata: PropTypes.func,      // 执行完成后数据刷新
    getexceloutparam: PropTypes.func, // 获取excel导出数据
    triggerBtn: PropTypes.any,        // 快捷键触发的按钮
  }
 
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    running: false,
    triggerBtn: null
  }
 
  /**
   * @description 上级菜单id变化时,刷新数据
   */
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (nextProps.triggerBtn && !is(fromJS(this.props.triggerBtn), fromJS(nextProps.triggerBtn)) && nextProps.triggerBtn.parentId === this.props.MenuID) {
      if (!this.state.running) {
        this.setState({
          triggerBtn: nextProps.triggerBtn
        })
      }
    }
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
 
  updateStatus = (type, positon, unclose) => {
    if (type === 'start') {
      this.setState({running: true})
    } else if (type === 'over') {
      this.setState({running: false})
    } else if (type === 'refresh') {
      this.props.refreshdata(positon)
      if (!unclose) {
        this.setState({running: false})
      }
    } else if (type === 'trigger') { // 日历中的新标签页触发事件
      this.props.refreshdata('trigger')
    }
  }
 
  getButtonList = (actions) => {
    const { BID, BData, MenuID, Tab, logcolumns, setting, ContainerId, selectedData, getexceloutparam } = this.props
 
    return actions.map(item => {
      if (['exec', 'prompt', 'pop'].includes(item.OpenType)) {
        return (
          <NormalButton
            key={item.uuid}
            BID={BID}
            Tab={Tab}
            btn={item}
            BData={BData}
            setting={setting}
            columns={logcolumns}
            ContainerId={ContainerId}
            selectedData={selectedData}
            triggerBtn={this.state.triggerBtn}
            updateStatus={this.updateStatus}
          />
        )
      } else if (item.OpenType === 'excelIn') {
        return (
          <ExcelInButton
            key={item.uuid}
            BID={BID}
            Tab={Tab}
            btn={item}
            setting={setting}
            selectedData={selectedData}
            triggerBtn={this.state.triggerBtn}
            updateStatus={this.updateStatus}
          />
        )
      } else if (item.OpenType === 'excelOut') {
        return (
          <ExcelOutButton
            key={item.uuid}
            BID={BID}
            Tab={Tab}
            btn={item}
            setting={setting}
            triggerBtn={this.state.triggerBtn}
            getexceloutparam={getexceloutparam}
            updateStatus={this.updateStatus}
          />
        )
      } else if (item.OpenType === 'popview') {
        return (
          <PopupButton
            key={item.uuid}
            BID={BID}
            Tab={Tab}
            btn={item}
            BData={BData}
            setting={setting}
            selectedData={selectedData}
            triggerBtn={this.state.triggerBtn}
            updateStatus={this.updateStatus}
          />
        )
      } else if (item.OpenType === 'tab' || item.OpenType === 'blank') {
        return (
          <TabButton
            key={item.uuid}
            btn={item}
            MenuID={MenuID}
            setting={setting}
            selectedData={selectedData}
            triggerBtn={this.state.triggerBtn}
            updateStatus={this.updateStatus}
          />
        )
      } else if (item.OpenType === 'innerpage' || item.OpenType === 'outerpage') {
        return (
          <NewPageButton
            key={item.uuid}
            btn={item}
            setting={setting}
            selectedData={selectedData}
            updateStatus={this.updateStatus}
            triggerBtn={this.state.triggerBtn}
          />
        )
      } else if (item.OpenType === 'funcbutton') {
        if (item.funcType === 'changeuser') {
          return (
            <ChangeUserButton
              key={item.uuid}
              BID={BID}
              btn={item}
              setting={setting}
              selectedData={selectedData}
              triggerBtn={this.state.triggerBtn}
              updateStatus={this.updateStatus}
            />
          )
        } else if (item.funcType === 'print') {
          return (
            <PrintButton
              key={item.uuid}
              BID={BID}
              Tab={Tab}
              btn={item}
              BData={BData}
              setting={setting}
              ContainerId={ContainerId}
              selectedData={selectedData}
              triggerBtn={this.state.triggerBtn}
              updateStatus={this.updateStatus}
            />
          )
        }
      }
      return null
    })
  }
 
  render() {
    const { setting, MenuID, actions, operations } = this.props
    let fixed = setting.actionfixed && setting.tabType === 'main' // 按钮是否固定在头部
 
    if (fixed) {
      return (
        <Affix offsetTop={48}>
          <div className="button-list toolbar-button" id={fixed ? MenuID + 'mainaction' : ''}>
            {this.getButtonList(actions)}
            {operations && operations.length > 0 ? <div className="grid-button-list">{this.getButtonList(operations)}</div> : null}
          </div>
        </Affix>
      )
    } else {
      return (
        <div className="button-list toolbar-button" id={fixed ? MenuID + 'mainaction' : ''}>
          {this.getButtonList(actions)}
          {operations && operations.length > 0 ? <div className="grid-button-list">{this.getButtonList(operations)}</div> : null}
        </div>
      )
    }
  }
}
 
export default ActionList