king
2019-11-23 9f9d68cf40f1d7470bfb49220266b26663cbb722
src/templates/comtableconfig/index.jsx
@@ -198,6 +198,7 @@
                field: item.FieldName,
                label: item.FieldDec,
                type: _type,
                datatype: _type,
                decimal: _decimal
              }
            })
@@ -273,20 +274,26 @@
          initVal: card.type,
          required: true,
          options: [{
            MenuID: 'text',
            value: 'text',
            text: this.state.dict['header.form.text']
          }, {
            MenuID: 'select',
            value: 'select',
            text: this.state.dict['header.form.select']
          }, {
            MenuID: 'link',
            value: 'link',
            text: this.state.dict['header.form.link']
          }, {
            MenuID: 'date',
            value: 'date',
            text: this.state.dict['header.form.dateday']
          }, {
            MenuID: 'datetime',
            text: this.state.dict['header.form.datetime']
            value: 'dateweek',
            text: this.state.dict['header.form.dateweek']
          }, {
            value: 'datemonth',
            text: this.state.dict['header.form.datemonth']
          }, {
            value: 'dateyear',
            text: this.state.dict['header.form.dateyear']
          }]
        },
        {
@@ -303,10 +310,10 @@
          initVal: card.resourceType || '0',
          required: true,
          options: [{
            MenuID: '0',
            value: '0',
            text: this.state.dict['header.form.custom']
          }, {
            MenuID: '1',
            value: '1',
            text: this.state.dict['header.form.datasource']
          }]
        },
@@ -316,10 +323,10 @@
          label: this.state.dict['header.form.setAll'],
          initVal: card.setAll || 'false',
          options: [{
            MenuID: 'true',
            value: 'true',
            text: this.state.dict['header.form.true']
          }, {
            MenuID: 'false',
            value: 'false',
            text: this.state.dict['header.form.false']
          }]
        },
@@ -377,10 +384,10 @@
          label: this.state.dict['header.form.orderType'],
          initVal: card.orderType || 'asc',
          options: [{
            MenuID: 'asc',
            value: 'asc',
            text: this.state.dict['header.form.asc']
          }, {
            MenuID: 'desc',
            value: 'desc',
            text: this.state.dict['header.form.desc']
          }]
        },
@@ -391,19 +398,19 @@
          initVal: card.match || 'like',
          required: true,
          options: [{
            MenuID: 'like',
            value: 'like',
            text: 'like'
          }, {
            MenuID: 'equal',
            value: 'equal',
            text: 'equal'
          }, {
            MenuID: 'greater',
            value: 'greater',
            text: '>'
          }, {
            MenuID: 'less',
            value: 'less',
            text: '<'
          }, {
            MenuID: 'greaterequal',
            value: 'greaterequal',
            text: '>='
          }]
        },
@@ -414,10 +421,10 @@
          initVal: card.display || 'dropdown',
          required: true,
          options: [{
            MenuID: 'dropdown',
            value: 'dropdown',
            text: this.state.dict['header.form.dropdown']
          }, {
            MenuID: 'button',
            value: 'button',
            text: this.state.dict['header.form.button']
          }]
        }
