From 5354b648a9765d8c9ca3f8c7ce065b58c3d55716 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 10 十月 2022 18:47:36 +0800
Subject: [PATCH] 2022-10-10

---
 src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.jsx |  217 +++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 151 insertions(+), 66 deletions(-)

diff --git a/src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.jsx b/src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.jsx
index a559a1f..8cdffeb 100644
--- a/src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.jsx
+++ b/src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.jsx
@@ -1,11 +1,13 @@
 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, Button, notification, Select, Popconfirm, Typography, Modal, Radio, Tooltip } from 'antd'
+import { StopOutlined, CheckCircleOutlined, EditOutlined, SwapOutlined, DeleteOutlined } from '@ant-design/icons'
 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,32 +21,47 @@
     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   // 琛ㄥ崟
   }
 
   state = {
+    wrapId: Utils.getuuid(),
     editItem: null,
     loading: false,
     usefulFields: '',
+    urlFields: '',
     systemScripts: [],
     scriptsColumns: [
       {
         title: 'SQL',
         dataIndex: 'sql',
-        width: '73%',
+        width: '60%',
         render: (text) => {
           let title = text.match(/^\s*\/\*.+\*\//)
           title = title && title[0] ? title[0] : ''
-          text = title ? text.replace(title, '') : text
+          let _text = title ? text.replace(title, '') : text
 
           return (
             <div>
-              {title ? <span style={{color: '#a50'}}>{title}</span> : null}
-              <Paragraph copyable ellipsis={{ rows: 4, expandable: true }}>{text}</Paragraph>
+              {title ? <span style={{color: '#a50'}}>{title}<span style={{fontSize: '12px', marginLeft: '5px'}}>{_text.length}</span></span> : null}
+              <Paragraph copyable={{ text: text }} ellipsis={{ rows: 4, expandable: true }}>{_text}</Paragraph>
             </div>
           )
+        }
+      },
+      {
+        title: '鎵ц浣嶇疆',
+        dataIndex: 'position',
+        width: '13%',
+        render: (text, record) => {
+          if (record.position === 'front') {
+            return <span style={{color: '#26C281'}}>sql鍓�</span>
+          } else {
+            return <span style={{color: '#1890ff'}}>sql鍚�</span>
+          }
         }
       },
       {
@@ -53,15 +70,15 @@
         width: '12%',
         render: (text, record) => record.status === 'false' ?
           (
-            <div>
-              {this.props.dict['model.status.forbidden']}
-              <Icon style={{marginLeft: '5px'}} type="stop" theme="twoTone" twoToneColor="#ff4d4f" />
+            <div style={{color: '#ff4d4f'}}>
+              绂佺敤
+              <StopOutlined style={{marginLeft: '5px'}} />
             </div>
           ) :
           (
-            <div>
-              {this.props.dict['model.status.open']}
-              <Icon style={{marginLeft: '5px'}} type="check-circle" theme="twoTone" twoToneColor="#52c41a" />
+            <div style={{color: '#26C281'}}>
+              鍚敤
+              <CheckCircleOutlined style={{marginLeft: '5px'}}/>
             </div>
           )
       },
@@ -72,14 +89,14 @@
         dataIndex: 'operation',
         render: (text, record) =>
           (<div style={{textAlign: 'center'}}>
-            <span className="operation-btn" title={this.props.dict['model.edit']} onClick={() => this.handleEdit(record)} style={{color: '#1890ff'}}><Icon type="edit" /></span>
-            <span className="operation-btn" title={this.props.dict['header.form.status.change']} onClick={() => this.handleStatus(record)} style={{color: '#8E44AD'}}><Icon type="swap" /></span>
+            <span className="operation-btn" title={this.props.dict['model.edit']} onClick={() => this.handleEdit(record)} style={{color: '#1890ff'}}><EditOutlined /></span>
+            <span className="operation-btn" title={this.props.dict['header.form.status.change']} onClick={() => this.handleStatus(record)} style={{color: '#8E44AD'}}><SwapOutlined /></span>
             <Popconfirm
               overlayClassName="popover-confirm"
               title={this.props.dict['model.query.delete']}
               onConfirm={() => this.handleDelete(record)
             }>
-              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
+              <span className="operation-btn" style={{color: '#ff4d4f'}}><DeleteOutlined /></span>
             </Popconfirm>
           </div>)
       }
@@ -87,30 +104,46 @@
   }
 
   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()
+    let _urlFields = ''
+
+    if (searches) {
+      searches.forEach(item => {
+        if (!item.field) return
+        if (item.type === 'group') {
           _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.replace(/,/ig, ', '))
         }
-        _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)
-      }
-    })
+      })
+
+      _urlFields = urlFields ? urlFields.join(', ') : ''
+      _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()
+      urlFields: _urlFields,
+      usefulFields: _usefulFields,
+      scripts: fromJS(scripts).toJS(),
+      scriptsColumns
     })
   }
 
