king
2021-05-08 6afdec0062dacbded57e166230eb22cc55ced0c1
src/tabviews/custom/components/card/cardcellList/index.jsx
@@ -4,11 +4,10 @@
import { Icon, Col, Tooltip, notification } from 'antd'
import moment from 'moment'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import asyncComponent from './asyncButtonComponent'
import asyncElementComponent from '@/utils/asyncComponent'
import LostPng from '@/assets/img/lost.png'
import './index.scss'
const NormalButton = asyncComponent(() => import('@/tabviews/zshare/actionList/normalbutton'))
@@ -21,20 +20,22 @@
const PrintButton = asyncComponent(() => import('@/tabviews/zshare/actionList/printbutton'))
const BarCode = asyncElementComponent(() => import('@/components/barcode'))
const QrCode = asyncElementComponent(() => import('@/components/qrcode'))
const Video = asyncComponent(() => import('@/components/video'))
const PicRadio = {
  '4:3': '75%', '3:2': '66.67%', '16:9': '56.25%', '2:1': '50%', '3:1': '33.33%', '4:1': '25%',
  '5:1': '20%', '6:1': '16.67%', '7:1': '14.29%', '8:1': '12.5%', '9:1': '11.11%',
  '10:1': '10%', '3:4': '133.33%', '2:3': '150%', '9:16': '177.78%'
}
class CardCellComponent extends Component {
  static propTpyes = {
    BID: PropTypes.any,              // 上级ID
    seq: PropTypes.any,              // 序号
    cards: PropTypes.object,         // 菜单配置信息
    cardCell: PropTypes.object,
    data: PropTypes.object,
    elements: PropTypes.array,       // 元素集
    updateStatus: PropTypes.func,    // 状态更新
  }
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    card: null,          // 编辑中元素
    elements: null,      // 按钮组
  }
