king
2022-10-22 03a22ec6f9ad7303d10b4c65bb5bc6fa5cbd448a
src/menu/datasource/index.jsx
@@ -1,11 +1,11 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Icon, Modal } from 'antd'
import { Modal } from 'antd'
import { SettingOutlined } from '@ant-design/icons'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import VerifyCard from './verifycard'
import MKEmitter from '@/utils/events.js'
import './index.scss'
class DataSource extends Component {
@@ -15,7 +15,6 @@
  }
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    appType: sessionStorage.getItem('appType'),
    sourcelist: [],
    mainSearch: [],
@@ -38,51 +37,30 @@
    const { config } = this.props
    const { appType } = this.state
    if (config.type === 'interface') { // 公共数据源不使用搜索
      this.setState({visible: true})
      return
    }
    let search = []
    let menu = fromJS(window.GLOB.customMenu).toJS()
    if (appType === 'mob') {
      let ms = null
      menu.components.forEach(item => {
        if (item.type === 'topbar' && (item.wrap.type === 'search' || (item.wrap.type === 'navbar' && item.wrap.search === 'true'))) {
        if (item.type === 'topbar' && item.wrap.type !== 'navbar' && item.search) {
          ms = item.search
        }
      })
      if (config.floor > 1) {
        let _search = null
        let filterComponent = (box) => {
          box.components.forEach(item => {
            if (_search) return
            if (item.uuid === config.uuid) {
              _search = box.slist.pop()
            } else if (item.type === 'group') {
              item.components.forEach(m => {
                if (m.uuid !== config.uuid) return
                _search = box.slist.pop()
              })
            } else if (item.type === 'tabs') {
              let able = item.setting.display === 'inline-block' && item.setting.position === 'top'
              item.subtabs.forEach(tab => {
                if (able && tab.hasSearch === 'icon' && tab.search) {
                  tab.slist = [...box.slist, tab.search]
                } else {
                  tab.slist = [...box.slist]
                }
                filterComponent(tab)
              })
            }
        } else if (item.type === 'search' && item.wrap.field) {
          search.push({
            type: 'text',
            label: item.wrap.label,
            field: item.wrap.field,
            match: item.wrap.match,
            required: item.wrap.required,
            value: item.wrap.initval || ''
          })
        }
        menu.slist = []
        filterComponent(menu)
        if (_search) {
          ms = _search
        }
      }
      })
      if (ms) {
        if (ms.setting.type === 'search') {
@@ -123,35 +101,33 @@
        })
      }
    } else {
      if (config.floor > 1) {
        let _search = null
        let filterComponent = (box) => {
          box.components.forEach(item => {
            if (_search) return
      let _search = null
      let filterComponent = (box) => {
        box.components.forEach(item => {
          if (_search) return
            if (item.type === 'search') {
              box.slist = [...box.slist, item.search]
            } else if (item.uuid === config.uuid) {
          if (item.type === 'search') {
            box.slist = [...box.slist, item.search]
          } else if (item.uuid === config.uuid) {
            _search = box.slist.pop()
          } else if (item.type === 'group') {
            item.components.forEach(m => {
              if (m.uuid !== config.uuid) return
              _search = box.slist.pop()
            } else if (item.type === 'group') {
              item.components.forEach(m => {
                if (m.uuid !== config.uuid) return
                _search = box.slist.pop()
              })
            } else if (item.type === 'tabs') {
              item.subtabs.forEach(tab => {
                tab.slist = [...box.slist]
                filterComponent(tab)
              })
            }
          })
        }
        menu.slist = []
        filterComponent(menu)
            })
          } else if (item.type === 'tabs') {
            item.subtabs.forEach(tab => {
              tab.slist = [...box.slist]
              filterComponent(tab)
            })
          }
        })
      }
      menu.slist = []
      filterComponent(menu)
        if (_search) {
          search = _search
        }
      if (_search) {
        search = _search
      } else {
        menu.components.forEach(item => {
          if (item.type !== 'search') return
@@ -164,6 +140,8 @@
      visible: true,
      mainSearch: search
    })
    MKEmitter.emit('modalStatus', '数据源')
  }
  verifySubmit = () => {
@@ -203,11 +181,21 @@
            if (item.status === 'false') return
            if (/exec\s/ig.test(item.sql)) {
              maxScript = 100
              maxScript = 1000
            } else if (item.sql.length > maxScript) {
              maxScript = item.sql.length
            }
          })
        })
      } else {
        res.scripts.forEach(item => {
          if (item.status === 'false') return
          if (/exec\s/ig.test(item.sql)) {
            maxScript = 1000
          } else if (item.sql.length > maxScript) {
            maxScript = item.sql.length
          }
        })
      }
@@ -215,6 +203,8 @@
      this.setState({loading: false, visible: false})
      this.props.updateConfig({...config, ...res})
      MKEmitter.emit('modalStatus', false)
    }, () => {
      this.setState({loading: false})
    })
@@ -222,26 +212,24 @@
  render () {
    const { config } = this.props
    const { visible, dict, loading, mainSearch } = this.state
    const { visible, loading, mainSearch } = this.state
    return (
      <div className="model-datasource">
        <Icon type="setting" title="数据源" onClick={() => this.editDataSource()} />
        <SettingOutlined title="数据源" onClick={() => this.editDataSource()} />
        <Modal
          wrapClassName="popview-modal"
          title={'数据源配置'}
          wrapClassName="mk-pop-modal"
          title=""
          visible={visible}
          width={'75vw'}
          maskClosable={false}
          okText={dict['model.submit']}
          okText="提交"
          onOk={this.verifySubmit}
          confirmLoading={loading}
          onCancel={() => { this.setState({ visible: false }) }}
          onCancel={() => { MKEmitter.emit('modalStatus', false);this.setState({ visible: false }) }}
          destroyOnClose
        >
          <VerifyCard
            dict={dict}
            menu={window.GLOB.customMenu}
            mainSearch={mainSearch}
            config={config}
            wrappedComponentRef={(inst) => this.verifyRef = inst}