From e543372cc70a19ff2630c79d8421c2c593e54e5f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 02 六月 2021 17:15:21 +0800
Subject: [PATCH] 2021-06-02

---
 src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.jsx |  179 ++++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 128 insertions(+), 51 deletions(-)

diff --git a/src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.jsx b/src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.jsx
index a559a1f..a310f50 100644
--- a/src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.jsx
+++ b/src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.jsx
@@ -1,11 +1,12 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { fromJS } from 'immutable'
-import { Form, Row, Col, Icon, Button, notification, Select, Popconfirm, Typography } from 'antd'
+import { Form, Row, Col, Icon, Button, notification, Select, Popconfirm, Typography, Modal, Radio } from 'antd'
 import moment from 'moment'
 
 import Utils from '@/utils/utils.js'
 import Api from '@/api'
+import SettingUtils from '../utils'
 import CodeMirror from '@/templates/zshare/codemirror'
 import asyncComponent from '@/utils/asyncComponent'
 import './index.scss'
@@ -19,7 +20,8 @@
     setting: PropTypes.object,      // 璁剧疆
     scripts: PropTypes.array,       // 鑷畾涔夎剼鏈垪琛�
     searches: PropTypes.array,      // 鎼滅储鏉′欢
-    defaultSql: PropTypes.string,   // 榛樿sql
+    urlFields: PropTypes.any,       // url鍙橀噺
+    regoptions: PropTypes.any,      // 姝e垯鏇挎崲
     scriptsChange: PropTypes.func,  // 鑷畾涔夎剼鏈垏鎹㈡椂楠岃瘉
     scriptsUpdate: PropTypes.func   // 琛ㄥ崟
   }
@@ -33,7 +35,7 @@
       {
         title: 'SQL',
         dataIndex: 'sql',
-        width: '73%',
+        width: '60%',
         render: (text) => {
           let title = text.match(/^\s*\/\*.+\*\//)
           title = title && title[0] ? title[0] : ''
@@ -45,6 +47,18 @@
               <Paragraph copyable ellipsis={{ rows: 4, expandable: true }}>{text}</Paragraph>
             </div>
           )
+        }
+      },
+      {
+        title: '鎵ц浣嶇疆',
+        dataIndex: 'position',
+        width: '13%',
+        render: (text, record) => {
+          if (record.position === 'front') {
+            return 'sql鍓�'
+          } else {
+            return 'sql鍚�'
+          }
         }
       },
       {
@@ -87,30 +101,49 @@
   }
 
   UNSAFE_componentWillMount() {
-    const { searches, scripts } = this.props
+    const { searches, scripts, urlFields } = this.props
 
     let _usefulFields = []
-    searches.forEach(item => {
-      if (!item.field) return
-      if (item.type === 'group') {
-        if (item.transfer === 'true') {
+    let scriptsColumns = fromJS(this.state.scriptsColumns).toJS()
+
+    if (searches) {
+      searches.forEach(item => {
+        if (!item.field) return
+        if (item.type === 'group') {
+          if (item.transfer === 'true') {
+            _usefulFields.push(item.field)
+          }
+          _usefulFields.push(item.datefield)
+          _usefulFields.push(item.datefield + '1')
+        } else if (['dateweek', 'datemonth', 'daterange'].includes(item.type)) {
+          _usefulFields.push(item.field)
+          _usefulFields.push(item.field + '1')
+        } else if (_usefulFields.includes(item.field)) {
+          _usefulFields.push(item.field + '1')
+        } else {
           _usefulFields.push(item.field)
         }
-        _usefulFields.push(item.datefield)
-        _usefulFields.push(item.datefield + '1')
-      } else if (['dateweek', 'datemonth', 'daterange'].includes(item.type)) {
-        _usefulFields.push(item.field)
-        _usefulFields.push(item.field + '1')
-      } else if (_usefulFields.includes(item.field)) {
-        _usefulFields.push(item.field + '1')
-      } else {
-        _usefulFields.push(item.field)
+      })
+
+      if (urlFields) {
+        _usefulFields.push(...urlFields)
       }
-    })
+      
+      _usefulFields = _usefulFields.join(', ')
+      scriptsColumns = scriptsColumns.filter(item => {
+        if (item.dataIndex === 'sql') {
+          item.width = '70%'
+        }
+        return item.dataIndex !== 'position'
+      })
+    } else {
+      _usefulFields = null
+    }
 
     this.setState({
-      usefulFields: _usefulFields.join(', '),
-      scripts: fromJS(scripts).toJS()
+      usefulFields: _usefulFields,
+      scripts: fromJS(scripts).toJS(),
+      scriptsColumns
     })
   }
 
@@ -140,7 +173,6 @@
           let _item = {
             name: item.funcname,
             value: window.decodeURIComponent(window.atob(item.longparam))
-            // value: Utils.UnformatOptions(item.longparam)
           }
           return _item
         })
@@ -190,7 +222,11 @@
 
     let values = {
       uuid: editItem && editItem.uuid ? editItem.uuid : Utils.getuuid(),
-      sql: _sql
+      sql: _sql,
+    }
+
+    if (this.props.form.getFieldValue('position')) {
+      values.position = this.props.form.getFieldValue('position')
     }
 
     let _quot = values.sql.match(/'{1}/g)
@@ -249,24 +285,39 @@
       _scripts.push(values)
     }
 
+    let param = {
+      func: 's_debug_sql',
+      exec_type: 'y',
+      LText: SettingUtils.getCustomDebugSql(_scripts, this.props.regoptions)
+    }
+    param.LText = Utils.formatOptions(param.LText)
+    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+    param.secretkey = Utils.encrypt('', param.timestamp)
+    
     this.setState({loading: true})
