From 0c84df247914f893ef5e41d57a422e10a2dc814c Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 12 十一月 2021 17:02:06 +0800
Subject: [PATCH] 2021-11-12

---
 src/menu/components/chart/antv-pie/chartcompile/index.jsx |  186 +++++++++++++++++++++++++++++++++++-----------
 1 files changed, 141 insertions(+), 45 deletions(-)

diff --git a/src/menu/components/chart/antv-pie/chartcompile/index.jsx b/src/menu/components/chart/antv-pie/chartcompile/index.jsx
index 88c9d4e..e9ec92e 100644
--- a/src/menu/components/chart/antv-pie/chartcompile/index.jsx
+++ b/src/menu/components/chart/antv-pie/chartcompile/index.jsx
@@ -1,11 +1,19 @@
 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, Radio, Tooltip, Input, InputNumber, Tabs, Button } from 'antd'
+import { QuestionCircleOutlined, EditOutlined } from '@ant-design/icons'
 
-import { getPieChartOptionForm } from './formconfig'
+import Utils from '@/utils/utils.js'
+import { getBaseForm, getOptionForm } 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'))
+const NormalForm = asyncComponent(() => import('@/menu/components/share/normalform'))
 
 class LineChartDrawerForm extends Component {
   static propTpyes = {
@@ -18,7 +26,28 @@
   state = {
     visible: false,
     plot: null,
-    formlist: null
+    formlist: null,
+    baseFormlist: 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 = () => {
@@ -26,8 +55,10 @@
 
     this.setState({
       visible: true,
+      view: 'normal',
       plot: fromJS(config.plot).toJS(),
-      formlist: getPieChartOptionForm(config.plot, config.columns, config.setting)
+      baseFormlist: getBaseForm(config.plot),
+      formlist: getOptionForm(config.plot, config.columns)
     })
   }
 
@@ -40,6 +71,10 @@
         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
         })
@@ -70,7 +105,7 @@
           <Col span={12} key={index}>
             <Form.Item label={item.tooltip ?
               <Tooltip placement="topLeft" title={item.tooltip}>
-                <Icon type="question-circle" />
+                <QuestionCircleOutlined className="mk-form-tip" />
                 {item.label}
               </Tooltip> : item.label
             }>
@@ -82,7 +117,7 @@
                     message: this.props.dict['form.required.input'] + item.label + '!'
                   }
                 ]
-              })(<Input placeholder="" autoComplete="off" disabled={item.readonly}/>)}
+              })(<Input placeholder="" autoComplete="off" disabled={item.readonly} onPressEnter={this.onSubmit}/>)}
             </Form.Item>
           </Col>
         )
@@ -91,7 +126,7 @@
           <Col span={12} key={index}>
             <Form.Item label={item.tooltip ?
               <Tooltip placement="topLeft" title={item.tooltip}>
-                <Icon type="question-circle" />
+                <QuestionCircleOutlined className="mk-form-tip" />
                 {item.label}
               </Tooltip> : item.label
             }>
@@ -103,7 +138,7 @@
                     message: this.props.dict['form.required.input'] + item.label + '!'
                   }
                 ]
-              })(<InputNumber min={item.min} max={item.max} precision={item.decimal} />)}
+              })(<InputNumber min={item.min} max={item.max} precision={item.decimal} onPressEnter={this.onSubmit}/>)}
             </Form.Item>
           </Col>
         )
@@ -112,7 +147,7 @@
           <Col span={12} key={index}>
             <Form.Item label={item.tooltip ?
               <Tooltip placement="topLeft" title={item.tooltip}>
-                <Icon type="question-circle" />
+                <QuestionCircleOutlined className="mk-form-tip" />
                 {item.label}
               </Tooltip> : item.label
             }>
@@ -127,7 +162,7 @@
               })(
                 <Select mode={item.multi ? 'multiple' : ''}>
                   {item.options.map((option, index) =>
-                    <Select.Option key={index} value={option.field}>
+                    <Select.Option key={index} value={option.field || option.value}>
                       {option.label}
                     </Select.Option>
                   )}
@@ -141,7 +176,7 @@
           <Col span={12} key={index}>
             <Form.Item label={item.tooltip ?
               <Tooltip placement="topLeft" title={item.tooltip}>
-                <Icon type="question-circle" />
+                <QuestionCircleOutlined className="mk-form-tip" />
                 {item.label}
               </Tooltip> : item.label
             }>
@@ -154,7 +189,7 @@
                   }
                 ]
               })(
-                <Radio.Group disabled={item.readonly} onChange={(e) => this.radioChange(e, item.key)}>
+                <Radio.Group style={{whiteSpace: 'nowrap'}} 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>
@@ -170,7 +205,7 @@
           <Col span={12} key={index}>
             <Form.Item label={item.tooltip ?
               <Tooltip placement="topLeft" title={item.tooltip}>
-                <Icon type="question-circle" />
+                <QuestionCircleOutlined className="mk-form-tip" />
                 {item.label}
               </Tooltip> : item.label
             }>
@@ -187,47 +222,94 @@
     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
+    const { plot, view } = this.state
 
-    this.props.form.validateFieldsAndScroll((err, values) => {
-      if (!err) {
-        let _plot = {...plot, ...values}
-        
+    if (view === 'normal') {
+      this.props.form.validateFieldsAndScroll((err, values) => {
+        if (!err) {
+          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.props.form.validateFieldsAndScroll((err, values) => {
+        if (!err) {
+          let _plot = {...plot, ...values}
+
+          this.setState({
+            plot: _plot,
+            view: tab
+          })
+        }
+      })
+    } else if (view === 'base') {
+      this.baseRef.handleConfirm().then(res => {
+        let _plot = {...plot, ...res}
+
+        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, baseFormlist } = this.state
     const formItemLayout = {
       labelCol: {
         xs: { span: 24 },
@@ -241,7 +323,7 @@
 
     return (
       <div className="line-chart-drawer-form">
-        <Icon type="edit" onClick={this.showDrawer} />
+        <EditOutlined title="缂栬緫" onClick={this.showDrawer} />
         <Modal
           wrapClassName="popview-modal menu-chart-edit-modal"
           title="鍥捐〃缂栬緫"
@@ -252,9 +334,23 @@
           onCancel={() => { this.setState({ visible: false }) }}
           destroyOnClose
         >
-          <Form {...formItemLayout}>
-            <Row gutter={16}>{this.getFields()}</Row>
-          </Form>
+          <Tabs activeKey={view} className="menu-chart-edit-box" onChange={this.changeTab}>
+            <TabPane tab="缁勪欢璁剧疆" key="base">
+              <NormalForm dict={this.props.dict} formlist={baseFormlist} inputSubmit={this.onSubmit} wrappedComponentRef={(inst) => this.baseRef = inst}/>
+            </TabPane>
+            <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 actions={['edit', 'move', 'del']} data={plot.colors || []} columns={colorColumns} onChange={this.changeColor}/>
+              </div>
+            </TabPane> : null}
+          </Tabs>
+          
         </Modal>
       </div>
     );

--
Gitblit v1.8.0