king
2022-09-06 bdfec44c9f3a37dbbe05bf14a252ffec04132a86
src/tabviews/custom/components/card/cardcellList/index.jsx
@@ -11,6 +11,7 @@
import MkIcon from '@/components/mk-icon'
import MKEmitter from '@/utils/events.js'
import LostPng from '@/assets/img/lost.png'
import Encrypts from '@/components/encrypts'
import './index.scss'
const { Paragraph } = Typography
@@ -43,21 +44,7 @@
    elements: PropTypes.array,       // 元素集
  }
  state = {
    card: null,          // 编辑中元素
    elements: null,      // 按钮组
  }
  /**
   * @description 搜索条件初始化
   */
  UNSAFE_componentWillMount () {
    const { elements } = this.props
    this.setState({
      elements: fromJS(elements).toJS()
    })
  }
  state = {}
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState)) || !is(fromJS(this.props), fromJS(nextProps))
@@ -236,9 +223,12 @@
    return color
  }
  getContent = (card) => {
    const { data, cards } = this.props
  getContent = () => {
    const { data, cards, elements } = this.props
    let contents = []
    elements.forEach(card => {
    if (card.eleType === 'sequence') {
      let _style = {}
      if (card.marks) {
@@ -250,7 +240,7 @@
        _style = mark.style
      }
      return (
        contents.push(
        <Col key={card.uuid} span={card.width}>
          <div style={card.style}>
            <div className="ant-mk-text"><span className="sequence-wrap" style={_style}>{data.$Index || ''}</span></div>
@@ -263,11 +253,12 @@
      if (card.datatype === 'static') {
        val = card.value || ''
        if (/@username@|@fullName@|@mk_city@/ig.test(val)) {
          if (/@username@|@fullName@|@mk_city@|@bid@/ig.test(val)) {
          let userName = sessionStorage.getItem('User_Name') || ''
          let fullName = sessionStorage.getItem('Full_Name') || ''
          let city = sessionStorage.getItem('city') || ''
          val = val.replace(/@username@/ig, userName).replace(/@fullName@/ig, fullName).replace(/@mk_city@/ig, city)
            let bid = data.$$BID || ''
            val = val.replace(/@username@/ig, userName).replace(/@fullName@/ig, fullName).replace(/@mk_city@/ig, city).replace(/@bid@/ig, bid)
        }
      } else if (data.hasOwnProperty(card.field)) {
        val = data[card.field]
@@ -338,11 +329,14 @@
      if (val !== '') {
        let orival = val
          if (card.format === 'encryption') {
            val = <Encrypts value={val} />
          }
        if (card.fixStyle === 'alone') {
          let _s = {fontSize: card.fixSize, color: card.fixColor, marginLeft: card.fixLeft, marginRight: card.fixRight}
          val = <><span style={_s}>{card.prefix || ''}</span>{val}<span style={_s}>{card.postfix || ''}</span></>
        } else {
          val = `${card.prefix || ''}${val}${card.postfix || ''}`
            val = <span>{card.prefix || ''}{val}{card.postfix || ''}</span>
        }
        if (card.copyable === 'true') {
          val = <Paragraph copyable={{ text: orival }}>{val}</Paragraph>
@@ -371,7 +365,7 @@
        _style.backgroundImage = `url('${data[card.bgImage]}')`
      }
      return (
        contents.push(
        <Col key={card.uuid} span={card.width}>
          <div style={_style} onClick={(e) => {this.openNewView(e, card)}}>
            <div className={'ant-mk-text line' + (card.height || '')} style={{height: card.innerHeight || 'auto'}}>{val}</div>
@@ -393,23 +387,17 @@
      }
      if (typeof(val) === 'number') {
          if (card.round) {
            val = Math.round(val * card.round) / card.round
          }
        if (card.format === 'percent') {
          val = val * 100
        } else if (card.format === 'abs') {
          val = Math.abs(val)
        }
        if (typeof(card.decimal) === 'number') {
          let decimal = card.decimal
          if (card.format === 'percent') {
            decimal = decimal - 2
          }
          if (decimal < 0) {
            decimal = 0
          }
          val = val.toFixed(decimal)
          if (card.round) {
            val = val.toFixed(card.decimal)
        } else {
          val = '' + val
        }
@@ -444,7 +432,7 @@
        }
      }
      return (
        contents.push(
        <Col key={card.uuid} span={card.width}>
          <div style={_style}>
            <div className={'ant-mk-text line' + (card.height || '')} style={{height: card.innerHeight || 'auto'}}>{val}</div>
@@ -460,7 +448,7 @@
        val = data[card.field]
      }
      return (
        contents.push(
        <Col key={card.uuid} span={card.width}>
          <div style={card.style}>
            {val ? <Tooltip title={val}>
@@ -490,7 +478,7 @@
        color = _color ? _color : color
      }
      return (
        contents.push(
        <Col key={card.uuid} span={card.width}>
          <div style={card.style}>
            <MkProgress value={val} config={card} color={color}/>
@@ -524,12 +512,6 @@
        return null
      }
      
      if (url) {
        _imagestyle = {backgroundImage: `url('${url}')`}
      } else {
        _imagestyle = {backgroundImage: `url(${LostPng})`, backgroundSize: 'contain'}
      }
      if (_style.borderRadius) {
        _imagestyle.borderRadius = _style.borderRadius
      }
@@ -545,30 +527,33 @@
      }
      let scale = url && card.scale === 'true'
        let urls = url ? url.split(',').filter(Boolean) : [LostPng]
      
      return (
        <Col key={card.uuid} span={card.width}>
        if (!url) {
          _imagestyle = {backgroundSize: 'contain'}
        }
        urls.forEach((u, i) => {
          contents.push(<Col key={card.uuid + i} span={card.width}>
          <div style={_style} onClick={(e) => {this.openNewView(e, card)}}>
            <div
              className={'ant-mk-picture' + (scale ? ' scale' : '')}
              onClick={(e) => {
                if (scale) {
                  e.stopPropagation()
                } else {
                  return
                }
                  if (!scale) return
                MKEmitter.emit('mkImageScale', url)
                  e.stopPropagation()
                  MKEmitter.emit('mkImageScale', url, urls)
              }}
              style={_imagestyle}
                style={{..._imagestyle, backgroundImage: `url('${u}')`}}
            ></div>
          </div>
        </Col>
      )
          </Col>)
        })
    } else if (card.eleType === 'splitline') {
      let _borderWidth = card.borderWidth === undefined ? 1 : card.borderWidth
      return (
        <Col key={card.uuid} span={card.width}>
        contents.push(
          <Col key={card.uuid} span={card.width} style={{minHeight: _borderWidth}}>
          <div style={card.style}>
            <div className="ant-mk-splitline" style={{borderColor: card.color, borderWidth: _borderWidth}}></div>
          </div>
@@ -587,7 +572,7 @@
        return null
      }
      return (
        contents.push(
        <Col key={card.uuid} span={card.width}>
          <div style={card.style}>
            <div style={{height: card.innerHeight || 25}}>
@@ -617,13 +602,17 @@
        poster = card.posterUrl || ''
      }
      return (
        <Col key={card.uuid} span={card.width}>
        let urls = url.split(',').filter(Boolean)
        urls.forEach((u, i) => {
          contents.push(
            <Col key={card.uuid + i} span={card.width}>
          <div className="video-wrap" style={card.style}>
            <Video card={card} poster={poster} value={url}/>
                <Video card={card} poster={poster} value={u}/>
          </div>
        </Col>
      )
        })
    } else if (card.eleType === 'qrcode') {
      let val = ''
@@ -637,7 +626,7 @@
        return null
      }
      return (
        contents.push(
        <Col key={card.uuid} span={card.width}>
          <div style={card.style}>
            <div style={{minHeight: card.qrWidth || 50}}>
@@ -656,7 +645,7 @@
        val = `${card.prefix || ''}${val}${card.postfix || ''}`
      }
      return (
        contents.push(
        <Col key={card.uuid} span={card.width}>
          <div className="ant-mk-date" style={card.style}>
            {val}
@@ -741,7 +730,7 @@
        }
      }
      return (
        contents.push(
        <Col key={card.uuid} span={card.width}>
          <div style={_style}>
            <div className={'ant-mk-text line' + (card.height || '')} style={{height: card.innerHeight || 'auto'}}>{val}</div>
@@ -773,7 +762,7 @@
      }
      if (['exec', 'prompt', 'pop', 'form'].includes(card.OpenType)) {
        return (
          contents.push(
          <Col key={card.uuid} className="mk-cell-btn" style={card.wrapStyle} span={card.width}>
            <NormalButton
              btn={card}
@@ -787,7 +776,7 @@
          </Col>
        )
      } else if (card.OpenType === 'excelIn') {
        return (
          contents.push(
          <Col key={card.uuid} className="mk-cell-btn" style={card.wrapStyle} span={card.width}>
            <ExcelInButton
              btn={card}
@@ -800,7 +789,7 @@
          </Col>
        )
      } else if (card.OpenType === 'excelOut') {
        return (
          contents.push(
          <Col key={card.uuid} className="mk-cell-btn" style={card.wrapStyle} span={card.width}>
            <ExcelOutButton
              btn={card}
@@ -813,7 +802,7 @@
          </Col>
        )
      } else if (card.OpenType === 'popview') {
        return (
          contents.push(
          <Col key={card.uuid} className="mk-cell-btn" style={card.wrapStyle} span={card.width}>
            <PopupButton
              btn={card}
@@ -826,7 +815,7 @@
          </Col>
        )
      } else if (card.OpenType === 'tab') {
        return (
          contents.push(
          <Col key={card.uuid} className="mk-cell-btn" style={card.wrapStyle} span={card.width}>
            <TabButton
              btn={card}
@@ -838,7 +827,7 @@
          </Col>
        )
      } else if (card.OpenType === 'innerpage') {
        return (
          contents.push(
          <Col key={card.uuid} className="mk-cell-btn" style={card.wrapStyle} span={card.width}>
            <NewPageButton
              btn={card}
@@ -851,7 +840,7 @@
        )
      } else if (card.OpenType === 'funcbutton') {
        if (card.funcType === 'changeuser' || card.funcType === 'closetab') {
          return (
            contents.push(
            <Col key={card.uuid} className="mk-cell-btn" style={card.wrapStyle} span={card.width}>
              <ChangeUserButton
                btn={card}
@@ -864,7 +853,7 @@
            </Col>
          )
        } else if (card.funcType === 'print') {
          return (
            contents.push(
            <Col key={card.uuid} className="mk-cell-btn" style={card.wrapStyle} span={card.width}>
              <PrintButton
                btn={card}
@@ -877,7 +866,7 @@
            </Col>
          )
        } else if (card.funcType === 'megvii') {
          return (
            contents.push(
            <Col key={card.uuid} className="mk-cell-btn" style={card.wrapStyle} span={card.width}>
              <FuncMegvii
                btn={card}
@@ -889,7 +878,7 @@
            </Col>
          )
        } else if (card.funcType === 'filezip') {
          return (
            contents.push(
            <Col key={card.uuid} className="mk-cell-btn" style={card.wrapStyle} span={card.width}>
              <FuncZip
                btn={card}
@@ -903,16 +892,15 @@
        }
      }
    }
    })
    return null
    return contents
  }
  render() {
    const { elements } = this.state
    return (
      <div className="card-cell-list">
        {elements.map(item => this.getContent(item))}
        {this.getContent()}
      </div>
    )
  }