From aa15f061ba185b05f22c98a0a979c72d08bcd974 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 11 二月 2025 09:42:38 +0800
Subject: [PATCH] 2025-02-11

---
 src/templates/sharecomponent/chartcomponent/chartcompile/index.jsx |  412 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 371 insertions(+), 41 deletions(-)

diff --git a/src/templates/sharecomponent/chartcomponent/chartcompile/index.jsx b/src/templates/sharecomponent/chartcomponent/chartcompile/index.jsx
index 3ea5f49..be87511 100644
--- a/src/templates/sharecomponent/chartcomponent/chartcompile/index.jsx
+++ b/src/templates/sharecomponent/chartcomponent/chartcompile/index.jsx
@@ -1,50 +1,115 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-// import { is, fromJS } from 'immutable'
-import { Drawer, Form, Button, Col, Row, Select, Icon, Radio, Tooltip, Input, InputNumber } from 'antd'
+import { fromJS } from 'immutable'
+import { Drawer, Form, Button, Col, Row, Select, Radio, Tooltip, Input, InputNumber, Cascader } from 'antd'
+import { QuestionCircleOutlined, RightOutlined, EditOutlined, LeftOutlined } from '@ant-design/icons'
 
-import { getChartOptionForm } from '@/templates/zshare/formconfig'
+import { getChartOptionForm } from './formconfig'
+import { minkeColorSystem, colorTransform } from '@/utils/option.js'
 import './index.scss'
 
 class LineChartDrawerForm extends Component {
   static propTpyes = {
-    type: PropTypes.string,
-    dict: PropTypes.object,
     plot: PropTypes.object,
-    columns: PropTypes.array,
+    config: PropTypes.object,
     plotchange: PropTypes.func
   }
 
   state = {
+    view: 'normal',
     visible: false,
-    formlist: null
+    plot: null,
+    formlist: null,
+    datatype: null,
+    fieldName: null,
+    colorOptions: fromJS(minkeColorSystem).toJS().map(option => {
+      option.children = option.children.map(cell => {
+        let _cell = {}
+        _cell.label = <div className={'background ' + cell.value}>{cell.value}</div>
+        _cell.value = colorTransform[cell.value]
+        
+        return _cell
+      })
+      return option
+    }),
+    shapeOptions: [
+      {
+        value: 'line',
+        label: '鎶樼嚎',
+        children: [
+          { value: 'smooth', label: 'smooth' },
+          { value: 'line', label: 'line' },
+          { value: 'dot', label: 'dot' },
+          { value: 'dash', label: 'dash' },
+          { value: 'hv', label: 'hv' },
+          { value: 'vh', label: 'vh' },
+          { value: 'hvh', label: 'hvh' },
+          { value: 'vhv', label: 'vhv' }
+        ]
+      },
+      {
+        value: 'bar',
+        label: '鏌卞舰',
+        children: [
+          { value: 'rect', label: 'rect' },
+          { value: 'hollow-rect', label: 'hollow-rect' },
+          { value: 'line', label: 'line' },
+          { value: 'tick', label: 'tick' },
+          { value: 'funnel', label: 'funnel' },
+          { value: 'pyramid', label: 'pyramid' }
+        ],
+      }
+    ]
   }
 
   showDrawer = () => {
-    const { columns, plot, type } = this.props
+    const { config, plot } = this.props
+
+    let datatype = null
+    if (['line', 'bar'].includes(plot.chartType)) {
+      datatype = plot.datatype || 'query'
+    }
+
+    let fieldName = {}
+    config.columns.forEach(col => {
+      if (col.field) {
+        fieldName[col.field] = col.label
+      }
+    })
+
+    if (plot.correction) {
+      delete plot.correction // 鏁版嵁淇锛堝凡寮冪敤锛�
+      plot.barSize = 35
+    }
 
     this.setState({
       visible: true,
-      formlist: getChartOptionForm(plot, columns, type)
+      view: 'normal',
+      datatype: datatype,
+      fieldName: fieldName,
+      enabled: plot.enabled || 'false',
+      plot: fromJS(plot).toJS(),
+      formlist: getChartOptionForm(plot, config.columns, config.setting)
     })
   }
 
-  onClose = (type) => {
-    if (type !== 'submit') {
-      this.setState({
-        visible: false
-      })
-      return
-    }
+  radioChange = (e, key) => {
+    const { formlist } = this.state
+    let val = e.target.value
 
-    this.props.form.validateFieldsAndScroll((err, values) => {
-      if (!err) {
-        this.setState({
-          visible: false
+    if (key === 'datatype') {
+      this.setState({
+        datatype: val,
+        formlist: formlist.map(item => {
+          if (['Yaxis'].includes(item.key)) {
+            item.hidden = val === 'statistics'
+          } else if (['InfoType', 'InfoValue', 'InfoDefNumber'].includes(item.key)) {
+            item.hidden = val !== 'statistics'
+          }
+          return item
         })
-        this.props.plotchange(values)
-      }
-    })
+      })
+    }
   }
 
   getFields() {
@@ -57,14 +122,14 @@
     }
 
     formlist.forEach((item, index) => {
-      if (item.hidden) return
+      if (item.hidden || item.forbid) return
       
-      if (item.type === 'text') { // 鏂囨湰鎼滅储
+      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" />
+                <QuestionCircleOutlined className="mk-form-tip" />
                 {item.label}
               </Tooltip> : item.label
             }>
@@ -73,7 +138,7 @@
                 rules: [
                   {
                     required: !!item.required,
-                    message: this.props.dict['form.required.input'] + item.label + '!'
+                    message: '璇疯緭鍏�' + item.label + '!'
                   }
                 ]
               })(<Input placeholder="" autoComplete="off" disabled={item.readonly}/>)}
@@ -85,7 +150,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
             }>
@@ -94,19 +159,19 @@
                 rules: [
                   {
                     required: !!item.required,
-                    message: this.props.dict['form.required.input'] + item.label + '!'
+                    message: '璇疯緭鍏�' + item.label + '!'
                   }
                 ]
               })(<InputNumber min={item.min} max={item.max} precision={item.decimal} />)}
             </Form.Item>
           </Col>
         )
