import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Icon, Popover } from 'antd'
|
|
import asyncComponent from '@/utils/asyncComponent'
|
import asyncIconComponent from '@/utils/asyncIconComponent'
|
import { resetStyle } from '@/utils/utils-custom.js'
|
import MKEmitter from '@/utils/events.js'
|
import Utils from '@/utils/utils.js'
|
import getWrapForm from './options'
|
import zhCN from '@/locales/zh-CN/model.js'
|
import enUS from '@/locales/en-US/model.js'
|
import './index.scss'
|
|
const SettingComponent = asyncIconComponent(() => import('@/menu/datasource'))
|
const NormalForm = asyncIconComponent(() => import('@/components/normalform'))
|
const CardSimpleComponent = asyncComponent(() => import('@/menu/components/card/cardsimplecomponent'))
|
const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent'))
|
const UserComponent = asyncIconComponent(() => import('@/menu/components/share/usercomponent'))
|
const NormalHeader = asyncComponent(() => import('@/menu/components/share/normalheader'))
|
|
class NormalTimelineComponent extends Component {
|
static propTpyes = {
|
card: PropTypes.object,
|
deletecomponent: PropTypes.func,
|
updateConfig: PropTypes.func,
|
}
|
|
state = {
|
dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
card: null,
|
back: false
|
}
|
|
UNSAFE_componentWillMount () {
|
const { card } = this.props
|
|
if (card.isNew) {
|
let _card = {
|
uuid: card.uuid,
|
type: card.type,
|
floor: card.floor,
|
tabId: card.tabId || '',
|
parentId: card.parentId || '',
|
format: 'array', // 组件属性 - 数据格式
|
pageable: false, // 组件属性 - 是否可分页
|
switchable: false, // 组件属性 - 数据是否可切换
|
dataName: card.dataName || '',
|
width: card.width || 24,
|
name: card.name,
|
subtype: card.subtype,
|
setting: { interType: 'system' },
|
wrap: { title: '', name: card.name, width: card.width || 24, color: '#1890ff', mode: 'left' },
|
style: { marginLeft: '0px', marginRight: '0px', marginTop: '0px', marginBottom: '0px' },
|
subcards: [{
|
uuid: Utils.getuuid(),
|
setting: { width: 24, type: 'simple'},
|
style: {
|
paddingTop: '5px', paddingBottom: '5px', paddingLeft: '15px', paddingRight: '15px',
|
},
|
elements: []
|
}],
|
columns: [],
|
scripts: [],
|
}
|
|
if (card.config) {
|
let config = fromJS(card.config).toJS()
|
|
_card.wrap = config.wrap
|
_card.wrap.name = card.name
|
_card.style = config.style
|
|
_card.subcards = config.subcards.map(scard => {
|
scard.uuid = Utils.getuuid()
|
scard.elements = scard.elements.map(elem => {
|
elem.uuid = Utils.getuuid()
|
return elem
|
})
|
return scard
|
})
|
}
|
this.setState({
|
card: _card
|
})
|
this.props.updateConfig(_card)
|
} else {
|
this.setState({
|
card: fromJS(card).toJS()
|
})
|
}
|
}
|
|
componentDidMount () {
|
MKEmitter.addListener('submitStyle', this.getStyle)
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
/**
|
* @description 组件销毁,清除state更新,清除快捷键设置
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('submitStyle', this.getStyle)
|
}
|
|
/**
|
* @description 卡片行外层信息更新(数据源,样式等)
|
*/
|
updateComponent = (component) => {
|
this.setState({
|
card: component
|
})
|
|
component.width = component.wrap.width
|
component.name = component.wrap.name
|
|
this.props.updateConfig(component)
|
}
|
|
updateCard = (cell) => {
|
let card = fromJS(this.state.card).toJS()
|
|
card.subcards = card.subcards.map(item => {
|
if (item.uuid === cell.uuid) return cell
|
return item
|
})
|
|
this.setState({card})
|
|
this.props.updateConfig(card)
|
}
|
|
changeStyle = () => {
|
const { card } = this.state
|
|
MKEmitter.emit('changeStyle', [card.uuid], ['height', 'background', 'border', 'padding', 'margin', 'shadow'], card.style)
|
}
|
|
getStyle = (comIds, style) => {
|
const { card } = this.state
|
|
if (comIds.length !== 1 || comIds[0] !== card.uuid) return
|
|
let _card = {...card, style}
|
|
this.setState({
|
card: _card
|
})
|
|
this.props.updateConfig(_card)
|
}
|
|
getWrapForms = () => {
|
const { card } = this.state
|
|
return getWrapForm(card.wrap, card.columns)
|
}
|
|
updateWrap = (res) => {
|
delete res.quick
|
this.updateComponent({...this.state.card, wrap: res})
|
}
|
|
render() {
|
const { card } = this.state
|
|
let _style = resetStyle(card.style)
|
|
return (
|
<div className="menu-timeline-edit-box" style={_style} id={card.uuid}>
|
<Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
|
<div className="mk-popover-control">
|
{/* <Icon className="plus" title="添加元素" onClick={this.addElement} type="plus" /> */}
|
{/* <Icon className="plus" title="添加按钮" onClick={this.addButton} type="plus-square" /> */}
|
<NormalForm title="时间轴设置" width={800} update={this.updateWrap} getForms={this.getWrapForms}>
|
<Icon type="edit" style={{color: '#1890ff'}} title="编辑"/>
|
</NormalForm>
|
<CopyComponent type="timeline" card={card}/>
|
<Icon className="style" title="调整样式" onClick={this.changeStyle} type="font-colors" />
|
<UserComponent config={card}/>
|
<Icon className="close" title="删除组件" type="delete" onClick={() => this.props.deletecomponent(card.uuid)} />
|
<SettingComponent config={card} updateConfig={this.updateComponent} />
|
</div>
|
} trigger="hover">
|
<Icon type="tool" />
|
</Popover>
|
<NormalHeader hideSearch="true" config={card} updateComponent={this.updateComponent}/>
|
{card.subcards.map(subcard => (<CardSimpleComponent key={subcard.uuid} cards={card} card={subcard} updateElement={this.updateCard}/>))}
|
</div>
|
)
|
}
|
}
|
|
export default NormalTimelineComponent
|