king
2021-09-28 342d3498191f1683059fe586209ec920545e0bf9
src/templates/sharecomponent/searchcomponent/index.jsx
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Icon, Tooltip, Modal, notification } from 'antd'
import { Icon, Tooltip, Modal, notification, Switch } from 'antd'
import moment from 'moment'
import Api from '@/api'
@@ -9,12 +9,15 @@
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import { getSearchForm } from '@/templates/zshare/formconfig'
import asyncComponent from '@/utils/asyncComponent'
import MKEmitter from '@/utils/events.js'
import SearchForm from './searchform'
import DragElement from './dragsearch'
import './index.scss'
const { confirm } = Modal
const FieldsComponent = asyncComponent(() => import('@/templates/sharecomponent/fieldscomponent'))
class SearchComponent extends Component {
  static propTpyes = {
@@ -23,10 +26,11 @@
  }
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    searchlist: null,    // 搜索条件集
    sqlVerifing: false,  // sql验证中
    visible: false,      // 模态框控制
    showField: false,
    card: null           // 编辑中元素
  }
@@ -55,6 +59,32 @@
    }
  }
  componentDidMount () {
    MKEmitter.addListener('plusSearch', this.plusSearch)
  }
  plusSearch = (MenuId, item, type) => {
    const { config } = this.props
    const { searchlist } = this.state
    if (MenuId !== config.uuid) return
    if (type === 'simple') {
      this.setState({
        searchlist: [...searchlist, item],
      }, () => {
        this.handleSearch(item)
      })
    } else if (type === 'multil') {
      let list = [...searchlist, ...item]
      this.setState({
        searchlist: list
      }, () => {
        this.props.updatesearch({...config, search: list})
      })
    }
  }
  /**
   * @description 搜索条件顺序调整,或拖拽添加
   */
@@ -79,12 +109,14 @@
    let linkableFields = []
    searchlist.forEach(item => {
      if (item.uuid !== card.uuid && (item.type === 'select' || item.type === 'link')) {
        linkableFields.push({
          value: item.field,
          text: item.label
        })
      }
      if (item.uuid === card.uuid) return
      if (!['select', 'link', 'checkcard'].includes(item.type)) return
      if (item.type === 'checkcard' && item.multiple === 'true') return
      linkableFields.push({
        value: item.field,
        text: item.label
      })
    })
    this.setState({
@@ -174,26 +206,27 @@
      if (fieldrepet) {
        notification.warning({
          top: 92,
          message: this.state.dict['model.field.exist'] + ' !',
          message: '字段已存在!',
          duration: 5
        })
        return
      } else if (labelrepet) {
        notification.warning({
          top: 92,
          message: this.state.dict['model.name.exist'] + ' !',
          message: '名称已存在!',
          duration: 5
        })
        return
      }
      if ((res.type === 'select' || res.type === 'multiselect' || res.type === 'link') && res.resourceType === '1' && /\s/.test(res.dataSource)) {
      if (['checkcard', 'select', 'multiselect', 'link'].includes(res.type) && res.resourceType === '1' && /\s/.test(res.dataSource)) {
        this.setState({
          sqlVerifing: true
        })
        let param = {
          func: 's_debug_sql',
          exec_type: 'y',
          LText: res.dataSource
        }
@@ -201,7 +234,7 @@
        
        param.LText = Utils.formatOptions(param.LText)
        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
        param.secretkey = Utils.encrypt(param.LText, param.timestamp)
        param.secretkey = Utils.encrypt('', param.timestamp)
        if (window.GLOB.mainSystemApi && res.database === 'sso') {
          param.rduri = window.GLOB.mainSystemApi
@@ -260,6 +293,15 @@
    })
  }
  onFieldChange = () => {
    const { showField } = this.state
    this.setState({
      showField: !showField
    })
  }
  /**
   * @description 组件销毁,清除state更新
   */
@@ -267,22 +309,39 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('plusSearch', this.plusSearch)
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
    if (!is(fromJS(this.state), fromJS(nextState))) {
      return true
    } else if (this.props.config.wrap) {
      return this.props.config.wrap.show !== nextProps.config.wrap.show
    } else {
      return this.props.config.setting.show !== nextProps.config.setting.show
    }
  }
  render() {
    const { dict, searchlist, visible, sqlVerifing, card } = this.state
    const { config } = this.props
    const { dict, searchlist, visible, sqlVerifing, card, showField } = this.state
    let show = config.setting.show
    if (config.wrap) {
      show = config.wrap.show
    }
    return (
      <div className={'model-table-search-list length' + searchlist.length}>
        <Tooltip placement="bottomLeft" overlayClassName="middle" title={dict['model.tooltip.search.guide']}>
          <Icon type="question-circle" />
        </Tooltip>
        <FieldsComponent config={config} type="search" />
        <Switch checkedChildren={dict['model.switch.open']} unCheckedChildren={dict['model.switch.close']} defaultChecked={showField} onChange={this.onFieldChange} />
        <DragElement
          list={searchlist}
          show={show}
          showField={showField}
          handleList={this.handleList}
          handleMenu={this.handleSearch}
          deleteMenu={this.deleteElement}
@@ -290,7 +349,7 @@
        />
        {/* 编辑搜索条件 */}
        <Modal
          title={dict['model.searchCriteria'] + '-' + (card && card.copyType === 'search' ?  dict['model.copy'] : dict['model.edit'])}
          title={card && card.copyType === 'search' ?  '搜索条件-复制' : '搜索条件-编辑'}
          visible={visible}
          width={850}
          maskClosable={false}