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/customscript/index.jsx | 239 ++++++++++------------------------------------------------- 1 files changed, 40 insertions(+), 199 deletions(-) diff --git a/src/templates/zshare/verifycard/customscript/index.jsx b/src/templates/zshare/verifycard/customscript/index.jsx index 6924ddb..3a13b0e 100644 --- a/src/templates/zshare/verifycard/customscript/index.jsx +++ b/src/templates/zshare/verifycard/customscript/index.jsx @@ -1,9 +1,8 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import { Form, Row, Col, Button, notification, Modal, Tooltip, Radio, Select, Switch } from 'antd' +import { Form, Row, Col, Button, notification, Tooltip, Radio, Select, Switch } 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' @@ -14,11 +13,8 @@ btn: PropTypes.object, formfields: PropTypes.string, colfields: PropTypes.string, - initsql: PropTypes.string, - defaultsql: PropTypes.string, - useDefaultSql: PropTypes.any, + getSysDefSql: PropTypes.func, systemScripts: PropTypes.array, - customScripts: PropTypes.array, scriptsChange: PropTypes.func } @@ -46,11 +42,13 @@ } handleConfirm = () => { - const { type, workFlow, flowType, flowSql, flowRemark, useDefaultSql, defaultsql } = this.props + const { type } = this.props 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!', @@ -58,199 +56,43 @@ }) 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') - if (type === 'fullscreen' && editItem) { - values.status = editItem.status || 'true' - } + values.uuid = editItem ? editItem.uuid : '' + values.position = values.position || (editItem ? editItem.position : 'front') - let pass = checkSQL(values.sql, 'customscript') + if (type === 'fullscreen' && editItem) { + values.status = editItem.status || 'true' + } - if (!pass && !skip) return + let pass = checkSQL(values.sql, 'customscript') - let tail = ` - aaa: - ` - - let _initCustomScript = '' // 鍒濆鍖栬剼鏈� - let _prevCustomScript = '' // 榛樿sql鍓嶆墽琛岃剼鏈� - let _backCustomScript = '' // 榛樿sql鍚庢墽琛岃剼鏈� - - this.props.customScripts.forEach(item => { - let _item = values.uuid === item.uuid ? values : item - - if (_item.status === 'false') return - - if (_item.position === 'init') { - _initCustomScript += ` - /* 鍒濆鍖栬剼鏈� */ - ${_item.sql} - ` - } else if (_item.position === 'front') { - _prevCustomScript += ` - /* 榛樿sql鍓嶈剼鏈� */ - ${_item.sql} - ` - } else { - _backCustomScript += ` - /* 榛樿sql鍚庤剼鏈� */ - ${_item.sql} - ` - } + if (!pass && !skip) return + + if (skip) { + this.setState({ + skip: false, + editItem: null }) + this.props.form.setFieldsValue({ + sql: '' + }) + this.props.scriptsChange(values) + } else { + this.setState({loading: true}) - if (!values.uuid) { - if (values.position === 'init') { - _initCustomScript += ` - /* 鍒濆鍖栬剼鏈� */ - ${values.sql} - ` - } else if (values.position === 'front') { - _prevCustomScript += ` - /* 榛樿sql鍓嶈剼鏈� */ - ${values.sql} - ` - } else { - _backCustomScript += ` - /* 榛樿sql鍚庤剼鏈� */ - ${values.sql} - ` - } - } - - let sql = this.props.initsql + _initCustomScript + _prevCustomScript - - if (useDefaultSql) { - sql += `\n/* 榛樿sql */ - ${defaultsql} - ` - } - - if (window.GLOB.process && workFlow === 'true' && flowSql === 'true') { - if (flowType === 'start') { - sql += ` - /* 宸ヤ綔娴侀粯璁ql */ - insert into s_my_works_flow (works_flow_id,works_flow_code,works_flow_name,works_flow_param,status,statusname,work_group,works_flow_detail_id,work_grade,bid,createuserid,CreateUser,CreateStaff,upid) - select @ID@,@works_flow_code@,@works_flow_name@,@works_flow_param@,@status@,@statusname@,@work_group@,@works_flow_detail_id@,@work_grade@,@bid@,@UserID@,@UserName,@FullName,@time_id@ - insert into s_my_works_flow_log (works_flow_id,works_flow_code,works_flow_name,works_flow_param,status,statusname,works_flow_detail_id,work_group,work_grade,bid,createuserid,CreateUser,CreateStaff,upid) - select @ID@,@works_flow_code@,@works_flow_name@ ,@works_flow_param@,@status@,@statusname@,@works_flow_detail_id@,@work_group@,@work_grade@,@bid@,@UserID@,@UserName,@FullName,@time_id@ - insert into s_my_works_flow_notice (works_flow_id,works_flow_code,works_flow_detail_id,userid,notice_type,createuserid,CreateUser,CreateStaff,upid) - select @ID@,@works_flow_code@,@works_flow_detail_id@,@userid@,@start_type@,@userid@,@UserName,@FullName,@time_id@ - insert into s_my_works_flow_role (works_flow_id,works_flow_code,userid,works_flow_detail_id,createuserid,CreateUser,CreateStaff,upid,typecharone) - select @ID@,@works_flow_code@,@userid@,@works_flow_detail_id@,@userid@,@UserName,@FullName,@time_id@,'begin' - ` - } else { - sql += ` - /* 宸ヤ綔娴侀粯璁ql */ - update s_my_works_flow set status=@status@,statusname=@statusname@,works_flow_param=@works_flow_param@,works_flow_detail_id=@works_flow_detail_id@,modifydate=getdate(),upid=@time_id@,modifyuserid=@userid@,modifyuser=@username,modifystaff=@fullname${flowRemark ? ',remark=@' + flowRemark : ''} - where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and deleted=0 - insert into s_my_works_flow_log (works_flow_id,works_flow_code,works_flow_name,works_flow_param,status,statusname,works_flow_detail_id,work_group,work_grade,bid,createuserid,CreateUser,CreateStaff,upid${flowRemark ? ',remark' : ''}) - select @ID@,@works_flow_code@,@works_flow_name@ ,@works_flow_param@,@status@,@statusname@,@works_flow_detail_id@,@work_group@,@work_grade@,@bid@,@UserID@,@UserName,@FullName,@time_id@${flowRemark ? ',@' + flowRemark : ''} - - update s_my_works_flow_role set deleted=10,modifydate=getdate(),upid=@time_id@,modifyuserid=@userid@,modifyuser=@username,modifystaff=@fullname - where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and deleted=0 - - if @check_userids@ != '' - begin - insert into s_my_works_flow_role (works_flow_id,works_flow_code,userid,works_flow_detail_id,createuserid,CreateUser,CreateStaff,upid) - select @ID@,@works_flow_code@,ID,@works_flow_detail_id@,@userid@,@UserName,@FullName,@time_id@ from dbo.SplitComma(@check_userids@) - insert into s_my_works_flow_notice (works_flow_id,works_flow_code,works_flow_detail_id,userid,notice_type,createuserid,CreateUser,CreateStaff,upid) - select @ID@,@works_flow_code@,@works_flow_detail_id@,ID,@check_type@,@userid@,@UserName,@FullName,@time_id@ from dbo.SplitComma(@check_userids@) - end - if @notice_userids@ != '' - begin - update n - set deleted=10,modifydate=getdate(),upid=@time_id@,modifyuserid=@userid@,modifyuser=@username,modifystaff=@fullname - from (select * from s_my_works_flow_notice where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and deleted=0) n - inner join (select ID from dbo.SplitComma(@notice_userids@)) s - on n.userid = s.id - insert into s_my_works_flow_notice (works_flow_id,works_flow_code,works_flow_detail_id,userid,notice_type,createuserid,CreateUser,CreateStaff,upid) - select @ID@,@works_flow_code@,@works_flow_detail_id@,ID,@notice_type@,@userid@,@UserName,@FullName,@time_id@ from dbo.SplitComma(@notice_userids@) - end - ` - } - } - - sql += _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 (window.GLOB.process && workFlow === 'true') { - sql = sql.replace(/@works_flow_code@/ig, `'works_flow_code'`) - sql = sql.replace(/@works_flow_name@/ig, `'works_flow_name'`) - sql = sql.replace(/@works_flow_param@/ig, `'works_flow_param'`) - sql = sql.replace(/@works_flow_detail_id@/ig, `'works_flow_detail_id'`) - sql = sql.replace(/@status@/ig, `0`) - sql = sql.replace(/@statusname@/ig, `'寮�濮�'`) - sql = sql.replace(/@work_group@/ig, `'work_group'`) - sql = sql.replace(/@work_grade@/ig, '0') - - - if (flowType === 'start') { - sql = sql.replace(/@start_type@/ig, `'寮�濮�'`) - } else { - sql = sql.replace(/@check_type@/ig, `'瀹℃牳'`) - sql = sql.replace(/@notice_type@/ig, `'鎶勯��'`) - - sql = sql.replace(/@check_userids@/ig, `''`) - sql = sql.replace(/@notice_userids@/ig, `''`) - - sql = sql.replace(/@works_flow_sign@/ig, `''`) - } - } - - if (skip) { + this.props.scriptsChange(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 }) - } + }) } }) } @@ -261,12 +103,12 @@ }) this.props.form.setFieldsValue({ - sql: ' ' + sql: '' }) } selectScript = (value, option) => { - const { flowType, flowRemark } = this.props + const { flowType, flowRemark, getSysDefSql } = this.props if (!value || !option) return @@ -364,6 +206,11 @@ } value = value.replace(/\n\s{8}/g, '\n') + } else if (value === 'defaultsql') { + value = '' + if (getSysDefSql) { + value = getSysDefSql() + } } _sql = _sql.replace(/\s{6}$/, '') @@ -443,7 +290,7 @@ onSelect={this.selectScript} getPopupContainer={() => document.getElementById('verify-custom-scripts' + _type)} > - <Select.Option key="default" value={this.props.defaultsql}>榛樿sql</Select.Option> + <Select.Option key="default" value="defaultsql">榛樿sql</Select.Option> {window.GLOB.process && workFlow === 'true' ? <Select.Option key="flow" value="flowSql">榛樿sql锛堝伐浣滄祦锛�</Select.Option> : null} <Select.Option key="debugger" value={`z_debug: select @ErrorCode='E',@retmsg='娴嬭瘯鏂偣' goto aaa`}> 娴嬭瘯鏂偣 @@ -472,15 +319,9 @@ <QuestionCircleOutlined className="mk-form-tip" /> sql </Tooltip> - }> + } required> {getFieldDecorator('sql', { initialValue: '', - rules: [ - { - required: true, - message: '璇疯緭鍏ql!' - } - ] })(<CodeMirror />)} </Form.Item> </Col> -- Gitblit v1.8.0