king
2025-04-10 fcdfdc9670866fecd2d239d75a6ec28391175e9f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Modal, notification, Tabs, Button } from 'antd'
import { EditOutlined } from '@ant-design/icons'
 
import Utils from '@/utils/utils.js'
import { getBaseForm, getOptionForm } from './formconfig'
import asyncComponent from '@/utils/asyncComponent'
import './index.scss'
 
const { TabPane } = Tabs
 
const EditTable = asyncComponent(() => import('@/templates/zshare/editTable'))
const NormalForm = asyncComponent(() => import('@/components/normalform/modalform'))
 
class PieChartDrawerForm extends Component {
  static propTpyes = {
    plot: PropTypes.object,
    config: PropTypes.object,
    plotchange: PropTypes.func
  }
 
  state = {
    visible: false,
    plot: null,
    formlist: null,
    baseFormlist: null,
    view: 'base',
    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 = () => {
    const { config } = this.props
 
    this.setState({
      visible: true,
      view: 'base',
      plot: fromJS(config.plot).toJS(),
      baseFormlist: getBaseForm(config.plot),
      formlist: getOptionForm(config.plot, config.columns)
    })
  }
 
  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'
          } else if (item.key === 'type') {
            item.hidden = val !== 'nest'
          } else if (item.key === 'legend') {
            item.hidden = val === 'nest'
          }
          return item
        })
      }, () => {
        if (val === 'ring') {
          this.props.form.setFieldsValue({innerRadius: 50})
        }
      })
    }
  }
 
  onSubmit = () => {
    const { config } = this.props
    const { plot, view } = this.state
 
    if (view === 'normal') {
      this.normalRef.handleConfirm().then(values => {
        let _plot = {...plot, ...values}
        
        this.setState({
          plot: _plot,
          visible: false
        })
 
        this.props.plotchange({...config, plot: _plot})
      })
    } else if (view === 'base') {
      this.baseRef.handleConfirm().then(res => {
        let _plot = {...plot, ...res}
 
        this.setState({
          plot: _plot,
          visible: false
        })
 
        this.props.plotchange({...config, plot: _plot})
      })
    } else {
      this.setState({
        visible: false
      })
 
      this.props.plotchange({...config, plot: plot})
    }
  }
 
  changeTab = (tab) => {
    const { plot, view } = this.state
 
    if (view === 'normal') {
      this.normalRef.handleConfirm().then(values => {
        let _plot = {...plot, ...values}
 
        this.setState({
          plot: _plot,
          view: tab
        })
      })
    } else if (view === 'base') {
      this.baseRef.handleConfirm().then(res => {
        let _plot = {...plot, ...res}
 
        if (!plot.Xaxis && tab === 'color') {
          this.setState({
            plot: _plot,
            view: 'normal'
          })
          notification.warning({
            top: 92,
            message: '请添加图表设置。',
            duration: 3
          })
          return
        }
        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 { config } = this.props
    const { visible, plot, colorColumns, formlist, view, baseFormlist } = this.state
 
    return (
      <div className="line-chart-drawer-form">
        <EditOutlined title="编辑" onClick={this.showDrawer} />
        <Modal
          wrapClassName="mk-pop-modal"
          visible={visible}
          width={900}
          maskClosable={false}
          onOk={this.onSubmit}
          onCancel={() => { this.setState({ visible: false }) }}
          destroyOnClose
        >
          {config.name ? <div className="mk-com-name">{config.name} - 编辑</div> : null}
          <Tabs activeKey={view} className="menu-chart-edit-box" onChange={this.changeTab}>
            <TabPane tab="组件设置" key="base">
              <NormalForm formlist={baseFormlist} inputSubmit={this.onSubmit} wrappedComponentRef={(inst) => this.baseRef = inst}/>
            </TabPane>
            <TabPane tab="图表设置" key="normal">
              <NormalForm formlist={formlist} inputSubmit={this.onSubmit} wrappedComponentRef={(inst) => this.normalRef = inst}/>
            </TabPane>
            {plot ? <TabPane tab="颜色设置" key="color">
              <div>
                <Button className="color-add mk-green" onClick={this.addColor}>添加</Button>
                <EditTable actions={['edit', 'move', 'del']} data={plot.colors || []} columns={colorColumns} onChange={this.changeColor}/>
              </div>
            </TabPane> : null}
          </Tabs>
        </Modal>
      </div>
    );
  }
}
 
export default PieChartDrawerForm