From d3e3e32f62955e7ac7983bde70924daaacab5dc1 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 08 九月 2020 13:33:37 +0800
Subject: [PATCH] 2020-09-08

---
 src/templates/sharecomponent/settingcomponent/settingform/customscript/index.jsx |   95 ++++++++++++++---------------------------------
 1 files changed, 29 insertions(+), 66 deletions(-)

diff --git a/src/templates/sharecomponent/settingcomponent/settingform/customscript/index.jsx b/src/templates/sharecomponent/settingcomponent/settingform/customscript/index.jsx
index 60519c5..adb76d8 100644
--- a/src/templates/sharecomponent/settingcomponent/settingform/customscript/index.jsx
+++ b/src/templates/sharecomponent/settingcomponent/settingform/customscript/index.jsx
@@ -1,21 +1,26 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { Form, Row, Col, Input, Button, notification, Modal, Select, Radio } from 'antd'
+import { fromJS } from 'immutable'
+import { Form, Row, Col, Button, notification, Modal, Select } from 'antd'
 import moment from 'moment'
 
 import Utils from '@/utils/utils.js'
+import SettingUtils from '../utils.jsx'
 import Api from '@/api'
+import CodeMirror from '@/templates/zshare/codemirror'
 import './index.scss'
-
-const { TextArea } = Input
 
 class CustomForm extends Component {
   static propTpyes = {
+    type: PropTypes.string,         // 鑿滃崟绫诲瀷
     dict: PropTypes.object,         // 瀛楀吀椤�
     setting: PropTypes.object,      // 璁剧疆
     searches: PropTypes.array,      // 鎼滅储鏉′欢
+    swhere: PropTypes.string,       // where鏉′欢
+    defaultSql: PropTypes.string,   // 榛樿sql
+    arr_field: PropTypes.string,    // 鍒楀瓧娈�
+    regoptions: PropTypes.array,    // 姝e垯鏇挎崲
     systemScripts: PropTypes.array, // 绯荤粺鑴氭湰
-    customScripts: PropTypes.array, // 鑷畾涔夎剼鏈�
     scriptsChange: PropTypes.func   // 琛ㄥ崟
   }
 
@@ -57,8 +62,7 @@
     })
 
     this.props.form.setFieldsValue({
-      sql: record.sql,
-      initsql: record.initsql || 'false'
+      sql: record.sql
     })
   }
 
@@ -72,8 +76,8 @@
   }
 
   handleConfirm = () => {
-    const { searches, setting } = this.props
-
+    const { setting, arr_field, regoptions, swhere } = this.props
+    
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
     this.props.form.validateFieldsAndScroll((err, values) => {
       if (!err) {
@@ -121,54 +125,24 @@
           return
         }
 
-        let tail = `
-          aaa:
-        `
+        let scripts = fromJS(this.props.scripts).toJS()
 
-        let _initsql = ''
-        this.props.customScripts.forEach(script => {
-          if (this.state.editItem && this.state.editItem.uuid === script.uuid) return
-          if (script.status === 'false' || script.initsql !== 'true') return
-
-          _initsql += `
-            ${script.sql}
-            `
-        })
+        if (values.uuid) {
+          scripts = scripts.map(item => {
+            if (item.uuid === values.uuid) {
+              return values
+            } else {
+              return item
+            }
+          })
+        } else {
+          scripts.push(values)
+        }
 
         let param = {
           func: 's_debug_sql',
-          LText: _initsql + values.sql + tail
+          LText: SettingUtils.getDebugSql(setting, scripts, arr_field, regoptions, swhere)
         }
-
-        param.LText = param.LText.replace(/@\$|\$@/ig, '')
-
-        let allSearch = Utils.initMainSearch(searches)
-        allSearch = Utils.getAllSearchOptions(allSearch)
-
-        let regoptions = allSearch.map(item => {
-          return {
-            reg: new RegExp('@' + item.key + '@', 'ig'),
-            value: `'${item.value}'`
-          }
-        })
-
-        regoptions.push({
-          reg: new RegExp('@orderBy@', 'ig'),
-          value: setting.order
-        })
-        if (setting.laypage !== 'false') {
-          regoptions.push({
-            reg: new RegExp('@pageSize@', 'ig'),
-            value: 10
-          }, {
-            reg: new RegExp('@pageIndex@', 'ig'),
-            value: 1
-          })
-        }
-  
-        regoptions.forEach(item => {
-          param.LText = param.LText.replace(item.reg, item.value)
-        })
 
         param.LText = Utils.formatOptions(param.LText)
         param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
@@ -218,7 +192,7 @@
   }
 
   render() {
-    const { systemScripts, setting } = this.props
+    const { systemScripts, setting, type, defaultSql } = this.props
     const { getFieldDecorator } = this.props.form
     const { usefulFields } = this.state
     const formItemLayout = {
@@ -247,19 +221,7 @@
           </Col>
           <Col span={24} className="sqlfield">
             <Form.Item label={'鍙敤瀛楁'}>
-              id, bid, loginuid, sessionuid, userid, appkey, orderBy{setting.laypage !== 'false' ? ', pageSize, pageIndex': ''}{usefulFields ? ', ' + usefulFields : ''}
-            </Form.Item>
-          </Col>
-          <Col span={8} style={{whiteSpace: 'nowrap'}}>
-            <Form.Item style={{marginBottom: 0}} label="鍒濆鍖杝ql">
-              {getFieldDecorator('initsql', {
-                initialValue: 'false'
-              })(
-                <Radio.Group>
-                  <Radio value="true">鏄�</Radio>
-                  <Radio value="false">鍚�</Radio>
-                </Radio.Group>
-              )}
+              id, bid, loginuid, sessionuid, userid, appkey, {type === 'main' ? 'out_id, ' : '' }time_id, orderBy{setting.laypage !== 'false' ? ', pageSize, pageIndex': ''}{usefulFields ? ', ' + usefulFields : ''}
             </Form.Item>
           </Col>
           <Col span={10}>
@@ -269,6 +231,7 @@
                 filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                 onChange={this.selectScript}
               >
+                <Select.Option key="default" value={defaultSql}>榛樿sql</Select.Option>
                 {systemScripts.map((option, i) =>
                   <Select.Option style={{whiteSpace: 'normal'}} key={i} value={option.value}>{option.name}</Select.Option>
                 )}
@@ -293,7 +256,7 @@
                     message: this.props.dict['form.required.input'] + 'sql!'
                   }
                 ]
-              })(<TextArea rows={15} />)}
+              })(<CodeMirror />)}
             </Form.Item>
           </Col>
         </Row>

--
Gitblit v1.8.0