From 5e871a4164869bac7927ea6884dbadd650b1cadf Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 25 五月 2023 11:25:28 +0800
Subject: [PATCH] Merge branch 'master' into positec

---
 src/menu/components/table/normal-table/columns/editColumn/index.jsx |  101 ++++++++++++++++++++++++++++++++------------------
 1 files changed, 64 insertions(+), 37 deletions(-)

diff --git a/src/menu/components/table/normal-table/columns/editColumn/index.jsx b/src/menu/components/table/normal-table/columns/editColumn/index.jsx
index d971c8e..df3913f 100644
--- a/src/menu/components/table/normal-table/columns/editColumn/index.jsx
+++ b/src/menu/components/table/normal-table/columns/editColumn/index.jsx
@@ -25,7 +25,6 @@
 
 class NormalTableColumn extends Component {
   static propTpyes = {
-    visible: PropTypes.bool,
     column: PropTypes.object,
     fields: PropTypes.array,
     submitCol: PropTypes.func,  // 鎻愪氦浜嬩欢
@@ -36,6 +35,8 @@
     visible: false,
     formlist: null
   }
+
+  record = null
 
   UNSAFE_componentWillReceiveProps (nextProps) {
     if (nextProps.column && !is(fromJS(this.props.column), fromJS(nextProps.column))) {
@@ -50,18 +51,16 @@
     })
     
     let formlist = getColumnForm(column, fields)
-    let _options = fromJS(columnTypeOptions[column.type]).toJS()
-    if (column.type === 'text' || column.type === 'number') {
-      if (column.perspective === 'linkmenu') {
-        _options.push('linkmenu', 'linkfields', 'open')
-      } else if (column.perspective === 'linkurl') {
-        _options.push('linkurl', 'linkfields', 'open')
-      }
-    }
+    this.record = {}
+
+    formlist.forEach(item => {
+      this.record[item.key] = item.initVal
+    })
+    
+    let _options = this.getOptions()
 
     this.setState({
       visible: true,
-      type: column.type,
       formlist: formlist.map(item => {
         item.hidden = !_options.includes(item.key)
 
@@ -85,9 +84,29 @@
     }
   }
 
+  getOptions = () => {
+    let _options = fromJS(columnTypeOptions[this.record.type]).toJS()
+
+    if (this.record.type === 'text' || this.record.type === 'number') {
+      if (this.record.perspective === 'linkmenu') {
+        _options.push('linkmenu', 'linkfields', 'open')
+      } else if (this.record.perspective === 'linkurl') {
+        _options.push('linkurl', 'linkfields', 'open')
+      }
+    }
+    
+    if (this.record.type === 'formula' && this.record.eval === 'true') {
+      _options.push('decimal')
+    }
+
+    return _options
+  }
+
   typeChange = (key, value, option) => {
+    this.record[key] = value
+
     if (key === 'type') {
-      let _options = fromJS(columnTypeOptions[value]).toJS()
+      let _options = this.getOptions()
 
       let _field = ''
       if (value === 'formula') {
@@ -95,8 +114,12 @@
       }
 
       this.setState({
-        type: value,
         formlist: this.state.formlist.map(item => {
+          if (item.key === 'decimal' && value === 'formula') {
+            this.record.decimal = ''
+          }
+
+          item.initVal = this.record[item.key]
           item.hidden = !_options.includes(item.key)
 
           return item
@@ -110,8 +133,6 @@
           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: '搴忓彿'})
         }
@@ -129,13 +150,18 @@
         values.type = 'text'
       }
 
-      if (values.type !== this.state.type) {
+      let _type = this.record.type
+      this.record.type = values.type
+
+      if (values.type !== _type) {
         values.perspective = ''
-        let _options = fromJS(columnTypeOptions[values.type]).toJS()
+        this.record.perspective = ''
+
+        let _options = this.getOptions()
 
         this.setState({
-          type: values.type,
           formlist: this.state.formlist.map(item => {
+            item.initVal = this.record[item.key]
             item.hidden = !_options.includes(item.key)
 
             return item
@@ -148,21 +174,12 @@
       }
     } else if (key === 'format' && value === 'percent') {
       this.props.form.setFieldsValue({postfix: '%'})
-    }
-  }
-
-  changeRadio = (key, value) => {
-    if (key === 'perspective') {
-      let _options = fromJS(columnTypeOptions[this.state.type]).toJS()
-
-      if (value === 'linkmenu') {
-        _options.push('linkmenu', 'linkfields', 'open')
-      } else if (value === 'linkurl') {
-        _options.push('linkurl', 'linkfields', 'open')
-      }
+    } else if (['perspective', 'eval'].includes(key)) {
+      let _options = this.getOptions()
 
       this.setState({
         formlist: this.state.formlist.map(item => {
+          item.initVal = this.record[item.key]
           item.hidden = !_options.includes(item.key)
 
           return item
@@ -279,14 +296,10 @@
                   }
                 ]
               })(
-                <Radio.Group onChange={(e) => {this.changeRadio(item.key, e.target.value)}}>
-                  {
-                    item.options.map(option => {
-                      return (
-                        <Radio key={option.value} value={option.value}>{option.text}</Radio>
-                      )
-                    })
-                  }
+                <Radio.Group onChange={(e) => {this.typeChange(item.key, e.target.value)}}>
+                  {item.options.map(option => {
+                    return (<Radio key={option.value} value={option.value}>{option.text}</Radio>)
+                  })}
                 </Radio.Group>
               )}
             </Form.Item>
@@ -406,9 +419,23 @@
   }
 
   handleSubmit = () => {
+    const { fields } = this.props
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
     this.props.form.validateFieldsAndScroll((err, values) => {
       if (!err) {
+        // eslint-disable-next-line
+        if (values.type === 'formula' && values.eval !== 'false' && /^[\u4E00-\u9FA50-9a-zA-Z_\s@\+\-\*\/]*$/ig.test(values.formula) && /[\+\-\*\/]/ig.test(values.formula)) {
+          let cols = []
+          fields.forEach(col => {
+            if (/^(Int|Decimal)/ig.test(col.datatype)) {
+              cols.push({reg: new RegExp('@' + col.field + '@', 'ig'), value: `(@${col.field}@)`})
+            }
+          })
+
+          cols.forEach(col => {
+            values.formula = values.formula.replace(col.reg, col.value)
+          })
+        }
         this.setState({visible: false, formlist: null})
         this.props.submitCol(values)
       }

--
Gitblit v1.8.0