king
2022-06-08 c6f8e27d35cd31bb6393a1e7f747b6b2593dbd7a
src/tabviews/custom/components/card/table-card/index.jsx
@@ -1,5 +1,6 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { is, fromJS } from 'immutable'
import { Spin, notification, Row, Col, Empty, Pagination } from 'antd'
@@ -31,6 +32,7 @@
    total: 0,                  // 总数
    sync: false,               // 是否统一请求数据
    data: null,                // 数据
    BData: ''
  }
  /**
@@ -38,7 +40,7 @@
   * 1、 initdata 为打印时使用的数据集
   */
  UNSAFE_componentWillMount () {
    const { data, initdata, BID } = this.props
    const { data, initdata, BID, BData } = this.props
    let _config = fromJS(this.props.config).toJS()
    let _cols = new Map()
@@ -58,6 +60,7 @@
        item.key = index
        item.$$uuid = item[_config.setting.primaryKey] || ''
        item.$$BID = BID || ''
        item.$$BData = BData || ''
        item.$Index = index + 1 + ''
        return item
      })
@@ -75,13 +78,14 @@
    }
    _config.columns.forEach(item => {
      if (item.type !== 'number') return
      _cols.set(item.field, item)
    })
    _config.subcards.forEach(card => {
      card.elements = card.elements.map(item => {
        if (item.field && _cols.has(item.field)) {
          item.col = _cols.get(item.field)
        if (item.eleType === 'number' && item.field && _cols.has(item.field) && typeof(item.decimal) !== 'number') {
          item.decimal = _cols.get(item.field).decimal || 0
        }
        return item
      })
@@ -90,13 +94,16 @@
    this.setState({
      sync: _sync,
      BID: BID || '',
      BData: BData || '',
      data: _data,
      config: _config,
      search: Utils.initMainSearch(_config.search),
      arr_field: _config.columns.map(col => col.field).join(','),
    }, () => {
      if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') {
        this.loadData()
        setTimeout(() => {
          this.loadData()
        }, _config.setting.delay || 0)
      }
    })
  }
@@ -126,7 +133,7 @@
   * @description 图表数据更新,刷新内容
   */
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { sync, config, BID } = this.state
    const { sync, config, BID, BData } = this.state
    if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) {
      let _data = []
@@ -138,17 +145,16 @@
        item.key = index
        item.$$uuid = item[config.setting.primaryKey] || ''
        item.$$BID = BID || ''
        item.$$BData = BData || ''
        item.$Index = index + 1 + ''
        return item
      })
      this.setState({sync: false, data: _data})
    } else if (nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      if (config.setting.syncRefresh === 'true') {
        this.setState({}, () => {
          this.loadData()
        })
      }
    } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({}, () => {
        this.loadData()
      })
    }
  }
