king
2020-07-16 9a82bce9cf0ed4a51c1b0b0669eaa38cedbace07
src/mob/datasource/verifycard/settingform/index.jsx
@@ -3,6 +3,14 @@
// 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'
@@ -13,16 +21,16 @@
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) => {
@@ -31,10 +39,8 @@
    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: '请填写内部函数或数据源!',
@@ -42,7 +48,7 @@
            })
            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)
@@ -57,6 +63,7 @@
                message: '数据源中\'必须成对出现',
                duration: 5
              })
              reject()
              return
            } else if (_lparen !== _rparen) {
              notification.warning({
@@ -64,6 +71,7 @@
                message: '数据源中()必须成对出现',
                duration: 5
              })
              reject()
              return
            } else if (/--/ig.test(values.dataresource)) {
              notification.warning({
@@ -71,6 +79,7 @@
                message: '数据源中,不可出现字符 -- ,注释请用 /*内容*/',
                duration: 5
              })
              reject()
              return
            }
@@ -89,10 +98,8 @@
          // 数据源保存
          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',
@@ -107,17 +114,7 @@
            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)
        }
@@ -140,7 +137,7 @@
  }
  render() {
    const { columns } = this.props
    const { columns, setting } = this.props
    const { getFieldDecorator } = this.props.form
    const { interType, structure } = this.state
@@ -162,7 +159,7 @@
            <Col span={8}>
              <Form.Item label="名称">
                {getFieldDecorator('name', {
                  initialValue: '',
                  initialValue: setting.name,
                  rules: [
                    {
                      required: true,
@@ -175,7 +172,7 @@
            <Col span={8}>
              <Form.Item label="表名">
                {getFieldDecorator('tableName', {
                  initialValue: '',
                  initialValue: setting.tableName,
                  rules: [
                    {
                      required: true,
@@ -222,7 +219,7 @@
            {interType === 'inner' ? <Col span={8}>
              <Form.Item label="内部函数">
                {getFieldDecorator('innerFunc', {
                  initialValue: '',
                  initialValue: setting.innerFunc || '',
                  rules: [
                    
                  ]
@@ -232,7 +229,7 @@
            {interType === 'outer' ? <Col span={8}>
              <Form.Item label="接口地址">
                {getFieldDecorator('interface', {
                  initialValue: '',
                  initialValue: setting.interface || '',
                  rules: [
                    {
                      required: true,
@@ -245,14 +242,14 @@
            {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" />
@@ -260,17 +257,40 @@
                </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) =>
@@ -285,20 +305,14 @@
            {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>
@@ -306,13 +320,11 @@
                </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>
@@ -323,10 +335,7 @@
            <Col span={8}>
              <Form.Item label="搜索条件">
                {getFieldDecorator('search', {
                  initialValue: 'true',
                  rules: [
                  ]
                  initialValue: setting.search || 'true'
                })(
                <Radio.Group>
                  <Radio value="true">接收</Radio>