From 7b0dbecd1d6155d26ec67be0a47a16264c738c85 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 09 五月 2023 14:48:10 +0800
Subject: [PATCH] 2023-05-09

---
 src/menu/components/table/edit-table/columns/editColumn/index.jsx |   99 +++++++++++++++++++++++++++++++++++--------------
 1 files changed, 70 insertions(+), 29 deletions(-)

diff --git a/src/menu/components/table/edit-table/columns/editColumn/index.jsx b/src/menu/components/table/edit-table/columns/editColumn/index.jsx
index 3997baa..6e92415 100644
--- a/src/menu/components/table/edit-table/columns/editColumn/index.jsx
+++ b/src/menu/components/table/edit-table/columns/editColumn/index.jsx
@@ -1,7 +1,7 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Form, Row, Col, Input, Select, InputNumber, Radio, Tooltip, Modal, notification } from 'antd'
+import { Form, Row, Col, Input, Select, InputNumber, Radio, Tooltip, Modal, notification, Popover } from 'antd'
 import { QuestionCircleOutlined } from '@ant-design/icons'
 
 import { getColumnForm } from './formconfig'
@@ -14,17 +14,17 @@
 const { TextArea } = Input
 const columnTypeOptions = {
   text: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'textFormat', 'editable', 'initval', 'blacklist'],
-  number: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'decimal', 'format', 'prefix', 'postfix', 'editable', 'initval', 'sum', 'blacklist'],
+  number: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'decimal', 'format', 'prefix', 'postfix', 'editable', 'initval', 'sum', 'blacklist', 'noValue'],
   textarea: ['label', 'field', 'type', 'Align', 'Hide', 'Width', 'prefix', 'initval', 'postfix', 'blacklist'],
-  custom: ['label', 'type', 'Align', 'Hide', 'Width', 'blacklist'],
+  custom: ['label', 'type', 'Align', 'Width', 'blacklist'],
+  colspan: ['label', 'type', 'Align', 'Hide', 'blacklist'],
   action: ['label', 'type', 'Align', 'Width'],
