From 5e5a8bafcbc346cb6246aab4e63750e5454eb270 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 22 十一月 2024 12:05:04 +0800 Subject: [PATCH] 2024-11-22 --- src/templates/zshare/verifycard/customform/index.jsx | 94 +++++++++++++++++++--------------------------- 1 files changed, 39 insertions(+), 55 deletions(-) diff --git a/src/templates/zshare/verifycard/customform/index.jsx b/src/templates/zshare/verifycard/customform/index.jsx index 6433bfb..086a0e8 100644 --- a/src/templates/zshare/verifycard/customform/index.jsx +++ b/src/templates/zshare/verifycard/customform/index.jsx @@ -1,24 +1,23 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import { Form, Row, Col, Input, Select, Button, notification, Modal, Tooltip } from 'antd' +import { Form, Row, Col, Input, Select, Button, notification, Tooltip, Switch } from 'antd' -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 = { - btn: PropTypes.object, // 鎸夐挳 + btn: PropTypes.object, formfields: PropTypes.string, colfields: PropTypes.string, - initsql: PropTypes.string, // 鍙敤瀛楁 - customChange: PropTypes.func // 琛ㄥ崟 + customChange: PropTypes.func } state = { editItem: null, - loading: false + loading: false, + skip: false } edit = (record) => { @@ -40,16 +39,17 @@ }) this.props.form.setFieldsValue({ - sql: ' ', + sql: '', errmsg: '' }) } handleConfirm = () => { - // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭� + const { skip, editItem } = this.state + this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { - if (/^[\s\n]+$/.test(values.sql)) { + if (!values.sql || /^[\s\n]+$/.test(values.sql)) { notification.warning({ top: 92, message: '璇疯緭鍏ql!', @@ -58,55 +58,41 @@ return } - values.uuid = this.state.editItem ? this.state.editItem.uuid : '' + values.uuid = editItem ? editItem.uuid : '' values.resultName = values.result === 'false' ? '涓嶅瓨鍦�' : '瀛樺湪' let pass = checkSQL(values.sql, 'customscript') - if (!pass) return + if (!pass && !skip) 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 (skip) { + this.setState({ + skip: false, + editItem: null + }) + this.props.form.setFieldsValue({ + sql: '', + errmsg: '' + }) + this.props.customChange(values) + } else { + this.setState({loading: true}) - // 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.props.customChange(values, () => { this.setState({ loading: false, editItem: null - }, () => { - this.props.customChange(values) }) this.props.form.setFieldsValue({ - sql: ' ', + sql: '', errmsg: '' }) - } else { - this.setState({loading: false}) - - Modal.error({ - title: res.message + }, () => { + this.setState({ + loading: false }) - } - }) + }) + } } }) } @@ -114,6 +100,7 @@ render() { const { formfields, colfields, btn } = this.props const { getFieldDecorator } = this.props.form + const { skip } = this.state const formItemLayout = { labelCol: { xs: { span: 24 }, @@ -138,15 +125,9 @@ </Form.Item> </Col> <Col span={21} className="sql"> - <Form.Item label="sql"> + <Form.Item label="sql" required> {getFieldDecorator('sql', { - initialValue: '', - rules: [ - { - required: true, - message: '璇疯緭鍏ql!' - } - ] + initialValue: '' })(<CodeMirror />)} </Form.Item> </Col> @@ -161,9 +142,13 @@ {btn.sql ? <div style={{marginTop: '31px'}}> 琛ㄥ悕: <div style={{wordBreak: 'break-all'}}>{btn.sql}</div> </div> : null} + <div style={{paddingTop: '20px', fontSize: '12px'}}> + 寮哄埗淇濆瓨锛� + <Switch checked={skip} size="small" onChange={() => this.setState({skip: !skip})}/> + </div> </Col> <Col span={7}> - <Form.Item label={'缁撴灉澶勭悊'}> + <Form.Item label="缁撴灉澶勭悊"> {getFieldDecorator('result', { initialValue: 'true', rules: [ @@ -198,7 +183,7 @@ </Form.Item> </Col> <Col span={7}> - <Form.Item label={'鎶ラ敊缂栫爜'}> + <Form.Item label="鎶ラ敊缂栫爜"> {getFieldDecorator('errorCode', { initialValue: 'E', rules: [ @@ -219,7 +204,6 @@ )} </Form.Item> </Col> - </Row> </Form> ) -- Gitblit v1.8.0