import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Button, Icon } from 'antd'
|
|
import zhCN from '@/locales/zh-CN/model.js'
|
import enUS from '@/locales/en-US/model.js'
|
|
import './index.scss'
|
|
class CardCellComponent extends Component {
|
static propTpyes = {
|
cards: PropTypes.object, // 菜单配置信息
|
cardCell: PropTypes.object,
|
elements: PropTypes.array, // 元素集
|
}
|
|
state = {
|
dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
card: null, // 编辑中元素
|
elements: null, // 按钮组
|
}
|
|
/**
|
* @description 搜索条件初始化
|
*/
|
UNSAFE_componentWillMount () {
|
const { elements } = this.props
|
|
this.setState({
|
elements: fromJS(elements).toJS()
|
})
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
/**
|
* @description 组件销毁,清除state更新,清除快捷键设置
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
getContent = (card) => {
|
if (card.eleType === 'text' || card.eleType === 'number') {
|
let val = `${card.prefix || ''}${card.value || ''}${card.postfix || ''}`
|
return <span key={card.uuid}>{val}</span>
|
} else if (card.eleType === 'icon') {
|
return (<Icon key={card.uuid} type={card.icon}/>)
|
} else if (card.eleType === 'slider') {
|
return (
|
<div className="ant-mk-slider" key={card.uuid}>
|
<div className="ant-mk-slider-rail"></div>
|
<div className="ant-mk-slider-track" style={{width: '30%', backgroundColor: card.color}}></div>
|
<div className="ant-mk-slider-handle" style={{left: '30%', borderColor: card.color}}></div>
|
</div>
|
)
|
} else if (card.eleType === 'picture') {
|
let _imagestyle = {}
|
|
if (card.url) {
|
_imagestyle = {backgroundImage: `url('${card.url}')`}
|
} else {
|
_imagestyle = {backgroundImage: `url('')`}
|
}
|
|
if (card.radius === 'true') {
|
_imagestyle.borderRadius = '50%'
|
}
|
|
if (card.lenWidRadio === '16:9') {
|
_imagestyle.paddingTop = '56.25%'
|
} else if (card.lenWidRadio === '3:2') {
|
_imagestyle.paddingTop = '66.67%'
|
} else if (card.lenWidRadio === '4:3') {
|
_imagestyle.paddingTop = '75%'
|
} else {
|
_imagestyle.paddingTop = '100%'
|
}
|
|
return (
|
<div className="ant-mk-picture" key={card.uuid} style={_imagestyle}></div>
|
)
|
} else if (card.eleType === 'splitline') {
|
return (
|
<div className="ant-mk-splitline" key={card.uuid} style={{backgroundColor: card.color}}></div>
|
)
|
} else if (card.eleType === 'button') {
|
if (card.show === 'icon') {
|
return (card.icon ? <Button key={card.uuid} className={'mk-link mk-' + card.class} style={card.btnstyle} type="link"><Icon type={card.icon}/></Button> : null)
|
} else if (card.show === 'link') {
|
return (
|
<Button key={card.uuid} className={'mk-link mk-' + card.class} style={card.btnstyle} type="link">{card.label}{card.icon ? <Icon type={card.icon}/> : null}</Button>
|
)
|
} else {
|
return (
|
<Button
|
key={card.uuid}
|
className={'mk-btn mk-' + card.class}
|
icon={card.icon}
|
style={card.btnstyle}
|
>
|
{card.label}
|
</Button>
|
)
|
}
|
}
|
}
|
|
render() {
|
const { elements } = this.state
|
|
return (
|
<div className="model-menu-card-cell-list">
|
{elements.map(item => this.getContent(item))}
|
</div>
|
)
|
}
|
}
|
|
export default CardCellComponent
|