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 || data.$disabled) 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) {
|
let _menu = this.props.permMenus.filter(m => m.MenuID === card.setting.MenuID)[0] || ''
|
menu = {
|
MenuID: card.setting.MenuID,
|
MenuName: _menu ? _menu.MenuName : card.setting.MenuName,
|
MenuNo: card.setting.MenuNo,
|
type: _menu ? _menu.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, data.$$selectedData || [])
|
} else if (cards.subtype === 'datacard') {
|
MKEmitter.emit('triggerBtnId', card.setting.linkbtn, [data], 'linkbtn')
|
} else {
|
MKEmitter.emit('triggerBtnId', card.setting.linkbtn, data.$$empty ? [] : [data])
|
}
|
}
|
}
|
|
doubleClick = () => {
|
const { card, data, cards } = this.props
|
|
if (card.setting.click !== 'button' || card.setting.clickType !== 'multi' || data.$disabled) return
|
|
if (card.setting.linkbtn) {
|
if (data.$$type === 'extendCard') {
|
MKEmitter.emit('triggerBtnId', card.setting.linkbtn, data.$$selectedData || [])
|
} else if (cards.subtype === 'datacard') {
|
MKEmitter.emit('triggerBtnId', card.setting.linkbtn, [data], 'linkbtn')
|
} else {
|
MKEmitter.emit('triggerBtnId', card.setting.linkbtn, data.$$empty ? [] : [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)
|