king
2023-06-14 08cce3334a2dc81d690b518136b0aaea64e48b0b
src/menu/datasource/index.jsx
@@ -1,10 +1,9 @@
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 './index.scss'
@@ -15,7 +14,7 @@
  }
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    appType: sessionStorage.getItem('appType'),
    sourcelist: [],
    mainSearch: [],
    visible: false,
@@ -35,42 +34,106 @@
  editDataSource = () => {
    const { config } = this.props
    const { appType } = this.state
    if (config.type === 'interface') { // 公共数据源不使用搜索
      this.setState({visible: true})
      return
    }
    let search = []
    let parents = []
    let _conf = config
    let getParents = (box) => {
      box.components.forEach(item => {
        if (item.type !== 'tabs') return
    let menu = fromJS(window.GLOB.customMenu).toJS()
        item.subtabs.forEach(tab => {
          if (_conf.parentId === tab.parentId && _conf.tabId === tab.uuid) {
            parents.unshift(tab)
            _conf = item
            if (_conf.parentId && _conf.tabId) {
              getParents(tab)
            }
          } else {
            getParents(tab)
          }
        })
      })
    }
    if (config.parentId && config.tabId) {
      getParents(window.GLOB.customMenu)
    }
    parents.unshift(window.GLOB.customMenu)
    parents.forEach(parent => {
      parent.components.forEach(item => {
        if (item.type === 'search') {
          search = item.search
    if (appType === 'mob') {
      let ms = null
      menu.components.forEach(item => {
        if (item.type === 'topbar' && item.wrap.type !== 'navbar' && item.search) {
          ms = item.search
        } 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 || ''
          })
        }
      })
    })
      if (ms) {
        if (ms.setting.type === 'search') {
          search.push({
            type: 'text',
            label: '搜索栏',
            field: ms.setting.field,
            match: ms.setting.match,
            required: ms.setting.required,
            value: ms.setting.initval || ''
          })
        }
        ms.fields.forEach(item => {
          if (item.type === 'range') {
            item.initval = `${item.minValue},${item.maxValue}`
          }
          search.push(item)
        })
        ms.groups.forEach(group => {
          if (group.setting.type === 'search') {
            search.push({
              type: 'text',
              label: group.wrap.name,
              field: group.setting.field,
              match: group.setting.match,
              required: group.setting.required,
              value: group.setting.initval || ''
            })
          }
          group.fields.forEach(item => {
            if (item.type === 'range') {
              item.initval = `${item.minValue},${item.maxValue}`
            }
            search.push(item)
          })
        })
      }
    } else {
      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) {
            _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)
      if (_search) {
        search = _search
      } else {
        menu.components.forEach(item => {
          if (item.type !== 'search') return
          search = item.search
        })
      }
    }
    this.setState({
      visible: true,
@@ -99,7 +162,11 @@
          }
          return item
        })
        res.columns.reverse()
      }
      let maxScript = 0
      if (window.GLOB.funcs && window.GLOB.funcs.length > 0) {
        window.GLOB.funcs.forEach(m => {
@@ -109,8 +176,40 @@
          }
          res.scripts.forEach(item => {
            item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
            if (item.status === 'false') return
            if (/exec\s/ig.test(item.sql)) {
              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
          }
        })
      }
      res.setting.maxScript = maxScript
      if (config.subtype !== 'dualdatacard') {
        delete res.subColumns
      } else {
        res.subColumns.reverse()
      }
      if (this.verifyRef.state.debugId) {
        res.setting.debugId = this.verifyRef.state.debugId
      } else {
        delete res.setting.debugId
      }
      this.setState({loading: false, visible: false})
@@ -122,26 +221,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={() => {this.setState({ visible: false }) }}
          destroyOnClose
        >
          <VerifyCard
            dict={dict}
            menu={window.GLOB.customMenu}
            mainSearch={mainSearch}
            config={config}
            wrappedComponentRef={(inst) => this.verifyRef = inst}