From f9816a4078fdba44115c69025d9982997f23b484 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 29 四月 2024 16:00:49 +0800 Subject: [PATCH] Merge branch 'develop' --- src/menu/components/module/invoice/verifycard/callbackcustomscript/index.jsx | 294 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 294 insertions(+), 0 deletions(-) diff --git a/src/menu/components/module/invoice/verifycard/callbackcustomscript/index.jsx b/src/menu/components/module/invoice/verifycard/callbackcustomscript/index.jsx new file mode 100644 index 0000000..6eb1a0d --- /dev/null +++ b/src/menu/components/module/invoice/verifycard/callbackcustomscript/index.jsx @@ -0,0 +1,294 @@ +import React, {Component} from 'react' +import PropTypes from 'prop-types' +import { Form, Row, Col, Button, Modal, 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 = { + systemScripts: PropTypes.array, + customScripts: PropTypes.array, + scriptsChange: PropTypes.func + } + + state = { + editItem: null, + loading: false, + skip: false + } + + edit = (record) => { + this.setState({ + editItem: record + }) + + if (this.props.type) { + this.props.form.setFieldsValue({ + sql: record.sql + }) + } else { + this.props.form.setFieldsValue({ + sql: record.sql, + position: record.position || 'back' + }) + } + } + + handleConfirm = () => { + const { type } = this.props + const { editItem, skip } = this.state + // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭� + this.props.form.validateFieldsAndScroll((err, values) => { + if (type === 'fullscreen' && err) { + notification.warning({ + top: 92, + message: '璇疯緭鍏ql!', + duration: 5 + }) + 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' + } + + let pass = checkSQL(values.sql, 'customscript') + + if (!pass) return + + let sql = ` + /* 绯荤粺瀛楁 */ + + Declare @UserName nvarchar(50), @FullName nvarchar(50), @RoleID nvarchar(512), @mk_departmentcode nvarchar(512), @mk_organization nvarchar(512), @mk_user_type nvarchar(20), @mk_nation nvarchar(50), @mk_province nvarchar(50), @mk_city nvarchar(50), @mk_district nvarchar(50), @mk_address nvarchar(100), @ErrorCode nvarchar(50), @retmsg nvarchar(4000), @account_id nvarchar(50), @account_year_id nvarchar(50), @account_code nvarchar(50), @account_year_code nvarchar(50), @bid nvarchar(50), @tbid nvarchar(50) + + Select @UserName='', @FullName='', @RoleID='', @mk_departmentcode='', @mk_organization='', @mk_user_type='', @mk_nation='', @mk_province='', @mk_city='', @mk_district='', @mk_address='', @ErrorCode='', @retmsg='', @account_id='', @account_year_id='', @account_code='', @account_year_code='', @bid='' + + ` + + 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 (!values.uuid) { + if (values.position === 'front') { + _prevCustomScript += ` + /* 榛樿sql鍓嶈剼鏈� */ + ${values.sql} + ` + } else { + _backCustomScript += ` + /* 榛樿sql鍚庤剼鏈� */ + ${values.sql} + ` + } + } + + sql += _prevCustomScript + _backCustomScript + sql += ` + aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg + ` + + // 鏁版嵁鏉冮檺 + sql = sql.replace(/@\$|\$@/ig, '') + sql = sql.replace(/@datam@/ig, `''`) + sql = sql.replace(/@typename@/ig, `'debug'`) + + if (skip) { + this.setState({ + skip: false, + editItem: null + }, () => { + this.props.scriptsChange(values) + }) + this.props.form.setFieldsValue({ + 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 + }) + } + }) + } + } + }) + } + + handleCancel = () => { + this.setState({ + editItem: null + }) + + this.props.form.setFieldsValue({ + sql: ' ' + }) + } + + selectScript = (value, option) => { + if (!value || !option) return + let _sql = this.props.form.getFieldValue('sql') + if (/^\s+$/.test(_sql)) { + _sql = '' + } + if (_sql) { + _sql = _sql + ` + + ` + } + + _sql = _sql.replace(/\s{6}$/, '') + _sql = _sql + `/*${option.props.children}*/ + ` + _sql = _sql.replace(/\s{4}$/, '') + _sql = _sql + value + + this.props.form.setFieldsValue({ + sql: _sql + }) + } + + render() { + const { systemScripts, type } = this.props + const { getFieldDecorator } = this.props.form + const { editItem, skip } = this.state + const formItemLayout = { + labelCol: { + xs: { span: 24 }, + sm: { span: 8 } + }, + wrapperCol: { + xs: { span: 24 }, + sm: { span: 16 } + } + } + + return ( + <Form {...formItemLayout} className="verify-form"> + <Row gutter={24}> + {!type ? <Col span={8}> + <Form.Item label="鎶ラ敊瀛楁" style={{margin: 0, whiteSpace: 'nowrap'}}> + errorcode锛堝鍔犲悗缂�NT琛ㄧず鏁版嵁涓嶅洖婊氾紝濡侲NT銆丯NT銆丗NT銆丯MNT銆丆NT銆�-2NT锛�, retmsg + </Form.Item> + </Col> : null} + {!type ? <Col span={24} className="sqlfield"> + <Form.Item label="鍙敤瀛楁"> + <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'鍏叡鍊硷紝璇锋寜鐓xxx@鏍煎紡浣跨敤銆�'}><span style={{color: '#1890ff'}}>BID, ID, LoginUID, SessionUid, UserID, Appkey, time_id, typename, datam</span></Tooltip>, + <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>, + </Form.Item> + </Col> : null} + {!type ? <Col span={8} style={{whiteSpace: 'nowrap'}}> + <Form.Item style={{marginBottom: 0}} label={ + <Tooltip placement="bottomLeft" title={'鑷畾涔夎剼鏈笌榛樿sql浣嶇疆鍏崇郴銆�'}> + <QuestionCircleOutlined className="mk-form-tip" /> + 鎵ц浣嶇疆 + </Tooltip> + }> + {getFieldDecorator('position', { + initialValue: 'front' + })( + <Radio.Group> + <Radio value="front">sql鍓�</Radio> + <Radio value="back">sql鍚�</Radio> + </Radio.Group> + )} + </Form.Item> + </Col> : null} + {!type ? <Col span={8}> + <Form.Item label="蹇嵎娣诲姞" style={{marginBottom: 0}}> + <Select + showSearch + dropdownMatchSelectWidth={false} + filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} + onChange={this.selectScript} + > + <Select.Option key="default" value="defaultSql">榛樿sql</Select.Option> + {systemScripts.map((option, i) => + <Select.Option key={i} value={option.value}>{option.name}</Select.Option> + )} + </Select> + </Form.Item> + </Col> : null} + <Col span={5} className="add" style={{whiteSpace: 'nowrap'}}> + <Button onClick={this.handleConfirm} loading={this.state.loading} className="mk-green" style={{marginBottom: 15, marginLeft: 40}}> + {type === 'fullscreen' && !editItem ? '娣诲姞' : '淇濆瓨'} + </Button> + <Button onClick={this.handleCancel} style={{marginBottom: 15, marginLeft: 10}}> + 鍙栨秷 + </Button> + </Col> + <Col span={3} className="forced" style={{paddingTop: '12px', fontSize: '12px', whiteSpace: 'nowrap'}}> + 寮哄埗淇濆瓨锛� + <Switch checked={skip} size="small" onChange={() => this.setState({skip: !skip})}/> + </Col> + <Col span={24} className="sql"> + <Form.Item label={ + <Tooltip placement="bottomLeft" title="鏁版嵁鏉冮檺鏇挎崲绗� $@ -> /* 鎴� \'\'銆� @$ -> */ 鎴� \'\'"> + <QuestionCircleOutlined className="mk-form-tip" /> + sql + </Tooltip> + }> + {getFieldDecorator('sql', { + initialValue: '', + rules: [ + { + required: true, + message: '璇疯緭鍏ql!' + } + ] + })(<CodeMirror />)} + </Form.Item> + </Col> + </Row> + </Form> + ) + } +} + +export default Form.create()(CustomForm) \ No newline at end of file -- Gitblit v1.8.0