king
2022-11-21 f6626b05f1275cc2f8ca77f773d4f6a6af1b0a89
src/tabviews/custom/components/share/normalTable/index.jsx
@@ -15,8 +15,9 @@
import './index.scss'
const { Paragraph } = Typography
const CardCellComponent = asyncComponent(() => import('@/tabviews/custom/components/card/cardcellList'))
const Video = asyncComponent(() => import('@/components/video'))
const MkPicture = asyncComponent(() => import('@/components/mkPicture'))
const CardCellComponent = asyncComponent(() => import('@/tabviews/custom/components/card/cardcellList'))
const PicRadio = {
  '4:3': '75%', '3:2': '66.67%', '16:9': '56.25%', '2:1': '50%', '3:1': '33.33%', '4:1': '25%',
  '5:1': '20%', '6:1': '16.67%', '7:1': '14.29%', '8:1': '12.5%', '9:1': '11.11%',
@@ -24,7 +25,7 @@
}
class BodyRow extends React.Component {
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props.data), fromJS(nextProps.data)) || !is(fromJS(this.props.className), fromJS(nextProps.className))
    return !is(fromJS(this.props.data), fromJS(nextProps.data)) || this.props.className !== nextProps.className
  }
  render() {
@@ -259,6 +260,14 @@
          ))}
        </div>
      )
    } else if (col.type === 'video') {
      let url = record[col.field] || ''
      resProps.children = (
        <div className="video-wrap">
          {url ? <Video card={col} value={url}/> : null}
        </div>
      )
    } else if (col.type === 'textarea') {
      let content = ''
      if (record[col.field] !== undefined) {
@@ -395,12 +404,12 @@
    columns: PropTypes.array,        // 表格列
    lineMarks: PropTypes.array,      // 行标记
    fields: PropTypes.array,         // 组件字段集
    ContainerId: PropTypes.any,      // 标签页外层Id
    data: PropTypes.any,             // 表格数据
    total: PropTypes.any,            // 总数
    loading: PropTypes.bool,         // 表格加载中
    refreshdata: PropTypes.func,     // 表格中排序列、页码的变化时刷新
    chgSelectData: PropTypes.func,   // 数据切换
    autoMatic: PropTypes.any
  }
  state = {
@@ -434,52 +443,69 @@
      }
    }
    let getColumns = (cols) => {
      return cols.map(item => {
        let cell = null
        if (item.type === 'colspan') {
          cell = { title: item.label, align: item.Align }
          cell.children = getColumns(item.subcols)
        } else {
          if (item.rowspan === 'true') {
            rowspans.push(item.field)
          }
          if (item.type === 'index') {
            item.field = '$Index'
            item.type = 'text'
          } else if (_format && !Math.floor(Math.random() * radio)) {
            item.blur = true
          }
          if (item.marks && item.marks.length === 0) {
            item.marks = ''
          }
    let _columns = []
          if (item.field) {
            orderfields[item.uuid] = item.field
          }
          cell = {
            align: item.Align,
            dataIndex: item.uuid,
            title: item.label,
            sorter: item.field && item.IsSort === 'true',
            width: item.Width || 120,
            onCell: record => ({
              record,
              col: item,
              config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null,
              triggerLink: this.triggerLink
            })
          }
        }
    if (setting.tableMode !== 'fast') {
      let getColumns = (cols) => {
        return cols.map(item => {
          let cell = null
          if (item.type === 'colspan') {
            cell = { title: item.label, align: item.Align }
            cell.children = getColumns(item.subcols)
          } else {
            if (item.rowspan === 'true') {
              rowspans.push(item.field)
            }
            if (item.type === 'index') {
              item.field = '$Index'
              item.type = 'text'
            } else if (_format && !Math.floor(Math.random() * radio)) {
              item.blur = true
            }
            if (item.marks && item.marks.length === 0) {
              item.marks = ''
            }
  
        return cell
            if (item.field) {
              orderfields[item.uuid] = item.field
            }
            cell = {
              align: item.Align,
              dataIndex: item.uuid,
              title: item.label,
              sorter: item.field && item.IsSort === 'true',
              width: item.Width || 120,
              onCell: record => ({
                record,
                col: item,
                config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null,
                triggerLink: this.triggerLink
              })
            }
          }
          return cell
        })
      }
      _columns = getColumns(columns)
    } else {
      let fields = []
      columns.forEach(item => {
        if (!item.field || fields.includes(item.field)) return
        fields.push(item.field)
        _columns.push({
          align: item.Align,
          dataIndex: item.field,
          title: item.label,
          sorter: item.IsSort === 'true',
          width: item.Width || 120
        })
      })
    }
    let _columns = getColumns(columns)
    if (rowspans.length === 0) {
      rowspans = null
@@ -493,13 +519,6 @@
      }
      return uuid.join('')
    }) ()
    // if (setting.borderColor) { // 边框颜色
    //   let style = `#${tableId} table, #${tableId} tr, #${tableId} th, #${tableId} td {border-color: ${setting.borderColor}}`
    //   let ele = document.createElement('style')
    //   ele.innerHTML = style
    //   document.getElementsByTagName('head')[0].appendChild(ele)
    // }
    let size = (setting.pageSize || 10) + ''
    let pageOptions = ['10', '25', '50', '100', '500', '1000']
@@ -530,9 +549,17 @@
  }
  componentDidMount () {
    MKEmitter.addListener('mkCheckTopLine', this.mkCheckTopLine)
    const { autoMatic } = this.props
    MKEmitter.addListener('mkCheckAll', this.mkCheckAll)
    MKEmitter.addListener('resetTable', this.resetTable)
    if (autoMatic === true) {
      MKEmitter.addListener('autoQueryData', this.autoQueryData)
      MKEmitter.addListener('autoSelectData', this.autoSelectData)
    }
    MKEmitter.addListener('mkCheckTopLine', this.mkCheckTopLine)
  }
  /**
@@ -542,9 +569,50 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('mkCheckTopLine', this.mkCheckTopLine)
    MKEmitter.removeListener('mkCheckAll', this.mkCheckAll)
    MKEmitter.removeListener('resetTable', this.resetTable)
    MKEmitter.removeListener('autoQueryData', this.autoQueryData)
    MKEmitter.removeListener('autoSelectData', this.autoSelectData)
    MKEmitter.removeListener('mkCheckTopLine', this.mkCheckTopLine)
  }
  autoSelectData = (id, index) => {
    if (id !== this.props.MenuID) return
    const { pageSize, pageIndex } = this.state
    let i = index - (pageIndex - 1) * pageSize - 1
    if (this.props.data[i]) {
      this.changeRow(this.props.data[i], i)
      MKEmitter.emit('autoTransSelectData', this.props.MenuID, this.props.data[i])
    } else {
      MKEmitter.emit('autoMaticOver', this.props.MenuID)
    }
  }
  autoQueryData = (id, index) => {
    if (id !== this.props.MenuID) return
    const { total } = this.props
    const { pageSize } = this.state
    if (index !== 1 && (!total || index > total)) {
      MKEmitter.emit('autoMaticOver', this.props.MenuID)
      return
    }
    console.clear()
    let pageIndex = Math.ceil(index / pageSize)
    this.setState({
      pageIndex: pageIndex,
      selectedRowKeys: [],
      activeIndex: null
    })
    this.props.refreshdata({pageIndex})
  }
  mkCheckTopLine = (menuId, id) => {
@@ -856,11 +924,14 @@
      }
    }
    const components = {
    let components = {
      body: {
        row: BodyRow,
        cell: BodyCell
        row: BodyRow
      }
    }
    if (setting.tableMode !== 'fast') {
      components.body.cell = BodyCell
    }
    // 数据收起时,过滤已选数据
@@ -899,7 +970,6 @@
        }
        <Table
          components={components}
          // style={setting.style}
          size={setting.size || 'middle'}
          bordered={setting.bordered !== 'false'}
          rowSelection={rowSelection}
@@ -909,7 +979,7 @@
          scroll={{ x: '100%', y: height }}
          onRow={(record, index) => {
            return {
              lineMarks,
              lineMarks: setting.tableMode !== 'fast' ? lineMarks : null,
              data: record,
              className: index === activeIndex ? ' mk-row-active ' : '',
              onClick: () => {this.changeRow(record, index)},