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/callbackcustomscript/index.jsx | 143 +++++++++++------------------------------------ 1 files changed, 33 insertions(+), 110 deletions(-) diff --git a/src/templates/zshare/verifycard/callbackcustomscript/index.jsx b/src/templates/zshare/verifycard/callbackcustomscript/index.jsx index 2619cbe..1024b90 100644 --- a/src/templates/zshare/verifycard/callbackcustomscript/index.jsx +++ b/src/templates/zshare/verifycard/callbackcustomscript/index.jsx @@ -1,22 +1,19 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import { Form, Row, Col, Button, Modal, Tooltip, Radio, Select, Switch, notification } from 'antd' +import { Form, Row, Col, Button, Tooltip, Radio, Select, Switch, notification } from 'antd' import { QuestionCircleOutlined } from '@ant-design/icons' -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, // 鎸夐挳淇℃伅 - initsql: PropTypes.string, // 鍒濆鍖栬剼鏈� + btn: PropTypes.object, formfields: PropTypes.string, colfields: PropTypes.string, - systemScripts: PropTypes.array, // 绯荤粺鑴氭湰 - customScripts: PropTypes.array, // 鑷畾涔夎剼鏈� - scriptsChange: PropTypes.func // 琛ㄥ崟 + systemScripts: PropTypes.array, + cbScriptsChange: PropTypes.func } state = { @@ -47,7 +44,9 @@ const { editItem, skip } = this.state // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭� this.props.form.validateFieldsAndScroll((err, values) => { - if (type === 'fullscreen' && err) { + if (err) return + + if (!values.sql || /^[\s\n]+$/.test(values.sql)) { notification.warning({ top: 92, message: '璇疯緭鍏ql!', @@ -56,110 +55,40 @@ return } - if (!err) { - if (/^[\s\n]+$/.test(values.sql)) { - notification.warning({ - top: 92, - message: '璇疯緭鍏ql!', - duration: 5 - }) - return - } + values.uuid = editItem ? editItem.uuid : '' + values.position = values.position || (editItem ? editItem.position : 'front') - values.uuid = editItem ? editItem.uuid : '' - values.position = values.position || (editItem ? editItem.position : 'front') + if (type === 'fullscreen' && editItem) { + values.status = editItem.status || 'true' + } - if (type === 'fullscreen' && editItem) { - values.status = editItem.status || 'true' - } + let pass = checkSQL(values.sql, 'customscript') - let pass = checkSQL(values.sql, 'customscript') + if (!pass && !skip) return - if (!pass && !skip) return - - let tail = ` - aaa: - ` - - let _prevCustomScript = '' // 榛樿sql鍓嶆墽琛岃剼鏈� - let _backCustomScript = '' // 榛樿sql鍚庢墽琛岃剼鏈� - - this.props.customScripts.forEach(item => { - if (item.status === 'false') return - - if (item.position === 'front') { - _prevCustomScript += ` - /* 榛樿sql鍓嶈剼鏈� */ - ${values.uuid === item.uuid ? values.sql : item.sql} - ` - } else { - _backCustomScript += ` - /* 榛樿sql鍚庤剼鏈� */ - ${values.uuid === item.uuid ? values.sql : item.sql} - ` - } + if (skip) { + this.setState({ + skip: false, + editItem: null }) + this.props.form.setFieldsValue({ + sql: '' + }) + this.props.cbScriptsChange(values) + } else { + this.setState({loading: true}) - if (!values.uuid) { - if (values.position === 'front') { - _prevCustomScript += ` - /* 榛樿sql鍓嶈剼鏈� */ - ${values.sql} - ` - } else { - _backCustomScript += ` - /* 榛樿sql鍚庤剼鏈� */ - ${values.sql} - ` - } - } - - let sql = this.props.initsql + _prevCustomScript + _backCustomScript + tail - - // 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, '').replace(/\$check@|@check\$/ig, '') - sql = sql.replace(/@datam@/ig, `''`) - sql = sql.replace(/@typename@/ig, `'debug'`) - - if (skip) { + this.props.cbScriptsChange(values, () => { this.setState({ - skip: false, + loading: false, editItem: null - }, () => { - this.props.scriptsChange(values) }) this.props.form.setFieldsValue({ - sql: ' ' + sql: '' }) - } else { - this.setState({loading: true}) - Api.sDebug(sql).then(res => { - if (res.status || res.ErrCode === '-2') { - this.setState({ - loading: false, - editItem: null - }, () => { - this.props.scriptsChange(values) - }) - this.props.form.setFieldsValue({ - sql: ' ' - }) - } else { - this.setState({loading: false}) - - Modal.error({ - title: res.message - }) - } - }) - } + }, () => { + this.setState({loading: false}) + }) } }) } @@ -170,7 +99,7 @@ }) this.props.form.setFieldsValue({ - sql: ' ' + sql: '' }) } @@ -280,15 +209,9 @@ <Switch checked={skip} size="small" onChange={() => this.setState({skip: !skip})}/> </Col> <Col span={24} className="sql"> - <Form.Item label="sql"> + <Form.Item label="sql" required> {getFieldDecorator('sql', { - initialValue: '', - rules: [ - { - required: true, - message: '璇疯緭鍏ql!' - } - ] + initialValue: '' })(<CodeMirror />)} </Form.Item> </Col> -- Gitblit v1.8.0