king
2021-08-31 12add7610dc9a998b4296e3f203fa858694bdbd3
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
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,         // 按钮组
    columns: PropTypes.array,         // 显示列
    setting: PropTypes.any,           // 页面通用设置
    ContainerId: PropTypes.any        // tab页面ID,用于弹窗控制
  }
 
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
 
  getButtonList = (actions) => {
    const { BID, BData, MenuID, Tab, columns, setting, ContainerId, selectedData } = this.props
 
    return actions.map(item => {
      if (['exec', 'prompt', 'pop'].includes(item.OpenType)) {
        return (
          <NormalButton
            key={item.uuid}
            show={item.show || 'actionList'}
            BID={BID}
            Tab={Tab}
            btn={item}
            BData={BData}
            setting={setting}
            columns={columns}
            position="toolbar"
            ContainerId={ContainerId}
            selectedData={selectedData}
          />
        )
      } else if (item.OpenType === 'excelIn') {
        return (
          <ExcelInButton
            key={item.uuid}
            show={item.show || 'actionList'}
            BID={BID}
            Tab={Tab}
            btn={item}
            setting={setting}
            position="toolbar"
            selectedData={selectedData}
          />
        )
      } else if (item.OpenType === 'excelOut') {
        return (
          <ExcelOutButton
            key={item.uuid}
            show={item.show || 'actionList'}
            BID={BID}
            Tab={Tab}
            btn={item}
            setting={setting}
            position="toolbar"
          />
        )
      } else if (item.OpenType === 'popview') {
        return (
          <PopupButton
            key={item.uuid}
            show={item.show || 'actionList'}
            BID={BID}
            Tab={Tab}
            btn={item}
            BData={BData}
            setting={setting}
            position="toolbar"
            selectedData={selectedData}
          />
        )
      } else if (item.OpenType === 'tab') {
        return (
          <TabButton
            key={item.uuid}
            show={item.show || 'actionList'}
            btn={item}
            MenuID={MenuID}
            setting={setting}
            position="toolbar"
            selectedData={selectedData}
          />
        )
      } else if (item.OpenType === 'innerpage' || item.OpenType === 'outerpage') {
        return (
          <NewPageButton
            key={item.uuid}
            show="actionList"
            btn={item}
            setting={setting}
            position="toolbar"
            selectedData={selectedData}
          />
        )
      } else if (item.OpenType === 'funcbutton') {
        if (item.funcType === 'changeuser' || item.funcType === 'closetab') {
          return (
            <ChangeUserButton
              key={item.uuid}
              show={item.show || 'actionList'}
              BID={BID}
              btn={item}
              MenuID={MenuID}
              setting={setting}
              position="toolbar"
              selectedData={selectedData}
            />
          )
        } else if (item.funcType === 'print') {
          return (
            <PrintButton
              key={item.uuid}
              show={item.show || 'actionList'}
              BID={BID}
              Tab={Tab}
              btn={item}
              BData={BData}
              setting={setting}
              position="toolbar"
              ContainerId={ContainerId}
              selectedData={selectedData}
            />
          )
        }
      }
      return null
    })
  }
 
  render() {
    const { setting, MenuID, actions } = this.props
    let fixed = setting.actionfixed && setting.tabType === 'main' // 按钮是否固定在头部
 
    if (fixed && MenuID) {
      return (
        <Affix offsetTop={48}>
          <div className="button-list toolbar-button" id={fixed ? MenuID + 'mainaction' : ''}>
            {this.getButtonList(actions)}
          </div>
        </Affix>
      )
    } else {
      return (
        <div className="button-list toolbar-button" id={fixed ? MenuID + 'mainaction' : ''}>
          {this.getButtonList(actions)}
        </div>
      )
    }
  }
}
 
export default ActionList