-  formula: ['label', 'type', 'Align', 'Hide', 'Width', 'prefix', 'postfix', 'eval', 'formula', 'blacklist'],
+  formula: ['label', 'type', 'Align', 'Hide', 'Width', 'prefix', 'postfix', 'eval', 'formula', 'blacklist', 'noValue'],
   index: ['label', 'type', 'Align', 'Width']
 }
 
 class EdiTableColumn extends Component {
   static propTpyes = {
-    dict: PropTypes.object,     // 瀛楀吀椤�
     visible: PropTypes.bool,
     column: PropTypes.object,
     columns: PropTypes.array,
@@ -60,6 +60,10 @@
     let _options = fromJS(columnTypeOptions[this.column.type]).toJS()
 
     if (this.column.editable === 'true') {
+      _options.push('ctrlField')
+      if (this.column.ctrlField) {
+        _options.push('ctrlValue')
+      }
       if (this.column.type === 'text') {
         _options.push('editType')
 
@@ -86,9 +90,7 @@
 
   editColumn = (column) => {
     let fields = fromJS(this.props.fields).toJS().map(item => {
-      if (item.label.toLowerCase() !== item.field.toLowerCase()) {
-        item.text = item.label + '锛�' + item.field + '锛�'
-      }
+      item.text = `${item.field}锛�${item.label}锛塦
       return item
     })
 
@@ -104,6 +106,11 @@
       visible: true,
       formlist: formlist.map(item => {
         item.hidden = !_options.includes(item.key)
+
+        if (item.key === 'formula') {
+          item.fields = this.props.fields.map(col => col.field)
+          item.fields = item.fields.join(', ')
+        }
 
         return item
       })
@@ -126,6 +133,11 @@
     if (key === 'type') {
       let _options = this.getOptions()
 
+      let _field = ''
+      if (value === 'formula') {
+        _field = this.props.form.getFieldValue('field') || ''
+      }
+
       this.setState({
         formlist: this.state.formlist.map(item => {
           item.initVal = this.column[item.key] || item.initVal
@@ -134,8 +146,14 @@
           return item
         })
       }, () => {
-        if (value === 'action') {
+        if (value === 'colspan') {
           this.props.form.setFieldsValue({Align: 'center'})
+        } else if (value === 'formula' && _field) {
+          this.props.form.setFieldsValue({formula: '@' + _field + '@'})
+        } else if (value === 'action') {
+          this.props.form.setFieldsValue({Align: 'center', label: '鎿嶄綔'})
+        } else if (value === 'index') {
+          this.props.form.setFieldsValue({label: '搴忓彿'})
         }
       })
     } else if (key === 'field') {
@@ -172,7 +190,7 @@
       }
     } else if (key === 'format' && value === 'percent') {
       this.props.form.setFieldsValue({postfix: '%'})
-    } else if (key === 'editable' || key === 'editType' || key === 'resourceType') {
+    } else if (key === 'editable' || key === 'editType' || key === 'resourceType' || key === 'ctrlField') {
       let _options = this.getOptions()
 
       this.setState({
@@ -217,7 +235,11 @@
 
     let resource = this.props.form.getFieldValue('dataSource') || ''
 
-    resource = `select '' as ${field},'鍏ㄩ儴' as ${text} union all \n${resource}`
+    if (field === text) {
+      resource = `select '' as ${field} union all \n${resource}`
+    } else {
+      resource = `select '' as ${field},'鍏ㄩ儴' as ${text} union all \n${resource}`
+    }
 
     this.props.form.setFieldsValue({dataSource: resource})
   }
@@ -227,7 +249,6 @@
   }
 
   getFields() {
-    const { dict } = this.props 
     const { getFieldDecorator } = this.props.form
     const { formlist, transfield } = this.state
     const fields = []
@@ -246,7 +267,7 @@
 
       if (item.type === 'text') {
         rules = [
-          { required: item.required, message: dict['form.required.input'] + item.label + '!' },
+          { required: item.required, message: '璇疯緭鍏�' + item.label + '!' },
           {
             max: formRule.input.max,
             message: formRule.input.message
@@ -256,7 +277,7 @@
         content = <Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />
       } else if (item.type === 'number') {
         rules = [
-          { required: item.required, message: dict['form.required.input'] + item.label + '!' }
+          { required: item.required, message: '璇疯緭鍏�' + item.label + '!' }
         ]
         initVal = item.initVal
 
@@ -267,7 +288,7 @@
         }
       } else if (item.type === 'select') {
         rules = [
-          { required: item.required, message: dict['form.required.select'] + item.label + '!' }
+          { required: item.required, message: '璇烽�夋嫨' + item.label + '!' }
         ]
         content = <Select
           showSearch
@@ -284,7 +305,7 @@
         </Select>
       } else if (item.type === 'radio') {
         rules = [
-          { required: item.required, message: dict['form.required.select'] + item.label + '!' }
+          { required: item.required, message: '璇烽�夋嫨' + item.label + '!' }
         ]
         initVal = item.initVal
 
@@ -306,13 +327,35 @@
         span = 24
         className = 'text-area'
         rules = [
-          { required: item.required, message: dict['form.required.input'] + item.label + '!' }
+          { required: item.required, message: '璇疯緭鍏�' + item.label + '!' }
         ]
+
+        if (item.key === 'formula') {
+          fields.push(
+            <Col span={span} key={index}>
+              <Form.Item className={className} extra={extra} label={item.tooltip ?
+                <Tooltip placement="topLeft" title={item.tooltip}>
+                  <QuestionCircleOutlined className="mk-form-tip" />
+                  {item.label}
+                </Tooltip> : item.label
+              }>
+                {getFieldDecorator(item.key, {
+                  initialValue: initVal,
+                  rules: rules
+                })(<TextArea rows={item.rows || 2}/>)}
+              </Form.Item>
+              <Popover overlayClassName="formula-fields" placement="topLeft" title="" content={<div>{item.fields}</div>} trigger="click">
+                <span className="formula-icon">瀛楁闆�</span>
+              </Popover>
+            </Col>
+          )
+          return
+        }
 
         content = <TextArea rows={item.rows || 2}/>
       } else if (item.type === 'codemirror') {
         rules = [
-          { required: item.required, message: dict['form.required.input'] + item.label + '!' }
+          { required: item.required, message: '璇疯緭鍏�' + item.label + '!' }
         ]
         span = 24
         className = 'text-area'
@@ -349,20 +392,18 @@
   }
 
   handleSubmit = () => {
-    const { columns, column } = this.props
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
     this.props.form.validateFieldsAndScroll((err, values) => {
       if (!err) {
-        values.uuid = column.uuid
-        values.marks = column.marks || []
-        
-        if (values.field && columns.filter(col => col.field && col.uuid !== values.uuid && col.field === values.field).length > 0) {
-          notification.warning({
-            top: 92,
-            message: '瀛楁宸叉坊鍔狅紒',
-            duration: 5
-          })
-          return
+        if (values.type === 'number' && values.editable === 'true') {
+          if (typeof(values.max) === 'number' && typeof(values.min) === 'number' && values.max < values.min) {
+            notification.warning({
+              top: 92,
+              message: '鏈�澶у�间笉鍙皬浜庢渶灏忓�硷紒',
+              duration: 5
+            })
+            return
+          }
         }
         this.setState({visible: false, formlist: null})
         this.props.submitCol(values)

--
Gitblit v1.8.0