@@ -119,6 +152,13 @@
   }
 
   getsysScript = () => {
+    if (sessionStorage.getItem('mk_sys_scripts')) {
+      this.setState({
+        systemScripts: JSON.parse(sessionStorage.getItem('mk_sys_scripts'))
+      })
+      return
+    }
+    
     let _scriptSql = `Select distinct func+Remark as funcname,longparam, s.Sort from聽 s_custom_script s inner join (select OpenID from sapp where ID=@Appkey@) p on s.openid = case when s.appkey='' then s.openid else p.OpenID end order by s.Sort`
 
     _scriptSql = Utils.formatOptions(_scriptSql)
@@ -137,13 +177,13 @@
     Api.getSystemConfig(_sParam).then(res => {
       if (res.status) {
         let _scripts = res.data.map(item => {
-          let _item = {
+          return {
             name: item.funcname,
             value: window.decodeURIComponent(window.atob(item.longparam))
-            // value: Utils.UnformatOptions(item.longparam)
           }
-          return _item
         })
+
+        sessionStorage.setItem('mk_sys_scripts', JSON.stringify(_scripts))
 
         this.setState({
           systemScripts: _scripts
@@ -190,7 +230,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 +293,41 @@
       _scripts.push(values)
     }
 
-    this.setState({loading: true})
-    this.props.scriptsChange(_scripts).then(res => {
-      this.setState({
-        loading: false,
-        scripts: _scripts,
-        editItem: null
-      })
+    let param = {
+      func: 's_debug_sql',
+      exec_type: 'y',
+      LText: SettingUtils.getCustomDebugSql(_scripts, this.props.regoptions)
+    }
 
-      this.props.scriptsUpdate(_scripts)
-      this.props.form.setFieldsValue({
-        sql: ''
-      })
-    }, () => {
-      this.setState({loading: false})
+    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+    param.LText = param.LText.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id)@/ig, `'${param.timestamp}'`)
+    param.LText = Utils.formatOptions(param.LText)
+    param.secretkey = Utils.encrypt('', param.timestamp)
+    
+    this.setState({loading: true})
+    Api.genericInterface(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,19 +347,27 @@
   }
 
   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()
   }
 
   scrolltop = () => {
-    let node = document.getElementById('model-setting-form-body').parentNode
+    let node = document.getElementById(this.state.wrapId).parentNode
 
     if (node && node.scrollTop) {
       let inter = Math.ceil(node.scrollTop / 10)
@@ -344,9 +413,9 @@
   }
 
   render() {
-    const { setting, defaultSql, scripts } = this.props
+    const { setting, scripts } = this.props
     const { getFieldDecorator } = this.props.form
-    const { usefulFields, scriptsColumns, systemScripts } = this.state
+    const { usefulFields, scriptsColumns, systemScripts, urlFields, wrapId } = this.state
     const formItemLayout = {
       labelCol: {
         xs: { span: 24 },
@@ -359,32 +428,48 @@
     }
 
     return (
-      <div className="modal-menu-setting-script">
+      <div className="modal-menu-setting-script" id={wrapId}>
         <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> : null}
-            <Col span={16}>
-              <Form.Item label={'鎶ラ敊瀛楁'} style={{margin: 0}}>
-                ErrorCode, retmsg
+            </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>
             <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 : ''}
+                <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'鍏叡鍊硷紝璇锋寜鐓xxx@鏍煎紡浣跨敤銆�'}><span style={{color: '#1890ff'}}>BID, ID, LoginUID, SessionUid, UserID, Appkey, time_id</span></Tooltip>,&nbsp;
+                <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'绯荤粺鍙橀噺锛岀郴缁熶細瀹氫箟鍙橀噺骞惰祴鍊笺��'}><span style={{color: '#fa8c16'}}>UserName, FullName, RoleID, mk_departmentcode, mk_organization, mk_user_type, mk_nation, mk_province, mk_city, mk_district, mk_address</span></Tooltip>
+                {usefulFields ? <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'鎼滅储鏉′欢鍙橀噺锛岃鎸夌収@xxx@鏍煎紡浣跨敤銆�'}>, {usefulFields}</Tooltip> : ''}
+                {urlFields ?<Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'url鍙橀噺锛岃鎸夌収@xxx@鏍煎紡浣跨敤銆�'}>, <span style={{color: '#13c2c2'}}>{urlFields}</span></Tooltip> : ''}
               </Form.Item>
             </Col>
+            {!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