From 58826d6f4eab9f8c9acf9fa8696f60039c645cfe Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 20 八月 2024 18:18:00 +0800
Subject: [PATCH] 2024-08-20

---
 src/templates/zshare/verifycard/customform/index.jsx |  153 ++++++++++++++++++++++++++++++++------------------
 1 files changed, 98 insertions(+), 55 deletions(-)

diff --git a/src/templates/zshare/verifycard/customform/index.jsx b/src/templates/zshare/verifycard/customform/index.jsx
index 5ddb237..efca89b 100644
--- a/src/templates/zshare/verifycard/customform/index.jsx
+++ b/src/templates/zshare/verifycard/customform/index.jsx
@@ -1,19 +1,24 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { Form, Row, Col, Input, Select, Button, notification } from 'antd'
-import './index.scss'
+import { Form, Row, Col, Input, Select, Button, notification, Modal, Tooltip } from 'antd'
 
-const { TextArea } = Input
+import Api from '@/api'
+import { checkSQL } from '@/utils/utils-custom.js'
+import CodeMirror from '@/templates/zshare/codemirror'
+// import './index.scss'
 
 class CustomForm extends Component {
   static propTpyes = {
-    dict: PropTypes.object,         // 瀛楀吀椤�
-    usefulfields: PropTypes.string, // 鍙敤瀛楁
+    btn: PropTypes.object,          // 鎸夐挳
+    formfields: PropTypes.string,
+    colfields: PropTypes.string,
+    initsql: PropTypes.string,      // 鍙敤瀛楁
     customChange: PropTypes.func    // 琛ㄥ崟
   }
 
   state = {
-    editItem: null
+    editItem: null,
+    loading: false
   }
 
   edit = (record) => {
@@ -29,59 +34,85 @@
     })
   }
 
