import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import {connect} from 'react-redux'
|
import { is, fromJS } from 'immutable'
|
|
import asyncComponent from '@/utils/asyncComponent'
|
|
import Utils from '@/utils/utils.js'
|
import zhCN from '@/locales/zh-CN/model.js'
|
import enUS from '@/locales/en-US/model.js'
|
import './index.scss'
|
|
const SettingComponent = asyncComponent(() => import('@/menu/datasource'))
|
const ActionComponent = asyncComponent(() => import('@/menu/actioncomponent'))
|
|
class antvBarLineChart extends Component {
|
static propTpyes = {
|
card: PropTypes.object,
|
updateConfig: PropTypes.func,
|
}
|
|
state = {
|
dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
card: null
|
}
|
|
UNSAFE_componentWillMount () {
|
const { card, menu } = this.props
|
|
if (card.isNew) {
|
let dataName = ''
|
|
if (card.floor === 1) {
|
while (!dataName) {
|
let _dataName = Utils.getdataName()
|
if (menu.components.filter(com => com.dataName === _dataName).length === 0) {
|
dataName = _dataName
|
}
|
}
|
}
|
|
let _card = {
|
uuid: card.uuid,
|
type: card.type,
|
floor: card.floor,
|
tabId: card.tabId || '',
|
parentId: card.parentId || '',
|
format: 'array', // 组件属性 - 数据格式
|
pageable: false, // 组件属性 - 是否可分页
|
switchable: false, // 组件属性 - 数据是否可切换
|
dataName: dataName,
|
subtype: card.subtype,
|
setting: {span: 24, height: 200, interType: 'system', name: card.name},
|
columns: [],
|
scripts: [],
|
search: [],
|
action: [],
|
}
|
this.setState({
|
card: _card
|
})
|
this.props.updateConfig(_card)
|
} else {
|
this.setState({
|
card: fromJS(card).toJS()
|
})
|
}
|
}
|
|
componentDidMount () {
|
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
/**
|
* @description 组件销毁,清除state更新,清除快捷键设置
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
updateComponent = (component) => {
|
this.setState({
|
card: component
|
})
|
this.props.updateConfig(component)
|
}
|
|
render() {
|
const { card } = this.state
|
|
return (
|
<div className="menu-data-card-edit-box" style={{height: card.setting.height || 400}}>
|
<SettingComponent
|
config={card}
|
updateConfig={this.updateComponent}
|
/>
|
<div className="chart-header">
|
<span className="chart-title">{card.setting.title || ''}</span>
|
</div>
|
<ActionComponent
|
type="chart"
|
config={card}
|
tabs={[]}
|
// setSubConfig={(_btn) => this.setSubConfig(_btn, 'button')}
|
updateaction={this.updateComponent}
|
/>
|
<div className="canvas" id={card.uuid}></div>
|
</div>
|
)
|
}
|
}
|
|
const mapStateToProps = (state) => {
|
return {
|
menu: state.customMenu
|
}
|
}
|
|
const mapDispatchToProps = () => {
|
return {}
|
}
|
|
export default connect(mapStateToProps, mapDispatchToProps)(antvBarLineChart)
|