king
2021-10-21 1da6506bf58270bacc2a4345002c6b082835580e
src/tabviews/zshare/normalTable/index.jsx
@@ -5,7 +5,6 @@
import { is, fromJS } from 'immutable'
import { Table, Affix, Typography, Icon } from 'antd'
import { modifyTabview } from '@/store/action'
import asyncComponent from '@/utils/asyncComponent'
import MKEmitter from '@/utils/events.js'
import '@/assets/css/table.scss'
@@ -17,6 +16,17 @@
const PopupButton = asyncComponent(() => import('@/tabviews/zshare/actionList/popupbutton'))
const TabButton = asyncComponent(() => import('@/tabviews/zshare/actionList/tabbutton'))
const NewPageButton = asyncComponent(() => import('@/tabviews/zshare/actionList/newpagebutton'))
class BodyRow extends React.Component {
  shouldComponentUpdate (nextProps) {
    return !is(fromJS(this.props.record), fromJS(nextProps.record)) || this.props.className !== nextProps.className
  }
  render() {
    const { record, ...resProps } = this.props
    return <tr {...resProps}/>
  }
}
class NormalTable extends Component {
  static propTpyes = {
@@ -35,7 +45,6 @@
    total: PropTypes.any,            // 总数
    loading: PropTypes.bool,         // 表格加载中
    refreshdata: PropTypes.func,     // 表格中排序列、页码的变化时刷新
    handleTableId: PropTypes.func,   // 数据切换
    chgSelectData: PropTypes.func,   // 数据切换
  }
@@ -50,7 +59,7 @@
  }
  UNSAFE_componentWillMount () {
    const { menuType, memberLevel, pageSize } = this.props
    const { menuType, memberLevel, pageSize, setting } = this.props
    let columns = fromJS(this.props.columns).toJS()
    let lineMarks = []
    let _columns = []
@@ -58,6 +67,42 @@
    let _format = false    // 是否虚化处理
    let rowspans = []
    if (setting.tableMode === 'fast') {
      rowspans = null
      columns.forEach(item => {
        if (item.hidden === true || item.Hide === 'true') return
        let cell = null
        if (item.type === 'colspan' || item.type === 'old_colspan') {
          cell = {title: item.label, children: []}
          item.subcols.forEach(col => {
            cell.children.push({
              align: col.Align,
              title: col.label,
              dataIndex: col.field || col.uuid,
              key: col.uuid,
              width: col.Width || 120
            })
          })
        } else {
          if (item.type === 'index') {
            item.field = '$Index'
            item.type = 'text'
          }
          cell = {
            align: item.Align,
            dataIndex: item.field || item.uuid,
            title: item.label,
            sorter: item.field && item.IsSort === 'true',
            width: item.Width || 120
          }
        }
        _columns.push(cell)
      })
    } else {
    if (window.GLOB.dataFormat && menuType !== 'HS' && memberLevel) {
      _format = true
@@ -175,6 +220,7 @@
    if (rowspans.length === 0) {
      rowspans = null
    }
    }
    
    this.setState({
      columns: _columns,
@@ -190,6 +236,9 @@
  componentDidMount () {
    MKEmitter.addListener('resetTable', this.resetTable)
    MKEmitter.addListener('autoQueryData', this.autoQueryData)
    MKEmitter.addListener('autoSelectData', this.autoSelectData)
    MKEmitter.addListener('mkTableCheckTopLine', this.mkTableCheckTopLine)
  }
  /**
@@ -200,12 +249,60 @@
      return
    }
    MKEmitter.removeListener('resetTable', this.resetTable)
    MKEmitter.removeListener('autoQueryData', this.autoQueryData)
    MKEmitter.removeListener('autoSelectData', this.autoSelectData)
    MKEmitter.removeListener('mkTableCheckTopLine', this.mkTableCheckTopLine)
  }
  mkTableCheckTopLine = (id) => {
    if (id !== this.props.MenuID) return
    if (this.props.data.length > 0) {
      this.changeRow(null, 0)
    }
  }
  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(null, 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})
  }
  // 字段透视
  triggerLink = (e, item, record) => {
    const { tabviews, MenuID } = this.props
    e.stopPropagation()
    let __param = {
@@ -222,33 +319,13 @@
    if (item.linkThdMenu) {
      let tabmenu = item.linkThdMenu
      tabmenu.param = __param
      tabmenu.selected = true
  
      let index = 0
      let tabs = tabviews.filter((tab, i) => {
        tab.selected = false
        if (tab.MenuID === MenuID) {
          index = i
        }
        return tab.MenuID !== tabmenu.MenuID
      })
      if (tabviews.length > tabs.length) {
        this.props.modifyTabview(fromJS(tabs).toJS())
      }
      this.setState({}, () => {
        if (MenuID) {
          tabs.splice(index + 1, 0, tabmenu)
      if (['linkage_navigation', 'linkage', 'menu_board'].includes(window.GLOB.navBar)) {
        MKEmitter.emit('modifyTabs', tabmenu, 'replace')
        } else {
          tabs.push(tabmenu)
        MKEmitter.emit('modifyTabs', tabmenu, 'plus', true)
        }
        this.props.modifyTabview(tabs)
      })
    } else if (item.linkurl) {
      let src = item.linkurl
@@ -261,7 +338,7 @@
          _param.User_Name = sessionStorage.getItem('User_Name')
          _param.param = __param
          src = _url + window.btoa(window.encodeURIComponent(JSON.stringify(_param)))
        } catch {
        } catch (e) {
          console.warn('菜单参数解析错误!')
        }
      } else {
@@ -310,7 +387,7 @@
        try {
          originVal = parseFloat(originVal)
          contrastVal = parseFloat(contrastVal)
        } catch {
        } catch (e) {
          originVal = NaN
        }
@@ -321,7 +398,7 @@
        try {
          originVal = parseFloat(originVal)
          contrastVal = parseFloat(contrastVal)
        } catch {
        } catch (e) {
          originVal = NaN
        }
@@ -452,7 +529,7 @@
          if (isNaN(content)) {
            content = ''
          }
        } catch {
        } catch (e) {
          content = ''
        }
      }
@@ -605,7 +682,7 @@
        
        try {
          _param = window.btoa(_quary)
        } catch {
        } catch (e) {
          _param = window.btoa(window.encodeURIComponent(_quary))
        }
        
@@ -691,7 +768,7 @@
            if (isNaN(content)) {
              content = ''
            }
          } catch {
          } catch (e) {
            content = ''
          }
    
@@ -735,7 +812,7 @@
          try {
            photos = record[col.field] + ''
            photos = photos.split(',').filter(Boolean)
          } catch {
          } catch (e) {
            photos = []
          }
@@ -790,7 +867,7 @@
            try {
              _param = window.btoa(_quary)
            } catch {
            } catch (e) {
              _param = window.btoa(window.encodeURIComponent(_quary))
            }
@@ -981,7 +1058,9 @@
  }
  changedata = (index) => {
    const { data, setting } = this.props
    const { data, setting, tableId, ContainerId } = this.props
    if (!tableId || !ContainerId) return
    let _id = ''
    let _data = ''
@@ -991,13 +1070,13 @@
      _data = data[index] || ''
    }
    this.props.handleTableId(this.props.tableId, _id, _data)
    MKEmitter.emit('changeTableLine', ContainerId, tableId, _id, _data)
  }
  resetTable = (id, repage) => {
    const { MenuID, tableId } = this.props
    const { tableId } = this.props
    if (id !== (MenuID + tableId)) return
    if (id !== tableId) return
    if (repage === 'false') {
      this.setState({
@@ -1079,6 +1158,14 @@
    const { setting, pickup, statFValue } = this.props
    const { selectedRowKeys, lineMarks, activeIndex } = this.state
    let components = {
      body: {}
    }
    if (setting.tableMode === 'fast') {
      components.body.row = BodyRow
    }
    // 设置表格选择属性:单选、多选、不可选
    let rowSelection = null
    if (setting.tableType) {
@@ -1131,11 +1218,26 @@
      _footer = statFValue.map(f => `${f.label}(合计):${f.value}`).join(';')
    }
    let height = setting.height || false
    let style = {}
    if (setting.color) {
      style.color = setting.color
    }
    if (setting.fontSize) {
      style.fontSize = setting.fontSize
    }
    let loading = this.props.loading
    if (setting.mask === 'hidden') {
      loading = false
    }
    return (
      <div className="normal-data-table mingke-table">
      <div className={'normal-data-table mingke-table ' + (height ? 'fixed-height' : '')}>
        {offset && <Affix offsetTop={offset} className="fix-header">
          <Table
            size="middle"
            size={setting.size || 'middle'}
            style={style}
            bordered={setting.bordered !== 'false'}
            rowSelection={rowSelection}
            columns={this.state.columns.map(column => {
@@ -1149,7 +1251,9 @@
          />
        </Affix>}
        <Table
          size="middle"
          components={components}
          size={setting.size || 'middle'}
          style={style}
          bordered={setting.bordered !== 'false'}
          rowSelection={rowSelection}
          columns={this.state.columns}
@@ -1181,7 +1285,7 @@
                try {
                  originVal = parseFloat(originVal)
                  contrastVal = parseFloat(contrastVal)
                } catch {
                } catch (e) {
                  originVal = NaN
                }
        
@@ -1192,7 +1296,7 @@
                try {
                  originVal = parseFloat(originVal)
                  contrastVal = parseFloat(contrastVal)
                } catch {
                } catch (e) {
                  originVal = NaN
                }
        
@@ -1207,12 +1311,20 @@
            return className
          }}
          loading={this.props.loading}
          scroll={{ x: '100%', y: false }}
          loading={loading}
          scroll={{ x: '100%', y: height }}
          onRow={(record, index) => {
            if (setting.tableMode === 'fast') {
              return {
                record,
                onClick: () => {this.changeRow(record, index)},
                onDoubleClick: () => {this.doubleClickLine(record)}
              }
            } else {
            return {
              onClick: () => {this.changeRow(record, index)},
              onDoubleClick: () => {this.doubleClickLine(record)}
              }
            }
          }}
          onChange={this.changeTable}
@@ -1227,15 +1339,12 @@
const mapStateToProps = (state) => {
  return {
    menuType: state.editLevel,
    tabviews: state.tabviews,
    memberLevel: state.memberLevel
  }
}
const mapDispatchToProps = (dispatch) => {
  return {
    modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews))
  }
const mapDispatchToProps = () => {
  return {}
}
export default connect(mapStateToProps, mapDispatchToProps)(NormalTable)