@@ -686,6 +693,7 @@
            return item
          }
        })
        _config[res.type] = _config[res.type].filter(item => !item.origin)
      }
      this.setState({
@@ -916,6 +924,7 @@
  queryField = (type) => {
    const {selectedTables, tableColumns, config} = this.state
    // 判断是否已选择表名
    if (selectedTables.length === 0) {
      notification.warning({
        top: 92,
@@ -925,6 +934,7 @@
      return
    }
    // 表字段集转为map数据
    let columns = new Map()
    tableColumns.forEach(table => {
      table.columns.forEach(column => {
@@ -933,19 +943,24 @@
    })
    if (type === 'search') {
      // 添加搜索条件,字段集中存在搜索条件字段,使用搜索条件对象替换字段集,设置数据类型
      config.search.forEach(item => {
        if (columns.has(item.field)) {
          columns.set(item.field, {...item, selected: true, type: item.type})
          let _datatype = columns.get(item.field).datatype
          columns.set(item.field, {...item, selected: true, datatype: _datatype})
        }
      })
    } else if (type === 'columns') {
      // 添加显示列,字段集中存在显示列字段,使用显示列对象替换字段集,设置数据类型
      config.columns.forEach(item => {
        if (columns.has(item.field)) {
          columns.set(item.field, {...item, selected: true, type: item.type})
          let _datatype = columns.get(item.field).datatype
          columns.set(item.field, {...item, selected: true, datatype: _datatype})
        }
      })
    }
    // 显示字段集弹窗
    this.setState({
      addType: type,
      tableVisible: true,
@@ -954,6 +969,7 @@
  }
  addFieldSubmit = () => {
    // 字段集为空,关闭弹窗
    if (!this.state.fields || this.state.fields.length === 0) {
      this.setState({
        tableVisible: false,
@@ -962,34 +978,72 @@
    }
    const {addType, config} = this.state
    const textmatch = { // 选择text时匹配规则
      text: 'like',
      number: 'like',
      datetime: 'like',
      date: 'like'
    }
    const selectmatch = { // 选择select时匹配规则
      text: 'equal',
      number: 'equal',
      datetime: 'equal',
      date: 'equal'
    }
    const datematch = { // 选择date时匹配规则
      text: 'between',
      number: 'between',
      datetime: 'between',
      date: 'between'
    }
    // 获取已选字段集合
    let cards = this.refs.searchcard.getSelectedCard()
    let columns = new Map()
    let columnsMap = new Map()
    cards.forEach(card => {
      columns.set(card.field, card)
      columnsMap.set(card.field, card)
    })
    let items = []
    if (addType === 'search') {
      config.search.forEach(item => {
        if (columns.has(item.field)) {
          let cell = columns.get(item.field)
        if (columnsMap.has(item.field)) {
          let cell = columnsMap.get(item.field)
          if (cell.selected) {
          if (cell.selected && cell.type === item.type) { // 数据未修改
            items.push(item)
          } else if (cell.selected) { // 数据类型修改
            if (cell.type === 'text') {
              item.match = textmatch[cell.datatype]
            } else if (cell.type === 'select') {
              item.match = selectmatch[cell.datatype]
            } else if (cell.type === 'date') {
              item.match = datematch[cell.datatype]
            }
            item.initval = ''
            items.push(item)
          }
          columns.delete(item.field)
          columnsMap.delete(item.field)
        } else if (!item.origin) {
          items.push(item)
        }
      })
      let _columns = [...columns.values()]
      let _columns = [...columnsMap.values()]
      let indexes = items.map(card => {return card.id})
      let id = Math.max(...indexes, 0)
      let id = Math.max(...indexes, 0) + 1
      _columns.forEach(item => {
        if (item.selected) {
          let _match = ''
          if (item.type === 'text') {
            _match = textmatch[item.datatype]
          } else if (item.type === 'select') {
            _match = selectmatch[item.datatype]
          } else if (item.type === 'date') {
            _match = datematch[item.datatype]
          }
          let newcard = {
            id: id,
            uuid: Utils.getuuid(),
@@ -1006,6 +1060,7 @@
            valueText: '',
            orderBy: '',
            orderType: 'asc',
            match: _match,
            display: 'dropdown'
          }
@@ -1015,19 +1070,19 @@
      })
    } else {
      config.columns.forEach(item => {
        if (columns.has(item.field)) {
          let cell = columns.get(item.field)
        if (columnsMap.has(item.field)) {
          let cell = columnsMap.get(item.field)
          if (cell.selected) {
            items.push(item)
          }
          columns.delete(item.field)
          columnsMap.delete(item.field)
        } else if (!item.origin) {
          items.push(item)
        }
      })
      let _columns = [...columns.values()]
      let _columns = [...columnsMap.values()]
      let indexes = items.map(card => {return card.id})
      let id = Math.max(...indexes, 0)
@@ -1086,16 +1141,6 @@
              } else if (/^decimal/.test(_type)) {
                _decimal = _type.split(',')[1]
                _decimal = parseInt(_decimal)
                if (_decimal > 4) {
                  _decimal = 4
                }
                _type = 'number'
              } else if (/^decimal/.test(_type)) {
                _decimal = _type.split(',')[1]
                _decimal = parseInt(_decimal)
                if (_decimal > 4) {
                  _decimal = 4
                }
                _type = 'number'
              } else if (/^datetime/.test(_type)) {
                _type = 'datetime'
@@ -1109,6 +1154,7 @@
                field: item.FieldName,
                label: item.FieldDec,
                type: _type,
                datatype: _type,
                decimal: _decimal
              }
            })
@@ -1316,34 +1362,37 @@
            } style={{ width: '100%' }}>
              <Icon type="setting" onClick={this.changeSetting} />
              <div className="search-list">
                {this.state.config.search && !this.state.searchloading &&
                <DragElement
                  list={this.state.config.search}
                  type="search"
                  placeholder={this.state.dict['header.form.search.placeholder']}
                  handleList={this.handleList}
                  handleMenu={this.handleSearch}
                />}
                {!this.state.searchloading ?
                  <DragElement
                    list={this.state.config.search}
                    type="search"
                    placeholder={this.state.dict['header.form.search.placeholder']}
                    handleList={this.handleList}
                    handleMenu={this.handleSearch}
                  /> : null
                }
              </div>
              <div className="action-list">
                {this.state.config.action && !this.state.actionloading &&
                <DragElement
                  list={this.state.config.action}
                  type="action"
                  placeholder={this.state.dict['header.form.action.placeholder']}
                  handleList={this.handleList}
                  handleMenu={this.handleAction}
                />}
                {!this.state.actionloading ?
                  <DragElement
                    list={this.state.config.action}
                    type="action"
                    placeholder={this.state.dict['header.form.action.placeholder']}
                    handleList={this.handleList}
                    handleMenu={this.handleAction}
                  /> : null
                }
              </div>
              <div className="column-list">
                {this.state.config.columns && !this.state.columnsloading &&
                <DragElement
                  list={this.state.config.columns}
                  type="columns"
                  placeholder={this.state.dict['header.form.column.placeholder']}
                  handleList={this.handleList}
                  handleMenu={this.handleColumn}
                />}
                {!this.state.columnsloading ?
                  <DragElement
                    list={this.state.config.columns}
                    type="columns"
                    placeholder={this.state.dict['header.form.column.placeholder']}
                    handleList={this.handleList}
                    handleMenu={this.handleColumn}
                  /> : null
                }
              </div>
            </Card>
          </div>
@@ -1361,24 +1410,30 @@
          ]}
          destroyOnClose
        >
          {this.state.formtemp === 'search' && <SearchForm
            dict={this.state.dict}
            formlist={this.state.formlist}
            card={this.state.card}
            wrappedComponentRef={(inst) => this.formRef = inst}
          />}
          {this.state.formtemp === 'action' && <ActionForm
            dict={this.state.dict}
            card={this.state.card}
            formlist={this.state.formlist}
            wrappedComponentRef={(inst) => this.formRef = inst}
          />}
          {this.state.formtemp === 'columns' && <ColumnForm
            dict={this.state.dict}
            card={this.state.card}
            formlist={this.state.formlist}
            wrappedComponentRef={(inst) => this.formRef = inst}
          />}
          {this.state.formtemp === 'search' ?
            <SearchForm
              dict={this.state.dict}
              formlist={this.state.formlist}
              card={this.state.card}
              wrappedComponentRef={(inst) => this.formRef = inst}
            /> : null
          }
          {this.state.formtemp === 'action' ?
            <ActionForm
              dict={this.state.dict}
              card={this.state.card}
              formlist={this.state.formlist}
              wrappedComponentRef={(inst) => this.formRef = inst}
            /> : null
          }
          {this.state.formtemp === 'columns' ?
            <ColumnForm
              dict={this.state.dict}
              card={this.state.card}
              formlist={this.state.formlist}
              wrappedComponentRef={(inst) => this.formRef = inst}
            /> : null
          }
        </Modal>
        {/* 根据字段名添加显示列及搜索条件 */}
        <Modal
@@ -1396,11 +1451,8 @@
          }}
          destroyOnClose
        >
          {this.state.addType === 'search' && this.state.fields.length > 0 &&
            <EditCard data={this.state.fields} ref="searchcard" type="search" />
          }
          {this.state.addType === 'columns' && this.state.fields.length > 0 &&
            <EditCard data={this.state.fields} ref="searchcard" type="columns" />
          {this.state.addType && this.state.fields.length > 0 ?
            <EditCard data={this.state.fields} ref="searchcard" type={this.state.addType} /> : null
          }
          {(!this.state.fields || this.state.fields.length === 0) &&
            <Empty />