king
2021-09-28 342d3498191f1683059fe586209ec920545e0bf9
src/templates/sharecomponent/searchcomponent/index.jsx
@@ -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 = {
@@ -56,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 搜索条件顺序调整,或拖拽添加
   */
@@ -80,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({
@@ -188,7 +219,7 @@
        return
      }
      if (['checkcard', 'select', 'multiselect', 'link'].includes() && 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
        })
@@ -278,23 +309,38 @@
    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 { 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}