king
2020-07-14 f36141f3075edf9d41928d64f759ad6bd1b1ac60
src/templates/sharecomponent/searchcomponent/index.jsx
@@ -16,7 +16,6 @@
const { confirm } = Modal
// **悲观者往往正确,乐观者往往成功
class SearchComponent extends Component {
  static propTpyes = {
    menu: PropTypes.object,          // 当前菜单信息
@@ -28,7 +27,7 @@
  }
  state = {
    dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS,
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    searchlist: null,    // 搜索条件集
    sqlVerifing: false,  // sql验证中
    visible: false,      // 模态框控制
@@ -54,7 +53,7 @@
      this.setState({searchlist: [...searchlist, nextProps.pasteContent]})
      this.handleSearch(nextProps.pasteContent)
    } else if (!is(fromJS(nextProps.config.search), fromJS(this.props.config.search)) && !is(fromJS(nextProps.config.search), fromJS(searchlist))) {
      this.setState({searchlist: nextProps.config.search})
      this.setState({searchlist: fromJS(nextProps.config.search).toJS()})
    }
  }
@@ -68,8 +67,9 @@
      this.setState({searchlist: list})
      this.handleSearch(card)
    } else {
      this.setState({searchlist: list})
      this.props.updatesearch({...config, search: list})
      this.setState({searchlist: list}, ()=> {
        this.props.updatesearch({...config, search: list})
      })
    }
  }
@@ -77,10 +77,22 @@
   * @description 搜索条件编辑,获取搜索条件表单信息
   */
  handleSearch = (card) => {
    const { searchlist } = this.state
    let linkableFields = []
    searchlist.forEach(item => {
      if (item.uuid !== card.uuid && (item.type === 'select' || item.type === 'link')) {
        linkableFields.push({
          value: item.field,
          text: item.label
        })
      }
    })
    this.setState({
      visible: true,
      card: card,
      formlist: getSearchForm(card, this.props.sysRoles)
      formlist: getSearchForm(card, this.props.sysRoles, linkableFields)
    })
  }
@@ -127,7 +139,27 @@
      _searchlist = _searchlist.map(item => { // 数据更新及重复检测
        if (item.uuid !== res.uuid && res.field && item.field) {
          if (item.field === res.field) {
          let itemFields = []
          if (item.type === 'text') {
            itemFields = item.field.split(',')
          } else if (item.type === 'group') {
            itemFields = [item.field, item.datefield]
          } else {
            itemFields = [item.field]
          }
          let resFields = []
          if (res.type === 'text') {
            resFields = res.field.split(',')
          } else if (res.type === 'group') {
            resFields = [res.field, res.datefield]
          } else {
            resFields = [res.field]
          }
          let setFields = Array.from(new Set([...itemFields, ...resFields]))
          if (setFields.length < itemFields.length + resFields.length && (res.type !== 'date' || item.type !== 'date')) {
            fieldrepet = true
          } else if (item.label === res.label) {
            labelrepet = true
@@ -176,6 +208,9 @@
          func: 's_debug_sql',
          LText: res.dataSource
        }
        param.LText = param.LText.replace(/@\$|\$@/ig, '')
        param.LText = Utils.formatOptions(param.LText)
        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
        param.secretkey = Utils.encrypt(param.LText, param.timestamp)
@@ -190,8 +225,9 @@
              sqlVerifing: false,
              searchlist: _searchlist,
              visible: false
            }, ()=> {
              this.props.updatesearch({...config, search: _searchlist}, optionLibs)
            })
            this.props.updatesearch({...config, search: _searchlist}, optionLibs)
          } else {
            this.setState({sqlVerifing: false})
            
@@ -204,8 +240,9 @@
        this.setState({
          searchlist: _searchlist,
          visible: false
        }, ()=> {
          this.props.updatesearch({...config, search: _searchlist}, optionLibs)
        })
        this.props.updatesearch({...config, search: _searchlist}, optionLibs)
      }
    })
  }
@@ -221,7 +258,7 @@
    confirm({
      content: dict['model.confirm'] + dict['model.delete'] + ` - ${card.label} ?`,
      okText: dict['model.confirm'],
      cancelText: this.state.dict['header.cancel'],
      cancelText: this.state.dict['model.cancel'],
      onOk() {
        let _searchlist = fromJS(_this.state.searchlist).toJS()
@@ -246,6 +283,10 @@
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
  render() {
    const { dict, searchlist, visible, sqlVerifing, card } = this.state
@@ -265,7 +306,7 @@
        <Modal
          title={dict['model.searchCriteria'] + '-' + (card && card.copyType === 'search' ?  dict['model.copy'] : dict['model.edit'])}
          visible={visible}
          width={750}
          width={850}
          maskClosable={false}
          onOk={this.handleSubmit}
          confirmLoading={sqlVerifing}