+  handleCancel = () => {
+    this.setState({
+      editItem: null
+    })
+
+    this.props.form.setFieldsValue({
+      sql: ' ',
+      errmsg: ''
+    })
+  }
 
   handleConfirm = () => {
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
     this.props.form.validateFieldsAndScroll((err, values) => {
       if (!err) {
-        values.uuid = this.state.editItem ? this.state.editItem.uuid : ''
-        values.resultName = values.result === 'false' ? '涓嶅瓨鍦�' : '瀛樺湪'
-
-        let _quot = values.sql.match(/'{1}/g)
-        let _lparen = values.sql.match(/\({1}/g)
-        let _rparen = values.sql.match(/\){1}/g)
-
-        _quot = _quot ? _quot.length : 0
-        _lparen = _lparen ? _lparen.length : 0
-        _rparen = _rparen ? _rparen.length : 0
-
-        if (_quot % 2 !== 0) {
+        if (/^[\s\n]+$/.test(values.sql)) {
           notification.warning({
             top: 92,
-            message: 'sql涓璡'蹇呴』鎴愬鍑虹幇',
-            duration: 10
-          })
-          return
-        } else if (_lparen !== _rparen) {
-          notification.warning({
-            top: 92,
-            message: 'sql涓�()蹇呴』鎴愬鍑虹幇',
-            duration: 10
-          })
-          return
-        } else if (/--/ig.test(values.sql)) {
-          notification.warning({
-            top: 92,
-            message: '鑷畾涔塻ql璇彞涓紝涓嶅彲鍑虹幇瀛楃 -- 锛屾敞閲婅鐢� /*鍐呭*/',
-            duration: 10
+            message: '璇疯緭鍏ql!',
+            duration: 5
           })
           return
         }
         
-        this.props.customChange(values)
-        this.setState({
-          editItem: null
-        })
-        this.props.form.setFieldsValue({
-          sql: '',
-          errmsg: ''
+        values.uuid = this.state.editItem ? this.state.editItem.uuid : ''
+        values.resultName = values.result === 'false' ? '涓嶅瓨鍦�' : '瀛樺湪'
+
+        let pass = checkSQL(values.sql, 'customscript')
+
+        if (!pass) return
+
+        let sql = `${this.props.initsql}
+          /* 鑷畾涔夐獙璇� */
+          select @tbid='', @ErrorCode='',@retmsg=''
+          select top 1 @tbid='X' from (${values.sql}) a
+          If @tbid = ''
+          Begin
+            select @ErrorCode='${values.errorCode}',@retmsg='${values.errmsg}'
+            goto aaa
+          end
+          aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
+
+        // if (window.GLOB.funcs && window.GLOB.funcs.length > 0) {
+        //   window.GLOB.funcs.forEach(item => {
+        //     let reg = new RegExp('\\$ex@' + item.func_code + '@ex\\$', 'ig')
+        //     sql = sql.replace(reg, `/*$ex@${item.func_code}-begin*/\n${item.key_sql}\n/*@ex$-end*/`)
+        //   })
+        // }
+        
+        // 鏁版嵁鏉冮檺
+        sql = sql.replace(/@\$|\$@/ig, '')
+        
+        this.setState({loading: true})
+        Api.sDebug(sql).then(res => {
+          if (res.status || res.ErrCode === '-2') {
+            this.setState({
+              loading: false,
+              editItem: null
+            }, () => {
+              this.props.customChange(values)
+            })
+            this.props.form.setFieldsValue({
+              sql: ' ',
+              errmsg: ''
+            })
+          } else {
+            this.setState({loading: false})
+            
+            Modal.error({
+              title: res.message
+            })
+          }
         })
       }
     })
   }
 
   render() {
-    const { usefulfields } = this.props
+    const { formfields, colfields, btn } = this.props
     const { getFieldDecorator } = this.props.form
     const formItemLayout = {
       labelCol: {
@@ -93,31 +124,43 @@
         sm: { span: 16 }
       }
     }
+
     return (
       <Form {...formItemLayout} className="verify-form" id="verifycard2">
         <Row gutter={24}>
-          {usefulfields ? <Col span={21} className="sqlfield">
+          <Col span={21} className="sqlfield">
             <Form.Item label={'鍙敤瀛楁'}>
-              {usefulfields}
+              <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'鍏叡鍊硷紝璇锋寜鐓xxx@鏍煎紡浣跨敤銆�'}><span style={{color: '#1890ff'}}>BID, ID, LoginUID, SessionUid, UserID, Appkey, lang, 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, mk_deleted</span></Tooltip>,&nbsp;
+              <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'绯荤粺鍙橀噺锛岀郴缁熶細瀹氫箟鍙橀噺骞跺湪鍗曞彿鐢熸垚鎴栧垱寤哄嚟璇佹椂浣跨敤銆�'}><span style={{color: '#13c2c2'}}>BillCode, BVoucher, FIBVoucherDate, FiYear, ModularDetailCode</span></Tooltip>
+              {formfields ? <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title="琛ㄥ崟鍙橀噺锛岀郴缁熶細瀹氫箟鍙橀噺骞惰祴鍊笺��">, <span style={{color: '#8E44AD'}}>{formfields}</span></Tooltip> : ''}
+              {colfields ? <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title="瀛楁闆嗗彉閲忥紝绯荤粺浼氬畾涔夊彉閲忓苟璧嬪�笺��">, {colfields}</Tooltip> : ''}
             </Form.Item>
-          </Col> : null}
+          </Col>
           <Col span={21} className="sql">
-            <Form.Item label={'sql'}>
+            <Form.Item label="sql">
               {getFieldDecorator('sql', {
                 initialValue: '',
                 rules: [
                   {
                     required: true,
-                    message: this.props.dict['form.required.input'] + 'sql!'
+                    message: '璇疯緭鍏ql!'
                   }
                 ]
-              })(<TextArea rows={15} />)}
+              })(<CodeMirror />)}
             </Form.Item>
           </Col>
           <Col span={3} className="add">
-            <Button onClick={this.handleConfirm} type="primary" className="add-row">
-              纭畾
+            <Button onClick={this.handleConfirm} loading={this.state.loading} className="mk-green">
+              淇濆瓨
             </Button>
+            <div></div>
+            <Button onClick={this.handleCancel}>
+              鍙栨秷
+            </Button>
+            {btn.sql ? <div style={{marginTop: '31px'}}>
+              琛ㄥ悕:  <div style={{wordBreak: 'break-all'}}>{btn.sql}</div>
+            </div> : null}
           </Col>
           <Col span={7}>
             <Form.Item label={'缁撴灉澶勭悊'}>
@@ -126,7 +169,7 @@
                 rules: [
                   {
                     required: true,
-                    message: this.props.dict['form.required.select'] + '缁撴灉澶勭悊!'
+                    message: '璇烽�夋嫨缁撴灉澶勭悊!'
                   }
                 ]
               })(
@@ -138,20 +181,20 @@
             </Form.Item>
           </Col>
           <Col span={7}>
-            <Form.Item label={'鎻愮ず淇℃伅'}>
+            <Form.Item label="鎻愮ず淇℃伅">
               {getFieldDecorator('errmsg', {
                 initialValue: '',
                 rules: [
                   {
                     required: true,
-                    message: this.props.dict['form.required.input'] + '鎻愮ず淇℃伅!'
+                    message: '璇疯緭鍏ユ彁绀轰俊鎭�!'
                   },
                   {
                     pattern: /^[^']*$/ig,
                     message: '鎻愮ず淇℃伅涓嶅厑璁稿寘鍚玕''
                   }
                 ]
-              })(<Input placeholder="" autoComplete="off" />)}
+              })(<Input placeholder="" autoComplete="off" onPressEnter={this.handleConfirm}/>)}
             </Form.Item>
           </Col>
           <Col span={7}>
@@ -161,7 +204,7 @@
                 rules: [
                   {
                     required: true,
-                    message: this.props.dict['form.required.select'] + '鎶ラ敊缂栫爜!'
+                    message: '璇烽�夋嫨鎶ラ敊缂栫爜!'
                   }
                 ]
               })(

--
Gitblit v1.8.0