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 { modifyTabview } from '@/store/action'
|
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 } = this.props
|
|
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,
|
selected: true,
|
param: {}
|
}
|
|
if (card.setting.joint === 'true') {
|
newtab.param.$BID = data.$$uuid || ''
|
}
|
|
if (['linkage_navigation', 'linkage', 'menu_board'].includes(window.GLOB.navBar)) {
|
this.props.modifyTabview([newtab])
|
} else {
|
let tabs = this.props.tabviews.filter((tab, i) => {
|
tab.selected = false
|
return tab.MenuID !== newtab.MenuID
|
})
|
|
if (this.props.tabviews.length > tabs.length) {
|
this.props.modifyTabview(fromJS(tabs).toJS())
|
}
|
|
this.setState({}, () => {
|
tabs.push(newtab)
|
this.props.modifyTabview(tabs)
|
})
|
}
|
} 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.linkbtn) {
|
MKEmitter.emit('triggerBtnId', card.setting.linkbtn, [data])
|
}
|
}
|
|
render() {
|
const { card, data, cards } = this.props
|
|
return (
|
<div className="card-item-box" style={card.style} onClick={this.openView}>
|
<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,
|
tabviews: state.tabviews,
|
}
|
}
|
|
const mapDispatchToProps = (dispatch) => {
|
return {
|
modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews))
|
}
|
}
|
|
export default connect(mapStateToProps, mapDispatchToProps)(CardBoxComponent)
|