import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { fromJS } from 'immutable'
|
import { Modal, Form, Row, Col, Select, Icon, Radio, Tooltip, Input, InputNumber } from 'antd'
|
|
import { getPieChartOptionForm } from './formconfig'
|
import ColorSketch from '@/mob/colorsketch'
|
import './index.scss'
|
|
class LineChartDrawerForm extends Component {
|
static propTpyes = {
|
dict: PropTypes.object,
|
plot: PropTypes.object,
|
config: PropTypes.object,
|
plotchange: PropTypes.func
|
}
|
|
state = {
|
visible: false,
|
plot: null,
|
formlist: null
|
}
|
|
showDrawer = () => {
|
const { config } = this.props
|
|
this.setState({
|
visible: true,
|
plot: fromJS(config.plot).toJS(),
|
formlist: getPieChartOptionForm(config.plot, config.columns, config.setting)
|
})
|
}
|
|
radioChange = (e, key) => {
|
const { formlist } = this.state
|
let val = e.target.value
|
|
if (key === 'shape') {
|
this.setState({
|
formlist: formlist.map(item => {
|
if (item.key === 'innerRadius') {
|
item.hidden = val === 'pie'
|
}
|
return item
|
})
|
})
|
}
|
}
|
|
getFields() {
|
const { formlist } = this.state
|
const { getFieldDecorator } = this.props.form
|
const fields = []
|
|
if (!formlist) {
|
return fields
|
}
|
|
formlist.forEach((item, index) => {
|
if (item.hidden || item.forbid) return
|
|
if (item.type === 'text') {
|
fields.push(
|
<Col span={12} key={index}>
|
<Form.Item label={item.tooltip ?
|
<Tooltip placement="topLeft" title={item.tooltip}>
|
<Icon type="question-circle" />
|
{item.label}
|
</Tooltip> : item.label
|
}>
|
{getFieldDecorator(item.key, {
|
initialValue: item.initVal,
|
rules: [
|
{
|
required: !!item.required,
|
message: this.props.dict['form.required.input'] + item.label + '!'
|
}
|
]
|
})(<Input placeholder="" autoComplete="off" disabled={item.readonly}/>)}
|
</Form.Item>
|
</Col>
|
)
|
} else if (item.type === 'number') {
|
fields.push(
|
<Col span={12} key={index}>
|
<Form.Item label={item.tooltip ?
|
<Tooltip placement="topLeft" title={item.tooltip}>
|
<Icon type="question-circle" />
|
{item.label}
|
</Tooltip> : item.label
|
}>
|
{getFieldDecorator(item.key, {
|
initialValue: item.initVal,
|
rules: [
|
{
|
required: !!item.required,
|
message: this.props.dict['form.required.input'] + item.label + '!'
|
}
|
]
|
})(<InputNumber min={item.min} max={item.max} precision={item.decimal} />)}
|
</Form.Item>
|
</Col>
|
)
|
} else if (item.type === 'select') { // 下拉
|
fields.push(
|
<Col span={12} key={index}>
|
<Form.Item label={item.tooltip ?
|
<Tooltip placement="topLeft" title={item.tooltip}>
|
<Icon type="question-circle" />
|
{item.label}
|
</Tooltip> : item.label
|
}>
|
{getFieldDecorator(item.key, {
|
initialValue: item.initVal,
|
rules: [
|
{
|
required: !!item.required,
|
message: this.props.dict['form.required.select'] + item.label + '!'
|
}
|
]
|
})(
|
<Select mode={item.multi ? 'multiple' : ''}>
|
{item.options.map((option, index) =>
|
<Select.Option key={index} value={option.field}>
|
{option.label}
|
</Select.Option>
|
)}
|
</Select>
|
)}
|
</Form.Item>
|
</Col>
|
)
|
} else if (item.type === 'radio') {
|
fields.push(
|
<Col span={12} key={index}>
|
<Form.Item label={item.tooltip ?
|
<Tooltip placement="topLeft" title={item.tooltip}>
|
<Icon type="question-circle" />
|
{item.label}
|
</Tooltip> : item.label
|
}>
|
{getFieldDecorator(item.key, {
|
initialValue: item.initVal,
|
rules: [
|
{
|
required: !!item.required,
|
message: this.props.dict['form.required.select'] + item.label + '!'
|
}
|
]
|
})(
|
<Radio.Group disabled={item.readonly} onChange={(e) => this.radioChange(e, item.key)}>
|
{item.options.map(option => {
|
return (
|
<Radio key={option.value} value={option.value}>{option.text}</Radio>
|
)
|
})}
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
)
|
} else if (item.type === 'color') {
|
fields.push(
|
<Col span={12} key={index}>
|
<Form.Item label={item.tooltip ?
|
<Tooltip placement="topLeft" title={item.tooltip}>
|
<Icon type="question-circle" />
|
{item.label}
|
</Tooltip> : item.label
|
}>
|
{getFieldDecorator(item.key, {
|
initialValue: item.initVal
|
})(
|
<ColorSketch />
|
)}
|
</Form.Item>
|
</Col>
|
)
|
}
|
})
|
return fields
|
}
|
|
axisChange = (e) => {
|
const { plot } = this.state
|
let val = e.target.value
|
let fieldvalue = {}
|
|
plot.customs.forEach(item => {
|
if (this.props.form.getFieldValue(item.field + '$axis') === val) {
|
fieldvalue[item.field + '$axis'] = 'unset'
|
}
|
})
|
|
this.props.form.setFieldsValue(fieldvalue)
|
}
|
|
enabledChange = (e) => {
|
let val = e.target.value
|
|
this.setState({enabled: val})
|
}
|
|
onSubmit = () => {
|
const { config } = this.props
|
const { plot } = this.state
|
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
if (!err) {
|
let _plot = {...plot, ...values}
|
|
this.setState({
|
plot: _plot,
|
visible: false
|
})
|
|
this.props.plotchange({...config, plot: _plot})
|
}
|
})
|
}
|
|
|
render() {
|
const { visible } = this.state
|
const formItemLayout = {
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 6 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 18 }
|
}
|
}
|
|
return (
|
<div className="line-chart-drawer-form">
|
<Icon type="edit" onClick={this.showDrawer} />
|
<Modal
|
wrapClassName="popview-modal menu-chart-edit-modal"
|
title="图表编辑"
|
visible={visible}
|
width={850}
|
maskClosable={false}
|
onOk={this.onSubmit}
|
onCancel={() => { this.setState({ visible: false }) }}
|
destroyOnClose
|
>
|
<Form {...formItemLayout}>
|
<Row gutter={16}>{this.getFields()}</Row>
|
</Form>
|
</Modal>
|
</div>
|
);
|
}
|
}
|
|
export default Form.create()(LineChartDrawerForm)
|