king
2023-10-24 c81296b147b3b6e578a241e21bae7bded4b5f6c6
src/tabviews/custom/components/share/normalTable/index.jsx
@@ -442,7 +442,9 @@
    loading: PropTypes.bool,         // 表格加载中
    refreshdata: PropTypes.func,     // 表格中排序列、页码的变化时刷新
    chgSelectData: PropTypes.func,   // 数据切换
    autoMatic: PropTypes.any
    autoMatic: PropTypes.any,
    allSearch: PropTypes.any,
    colsCtrls: PropTypes.any
  }
  state = {
@@ -455,11 +457,13 @@
    rowspans: null,       // 行合并字段信息
    pickup: false,        // 收起未选择项
    orderfields: {},      // 排序id与field转换
    pageOptions: []
    pageOptions: [],
    allColumns: null,
    reseting: false
  }
  UNSAFE_componentWillMount () {
    const { setting, fields, columns } = this.props
    const { setting, columns, fields, colsCtrls } = this.props
    let radio = 5          // 虚化比例
    let _format = false    // 是否虚化处理
    let rowspans = []
@@ -483,7 +487,7 @@
          let cell = null
    
          if (item.type === 'colspan') {
            cell = { title: item.label, align: item.Align }
            cell = { title: item.label, align: item.Align, $key: item.uuid }
            cell.children = getColumns(item.subcols)
          } else {
            if (item.rowspan === 'true') {
@@ -507,6 +511,7 @@
            }
  
            cell = {
              $key: item.uuid,
              align: item.Align,
              dataIndex: item.uuid,
              title: item.label,
@@ -532,6 +537,7 @@
        fields.push(item.field)
        _columns.push({
          $key: item.uuid,
          align: item.Align,
          dataIndex: item.field,
          title: item.label,
@@ -564,9 +570,17 @@
      pageOptions = pageOptions.sort((a, b) => a - b)
    }
    let allColumns = null
    if (colsCtrls) {
      rowspans = null
      allColumns = [..._columns]
      _columns = this.getCurColumns(_columns, this.props.allSearch)
    }
    this.setState({
      pageSize: setting.pageSize || 10,
      pageOptions,
      allColumns,
      columns: _columns,
      rowspans,
      tableId,
@@ -582,6 +596,20 @@
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
    const { allSearch } = this.props
    const { allColumns } = this.state
    if (allSearch && !is(fromJS(allSearch), fromJS(nextProps.allSearch))) {
      this.setState({
        reseting: true,
        columns: this.getCurColumns(allColumns, nextProps.allSearch)
      }, () => {
        this.setState({reseting: false})
      })
    }
  }
  componentDidMount () {
@@ -610,6 +638,47 @@
    MKEmitter.removeListener('autoQueryData', this.autoQueryData)
    MKEmitter.removeListener('autoSelectData', this.autoSelectData)
    MKEmitter.removeListener('mkCheckTopLine', this.mkCheckTopLine)
  }
  getCurColumns = (columns, allSearch) => {
    const { colsCtrls } = this.props
    let values = {}
    allSearch.forEach(item => {
      values[item.key] = item.value
    })
    let cols = null
    colsCtrls.some(item => {
      let originVal = item.field.map(f => values[f] || '').join('')
      let contrastVal = item.contrastValue
      let result = false
      if (item.match === '=') {
        result = originVal === contrastVal
      } else if (item.match === '!=') {
        result = originVal !== contrastVal
      } else {
        originVal = isNaN(originVal) ? originVal : +originVal
        contrastVal = isNaN(contrastVal) ? contrastVal : +contrastVal
        if (item.match === '>') {
          result = originVal > contrastVal
        } else if (item.match === '<') {
          result = originVal < contrastVal
        }
      }
      if (!result) return false
      cols = item.cols
      return true
    })
    if (cols) {
      return columns.filter(col => cols.includes(col.$key))
    }
    return columns
  }
  autoSelectData = (id, index) => {
@@ -1004,7 +1073,9 @@
  render() {
    const { setting, statFValue, lineMarks, data } = this.props
    const { selectedRowKeys, activeIndex, pickup, tableId, pageOptions, columns } = this.state
    const { selectedRowKeys, activeIndex, pickup, tableId, pageOptions, columns, reseting } = this.state
    if (reseting) return null
    // 设置表格选择属性:单选、多选、不可选
    let rowSelection = null