| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { Form, Row, Col, Input, Button, notification, Modal, Select, Tooltip, Icon, Radio } from 'antd' |
| | | import { Form, Row, Col, Input, Button, notification, Modal, Menu, Tooltip, Icon, Radio, Dropdown } from 'antd' |
| | | import moment from 'moment' |
| | | |
| | | import Utils from '@/utils/utils.js' |
| | |
| | | class CustomForm extends Component { |
| | | static propTpyes = { |
| | | dict: PropTypes.object, // 字典项 |
| | | btn: PropTypes.object, // 按钮信息 |
| | | usefulfields: PropTypes.string, // 可用字段 |
| | | initsql: PropTypes.string, // sql前缀 |
| | | systemScripts: PropTypes.array, // 系统脚本 |
| | |
| | | }) |
| | | } |
| | | |
| | | selectScript = (val, option) => { |
| | | selectScript = (e) => { |
| | | const { systemScripts } = this.props |
| | | |
| | | let option = systemScripts[+e.key] |
| | | |
| | | let _sql = this.props.form.getFieldValue('sql') |
| | | if (_sql) { |
| | | _sql = _sql + ` |
| | |
| | | } |
| | | |
| | | _sql = _sql.replace(/\s{6}$/, '') |
| | | _sql = _sql + `/*${option.props.title}*/ |
| | | _sql = _sql + `/*${option.name}*/ |
| | | ` |
| | | _sql = _sql.replace(/\s{4}$/, '') |
| | | _sql = _sql + val |
| | | _sql = _sql + option.value |
| | | |
| | | this.props.form.setFieldsValue({ |
| | | sql: _sql |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { usefulfields, systemScripts } = this.props |
| | | const { usefulfields, systemScripts, btn } = this.props |
| | | const { getFieldDecorator } = this.props.form |
| | | const formItemLayout = { |
| | | labelCol: { |
| | |
| | | {usefulfields} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | <Col span={8}> |
| | | <Col span={8} style={{whiteSpace: 'nowrap'}}> |
| | | <Form.Item style={{marginBottom: 0}} label={ |
| | | <Tooltip placement="bottomLeft" title={'自定义脚本与默认sql位置关系。'}> |
| | | <Icon type="question-circle" style={{color: '#c49f47', marginRight: '5px'}} /> |
| | |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={8}> |
| | | <Form.Item style={{marginBottom: 0}} label={ |
| | | <Tooltip placement="bottomLeft" title={'从系统函数集中选择需要的函数,可快速添加至sql中。'}> |
| | | <Icon type="question-circle" style={{color: '#c49f47', marginRight: '5px'}} /> |
| | | 快捷添加 |
| | | </Tooltip> |
| | | }> |
| | | <Select value="" onChange={this.selectScript}> |
| | | <Col span={4} style={{lineHeight: '40px', textAlign: 'center'}}> |
| | | <Dropdown trigger={['click']} overlayClassName="mk-normal-dropdown" overlay={ |
| | | <Menu onClick={this.selectScript}> |
| | | {systemScripts.map((option, i) => |
| | | <Select.Option title={option.name} key={i} value={option.value}> |
| | | {option.name} |
| | | </Select.Option> |
| | | <Menu.Item key={i}>{option.name}</Menu.Item> |
| | | )} |
| | | </Select> |
| | | </Form.Item> |
| | | </Menu> |
| | | }> |
| | | <span style={{color: '#1890ff', display: 'inline-block', cursor: 'pointer'}}> |
| | | 快捷添加 <Icon type="down" style={{marginRight: '5px'}} /> |
| | | </span> |
| | | </Dropdown> |
| | | </Col> |
| | | <Col span={4} className="add"> |
| | | <Button onClick={this.handleConfirm} loading={this.state.loading} className="mk-green" style={{marginBottom: 15, marginLeft: 40}}> |
| | | 保存 |
| | | </Button> |
| | | </Col> |
| | | <Col span={8} style={{textAlign: 'right'}}> |
| | | {btn.sql ? <span style={{maxWidth: '100%', display: 'inline-block', position: 'relative', top: '20px', whiteSpace: 'nowrap', textOverflow: 'ellipsis', overflow: 'hidden'}}> |
| | | 表名: {btn.sql} |
| | | </span> : null} |
| | | </Col> |
| | | <Col span={24} className="sql"> |
| | | <Form.Item label={'sql'}> |
| | | {getFieldDecorator('sql', { |