king
2020-11-18 d3272e82652361e5e9bd045925222ef042b6731f
src/menu/components/chart/antv-pie/chartcompile/index.jsx
@@ -1,11 +1,17 @@
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 { Modal, Form, Row, Col, Select, Icon, Radio, Tooltip, Input, InputNumber, Tabs, Button } from 'antd'
import Utils from '@/utils/utils.js'
import { getPieChartOptionForm } from './formconfig'
import asyncComponent from '@/utils/asyncComponent'
import ColorSketch from '@/mob/colorsketch'
import './index.scss'
const { TabPane } = Tabs
const EditTable = asyncComponent(() => import('@/templates/zshare/editTable'))
class LineChartDrawerForm extends Component {
  static propTpyes = {
@@ -20,7 +26,27 @@
  state = {
    visible: false,
    plot: null,
    formlist: null
    formlist: null,
    view: 'normal',
    colorColumns: [
      {
        title: '指标',
        dataIndex: 'label',
        inputType: 'input',
        editable: true,
        width: '40%'
      },
      {
        title: '颜色',
        dataIndex: 'color',
        inputType: 'color',
        editable: true,
        width: '40%',
        render: (text, record) => {
          return (<div style={{width: '80px', height: '23px', background: text}}></div>)
        }
      },
    ]
  }
  showDrawer = () => {
@@ -28,6 +54,7 @@
    this.setState({
      visible: true,
      view: 'normal',
      plot: fromJS(config.plot).toJS(),
      formlist: getPieChartOptionForm(config.plot, config.columns, sysRoles, MenuType)
    })
@@ -211,8 +238,9 @@
  onSubmit = () => {
    const { config } = this.props
    const { plot } = this.state
    const { plot, view } = this.state
    if (view === 'normal') {
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        let _plot = {...plot, ...values}
@@ -225,11 +253,57 @@
        this.props.plotchange({...config, plot: _plot})
      }
    })
    } else {
      this.setState({
        visible: false
      })
      this.props.plotchange({...config, plot: plot})
    }
  }
  changeTab = (tab) => {
    const { plot } = this.state
    if (tab === 'color') {
      this.props.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          let _plot = {...plot, ...values}
          this.setState({
            plot: _plot,
            view: tab
          })
        }
      })
    } else {
      this.setState({
        view: tab
      })
    }
  }
  addColor = () => {
    let plot = fromJS(this.state.plot).toJS()
    plot.colors = plot.colors || []
    plot.colors.push({
      uuid: Utils.getuuid(),
      label: `指标${plot.colors.length}`,
      color: 'rgb(91, 143, 249)'
    })
    this.setState({plot})
  }
  changeColor = (colors) => {
    const { plot } = this.state
    this.setState({plot: {...plot, colors}})
  }
  render() {
    const { visible } = this.state
    const { visible, plot, colorColumns, view } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
@@ -254,9 +328,20 @@
          onCancel={() => { this.setState({ visible: false }) }}
          destroyOnClose
        >
          <Tabs activeKey={view} className="menu-chart-edit-box" onChange={this.changeTab}>
            <TabPane tab="基础设置" key="normal">
          <Form {...formItemLayout}>
            <Row gutter={16}>{this.getFields()}</Row>
          </Form>
            </TabPane>
            {plot ? <TabPane tab="颜色设置" key="color">
              <div>
                <Button className="color-add mk-green" onClick={this.addColor}>{this.props.dict['model.add']}</Button>
                <EditTable data={plot.colors || []} columns={colorColumns} onChange={this.changeColor}/>
              </div>
            </TabPane> : null}
          </Tabs>
        </Modal>
      </div>
    );