-      } else if (item.type === 'select') { // 涓嬫媺鎼滅储
+      } 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" />
+                <QuestionCircleOutlined className="mk-form-tip" />
                 {item.label}
               </Tooltip> : item.label
             }>
@@ -115,7 +180,7 @@
                 rules: [
                   {
                     required: !!item.required,
-                    message: this.props.dict['form.required.select'] + item.label + '!'
+                    message: '璇烽�夋嫨' + item.label + '!'
                   }
                 ]
               })(
@@ -133,17 +198,22 @@
       } else if (item.type === 'radio') {
         fields.push(
           <Col span={12} key={index}>
-            <Form.Item label={item.label}>
+            <Form.Item label={item.tooltip ?
+              <Tooltip placement="topLeft" title={item.tooltip}>
+                <QuestionCircleOutlined className="mk-form-tip" />
+                {item.label}
+              </Tooltip> : item.label
+            }>
               {getFieldDecorator(item.key, {
                 initialValue: item.initVal,
                 rules: [
                   {
                     required: !!item.required,
-                    message: this.props.dict['form.required.select'] + item.label + '!'
+                    message: '璇烽�夋嫨' + item.label + '!'
                   }
                 ]
               })(
-                <Radio.Group>
+                <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>
@@ -159,7 +229,258 @@
     return fields
   }
 
+  getCustomFields = () => {
+    const { getFieldDecorator } = this.props.form
+    const { plot, fieldName, enabled, colorOptions, shapeOptions } = this.state
+    const fields = []
+
+    if (!plot.customs) return null
+
+    fields.push(<Col span={12} key="enabled">
+      <Form.Item label="鏄惁鍚敤" style={{marginBottom: 10}}>
+        {getFieldDecorator('enabled', {
+          initialValue: plot.enabled || 'false'
+        })(
+          <Radio.Group onChange={this.enabledChange}>
+            <Radio value="true">鏄�</Radio>
+            <Radio value="false">鍚�</Radio>
+          </Radio.Group>
+        )}
+      </Form.Item>
+    </Col>)
+
+    plot.customs.forEach((item, i) => {
+      fields.push(<Col span={24} key={'field' + i}>
+        <p className="field-title">{fieldName[item.field]}</p>
+      </Col>)
+      fields.push(<Col span={12} key={'shape' + i}>
+        <Form.Item label="褰㈢姸">
+          {getFieldDecorator(item.field + '$shape', {
+            initialValue: item.$shape,
+            rules: [
+              {
+                required: enabled === 'true',
+                message: '璇烽�夋嫨褰㈢姸!'
+              }
+            ]
+          })(
+            <Cascader
+              disabled={enabled === 'false'}
+              options={shapeOptions}
+              placeholder=""
+              displayRender={(label, selectedOptions) => selectedOptions[0] ? selectedOptions[0].label + ' / ' + selectedOptions[1].value : ''}
+            />
+          )}
+        </Form.Item>
+      </Col>)
+      fields.push(<Col span={12} key={'color' + i}>
+        <Form.Item label="棰滆壊">
+          {getFieldDecorator(item.field + '$color', {
+            initialValue: item.$color,
+            rules: [
+              {
+                required: enabled === 'true',
+                message: '璇烽�夋嫨棰滆壊!'
+              }
+            ]
+          })(
+            <Cascader
+              disabled={enabled === 'false'}
+              options={colorOptions}
+              placeholder=""
+              getPopupContainer={() => document.getElementById('chart-custom-drawer-form')}
+              displayRender={(label, selectedOptions) => selectedOptions[0] ? <div style={{background: selectedOptions[1].value, width: '20px', height: '20px'}}></div> : ''}
+            />
+          )}
+        </Form.Item>
+      </Col>)
+      fields.push(<Col span={12} key={'axis' + i}>
+        <Form.Item label="鍧愭爣杞�">
+          {getFieldDecorator(item.field + '$axis', {
+            initialValue: item.axis
+          })(
+            <Radio.Group disabled={enabled === 'false'} onChange={this.axisChange}>
+              <Radio value="left">宸︿晶</Radio>
+              <Radio value="right">鍙充晶</Radio>
+              <Radio value="unset">涓嶆樉绀�</Radio>
+            </Radio.Group>
+          )}
+        </Form.Item>
+      </Col>)
+      fields.push(<Col span={12} key={'label' + i}>
+        <Form.Item label="鏍囨敞-鍊�">
+          {getFieldDecorator(item.field + '$label', {
+            initialValue: item.label
+          })(
+            <Radio.Group disabled={enabled === 'false'}>
+              <Radio value="true">鏄剧ず</Radio>
+              <Radio value="false">闅愯棌</Radio>
+            </Radio.Group>
+          )}
+        </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 { plot, view, datatype } = this.state
+
+    if (view !== 'custom') {
+      this.props.form.validateFieldsAndScroll((err, values) => {
+        if (!err) {
+          let _plot = {...plot, ...values}
+
+          if (datatype === 'query') {
+            if (_plot.enabled === 'true') {
+              if (_plot.customs.map(_cell => _cell.field).sort().toString() !== _plot.Yaxis.sort().toString()) {
+                _plot.customs = null
+                _plot.enabled = 'false'
+              }
+            }
+          } else {
+            _plot.customs = null
+            _plot.enabled = 'false'
+          }
+          
+          this.setState({
+            plot: _plot,
+            visible: false
+          })
+
+          this.props.plotchange(_plot)
+        }
+      })
+    } else {
+      this.props.form.validateFieldsAndScroll((err, values) => {
+        if (!err) {
+          let _plot = {...plot, enabled: values.enabled}
+
+          if (_plot.enabled === 'true') {
+            _plot.customs = _plot.Yaxis.map(field => {
+              let _item = {field: field}
+
+              _item.$shape = values[field + '$shape']
+              _item.chartType = _item.$shape[0]
+              _item.shape = _item.$shape[1]
+              
+              _item.$color = values[field + '$color']
+              _item.color = _item.$color[1]
+
+              _item.axis = values[field + '$axis']
+              
+              _item.label = values[field + '$label']
+
+              return _item
+            })
+          } else {
+            _plot.customs = null
+          }
+
+          this.setState({
+            plot: _plot,
+            visible: false
+          })
+
+          this.props.plotchange(_plot)
+        }
+      })
+    }
+  }
+
+  changeView = () => {
+    const { config } = this.props
+    const { plot, view } = this.state
+    let _view = view === 'normal' ? 'custom' : 'normal'
+
+    if (_view === 'custom') {
+      this.props.form.validateFieldsAndScroll((err, values) => {
+        if (!err) {
+          let _plot = {...plot, ...values}
+
+          if (_plot.enabled !== 'true' || _plot.customs.map(_cell => _cell.field).sort().toString() !== _plot.Yaxis.sort().toString()) {
+            _plot.enabled = 'false'
+            _plot.customs = _plot.Yaxis.map((field, i) => {
+              let _item = {field: field}
+              _item.$shape = [_plot.chartType, _plot.shape]
+              _item.$color = []
+              _item.axis = i === 0 ? 'left' : 'unset'
+              _item.label = _plot.label
+              
+              return _item
+            })
+          }
+          
+          this.setState({
+            enabled: _plot.enabled || 'false',
+            plot: _plot,
+            view: _view
+          })
+        }
+      })
+    } else {
+      this.props.form.validateFieldsAndScroll((err, values) => {
+        if (!err) {
+          let _values = {enabled: values.enabled}
+
+          if (values.enabled === 'true') {
+            let _customs = []
+            plot.Yaxis.forEach(field => {
+              let _item = {field: field}
+
+              _item.$shape = values[field + '$shape']
+              _item.chartType = _item.$shape[0]
+              _item.shape = _item.$shape[1]
+              
+              _item.$color = values[field + '$color']
+              _item.color = _item.$color[1]
+
+              _item.axis = values[field + '$axis']
+              _item.label = values[field + '$label']
+              
+              _customs.push(_item)
+            })
+
+            _values.customs = _customs
+          } else {
+            _values.customs = null
+          }
+
+          let _plot = {...plot, ..._values}
+
+          this.setState({
+            plot: _plot,
+            view: _view,
+            formlist: getChartOptionForm(_plot, config.columns, config.setting)
+          })
+        }
+      })
+    }
+  }
+
   render() {
+    const { view, datatype } = this.state
     const formItemLayout = {
       labelCol: {
         xs: { span: 24 },
@@ -173,18 +494,27 @@
 
     return (
       <div className="line-chart-drawer-form">
-        <Icon type="edit" onClick={this.showDrawer} />
+        <EditOutlined onClick={this.showDrawer} />
         <Drawer
           title="鍥捐〃缂栬緫"
           className="chart-drawer-form"
           width={720}
-          onClose={this.onClose}
+          onClose={() => this.setState({ visible: false })}
           visible={this.state.visible}
           bodyStyle={{ paddingBottom: 80 }}
         >
-          <Form {...formItemLayout}>
+          {view !== 'custom' ? <Form {...formItemLayout} className="base-setting">
             <Row gutter={16}>{this.getFields()}</Row>
-          </Form>
+            {datatype === 'query' ? <Row gutter={16}>
+              <Button onClick={this.changeView} style={{border: 0, boxShadow: 'unset',float: 'right', color: '#1890ff', marginRight: 12, cursor: 'pointer'}}>鑷畾涔夎缃�<RightOutlined style={{marginLeft: 5}} /></Button>
+            </Row> : null}
+          </Form> : null}
+          {view === 'custom' ? <Form {...formItemLayout} id="chart-custom-drawer-form" className="mingke-table">
+            <Row gutter={16} style={{minHeight: 'calc(100vh - 180px)'}}>{this.getCustomFields()}</Row>
+            <Row gutter={16}>
+              <Button onClick={this.changeView} style={{border: 0, boxShadow: 'unset', color: '#1890ff', marginRight: 12, cursor: 'pointer'}}><LeftOutlined style={{marginRight: 5}} />鍩烘湰璁剧疆</Button>
+            </Row>
+          </Form> : null}
           <div
             style={{
               position: 'absolute',
@@ -197,10 +527,10 @@
               textAlign: 'right',
             }}
           >
-            <Button onClick={this.onClose} style={{ marginRight: 8 }}>
+            <Button onClick={() => this.setState({ visible: false })} style={{ marginRight: 8 }}>
               鍙栨秷
             </Button>
-            <Button onClick={() => this.onClose('submit')} type="primary">
+            <Button onClick={() => this.onSubmit()} type="primary">
               鎻愪氦
             </Button>
           </div>

--
Gitblit v1.8.0