king
2020-11-10 5df578ff69f6b02e821d59a8883bc75d78695a62
src/templates/sharecomponent/fieldscomponent/index.jsx
@@ -19,7 +19,7 @@
  }
  state = {
    dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS,
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    fields: [],          // 字段集
    tableVisible: false,    // 模态框控制
  }
@@ -27,7 +27,7 @@
  queryField = () => {
    const { type, config, tableFields } = this.props
    // 判断是否已选择表名
    if (!config.tables || config.tables.length === 0) {
    if (!tableFields || tableFields.length === 0) {
      notification.warning({
        top: 92,
        message: '请选择表名!',
@@ -54,6 +54,13 @@
      })
    } else if (type === 'columns') {
      // 添加显示列,字段集中存在显示列字段,使用显示列对象替换字段集,设置数据类型
      config.columns.forEach(item => {
        if (columns.has(item.field)) {
          let _datatype = columns.get(item.field).datatype
          columns.set(item.field, {...item, selected: true, datatype: _datatype})
        }
      })
    } else if (type === 'fields') {
      config.columns.forEach(item => {
        if (columns.has(item.field)) {
          let _datatype = columns.get(item.field).datatype
@@ -138,11 +145,6 @@
            resourceType: '0',
            setAll: 'false',
            options: [],
            dataSource: '',
            linkField: '',
            valueField: '',
            valueText: '',
            orderBy: '',
            orderType: 'asc',
            match: _match,
            display: 'dropdown'
@@ -180,6 +182,40 @@
            Width: 120
          }
          if (item.type === 'number') {
            newcard.decimal = item.decimal
          } else {
            newcard.fieldlength = item.length || 50
          }
          items.push(newcard)
        }
      })
    } else if (type === 'fields') {
      config.columns.forEach(item => {
        if (columnsMap.has(item.field)) {
          let cell = columnsMap.get(item.field)
          if (cell.selected) {
            items.push(item)
          }
          columnsMap.delete(item.field)
        } else {
          items.push(item)
        }
      })
      let _columns = [...columnsMap.values()]
      _columns.forEach(item => {
        if (item.selected) {
          let newcard = {
            uuid: Utils.getuuid(),
            label: item.label,
            field: item.field,
            datatype: item.type === 'number' ? 'Decimal(18,0)' : 'Nvarchar(50)'
          }
          items.push(newcard)
        }
      })
@@ -189,12 +225,26 @@
    if (type === 'search') {
      _config = {...this.props.config, search: items}
      this.props.updatefield(_config)
      notification.success({
        top: 92,
        message: '操作成功',
        duration: 2
      })
    } else if (type === 'columns') {
      _config = {...this.props.config, columns: items}
    }
    if (_config) {
      this.props.updatefield(_config)
      notification.success({
        top: 92,
        message: '操作成功',
        duration: 2
      })
    } else if (type === 'fields') {
      this.props.updatefield(items)
      notification.success({
        top: 92,
@@ -205,7 +255,7 @@
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
    return !is(fromJS(this.state), fromJS(nextState))
  }
  /**
@@ -221,16 +271,9 @@
    const { type } = this.props
    const { dict, fields } = this.state
    let label = ''
    if (type === 'search') {
      label = dict['header.menu.search.add']
    } else if (type === 'columns') {
      label = dict['header.menu.column.add']
    }
    return (
      <div>
        <Button type="primary" block onClick={this.queryField}>{label}</Button>
      <div className="quickly-add">
        <Button type="primary" block onClick={this.queryField}>{dict['model.batchAdd']}</Button>
        {/* 根据字段名添加显示列及搜索条件 */}
        <Modal
          wrapClassName="model-table-fieldmanage-modal"
@@ -239,7 +282,7 @@
          width={'65vw'}
          maskClosable={false}
          style={{minWidth: '900px', maxWidth: '1200px'}}
          cancelText={dict['header.close']}
          cancelText={dict['model.close']}
          onOk={this.addFieldSubmit}
          onCancel={() => { // 取消添加
            this.setState({