| | |
| | | // import { fromJS } from 'immutable' |
| | | import { Form, Row, Col, Input, Radio, Select, Tooltip, Icon, notification } from 'antd' |
| | | import moment from 'moment' |
| | | // import CodeMirror from '@uiw/react-codemirror' |
| | | |
| | | // import 'codemirror/theme/monokai.css' |
| | | // import 'codemirror/theme/eclipse.css' |
| | | // import 'codemirror/addon/selection/active-line' |
| | | // import 'codemirror/addon/hint/javascript-hint' |
| | | // import 'codemirror/addon/hint/show-hint' |
| | | // import 'codemirror/addon/hint/show-hint.css' |
| | | |
| | | import Api from '@/api' |
| | | import Utils from '@/utils/utils.js' |
| | |
| | | |
| | | class SettingForm extends Component { |
| | | static propTpyes = { |
| | | type: PropTypes.string, // 菜单类型 |
| | | dict: PropTypes.object, // 字典项 |
| | | menuId: PropTypes.string, // 菜单Id |
| | | setting: PropTypes.object, // 数据源配置 |
| | | formlist: PropTypes.array, // 表单信息 |
| | | columns: PropTypes.array, // 列设置 |
| | | scripts: PropTypes.array, // 自定义脚本 |
| | | } |
| | | |
| | | state = { |
| | | interType: 'inner', |
| | | structure: 'array' |
| | | interType: this.props.setting.interType || 'inner', |
| | | structure: this.props.setting.structure || 'array' |
| | | } |
| | | |
| | | handleConfirm = (otype) => { |
| | |
| | | return new Promise((resolve, reject) => { |
| | | this.props.form.validateFieldsAndScroll((err, values) => { |
| | | if (!err) { |
| | | values = {...setting, ...values} |
| | | |
| | | // 数据源前端验证 |
| | | if (values.interType === 'inner' && !values.innerFunc && values.default !== 'false' && !values.dataresource) { |
| | | if (values.interType === 'inner' && !values.innerFunc && values.execute !== 'false' && !values.dataresource) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请填写内部函数或数据源!', |
| | |
| | | }) |
| | | reject() |
| | | return |
| | | } else if (values.interType === 'inner' && !values.innerFunc && values.default !== 'false' && values.dataresource) { |
| | | } else if (values.interType === 'inner' && !values.innerFunc && values.execute !== 'false' && values.dataresource) { |
| | | let _quot = values.dataresource.match(/'{1}/g) |
| | | let _lparen = values.dataresource.match(/\({1}/g) |
| | | let _rparen = values.dataresource.match(/\){1}/g) |
| | |
| | | message: '数据源中\'必须成对出现', |
| | | duration: 5 |
| | | }) |
| | | reject() |
| | | return |
| | | } else if (_lparen !== _rparen) { |
| | | notification.warning({ |
| | |
| | | message: '数据源中()必须成对出现', |
| | | duration: 5 |
| | | }) |
| | | reject() |
| | | return |
| | | } else if (/--/ig.test(values.dataresource)) { |
| | | notification.warning({ |
| | |
| | | message: '数据源中,不可出现字符 -- ,注释请用 /*内容*/', |
| | | duration: 5 |
| | | }) |
| | | reject() |
| | | return |
| | | } |
| | | |
| | |
| | | |
| | | // 数据源保存 |
| | | if ( |
| | | values.interType === 'inner' && !values.innerFunc && |
| | | values.default !== 'false' && |
| | | /[^\s]+\s+[^\s]+/ig.test(values.dataresource) && |
| | | setting.dataresource !== values.dataresource |
| | | values.interType === 'inner' && !values.innerFunc && values.execute !== 'false' && |
| | | /[^\s]+\s+[^\s]+/ig.test(values.dataresource) && setting.dataresource !== values.dataresource |
| | | ) { |
| | | let param = { |
| | | func: 's_DataSrc_Save', |
| | |
| | | Api.getLocalConfig(param) |
| | | } |
| | | |
| | | if (otype === 'change') { |
| | | this.setState({ |
| | | setting: values, |
| | | }, () => { |
| | | resolve() |
| | | }) |
| | | } else { |
| | | values.customScript = this.getCustomScript(values) |
| | | |
| | | this.sqlverify(values, resolve, reject) |
| | | } |
| | | resolve(values) |
| | | } else { |
| | | reject(err) |
| | | } |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { columns } = this.props |
| | | const { columns, setting } = this.props |
| | | const { getFieldDecorator } = this.props.form |
| | | const { interType, structure } = this.state |
| | | |
| | |
| | | <Col span={8}> |
| | | <Form.Item label="名称"> |
| | | {getFieldDecorator('name', { |
| | | initialValue: '', |
| | | initialValue: setting.name, |
| | | rules: [ |
| | | { |
| | | required: true, |
| | |
| | | <Col span={8}> |
| | | <Form.Item label="表名"> |
| | | {getFieldDecorator('tableName', { |
| | | initialValue: '', |
| | | initialValue: setting.tableName, |
| | | rules: [ |
| | | { |
| | | required: true, |
| | |
| | | {interType === 'inner' ? <Col span={8}> |
| | | <Form.Item label="内部函数"> |
| | | {getFieldDecorator('innerFunc', { |
| | | initialValue: '', |
| | | initialValue: setting.innerFunc || '', |
| | | rules: [ |
| | | |
| | | ] |
| | |
| | | {interType === 'outer' ? <Col span={8}> |
| | | <Form.Item label="接口地址"> |
| | | {getFieldDecorator('interface', { |
| | | initialValue: '', |
| | | initialValue: setting.interface || '', |
| | | rules: [ |
| | | { |
| | | required: true, |
| | |
| | | {interType === 'outer' ? <Col span={8}> |
| | | <Form.Item label="外部函数"> |
| | | {getFieldDecorator('outerFunc', { |
| | | initialValue: '', |
| | | initialValue: setting.outerFunc || '', |
| | | rules: [ |
| | | |
| | | ] |
| | | })(<Input placeholder={''} autoComplete="off" />)} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | <Col span={24} className="data-source" style={{paddingLeft: '7px'}}> |
| | | {interType === 'inner' ? <Col span={24} className="data-source" style={{paddingLeft: '7px'}}> |
| | | <Form.Item labelCol={{xs: { span: 24 }, sm: { span: 2 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 22 }} } label={ |
| | | <Tooltip placement="topLeft" title={'使用系统函数时,需填写数据源。注:数据权限替换符 $@ -> /* 或 \'\'、 @$ -> */ 或 \'\''}> |
| | | <Icon type="question-circle" /> |
| | |
| | | </Tooltip> |
| | | }> |
| | | {getFieldDecorator('dataresource', { |
| | | initialValue: '' |
| | | initialValue: setting.dataresource || '' |
| | | })(<TextArea rows={4} />)} |
| | | {/* <CodeMirror |
| | | value={'code'} |
| | | options={{ |
| | | theme: 'eclipse', |
| | | lineNumbers: false, |
| | | mode: 'SQL', |
| | | extraKeys: {"Ctrl": "autocomplete"}, |
| | | styleActiveLine: true |
| | | }} |
| | | /> */} |
| | | </Form.Item> |
| | | </Col> |
| | | </Col> : null} |
| | | {interType === 'inner' ? <Col span={8}> |
| | | <Form.Item label={ |
| | | <Tooltip placement="topLeft" title={'查询时,搜索条件以where条件拼接进入sql,统计时,将数据源中以“@+搜索字段+@”的内容,以搜索条件中的值进行替换后,提交查询,注:查询类型仅在使用系统函数时有效。'}> |
| | | <Icon type="question-circle" /> |
| | | 查询类型 |
| | | </Tooltip> |
| | | }> |
| | | {getFieldDecorator('queryType', { |
| | | initialValue: setting.queryType || 'query' |
| | | })( |
| | | <Radio.Group> |
| | | <Radio value="query">查询</Radio> |
| | | <Radio value="statistics">统计</Radio> |
| | | </Radio.Group>)} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | {structure === 'array' ? <Col span={8}> |
| | | <Form.Item label="主键"> |
| | | {getFieldDecorator('primaryKey', { |
| | | initialValue: '', |
| | | rules: [ |
| | | |
| | | ] |
| | | initialValue: setting.primaryKey || '' |
| | | })( |
| | | <Select onChange={(value) => {this.selectChange('primaryKey', value)}}> |
| | | {columns.map((option, i) => |
| | |
| | | {structure === 'array' ? <Col span={8}> |
| | | <Form.Item label="默认排序"> |
| | | {getFieldDecorator('order', { |
| | | initialValue: '', |
| | | rules: [ |
| | | |
| | | ] |
| | | initialValue: setting.order || '' |
| | | })(<Input placeholder={'ID asc, UID desc'} autoComplete="off" />)} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | {structure === 'array' ? <Col span={8}> |
| | | <Form.Item label="分页"> |
| | | {getFieldDecorator('laypage', { |
| | | initialValue: '', |
| | | rules: [ |
| | | |
| | | ] |
| | | initialValue: setting.laypage || 'true' |
| | | })( |
| | | <Radio.Group> |
| | | <Radio value="true">是</Radio> |
| | |
| | | </Radio.Group>)} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | |
| | | {interType === 'inner' ? <Col span={8}> |
| | | <Form.Item label="默认sql"> |
| | | {getFieldDecorator('execute', { |
| | | initialValue: 'true', |
| | | rules: [ |
| | | |
| | | ] |
| | | initialValue: setting.execute || 'true' |
| | | })( |
| | | <Radio.Group> |
| | | <Radio value="true">执行</Radio> |
| | |
| | | <Col span={8}> |
| | | <Form.Item label="搜索条件"> |
| | | {getFieldDecorator('search', { |
| | | initialValue: 'true', |
| | | rules: [ |
| | | |
| | | ] |
| | | initialValue: setting.search || 'true' |
| | | })( |
| | | <Radio.Group> |
| | | <Radio value="true">接收</Radio> |