-    this.props.scriptsChange(_scripts).then(res => {
-      this.setState({
-        loading: false,
-        scripts: _scripts,
-        editItem: null
-      })
-
-      this.props.scriptsUpdate(_scripts)
-      this.props.form.setFieldsValue({
-        sql: ''
-      })
-    }, () => {
-      this.setState({loading: false})
+    Api.getLocalConfig(param).then(result => {
+      if (result.status) {
+        this.setState({
+          loading: false,
+          scripts: _scripts,
+          editItem: null
+        })
+  
+        this.props.scriptsUpdate(_scripts)
+        this.props.form.setFieldsValue({
+          sql: ''
+        })
+      } else {
+        this.setState({loading: false})
+        Modal.error({
+          title: result.message
+        })
+      }
     })
   }
 
   selectScript = (value, option) => {
+    if (!value || !option) return
     let _sql = this.props.form.getFieldValue('sql')
     if (_sql) {
       _sql = _sql + ` 
@@ -286,13 +337,21 @@
   }
 
   handleEdit = (record) => {
+    const { usefulFields } = this.state
     this.setState({
       editItem: record
     })
 
-    this.props.form.setFieldsValue({
-      sql: record.sql
-    })
+    if (usefulFields) {
+      this.props.form.setFieldsValue({
+        sql: record.sql
+      })
+    } else {
+      this.props.form.setFieldsValue({
+        sql: record.sql,
+        position: record.position || 'back'
+      })
+    }
 
     this.scrolltop()
   }
@@ -344,7 +403,7 @@
   }
 
   render() {
-    const { setting, defaultSql, scripts } = this.props
+    const { setting, scripts } = this.props
     const { getFieldDecorator } = this.props.form
     const { usefulFields, scriptsColumns, systemScripts } = this.state
     const formItemLayout = {
@@ -362,29 +421,47 @@
       <div className="modal-menu-setting-script">
         <Form {...formItemLayout}>
           <Row gutter={24}>
-            {setting.tableName ? <Col span={8}>
-              <Form.Item label={'琛ㄥ悕'} style={{whiteSpace: 'nowrap', margin: 0}}>
-                {setting.tableName}
+            <Col span={4}>
+              <Form.Item labelCol={{span: 17}} wrapperCol={{span: 7}} label={'鍥炶皟琛ㄥ悕'} style={{whiteSpace: 'nowrap', margin: 0}}>
+                {setting.cbTable}
+              </Form.Item>
+            </Col>
+            <Col span={20}>
+              <Form.Item labelCol={{span: 4}} wrapperCol={{span: 20}} label={'鎶ラ敊瀛楁'} style={{margin: 0}}>
+                ErrorCode锛堝鍔犲悗缂�NT琛ㄧず鏁版嵁涓嶅洖婊氾紝濡侲NT銆丯NT銆丗NT銆丯MNT锛�, retmsg
+              </Form.Item>
+            </Col>
+            {usefulFields ? <Col span={24} className="sqlfield">
+              <Form.Item label={'鍙敤瀛楁'}>
+                id, bid, loginuid, sessionuid, userid, username, fullname, login_city, appkey, time_id{usefulFields ? ', ' + usefulFields : ''}
               </Form.Item>
             </Col> : null}
-            <Col span={16}>
-              <Form.Item label={'鎶ラ敊瀛楁'} style={{margin: 0}}>
-                ErrorCode, retmsg
-              </Form.Item>
-            </Col>
-            <Col span={24} className="sqlfield">
+            {!usefulFields ? <Col span={24} className="sqlfield">
               <Form.Item label={'鍙敤瀛楁'}>
-                id, bid, loginuid, sessionuid, userid, username, fullname, appkey, time_id, orderBy{setting.laypage === 'true' ? ', pageSize, pageIndex': ''}{usefulFields ? ', ' + usefulFields : ''}
+                id, bid, loginuid, sessionuid, userid, username, fullname, login_city, appkey, time_id
               </Form.Item>
-            </Col>
+            </Col> : null}
+            {!usefulFields ? <Col span={8} style={{whiteSpace: 'nowrap'}}>
+              <Form.Item style={{marginBottom: 0}} label="鎵ц浣嶇疆">
+                {getFieldDecorator('position', {
+                  initialValue: 'front'
+                })(
+                  <Radio.Group>
+                    <Radio value="front">sql鍓�</Radio>
+                    <Radio value="back">sql鍚�</Radio>
+                  </Radio.Group>
+                )}
+              </Form.Item>
+            </Col> : null}
             <Col span={10} className="quick-add">
               <Form.Item label={'蹇嵎娣诲姞'} style={{marginBottom: 0}}>
                 <Select
+                  allowClear
                   showSearch
                   filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                   onChange={this.selectScript}
                 >
-                  <Select.Option key="default" value={defaultSql}>榛樿sql</Select.Option>
+                  {!usefulFields ? <Select.Option key="default" value={`declare @${setting.cbTable} table (mk_api_key nvarchar(100),mk_level nvarchar(10),mk_id nvarchar(50),mk_bid nvarchar(50))\n/*@${setting.cbTable}_data table (mk_level nvarchar(10),mk_id nvarchar(50),mk_bid nvarchar(50))*/`}>榛樿sql</Select.Option> : null}
                   {systemScripts.map((option, i) =>
                     <Select.Option style={{whiteSpace: 'normal'}} key={i} value={option.value}>{option.name}</Select.Option>
                   )}

--
Gitblit v1.8.0