@@ -63,52 +64,228 @@
    }
  }
  openNewView = (card, url) => {
  openNewView = (e, card) => {
    const { cardCell, data, cards } = this.props
    if (!card.link) return
    e.stopPropagation()
    let url = ''
    if (card.link === 'static') {
      url = card.linkurl
    } else {
      url = data[card.linkurl]
    }
    if (!url) {
      notification.warning({
        top: 92,
        message: '地址链接不可为空!',
        message: '链接地址不存在!',
        duration: 5
      })
      return
    }
    let Id = ''
    let con = '?'
    if (/\?/ig.test(url)) {
      con = '&'
    }
    if (/^sso$/ig.test(url)) {
      if (!data.LinkUrl1) {
        notification.warning({
          top: 92,
          message: '链接地址不存在!',
          duration: 5
        })
        return
      }
    if (cards.subtype === 'propcard') {
      Id = cardCell.setting.primaryId || ''
      let _url = data.LinkUrl1
      if (/index\.html/ig.test(_url)) {
        _url = _url.replace(/index\.html.*/ig, '')
      } else if (!/\/$/ig.test(_url)) {
        _url = _url + '/'
      }
      url = _url + 'index.html#/ssologin/' + window.btoa(window.encodeURIComponent(JSON.stringify({
        UserID: sessionStorage.getItem('UserID'),
        LoginUID: sessionStorage.getItem('LoginUID'),
        User_Name: sessionStorage.getItem('User_Name'),
        Full_Name: sessionStorage.getItem('Full_Name'),
        avatar: sessionStorage.getItem('avatar'),
        dataM: data.dataM ? 'true' : '',
        debug: data.debug || '',
        role_id: data.role_id || ''
      })))
    } else {
      Id = data[cards.setting.primaryKey] || ''
    }
    if (card.joint === 'true') {
      url = url + `${con}id=${Id}&appkey=${window.GLOB.appkey}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID') || ''}`
      let Id = ''
      let con = '?'
      if (/\?/ig.test(url)) {
        con = '&'
      }
      if (cards.subtype === 'propcard' && cardCell) {
        Id = cardCell.setting.primaryId || ''
      } else {
        Id = data[cards.setting.primaryKey] || ''
      }
      if (card.joint === 'true') {
        url = url + `${con}id=${Id}&appkey=${window.GLOB.appkey}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID') || ''}`
      }
    }
    window.open(url)
  }
  getMark = (marks, style, content) => {
    const { data } = this.props
    marks.some(mark => {
      let originVal = data[mark.field[0]] + ''
      let contrastVal = ''
      let result = false
      if (mark.field[1] === 'static') {
        contrastVal = mark.contrastValue + ''
      } else {
        contrastVal = data[mark.field[2]] + ''
      }
      if (mark.match === '=') {
        result = originVal === contrastVal
      } else if (mark.match === '!=') {
        result = originVal !== contrastVal
      } else if (mark.match === 'like') {
        result = originVal.indexOf(contrastVal) > -1
      } else if (mark.match === '>') {
        try {
          originVal = parseFloat(originVal)
          contrastVal = parseFloat(contrastVal)
        } catch {
          originVal = NaN
        }
        if (!isNaN(originVal) && !isNaN(contrastVal) && originVal > contrastVal) {
          result = true
        }
      } else if (mark.match === '<') {
        try {
          originVal = parseFloat(originVal)
          contrastVal = parseFloat(contrastVal)
        } catch {
          originVal = NaN
        }
        if (!isNaN(originVal) && !isNaN(contrastVal) && originVal < contrastVal) {
          result = true
        }
      }
      if (result && mark.signType) {
        if (mark.signType[0] === 'font') {
          style.color = mark.color
        } else if (mark.signType[0] === 'background') {
          style.background = mark.color
          if (mark.fontColor) {
            style.color = mark.fontColor
          }
        } else if (mark.signType[0] === 'underline') {
          style.textDecoration = 'underline'
          style.color = mark.color
        } else if (mark.signType[0] === 'line-through') {
          style.textDecoration = 'line-through'
          style.color = mark.color
        } else if (mark.signType[0] === 'icon') {
          let icon = (<Icon style={{color: mark.color}} type={mark.signType[3]} />)
          if (mark.signType[1] === 'front') {
            content = <span>{icon} {content}</span>
          } else {
            content = <span>{content} {icon}</span>
          }
        }
      }
      return result
    })
    return content
  }
  getColor = (marks) => {
    const { data } = this.props
    let color = ''
    marks.some(mark => {
      let originVal = data[mark.field[0]] + ''
      let contrastVal = ''
      let result = false
      if (mark.field[1] === 'static') {
        contrastVal = mark.contrastValue + ''
      } else {
        contrastVal = data[mark.field[2]] + ''
      }
      if (mark.match === '=') {
        result = originVal === contrastVal
      } else if (mark.match === '!=') {
        result = originVal !== contrastVal
      } else if (mark.match === 'like') {
        result = originVal.indexOf(contrastVal) > -1
      } else if (mark.match === '>') {
        try {
          originVal = parseFloat(originVal)
          contrastVal = parseFloat(contrastVal)
        } catch {
          originVal = NaN
        }
        if (!isNaN(originVal) && !isNaN(contrastVal) && originVal > contrastVal) {
          result = true
        }
      } else if (mark.match === '<') {
        try {
          originVal = parseFloat(originVal)
          contrastVal = parseFloat(contrastVal)
        } catch {
          originVal = NaN
        }
        if (!isNaN(originVal) && !isNaN(contrastVal) && originVal < contrastVal) {
          result = true
        }
      }
      if (result) {
        color = mark.color
      }
      return result
    })
    return color
  }
  getContent = (card) => {
    const { data, BID, cards, seq } = this.props
    const { data, cards } = this.props
    if (card.eleType === 'sequence') {
      return (
        <Col key={card.uuid} span={card.width}>
          <div style={card.style}>
            <div className={'ant-mk-text'}>{seq}</div>
            <div className={'ant-mk-text'}>{data.$Index || ''}</div>
          </div>
        </Col>
      )
    } else if (card.eleType === 'text') {
      let val = ''
      let _style = card.style ? {...card.style} : {}
      if (card.datatype === 'static') {
        val = card.value
        val = card.value || ''
        if (/@username@|@fullName@|@login_city@/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(/@login_city@/ig, city)
        }
      } else if (data.hasOwnProperty(card.field)) {
        val = data[card.field]
      }
@@ -123,15 +300,24 @@
        val = `${card.prefix || ''}${val}${card.postfix || ''}`
      }
      if (card.marks) {
        val = this.getMark(card.marks, _style, val)
      }
      if (card.link) {
        _style.cursor = 'pointer'
      }
      return (
        <Col key={card.uuid} span={card.width}>
          <div style={card.style}>
            <div className={'ant-mk-text line' + card.height} style={{height: card.innerHeight || 21}}>{val}</div>
          <div style={_style} onClick={(e) => {this.openNewView(e, card)}}>
            <div className={'ant-mk-text line' + (card.height || '')} style={{height: card.innerHeight || 'auto'}}>{val}</div>
          </div>
        </Col>
      )
    } else if (card.eleType === 'number') {
      let val = ''
      let _style = card.style ? {...card.style} : {}
      if (card.datatype === 'static') {
        val = card.value
@@ -159,7 +345,9 @@
          val = '' + val
        }
        
        if (card.format === 'thdSeparator') {
        if (card.format === 'percent' && (!card.postfix || card.postfix.indexOf('%') === -1)) {
          val = val + '%'
        } else if (card.format === 'thdSeparator') {
          val = val.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
        }
      }
@@ -167,31 +355,15 @@
      if (val !== '') {
        val = `${card.prefix || ''}${val}${card.postfix || ''}`
      }
      return (
        <Col key={card.uuid} span={card.width}>
          <div style={card.style}>
            <div className={'ant-mk-text line' + card.height} style={{height: card.innerHeight || 21}}>{val}</div>
          </div>
        </Col>
      )
    } else if (card.eleType === 'link') {
      let url = ''
      if (card.datatype === 'static') {
        url = card.value
      } else if (data.hasOwnProperty(card.field)) {
        url = data[card.field]
      if (card.marks) {
        val = this.getMark(card.marks, _style, val)
      }
      let val = card.label || url
      return (
        <Col key={card.uuid} span={card.width}>
          <div style={card.style}>
            <div className={'ant-mk-text line' + card.height} style={{height: card.innerHeight || 21}}>
              <span style={{cursor: 'pointer'}} onClick={(e) => {e.stopPropagation(); this.openNewView(card, url)}}>{val}</span>
            </div>
          <div style={_style}>
            <div className={'ant-mk-text line' + (card.height || '')} style={{height: card.innerHeight || 'auto'}}>{val}</div>
          </div>
        </Col>
      )
@@ -215,6 +387,7 @@
      )
    } else if (card.eleType === 'slider') {
      let val = 0
      let color = card.color
      if (card.datatype === 'static') {
        val = card.value
@@ -235,14 +408,19 @@
        _val = `${val}%`
      }
      if (card.marks) {
        let _color = this.getColor(card.marks)
        color = _color ? _color : color
      }
      return (
        <Col key={card.uuid} span={card.width}>
          <div style={card.style}>
            <div className="ant-mk-slider">
              <div className="ant-mk-slider-rail"></div>
              <div className="ant-mk-slider-track" style={{width: _val, backgroundColor: card.color}}></div>
              <Tooltip title={val}>
                <div className="ant-mk-slider-handle" style={{left: _val, borderColor: card.color}}></div>
              <div className="ant-mk-slider-track" style={{width: _val, backgroundColor: color}}></div>
              <Tooltip title={`${val}%`}>
                <div className="ant-mk-slider-handle" style={{left: _val, borderColor: color}}></div>
              </Tooltip>
            </div>
          </div>
@@ -250,30 +428,38 @@
      )
    } else if (card.eleType === 'picture') {
      let _imagestyle = {}
      let _style = card.style ? {...card.style} : {}
      let url = ''
      if (card.url) {
        _imagestyle = {backgroundImage: `url('${card.url}')`}
      if (card.datatype === 'static') {
        url = card.url
      } else {
        _imagestyle = {backgroundImage: `url('')`}
        url = data[card.field]
      }
      if (url) {
        _imagestyle = {backgroundImage: `url('${url}')`}
      } else {
        _imagestyle = {backgroundImage: `url(${LostPng})`, backgroundSize: 'contain'}
      }
      if (card.radius === 'true') {
        _imagestyle.borderRadius = '50%'
      if (_style.borderRadius) {
        _imagestyle.borderRadius = _style.borderRadius
      }
      if (card.lenWidRadio === '16:9') {
        _imagestyle.paddingTop = '56.25%'
      } else if (card.lenWidRadio === '3:2') {
        _imagestyle.paddingTop = '66.67%'
      } else if (card.lenWidRadio === '4:3') {
        _imagestyle.paddingTop = '75%'
      if (PicRadio[card.lenWidRadio]) {
        _imagestyle.paddingTop = PicRadio[card.lenWidRadio]
      } else {
        _imagestyle.paddingTop = '100%'
      }
      if (card.link) {
        _style.cursor = 'pointer'
      }
      return (
        <Col key={card.uuid} span={card.width}>
          <div style={card.style}>
          <div style={_style} onClick={(e) => {this.openNewView(e, card)}}>
            <div className="ant-mk-picture" style={_imagestyle}></div>
          </div>
        </Col>
@@ -305,6 +491,22 @@
          </div>
        </Col>
      )
    } else if (card.eleType === 'video') {
      let url = ''
      if (card.datatype === 'static') {
        url = card.url
      } else {
        url = data[card.field] || ''
      }
      return (
        <Col key={card.uuid} span={card.width}>
          <div style={card.style}>
            <Video card={card} value={url}/>
          </div>
        </Col>
      )
    } else if (card.eleType === 'qrcode') {
      let val = ''
@@ -332,137 +534,122 @@
        </Col>
      )
    } else if (card.eleType === 'button') {
      if (card.$type === 'tableButton' && card.controlField) { // 表格中按钮隐藏控制
        if (data[card.controlField] === card.controlVal) {
          return null
        } else if (card.controlVal && card.controlVal.split(',').includes(data[card.controlField])) {
          return null
        }
      }
      if (['exec', 'prompt', 'pop'].includes(card.OpenType)) {
        return (
          <Col key={card.uuid} span={card.width}>
            <div style={card.style}>
              <NormalButton
                BID={BID}
                btn={card}
                show={card.show}
                style={card.btnstyle}
                setting={cards.setting}
                columns={cards.columns}
                selectedData={[data]}
                updateStatus={this.props.updateStatus}
              />
            </div>
          <Col key={card.uuid} className="mk-cell-btn" span={card.width}>
            <NormalButton
              BID={data.$$BID}
              btn={card}
              show={card.show}
              style={card.style}
              setting={cards.setting}
              columns={cards.columns}
              selectedData={[data]}
            />
          </Col>
        )
      } else if (card.OpenType === 'excelIn') {
        return (
          <Col key={card.uuid} span={card.width}>
            <div style={card.style}>
              <ExcelInButton
                BID={BID}
                btn={card}
                show={card.show}
                style={card.btnstyle}
                setting={cards.setting}
                selectedData={[data]}
                updateStatus={this.props.updateStatus}
              />
            </div>
          <Col key={card.uuid} className="mk-cell-btn" span={card.width}>
            <ExcelInButton
              BID={data.$$BID}
              btn={card}
              show={card.show}
              style={card.style}
              setting={cards.setting}
              selectedData={[data]}
            />
          </Col>
        )
      } else if (card.OpenType === 'excelOut') {
        return (
          <Col key={card.uuid} span={card.width}>
            <div style={card.style}>
              <ExcelOutButton
                BID={BID}
                btn={card}
                show={card.show}
                style={card.btnstyle}
                setting={cards.setting}
                // getexceloutparam={getexceloutparam}
                updateStatus={this.props.updateStatus}
              />
            </div>
          <Col key={card.uuid} className="mk-cell-btn" span={card.width}>
            <ExcelOutButton
              BID={data.$$BID}
              btn={card}
              show={card.show}
              style={card.style}
              setting={cards.setting}
            />
          </Col>
        )
      } else if (card.OpenType === 'popview') {
        return (
          <Col key={card.uuid} span={card.width}>
            <div style={card.style}>
              <PopupButton
                BID={BID}
                btn={card}
                show={card.show}
                style={card.btnstyle}
                setting={cards.setting}
                selectedData={[data]}
                updateStatus={this.props.updateStatus}
              />
            </div>
          <Col key={card.uuid} className="mk-cell-btn" span={card.width}>
            <PopupButton
              BID={data.$$BID}
              btn={card}
              show={card.show}
              style={card.style}
              setting={cards.setting}
              selectedData={[data]}
            />
          </Col>
        )
      } else if (card.OpenType === 'tab') {
        return (
          <Col key={card.uuid} span={card.width}>
            <div style={card.style}>
              <TabButton
                btn={card}
                show={card.show}
                style={card.btnstyle}
                setting={cards.setting}
                selectedData={[data]}
                updateStatus={this.props.updateStatus}
              />
            </div>
          <Col key={card.uuid} className="mk-cell-btn" span={card.width}>
            <TabButton
              btn={card}
              show={card.show}
              style={card.style}
              setting={cards.setting}
              selectedData={[data]}
            />
          </Col>
        )
      } else if (card.OpenType === 'innerpage') {
        return (
          <Col key={card.uuid} span={card.width}>
            <div style={card.style}>
              <NewPageButton
                btn={card}
                show={card.show}
                style={card.btnstyle}
                setting={cards.setting}
                selectedData={[data]}
                updateStatus={this.props.updateStatus}
              />
            </div>
          <Col key={card.uuid} className="mk-cell-btn" span={card.width}>
            <NewPageButton
              btn={card}
              show={card.show}
              style={card.style}
              setting={cards.setting}
              selectedData={[data]}
            />
          </Col>
        )
      } else if (card.OpenType === 'funcbutton') {
        if (card.funcType === 'changeuser') {
          return (
            <Col key={card.uuid} span={card.width}>
              <div style={card.style}>
                <ChangeUserButton
                  BID={BID}
                  btn={card}
                  show={card.show}
                  style={card.btnstyle}
                  setting={cards.setting}
                  selectedData={[data]}
                  updateStatus={this.props.updateStatus}
                />
              </div>
            <Col key={card.uuid} className="mk-cell-btn" span={card.width}>
              <ChangeUserButton
                BID={data.$$BID}
                btn={card}
                show={card.show}
                style={card.style}
                setting={cards.setting}
                selectedData={[data]}
              />
            </Col>
          )
        } else if (card.funcType === 'print') {
          return (
            <Col key={card.uuid} span={card.width}>
              <div style={card.style}>
                <PrintButton
                  BID={BID}
                  btn={card}
                  show={card.show}
                  style={card.btnstyle}
                  setting={cards.setting}
                  selectedData={[data]}
                  updateStatus={this.props.updateStatus}
                />
              </div>
            <Col key={card.uuid} className="mk-cell-btn" span={card.width}>
              <PrintButton
                BID={data.$$BID}
                btn={card}
                show={card.show}
                style={card.style}
                setting={cards.setting}
                selectedData={[data]}
              />
            </Col>
          )
        }
      }
    }
    return null
  }
  render() {