From b20a4d7c75c2ff8951e93d9c0394df9277fc6093 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 15 五月 2023 21:05:17 +0800
Subject: [PATCH] 2023-05-15

---
 src/menu/components/table/edit-table/columns/editColumn/index.jsx |  138 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 116 insertions(+), 22 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 88c227d..0f479c0 100644
--- a/src/menu/components/table/edit-table/columns/editColumn/index.jsx
+++ b/src/menu/components/table/edit-table/columns/editColumn/index.jsx
@@ -1,9 +1,12 @@
 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 moment from 'moment'
 
+import Api from '@/api'
+import Utils from '@/utils/utils.js'
 import { getColumnForm } from './formconfig'
 import { formRule } from '@/utils/option.js'
 import CodeMirror from '@/templates/zshare/codemirror'
@@ -14,11 +17,12 @@
 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']
 }
 
@@ -34,6 +38,7 @@
 
   state = {
     visible: false,
+    loading: false,
     formlist: null,
     transfield: {}
   }
@@ -59,6 +64,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')
 
@@ -102,6 +111,11 @@
       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
       })
     })
@@ -123,6 +137,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
@@ -131,8 +150,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') {
@@ -169,7 +194,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({
@@ -309,6 +334,28 @@
           { 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 = [
@@ -349,37 +396,83 @@
   }
 
   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)
 
-        this.column = null
+        if (values.dataSource && /\s/.test(values.dataSource)) {
+          let error = Utils.verifySql(values.dataSource)
+
+          if (error) {
+            notification.warning({
+              top: 92,
+              message: '鏁版嵁婧愪腑涓嶅彲浣跨敤' + error,
+              duration: 5
+            })
+            return
+          }
+
+          this.setState({
+            loading: true
+          })
+    
+          let param = {
+            func: 's_debug_sql',
+            exec_type: 'y',
+            LText: `declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)
+              ${values.dataSource}`
+          }
+    
+          param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+          param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id)@/ig, `'${param.timestamp}'`)
+          param.LText = param.LText.replace(/\n/g, ' ')
+          
+          param.LText = Utils.formatOptions(param.LText)
+          param.secretkey = Utils.encrypt('', param.timestamp)
+    
+          if (window.GLOB.mainSystemApi && values.database === 'sso') {
+            param.rduri = window.GLOB.mainSystemApi
+          }
+          
+          Api.genericInterface(param).then(result => {
+            if (result.status) {
+              this.setState({visible: false, loading: false, formlist: null})
+              this.props.submitCol(values)
+              this.column = null
+            } else {
+              this.setState({loading: false})
+              Modal.error({
+                title: result.message
+              })
+            }
+          })
+        } else {
+          this.setState({visible: false, formlist: null})
+          this.props.submitCol(values)
+          this.column = null
+        }
       }
     })
   }
 
   editModalCancel = () => {
-    this.setState({visible: false, formlist: null})
+    this.setState({visible: false, loading: false, formlist: null})
 
     this.props.cancelCol()
   }
 
   render() {
-    const { visible } = this.state
+    const { visible, loading } = this.state
     const formItemLayout = {
       labelCol: {
         xs: { span: 24 },
@@ -400,6 +493,7 @@
           maskClosable={false}
           onOk={this.handleSubmit}
           onCancel={this.editModalCancel}
+          confirmLoading={loading}
           destroyOnClose
         >
           <Form {...formItemLayout} className="commontable-column-form" id="edit-table-column-winter">

--
Gitblit v1.8.0