king
2021-10-14 dddb2c96f42d9c852dba26ff9a27daa12bd85008
src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
@@ -192,6 +192,7 @@
  tdFocus = (id) => {
    const { col, record } = this.props
    if (id !== col.uuid + record.$Index) return
    this.focus()
  }
@@ -201,11 +202,13 @@
    const { value } = this.state
    this.setState({editing: false})
    if (col.enter === '$next') {
      MKEmitter.emit('nextLine', col, record.$Index)
    } else {
      MKEmitter.emit('tdFocus', col.enter + record.$Index)
    }
    setTimeout(() => {
      if (col.enter === '$next') {
        MKEmitter.emit('nextLine', col, record.$Index)
      } else {
        MKEmitter.emit('tdFocus', col.enter + record.$Index)
      }
    }, 50)
    if (value !== record[col.field]) {
      MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: value})
@@ -367,6 +370,39 @@
          {content ? <Paragraph copyable ellipsis={{ rows: 3, expandable: true }}>{content}</Paragraph> : null }
        </div>
      )
    } else if (col.type === 'formula') {
      let content = col.formula
      Object.keys(record).forEach(key => {
        let reg = new RegExp('@' + key + '@', 'ig')
        content = content.replace(reg, record[key])
      })
      if (col.eval !== 'false') {
        try {
          // eslint-disable-next-line
          content = eval(content)
        } catch (e) {
          content = ''
        }
      }
      content = content === undefined ? '' : content
      if (content !== '') {
        content = `${col.prefix || ''}${content}${col.postfix || ''}`
        if (col.eval === 'false') {
          content = content.replace(/\n/ig, '<br/>').replace(/\s/ig, '&nbsp;')
          content = <span dangerouslySetInnerHTML={{__html: content}}></span>
        }
      }
      if (col.marks) {
        style = style || {}
        content = this.getMark(record, col.marks, style, content)
      }
      children = content
    } else if (col.type === 'custom') {
      style.padding = '0px'
      if (col.style) {
@@ -419,7 +455,8 @@
    fields: [],
    pickup: false,        // 收起未选择项
    orderfields: {},      // 排序id与field转换
    loading: false
    loading: false,
    editable: 'false'
  }
  UNSAFE_componentWillMount () {
@@ -474,22 +511,28 @@
      if (item.type !== 'action') {
        let _copy = fromJS(_item).toJS()
        _copy.sorter = false
        if (item.editable === 'true') {
          _copy.title = <span>{item.label}<Icon className="system-color" style={{position: 'absolute', bottom: 0, right: 0}} type="edit" /></span>
        }
        edColumns.push(_copy)
      }
      _columns.push(_item)
    })
    edColumns.push({
      align: 'center',
      dataIndex: 'mkoperation',
      title: '操作',
      sorter: false,
      width: 100,
      onCell: record => ({
        record,
        col: {type: 'operation', tableId: tableId},
    if (setting.delable !== 'false') {
      edColumns.push({
        align: 'center',
        dataIndex: 'mkoperation',
        title: '操作',
        sorter: false,
        width: 100,
        onCell: record => ({
          record,
          col: {type: 'operation', tableId: tableId},
        })
      })
    })
    }
    if (setting.borderColor) { // 边框颜色
      let style = `#${tableId} table, #${tableId} tr, #${tableId} th, #${tableId} td {border-color: ${setting.borderColor}}`
@@ -504,7 +547,8 @@
      edColumns,
      tableId,
      orderfields,
      initEditLine
      initEditLine,
      editable: setting.editable
    })
  }
@@ -514,6 +558,7 @@
  componentDidMount () {
    const { fields, columns } = this.props
    const { data, editable } = this.state
    let _fields = []
@@ -531,6 +576,12 @@
    this.setState({
      fields: _fields,
    })
    if (editable === 'true' && data && data.length > 0) {
      setTimeout(() => {
        this.pickupChange()
      }, 200)
    }
    MKEmitter.addListener('nextLine', this.nextLine)
    MKEmitter.addListener('delRecord', this.delRecord)
@@ -554,6 +605,11 @@
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (!is(fromJS(this.props.data), fromJS(nextProps.data))) {
      this.setState({data: nextProps.data || []})
      if (this.state.editable === 'true') {
        setTimeout(() => {
          this.pickupChange()
        }, 200)
      }
    }
  }
  
@@ -844,6 +900,9 @@
      loading: false
    })
    if (submit.closetab === 'true') {
      MKEmitter.emit('popclose')
    }
    if (submit.execSuccess !== 'never') {
      this.repick()
      MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execSuccess, submit)
@@ -924,9 +983,19 @@
  }
  pickupChange = () => {
    const { submit } = this.props
    const { data } = this.state
    let pickup = !this.state.pickup
    if (!submit.sheet) {
      notification.warning({
        top: 92,
        message: '提交按钮尚未设置,不可编辑!',
        duration: 5
      })
      return
    }
    if (!pickup && !is(fromJS(data), fromJS(this.state.edData))) {
      const _this = this
@@ -951,7 +1020,8 @@
        data: [],
        edData: [],
        pickup,
        loading: false
        loading: false,
        editable: 'false'
      }, () => {
        this.setState({
          data: data,
@@ -962,7 +1032,7 @@
  }
  render() {
    const { setting, statFValue, lineMarks } = this.props
    const { setting, statFValue, lineMarks, submit } = this.props
    const { pickup, tableId, data, edData, columns, edColumns, loading } = this.state
    const components = {
@@ -1005,7 +1075,7 @@
    return (
      <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''}`} id={tableId}>
        <Switch title="编辑" className="main-pickup" checkedChildren="开" unCheckedChildren="关" checked={pickup} onChange={this.pickupChange} />
        {pickup ? <Button onClick={() => setTimeout(() => {this.checkData()}, 10)} loading={loading} className="submit-table" type="link">提交</Button> : null}
        {pickup ? <Button style={submit.style} onClick={() => setTimeout(() => {this.checkData()}, 10)} loading={loading} className="submit-table" type="link">提交</Button> : null}
        <Table
          components={components}
          style={setting.style}
@@ -1025,7 +1095,7 @@
          pagination={_pagination}
        />
        {_footer ? <div className={'normal-table-footer ' + (_pagination ? 'pagination' : '')}>{_footer}</div> : null}
        {pickup && setting.addable === 'true' ? <Button onClick={this.addLine} style={{display: 'block', width: '100%', color: '#26C281'}} icon="plus" type="link"></Button> : null}
        {pickup && setting.addable === 'true' ? <Button onClick={this.addLine} style={{display: 'block', width: '100%', color: '#26C281', border: '1px solid #dddddd', borderRadius: 0}} icon="plus" type="link"></Button> : null}
      </div>
    )
  }