king
2021-12-22 bd1dfc9e6c9b9f8076ca2783ce598e0936b4c664
src/tabviews/zshare/cardcomponent/index.jsx
@@ -1,40 +1,46 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Icon, Card, Spin, Empty, Tabs } from 'antd'
import { Card, Spin, Empty } from 'antd'
import asyncComponent from '@/utils/asyncComponent'
import asyncExcelComponent from './asyncButtonComponent'
import MKEmitter from '@/utils/events.js'
import MkIcon from '@/components/mk-icon'
import '@/assets/css/table.scss'
import './index.scss'
const NormalButton = asyncComponent(() => import('@/tabviews/zshare/actionList/normalbutton'))
const PopupButton = asyncComponent(() => import('@/tabviews/zshare/actionList/popupbutton'))
const ExcelInButton = asyncExcelComponent(() => import('@/tabviews/zshare/actionList/excelInbutton'))
const ExcelOutButton = asyncExcelComponent(() => import('@/tabviews/zshare/actionList/exceloutbutton'))
const TabButton = asyncComponent(() => import('@/tabviews/zshare/actionList/tabbutton'))
const NewPageButton = asyncComponent(() => import('@/tabviews/zshare/actionList/newpagebutton'))
const ChangeUserButton = asyncComponent(() => import('@/tabviews/zshare/actionList/changeuserbutton'))
const PrintButton = asyncComponent(() => import('@/tabviews/zshare/actionList/printbutton'))
const { TabPane } = Tabs
class CardCell extends Component {
  static propTpyes = {
    type: PropTypes.any,              // 卡片类型,添加按钮为 insert
    BID: PropTypes.any,               // 主表ID
    BData: PropTypes.any,             // 主表数据
    Tab: PropTypes.any,               // 如果当前元素为标签时,tab为标签信息
    MenuID: PropTypes.string,         // 菜单ID
    setting: PropTypes.object,        // 页面设定
    logcolumns: PropTypes.array,      // 字段列
    columns: PropTypes.array,         // 显示列
    card: PropTypes.object,           // 卡片设置信息
    data: PropTypes.object,           // 卡片数据
    selectKey: PropTypes.string,      // 选择卡片的序号
    colMap: PropTypes.any,            // 显示列信息,用于设置标记
    refreshdata: PropTypes.func,      // 按钮操作后数据刷新
    switchCard: PropTypes.func        // 卡片切换
  }
  state = {
    extra: null,    // 顶部按钮信息
    actions: null   // 底部按钮行
    actions: null,  // 底部按钮行
    cardwidth: 0,
    cardheight: 0,
    plusSize: 0
  }
  UNSAFE_componentWillMount () {
@@ -54,6 +60,47 @@
  
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
  componentDidMount() {
    if (this.insertRef) {
      let _width = this.insertRef.offsetWidth
      let _height = this.insertRef.offsetHeight
      if (this.props.card.header) {
        _height += 46
      }
      if (this.props.card.bottom) {
        _height += 49
      }
      this.setState({
        cardwidth: _width,
        cardheight: _height,
        plusSize: _width > _height ? _height / 2 : _width / 2
      })
    }
  }
  componentDidUpdate() {
    if (this.insertRef) {
      let _width = this.insertRef.offsetWidth
      let _height = this.insertRef.offsetHeight
      if (this.props.card.header) {
        _height += 46
      }
      if (this.props.card.bottom) {
        _height += 49
      }
      if (_height !== this.state.cardheight || _width !== this.state.cardwidth) {
        this.setState({
          cardwidth: _width,
          cardheight: _height,
          plusSize: _width > _height ? _height / 2 : _width / 2
        })
      }
    }
  }
  /**
@@ -83,40 +130,38 @@
   * @description 获取按钮元素
   */
  getActionList = (actions, show) => {
    const { BID, BData, Tab, setting, logcolumns, ContainerId, data, MenuID } = this.props
    const { BData, Tab, setting, columns, ContainerId, data, MenuID } = this.props
    
    return actions.map(item => {
      if (['exec', 'prompt', 'pop'].includes(item.OpenType)) {
        return (
          <NormalButton
            key={item.uuid}
            BID={BID}
            BID={data.$$BID}
            Tab={Tab}
            btn={item}
            show={show}
            BData={BData}
            setting={setting}
            columns={logcolumns}
            columns={columns}
            selectedData={[data]}
            ContainerId={ContainerId}
            updateStatus={this.updateStatus}
          />
        )
      } else if (item.OpenType === 'popview') {
        return (
          <PopupButton
            key={item.uuid}
            BID={BID}
            BID={data.$$BID}
            Tab={Tab}
            btn={item}
            show={show}
            BData={BData}
            setting={setting}
            selectedData={[data]}
            updateStatus={this.updateStatus}
          />
        )
      } else if (item.OpenType === 'tab' || item.OpenType === 'blank') {
      } else if (item.OpenType === 'tab') {
        return (
          <TabButton
            key={item.uuid}
@@ -125,7 +170,6 @@
            MenuID={MenuID}
            setting={setting}
            selectedData={[data]}
            updateStatus={this.updateStatus}
          />
        )
      } else if (item.OpenType === 'innerpage' || item.OpenType === 'outerpage') {
@@ -139,23 +183,22 @@
          />
        )
      } else if (item.OpenType === 'funcbutton') {
        if (item.funcType === 'changeuser') {
        if (item.funcType === 'changeuser' || item.funcType === 'closetab') {
          return (
            <ChangeUserButton
              key={item.uuid}
              BID={BID}
              BID={data.$$BID}
              btn={item}
              show={show}
              setting={setting}
              selectedData={[data]}
              updateStatus={this.updateStatus}
            />
          )
        } else if (item.funcType === 'print') {
          return (
            <PrintButton
              key={item.uuid}
              BID={BID}
              BID={data.$$BID}
              Tab={Tab}
              btn={item}
              show={show}
@@ -163,7 +206,6 @@
              setting={setting}
              selectedData={[data]}
              ContainerId={ContainerId}
              updateStatus={this.updateStatus}
            />
          )
        }
@@ -171,15 +213,6 @@
      return null
    })
  }
  /**
   * @description 操作完成后,数据刷新
   */
  updateStatus = (type, positon) => {
    if (type === 'refresh') {
      this.props.refreshdata(positon)
    }
  }
  /**
@@ -213,7 +246,7 @@
          if (isNaN(originVal) || isNaN(contrastVal)) {
            originVal = ''
          }
        } catch {
        } catch (e) {
          originVal = ''
        }
      }
@@ -241,7 +274,7 @@
        if (mark.position === 'front') {
          position = 'front'
        }
        icon = <Icon className={'font ' + className} type={mark.icon} />
        icon = <MkIcon className={'font ' + className} type={mark.icon} />
        className = ''
      }
@@ -286,9 +319,9 @@
      }
      return (
        <div className={className}>
        <span className={className}>
          {content}
        </div>
        </span>
      )
    } else if (col.type === 'number') {
      let content = ''
@@ -300,7 +333,7 @@
          if (isNaN(content)) {
            content = ''
          }
        } catch {
        } catch (e) {
          content = ''
        }
      }
@@ -334,9 +367,29 @@
      }
      return (
        <div className={className}>
        <span className={className}>
          {content}
        </div>
        </span>
      )
    } else if (col.type === 'link') {
      let content = col.nameField ? data[col.nameField] : ''
      let _href = data[col.field] || ''
      if (!content && _href) {
        content = _href
      } else if (!_href) {
        content = ''
      }
      if (col.joint === 'true' && _href) {
        let _param = window.btoa('id=' + data[this.props.setting.primaryKey] + '&userid=' + sessionStorage.getItem('UserID') + '&loginuid=' + sessionStorage.getItem('LoginUID'))
        _href += '?' + _param
      }
      return (
        <span>
          {_href ? <a href={_href} target="_blank" rel="noopener noreferrer">{content}</a> : null}
        </span>
      )
    }
  }
@@ -376,8 +429,8 @@
  }
  render() {
    const { card, selectKey, data } = this.props
    const { extra, actions } = this.state
    const { card, selectKey, data, type } = this.props
    const { extra, actions, plusSize } = this.state
    let title = null
    if (card.header) {
@@ -389,8 +442,8 @@
    }
    return (
      <div className={'chart-card-box ' + card.outclass} style={card.outstyle || null} >
        <Card
      <div className={'chart-card-box ' + card.outclass}>
        {type !== 'insert' ? <Card
          size="small"
          className={'chart-card ' + (selectKey === data.key ? 'chart-card-selected' : '')}
          title={title}
@@ -416,7 +469,34 @@
              })}
            </div>
          </div>
        </Card>
        </Card> : null}
        {type === 'insert' ? <Card
          size="small"
          className="chart-card insert"
          title={card.header ? ' ' : null}
          bordered={card.bordered}
          actions={card.bottom.actions ? [''] : null}
        >
          <div className="ant-card-meta" ref={(ref) => this.insertRef = ref} style={card.flex ? {display: 'flex'} : null}>
            {card.avatar ? <div className="ant-card-meta-avatar" style={card.avatar.class}> </div> : null }
            <div className="ant-card-meta-detail" style={card.flex ? {flex: 1} : null}>
              {card.details.map((detail, i) => (<div className={detail.class} style={detail.style} key={i}></div>))}
            </div>
          </div>
          <div className="mk-card-insert">
            <NormalButton
              BID={this.props.BID}
              Tab={this.props.Tab}
              btn={card.insertAction}
              show={'plus' + plusSize}
              BData={this.props.BData}
              setting={this.props.setting}
              columns={this.props.columns}
              selectedData={[]}
              ContainerId={this.props.ContainerId}
            />
          </div>
        </Card> : null}
      </div>
    )
  }
@@ -429,20 +509,19 @@
    Tab: PropTypes.any,               // 如果当前元素为标签时,tab为标签信息
    MenuID: PropTypes.string,         // 菜单ID
    config: PropTypes.object,         // 页面配置信息
    logcolumns: PropTypes.array,      // 显示列
    columns: PropTypes.array,         // 显示列
    ContainerId: PropTypes.any,       // tab页面ID,用于弹窗控制
    plot: PropTypes.object,
    tableId: PropTypes.string,
    loading: PropTypes.bool,
    data: PropTypes.array,
    refreshdata: PropTypes.func,
    handleTableId: PropTypes.func
  }
  state = {
    card: null,
    colMap: null,
    selectKey: ''
    selectKey: '',
    actionList: null
  }
  /**
@@ -456,6 +535,8 @@
    let actionMap = new Map() // 按钮组
    let columns = fromJS(config.columns).toJS()
    let actions = fromJS(config.action).toJS()
    let insertAction = null
    let actionList = []
    columns.forEach(col => {
      if (col.field) {
@@ -463,9 +544,20 @@
      }
    })
    if (plot.widthType === 'absolute') {
      plot.cardWidth = 6
    }
    if (plot.avatar && plot.avatar.widthType === 'absolute') {
      card.avatar.width = 32
    }
    actions.forEach(item => {
      if ((item.Ot && item.Ot !== 'notRequired' && !['excelIn', 'excelOut'].includes(item.OpenType)) || item.funcType === 'changeuser') {
        actionMap.set(item.uuid, item)
      } else if (plot.extraAction && plot.extraAction === item.uuid && ['pop', 'prompt', 'exec'].includes(item.OpenType) && item.Ot === 'notRequired') {
        insertAction = item
      } else if (plot.actions && plot.actions.length > 0 && plot.actions.includes(item.uuid) && (item.OpenType === 'excelOut' || (item.OpenType === 'excelIn' && item.Ot === 'notRequired'))) {
        actionList.push(item)
      }
    })
@@ -494,7 +586,7 @@
    }
    if (plot.subelement.includes('avatar')) {
      card.avatar = { type: plot.avatar.type }
      card.avatar = { type: plot.avatar.type, display: plot.avatar.display || 'inline' }
      if (card.avatar.type === 'icon' && colMap.get(plot.avatar.field)) {
        let col = fromJS(colMap.get(plot.avatar.field)).toJS()
        let _marks = []
@@ -512,13 +604,9 @@
      } else if (card.avatar.type === 'picture' && colMap.get(plot.avatar.field)) {
        card.avatar.field = plot.avatar.field
        card.avatar.width = plot.avatar.width
        card.avatar.widthType = plot.avatar.widthType
        card.avatar.radius = plot.avatar.radius !== 'false'
        let _width = card.avatar.width
        if (plot.avatar.widthType === 'ratio') {
          _width = _width + '%'
        }
        let _width = card.avatar.width + '%'
        card.avatar.class = {width: _width, paddingTop: _width}
      }
@@ -576,18 +664,8 @@
      }
    }
    let outclass = ''
    if (plot.widthType === 'ratio' && plot.over !== 'roll') {
      outclass += ' ant-col ant-col-' + plot.cardWidth
    }
    card.outclass = outclass
    card.outclass = ' ant-col ant-col-' + plot.cardWidth
    card.bordered = plot.border !== 'hidden'
    if (plot.widthType === 'absolute') {
      card.outstyle = { width: plot.cardWidth }
    }
    if (plot.bgfield && colMap.get(plot.bgfield)) {
      let col = fromJS(colMap.get(plot.bgfield)).toJS()
@@ -603,7 +681,9 @@
    card.switch = plot.switch !== 'false'
    this.setState({card: card, colMap: colMap})
    card.insertAction = insertAction // 添加卡片
    this.setState({card: card, colMap: colMap, actionList: actionList})
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
@@ -622,24 +702,21 @@
    const { plot } = this.props
    const { card } = this.state
    let _flex = false
    if (card.avatar) {
      let _flex = false
      let _cardWidth = 300
      if (plot.widthType === 'absolute') {
        _cardWidth = plot.cardWidth
      } else {
        let _outWidth = document.body.offsetWidth - 260
        if (this.cardRef.offsetWidth) {
          _outWidth = this.cardRef.offsetWidth
        }
        _cardWidth = Math.floor(_outWidth * plot.cardWidth / 24 - 20)
      }
      if (card.avatar.widthType === 'ratio') {
      let _outWidth = document.body.offsetWidth - 260
      if (this.cardRef.offsetWidth) {
        _outWidth = this.cardRef.offsetWidth
      }
      _cardWidth = Math.floor(_outWidth * plot.cardWidth / 24 - 20)
      if (card.avatar.display !== 'block') {
        if (card.avatar.width < 90) {
          _flex = true
        }
      } else if (card.avatar.width < _cardWidth * 0.9) {
      } else if (card.avatar.width < _cardWidth * 0.9 && card.avatar.display !== 'block') {
        _flex = true
      }
@@ -659,13 +736,13 @@
    this.setState({selectKey: data.key})
    this.props.handleTableId(this.props.tableId, _id, data)
    MKEmitter.emit('changeTableLine', this.props.ContainerId, this.props.tableId, _id, data)
  }
  render() {
    const { plot, data, loading, BID, BData, Tab, MenuID, config, logcolumns, ContainerId } = this.props
    const { card, colMap, selectKey } = this.state
    const { plot, data, loading, BID, BData, Tab, MenuID, config, columns, ContainerId } = this.props
    const { card, colMap, selectKey, actionList } = this.state
    return (
      <div className="card-row-box mingke-table" ref={(ref) => this.cardRef = ref} style={!plot.title ? {paddingTop: '15px'} : null}>
        {loading ?
@@ -674,8 +751,38 @@
            <Spin />
          </div> : null
        }
        {plot.title ? <p className="chart-title">{plot.title}</p> : null}
        {plot.over !== 'roll' && data && data.length > 0 &&
        <div>
          {plot.title ? <p className="chart-title">{plot.title}</p> : null}
          <div style={{float: 'right', marginRight: 10}}>
            {actionList && actionList.map(action => {
              if (action.OpenType === 'excelIn') {
                return (
                  <ExcelInButton
                    key={action.uuid}
                    BID={BID}
                    Tab={Tab}
                    show="icon"
                    btn={action}
                    setting={config.setting}
                  />
                )
              } else {
                return (
                  <ExcelOutButton
                    key={action.uuid}
                    BID={BID}
                    Tab={Tab}
                    show="icon"
                    btn={action}
                    setting={config.setting}
                  />
                )
              }
            })}
          </div>
          <div style={{clear: 'both'}}></div>
        </div>
        {data && data.length > 0 &&
          data.map((item, i) => (
            <CardCell
              key={i}
@@ -686,38 +793,30 @@
              BData={BData}
              MenuID={MenuID}
              colMap={colMap}
              columns={columns}
              selectKey={selectKey}
              logcolumns={logcolumns}
              setting={config.setting}
              ContainerId={ContainerId}
              switchCard={this.switchCard}
              refreshdata={this.props.refreshdata}
            />
          ))
        }
        {plot.over === 'roll' && data && data.length > 0 ?
          <Tabs activeKey="">
            {data.map((item, i) => (
              <TabPane tab={<CardCell
                BID={BID}
                Tab={Tab}
                card={card}
                data={item}
                BData={BData}
                MenuID={MenuID}
                colMap={colMap}
                selectKey={selectKey}
                logcolumns={logcolumns}
                setting={config.setting}
                ContainerId={ContainerId}
                switchCard={this.switchCard}
                refreshdata={this.props.refreshdata}
              />} key={i}></TabPane>
            ))}
          </Tabs> : null
        {!loading && card.insertAction ?
          <CardCell
            key="insert"
            type="insert"
            BID={BID}
            Tab={Tab}
            card={card}
            data={{key: 'insert'}}
            BData={BData}
            MenuID={MenuID}
            setting={config.setting}
            ContainerId={ContainerId}
            switchCard={() => {}}
          /> : null
        }
        {!data || data.length === 0 ? <Empty description={false}/> : null}
        {(loading || !card.insertAction) && (!data || data.length === 0) ? <Empty description={false}/> : null}
        <div className="clear"></div>
      </div>
    )