king
2022-04-26 5046d0d13dc6a8563b8e54e31913bc44cfa1072f
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { is, fromJS } from 'immutable'
import { notification } from 'antd'
 
import asyncComponent from '@/utils/asyncComponent'
import MKEmitter from '@/utils/events.js'
import './index.scss'
 
const CardCellComponent = asyncComponent(() => import('../cardcellList'))
 
class CardBoxComponent extends Component {
  static propTpyes = {
    cards: PropTypes.object,    // 卡片行配置信息
    card: PropTypes.object,     // 卡片配置信息
    data: PropTypes.object,
  }
 
  state = {
    card: null,            // 卡片信息,包括正反面
  }
 
  /**
   * @description 搜索条件初始化
   */
  UNSAFE_componentWillMount () {
 
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState)) || !is(fromJS(this.props), fromJS(nextProps))
  }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  openView = () => {
    const { card, data, cards } = this.props
 
    if (!card.setting.click) return
 
    if (card.setting.click === 'menus' && cards.subtype === 'datacard' && card.$cardType !== 'extendCard') {
      let menu = null
      
      if (card.menus && card.menus.length > 0) {
        let s = data[card.setting.menuType] || ''
        card.menus.forEach(m => {
          if (s !== m.sign) return
          menu = m
        })
      }
      if (!menu || !menu.MenuID) {
        notification.warning({
          top: 92,
          message: '未查询到菜单信息!',
          duration: 5
        })
        return
      }
 
      menu.type = menu.tabType
 
      let newtab = {
        ...menu,
        param: {}
      }
 
      if (card.setting.joint === 'true') {
        newtab.param.$BID = data.$$uuid || ''
      }
 
      if (['linkage_navigation', 'linkage', 'menu_board'].includes(window.GLOB.navBar)) {
        MKEmitter.emit('modifyTabs', newtab, 'replace')
      } else {
        MKEmitter.emit('modifyTabs', newtab, 'plus', true)
      }
    } else if (card.setting.click === 'menu') {
      let menu = null
 
      if (card.setting.MenuID) {
        menu = {
          MenuID: card.setting.MenuID,
          MenuName: card.setting.MenuName,
          MenuNo: card.setting.MenuNo,
          type: card.setting.tabType
        }
      } else if (card.setting.menu && card.setting.menu.length > 0) {
        let menu_id = card.setting.menu.slice(-1)[0]
        menu = this.props.permMenus.filter(m => m.MenuID === menu_id)[0] || ''
 
        if (!menu) {
          notification.warning({
            top: 92,
            message: '菜单已删除或没有访问权限!',
            duration: 5
          })
          return
        }
      }
 
      let newtab = {
        ...menu,
        param: {}
      }
 
      if (card.setting.joint === 'true') {
        newtab.param.$BID = data.$$uuid || ''
      }
 
      if (['linkage_navigation', 'linkage', 'menu_board'].includes(window.GLOB.navBar)) {
        MKEmitter.emit('modifyTabs', newtab, 'replace')
      } else {
        MKEmitter.emit('modifyTabs', newtab, 'plus', true)
      }
    } else if (card.setting.click === 'link') {
      let src = card.setting.linkurl
 
      if (card.setting.joint === 'true') {
        let con = '?'
 
        if (/\?/ig.test(src)) {
          con = '&'
        }
 
        src = src + `${con}id=${data.$$uuid || ''}&appkey=${window.GLOB.appkey}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID') || ''}`
      }
 
      window.open(src)
    } else if (card.setting.click === 'button' && card.setting.clickType !== 'multi' && card.setting.linkbtn) {
      if (data.$$type === 'extendCard') {
        MKEmitter.emit('triggerBtnId', card.setting.linkbtn, [])
      } else if (cards.subtype === 'datacard') {
        MKEmitter.emit('triggerBtnId', card.setting.linkbtn, [data], 'linkbtn')
      } else {
        MKEmitter.emit('triggerBtnId', card.setting.linkbtn, [data])
      }
    }
  }
 
  doubleClick = () => {
    const { card, data, cards } = this.props
 
    if (card.setting.click !== 'button' || card.setting.clickType !== 'multi') return
 
    if (card.setting.linkbtn) {
      if (data.$$type === 'extendCard') {
        MKEmitter.emit('triggerBtnId', card.setting.linkbtn, [])
      } else if (cards.subtype === 'datacard') {
        MKEmitter.emit('triggerBtnId', card.setting.linkbtn, [data], 'linkbtn')
      } else {
        MKEmitter.emit('triggerBtnId', card.setting.linkbtn, [data])
      }
    }
  }
 
  render() {
    const { card, data, cards } = this.props
 
    return (
      <div className={'card-item-box ' + (card.setting.btnControl || '')} style={card.style} onClick={this.openView} onDoubleClick={this.doubleClick}>
        <CardCellComponent data={data} cards={cards} cardCell={card} elements={card.elements}/>
        {card.setting.type === 'multi' ? <div className={'back-side ' + card.setting.transform} style={card.backStyle}>
          <CardCellComponent data={data} cards={cards} cardCell={card} elements={card.backElements}/>
        </div> : null}
      </div>
    )
  }
}
 
const mapStateToProps = (state) => {
  return {
    permMenus: state.permMenus
  }
}
 
const mapDispatchToProps = () => {
  return {}
}
 
export default connect(mapStateToProps, mapDispatchToProps)(CardBoxComponent)