@@ -163,26 +169,23 @@
    if (config.uuid !== menuId) return
    this.loadData(btn)                                                         // 数据刷新
    if (btn.syncComponentId && btn.syncComponentId !== config.uuid && btn.syncComponentId !== config.setting.supModule) {
      MKEmitter.emit('reloadData', btn.syncComponentId)                        // 同级标签刷新
    if ((position === 'mainline' || position === 'popclose') && config.setting.supModule && BID) { // 刷新源组件时,附带刷新上级行与当前组件
      MKEmitter.emit('reloadData', config.setting.supModule, BID)
    } else {
      this.loadData()
    }
    if (position === 'mainline' && config.setting.supModule) {                 // 主表行刷新
      MKEmitter.emit('reloadData', config.setting.supModule, (BID || 'empty'))
    } else if (position === 'popclose') {                                      // 标签关闭刷新
      config.setting.supModule && MKEmitter.emit('reloadData', config.setting.supModule, (BID || 'empty'))
    if (position === 'popclose') { // 执行启动弹窗的按钮所选择的刷新项
      btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId)
    }
  }
  resetParentParam = (MenuID, id) => {
  resetParentParam = (MenuID, id, data) => {
    const { config } = this.state
    if (!config.setting.supModule || config.setting.supModule !== MenuID) return
    if (id !== this.state.BID) {
      this.setState({ BID: id, pageIndex: 1 }, () => {
    if (id !== this.state.BID || id !== '') {
      this.setState({ BID: id, BData: data, pageIndex: 1 }, () => {
        this.loadData()
      })
    }
@@ -206,7 +209,7 @@
    if (config.uuid !== menuId) return
    let searches = search ? fromJS(search).toJS() : []
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
    if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 主表搜索条件
      let keys = searches.map(item => item.key.toLowerCase())
      mainSearch.forEach(item => {
        if (!keys.includes(item.key.toLowerCase())) {
@@ -225,7 +228,7 @@
  async loadData () {
    const { mainSearch, menuType } = this.props
    const { config, arr_field, pageIndex, search, BID } = this.state
    const { config, arr_field, pageIndex, search, BID, BData } = this.state
    if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
      this.setState({
@@ -236,7 +239,7 @@
    }
    let searches = search ? fromJS(search).toJS() : []
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
    if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 主表搜索条件
      let keys = searches.map(item => item.key)
      mainSearch.forEach(item => {
        if (!keys.includes(item.key)) {
@@ -245,11 +248,8 @@
      })
    }
    let requireFields = searches.filter(item => item.required && (!item.value || item.value.length === 0))
    let requireFields = searches.filter(item => item.required && item.value === '')
    if (requireFields.length > 0) {
      this.setState({
        loading: false
      })
      return
    }
@@ -272,6 +272,7 @@
          item.key = index
          item.$$uuid = item[config.setting.primaryKey] || ''
          item.$$BID = BID || ''
          item.$$BData = BData || ''
          item.$Index = index + start + ''
          return item
        }),
@@ -296,6 +297,64 @@
    }, () => {
      this.loadData()
    })
  }
  openView = (card, data) => {
    if (card.setting.click === 'menu') {
      let menu = null
      if (card.setting.MenuID) {
        menu = {
          MenuID: card.setting.MenuID,
          MenuName: card.setting.MenuName,
          MenuNo: card.setting.MenuNo,
          type: card.setting.tabType
        }
      } else if (card.setting.menu && card.setting.menu.length > 0) {
        let menu_id = card.setting.menu.slice(-1)[0]
        menu = this.props.permMenus.filter(m => m.MenuID === menu_id)[0] || ''
        if (!menu) {
          notification.warning({
            top: 92,
            message: '菜单已删除或没有访问权限!',
            duration: 5
          })
          return
        }
      }
      let newtab = {
        ...menu,
        param: {}
      }
      if (card.setting.joint === 'true') {
        newtab.param.$BID = data.$$uuid || ''
      }
      if (['linkage_navigation', 'linkage', 'menu_board'].includes(window.GLOB.navBar)) {
        MKEmitter.emit('modifyTabs', newtab, 'replace')
      } else {
        MKEmitter.emit('modifyTabs', newtab, 'plus', true)
      }
    } else if (card.setting.click === 'link') {
      let src = card.setting.linkurl
      if (card.setting.joint === 'true') {
        let con = '?'
        if (/\?/ig.test(src)) {
          con = '&'
        }
        src = src + `${con}id=${data.$$uuid || ''}&appkey=${window.GLOB.appkey}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID') || ''}`
      }
      window.open(src)
    } else if (card.setting.click === 'button' && card.setting.linkbtn) {
      MKEmitter.emit('triggerBtnId', card.setting.linkbtn, [data], 'linkbtn')
    }
  }
  getLines = (data) => {
@@ -328,7 +387,7 @@
      line.push(
        <Col key={index} span={24}>
          <div className="card-item-box" style={item.style}>
          <div className="card-item-box" style={item.style} onClick={() => {this.openView(item, data)}}>
            <CardCellComponent data={data} cards={config} cardCell={item} elements={item.elements}/>
          </div>
        </Col>
@@ -350,8 +409,10 @@
  render() {
    const { config, loading, data, BID, pageIndex, total } = this.state
    if (config.wrap.empty === 'hidden' && (!data || data.length === 0)) return null
    return (
      <div className="custom-table-card-box" style={{...config.style}}>
      <div className="custom-table-card-box" id={'anchor' + config.uuid} style={{...config.style}}>
        {loading ?
          <div className="loading-mask">
            {data ? <div className="ant-spin-blur"></div> : null}
@@ -371,4 +432,14 @@
  }
}
export default TableCard
const mapStateToProps = (state) => {
  return {
    permMenus: state.permMenus,
  }
}
const mapDispatchToProps = () => {
  return {}
}
export default connect(mapStateToProps, mapDispatchToProps)(TableCard)