From e1cee96b38805bcccf48e7bcb9d296f2bc54c720 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 24 一月 2025 11:10:32 +0800
Subject: [PATCH] 2025-01-24

---
 src/menu/components/chart/antv-pie/chartcompile/index.jsx |  331 +++++++++++++++++++++++-------------------------------
 1 files changed, 142 insertions(+), 189 deletions(-)

diff --git a/src/menu/components/chart/antv-pie/chartcompile/index.jsx b/src/menu/components/chart/antv-pie/chartcompile/index.jsx
index da4c13c..dbec1e0 100644
--- a/src/menu/components/chart/antv-pie/chartcompile/index.jsx
+++ b/src/menu/components/chart/antv-pie/chartcompile/index.jsx
@@ -1,17 +1,22 @@
 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, notification, Tabs, Button } from 'antd'
+import { EditOutlined } from '@ant-design/icons'
 
-import { getPieChartOptionForm } from './formconfig'
-import ColorSketch from '@/mob/colorsketch'
+import Utils from '@/utils/utils.js'
+import { getBaseForm, getOptionForm } from './formconfig'
+import asyncComponent from '@/utils/asyncComponent'
 import './index.scss'
 
-class LineChartDrawerForm extends Component {
+const { TabPane } = Tabs
+
+const EditTable = asyncComponent(() => import('@/templates/zshare/editTable'))
+const NormalForm = asyncComponent(() => import('@/components/normalform/modalform'))
+
+class PieChartDrawerForm extends Component {
   static propTpyes = {
-    dict: PropTypes.object,
     plot: PropTypes.object,
-    sysRoles: PropTypes.array,
     config: PropTypes.object,
     plotchange: PropTypes.func
   }
@@ -19,16 +24,39 @@
   state = {
     visible: false,
     plot: null,
-    formlist: 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, sysRoles } = this.props
+    const { config } = this.props
 
     this.setState({
       visible: true,
+      view: 'base',
       plot: fromJS(config.plot).toJS(),
-      formlist: getPieChartOptionForm(config.plot, config.columns, sysRoles)
+      baseFormlist: getBaseForm(config.plot),
+      formlist: getOptionForm(config.plot, config.columns)
     })
   }
 
@@ -41,179 +69,27 @@
         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})
-        } else if (val === 'nightingale') {
-          this.props.form.setFieldsValue({innerRadius: 0})
         }
       })
     }
   }
 
-  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} onPressEnter={this.onSubmit}/>)}
-            </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} onPressEnter={this.onSubmit}/>)}
-            </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
+    const { plot, view } = this.state
 
-    this.props.form.validateFieldsAndScroll((err, values) => {
-      if (!err) {
+    if (view === 'normal') {
+      this.normalRef.handleConfirm().then(values => {
         let _plot = {...plot, ...values}
         
         this.setState({
@@ -222,44 +98,121 @@
         })
 
         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 { visible } = this.state
-    const formItemLayout = {
-      labelCol: {
-        xs: { span: 24 },
-        sm: { span: 6 }
-      },
-      wrapperCol: {
-        xs: { span: 24 },
-        sm: { span: 18 }
-      }
-    }
+    const { config } = this.props
+    const { visible, plot, colorColumns, formlist, view, baseFormlist } = this.state
 
     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="鍥捐〃缂栬緫"
+          wrapClassName="mk-pop-modal"
           visible={visible}
-          width={850}
+          width={900}
           maskClosable={false}
           onOk={this.onSubmit}
           onCancel={() => { this.setState({ visible: false }) }}
           destroyOnClose
         >
-          <Form {...formItemLayout}>
-            <Row gutter={16}>{this.getFields()}</Row>
-          </Form>
+          {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 Form.create()(LineChartDrawerForm)
\ No newline at end of file
+export default PieChartDrawerForm
\ No newline at end of file

--
Gitblit v1.8.0