From ff4295358a99b2d35265a5fed445e4407cf6ed9a Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 18 五月 2020 14:48:10 +0800 Subject: [PATCH] 2020-05-18 --- src/templates/sharecomponent/settingcomponent/settingform/customscript/index.jsx | 91 +++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 82 insertions(+), 9 deletions(-) diff --git a/src/templates/sharecomponent/settingcomponent/settingform/customscript/index.jsx b/src/templates/sharecomponent/settingcomponent/settingform/customscript/index.jsx index b606b5a..60519c5 100644 --- a/src/templates/sharecomponent/settingcomponent/settingform/customscript/index.jsx +++ b/src/templates/sharecomponent/settingcomponent/settingform/customscript/index.jsx @@ -12,7 +12,8 @@ class CustomForm extends Component { static propTpyes = { dict: PropTypes.object, // 瀛楀吀椤� - tableName: PropTypes.string, // 琛ㄥ悕 + setting: PropTypes.object, // 璁剧疆 + searches: PropTypes.array, // 鎼滅储鏉′欢 systemScripts: PropTypes.array, // 绯荤粺鑴氭湰 customScripts: PropTypes.array, // 鑷畾涔夎剼鏈� scriptsChange: PropTypes.func // 琛ㄥ崟 @@ -20,7 +21,34 @@ state = { editItem: null, - loading: false + loading: false, + usefulFields: '' + } + + UNSAFE_componentWillMount() { + const { searches } = this.props + + let _usefulFields = [] + searches.forEach(item => { + if (item.type === 'group') { + if (item.transfer === 'true') { + _usefulFields.push(item.field) + } + _usefulFields.push(item.datefield) + _usefulFields.push(item.datefield + '1') + } else if (['dateweek', 'datemonth', 'daterange'].includes(item.type)) { + _usefulFields.push(item.field) + _usefulFields.push(item.field + '1') + } else if (_usefulFields.includes(item.field)) { + _usefulFields.push(item.field + '1') + } else { + _usefulFields.push(item.field) + } + }) + + this.setState({ + usefulFields: _usefulFields.join(', ') + }) } edit = (record) => { @@ -34,7 +62,18 @@ }) } + handleCancel = () => { + this.setState({ + editItem: null + }) + this.props.form.setFieldsValue({ + sql: '' + }) + } + handleConfirm = () => { + const { searches, setting } = this.props + // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭� this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { @@ -101,6 +140,36 @@ LText: _initsql + values.sql + tail } + param.LText = param.LText.replace(/@\$|\$@/ig, '') + + let allSearch = Utils.initMainSearch(searches) + allSearch = Utils.getAllSearchOptions(allSearch) + + let regoptions = allSearch.map(item => { + return { + reg: new RegExp('@' + item.key + '@', 'ig'), + value: `'${item.value}'` + } + }) + + regoptions.push({ + reg: new RegExp('@orderBy@', 'ig'), + value: setting.order + }) + if (setting.laypage !== 'false') { + regoptions.push({ + reg: new RegExp('@pageSize@', 'ig'), + value: 10 + }, { + reg: new RegExp('@pageIndex@', 'ig'), + value: 1 + }) + } + + regoptions.forEach(item => { + param.LText = param.LText.replace(item.reg, item.value) + }) + param.LText = Utils.formatOptions(param.LText) param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' param.secretkey = Utils.encrypt(param.LText, param.timestamp) @@ -149,8 +218,9 @@ } render() { - const { systemScripts, tableName } = this.props + const { systemScripts, setting } = this.props const { getFieldDecorator } = this.props.form + const { usefulFields } = this.state const formItemLayout = { labelCol: { xs: { span: 24 }, @@ -165,19 +235,19 @@ return ( <Form {...formItemLayout} className="modal-menu-setting-script"> <Row gutter={24}> - {tableName ? <Col span={8}> + {setting.tableName ? <Col span={8}> <Form.Item label={'琛ㄥ悕'} style={{whiteSpace: 'nowrap', margin: 0}}> - {tableName} + {setting.tableName} </Form.Item> </Col> : null} <Col span={16}> <Form.Item label={'鎶ラ敊瀛楁'} style={{margin: 0}}> - errorCode, errmsg + ErrorCode, retmsg </Form.Item> </Col> <Col span={24} className="sqlfield"> <Form.Item label={'鍙敤瀛楁'}> - id, bid, loginuid, sessionuid, userid, appkey + id, bid, loginuid, sessionuid, userid, appkey, orderBy{setting.laypage !== 'false' ? ', pageSize, pageIndex': ''}{usefulFields ? ', ' + usefulFields : ''} </Form.Item> </Col> <Col span={8} style={{whiteSpace: 'nowrap'}}> @@ -205,10 +275,13 @@ </Select> </Form.Item> </Col> - <Col span={4} className="add"> - <Button onClick={this.handleConfirm} loading={this.state.loading} className="mk-green" style={{marginBottom: 15, marginLeft: 40}}> + <Col span={6} className="add"> + <Button onClick={this.handleConfirm} loading={this.state.loading} className="mk-green" style={{marginTop: 5, marginBottom: 15, marginLeft: 30}}> 淇濆瓨 </Button> + <Button onClick={this.handleCancel} style={{marginTop: 5, marginBottom: 15, marginLeft: 10}}> + 鍙栨秷 + </Button> </Col> <Col span={24} className="sql"> <Form.Item label={'sql'}> -- Gitblit v1.8.0