king
2024-11-21 6ed4e1dc4b9575a22f74f57fbf90abe02b315de7
src/menu/components/card/cardcellcomponent/dragaction/card.jsx
@@ -1,7 +1,7 @@
import React from 'react'
import { useDrag, useDrop } from 'react-dnd'
import { Popover } from 'antd'
import { EditOutlined, CopyOutlined, CloseOutlined, FontColorsOutlined } from '@ant-design/icons'
import { EditOutlined, CopyOutlined, CloseOutlined, FontColorsOutlined, CaretUpOutlined, CaretDownOutlined } from '@ant-design/icons'
import MkIcon from '@/components/mk-icon'
import moment from 'moment'
@@ -40,7 +40,13 @@
  const [, drop] = useDrop({
    accept: 'action',
    canDrop: () => true,
    drop({ id: draggedId }) {
    drop(item) {
      const { id: draggedId } = item
      if (item.$init) {
        item.overIndex = id
      }
      if (!draggedId || draggedId === id) return
      const { index: originIndex } = findCard(draggedId)
@@ -51,16 +57,22 @@
    },
  })
  let _style = {opacity: isDragging ? 0 : 1}
  let _style = {opacity: isDragging ? 0.3 : 1}
  
  if (card.style) {
    _style = {...card.style, opacity: isDragging ? 0 : 1}
  if (card.style && card.eleType !== 'tag') {
    _style = {...card.style, opacity: isDragging ? 0.3 : 1}
    _style = resetStyle(_style)
  }
  if (card.eleType === 'picture' && card.maxWidth) {
    _style.maxWidth = card.maxWidth
    let left = _style.marginLeft && _style.marginLeft !== '0px' ? _style.marginLeft : 'auto'
    let right = _style.marginRight && _style.marginRight !== '0px' ? _style.marginRight : 'auto'
    let left = _style.marginLeft || 'auto'
    let right = _style.marginRight || 'auto'
    if (_style.marginLeft === '0px' && _style.marginRight === '0px') {
      left = 'auto'
      right = 'auto'
    }
    _style.margin = (_style.marginTop || 0) + ' ' + right + ' ' + (_style.marginBottom || 0) + ' ' + left
    delete _style.marginLeft
    delete _style.marginRight
@@ -71,7 +83,7 @@
  const getContent = () => {
    if (card.eleType === 'sequence') {
      return (
        <div className={'ant-mk-text'}>1</div>
        <div style={{height: card.innerHeight || 'auto'}} className="ant-mk-text">{card.prefix || ''}1{card.postfix || ''}</div>
      )
    } else if (card.eleType === 'text' || card.eleType === 'number') {
      let val = `${card.prefix || ''}${card.datatype === 'static' ? (card.value || '') : (card.field || '')}${card.postfix || ''}`
@@ -79,11 +91,17 @@
        let _s = {fontSize: card.fixSize, color: card.fixColor, marginLeft: card.fixLeft, marginRight: card.fixRight}
        val = <><span style={_s}>{card.prefix || ''}</span>{`${card.datatype === 'static' ? (card.value || '') : (card.field || '')}`}<span style={_s}>{card.postfix || ''}</span></>
      }
      if (card.sortField) {
        val = <><span>{val}</span><span className="sort-wrap"><CaretUpOutlined /><CaretDownOutlined /></span></>
      }
      return (
        <div className={'ant-mk-text line' + (card.height || '')} style={{height: card.innerHeight || 'auto'}}>{val}</div>
      )
    } else if (card.eleType === 'icon') {
      return (<MkIcon type={card.icon}/>)
      if (card.tipType === 'text') {
        return <div className={'ant-mk-text line' + (card.height || '')} style={{height: card.innerHeight || 'auto'}}>{card.value || card.field || ''}</div>
      }
      return (<MkIcon style={{height: card.innerHeight || 'auto'}} className="ant-mk-icon" type={card.icon || 'bell'}/>)
    } else if (card.eleType === 'slider') {
      let val = card.value ? (card.value / card.maxValue) * 100 : 30
      return <MkProgress value={val} config={card}/>
@@ -95,20 +113,23 @@
      //   </div>
      // )
    } else if (card.eleType === 'picture') {
      let _imagestyle = {}
      let _imagestyle = {
        backgroundSize: card.style.backgroundSize || 'cover',
        backgroundPosition: card.style.backgroundPosition || 'center',
        backgroundRepeat: card.style.backgroundRepeat || 'no-repeat',
        borderRadius: card.style.borderRadius || 0
      }
      let url = card.url !== '@icon@' ? card.url : sessionStorage.getItem('CloudAvatar')
      if (card.url) {
        _imagestyle = {backgroundImage: `url('${card.url}')`}
      if (url) {
        url = url.replace(/@mywebsite@\//ig, window.GLOB.baseurl)
        _imagestyle.backgroundImage = `url('${url}')`
      } else {
        let index = card.uuid.match(/\d{1}/g)
        index = index.slice(-1)[0] % 5
        let demos = [demo1, demo2, demo3, demo4, demo5]
        _imagestyle = {backgroundImage: `url('${demos[index]}')`}
      }
      if (card.style && card.style.borderRadius) {
        _imagestyle.borderRadius = card.style.borderRadius
        _imagestyle.backgroundImage = `url('${demos[index]}')`
      }
      if (PicRadio[card.lenWidRadio]) {
@@ -123,7 +144,7 @@
    } else if (card.eleType === 'splitline') {
      let _borderWidth = card.borderWidth === undefined ? 1 : card.borderWidth
      return (
        <div style={{paddingTop: '1px'}}>
        <div style={{paddingTop: _borderWidth ? '1px' : '10px'}}>
          <div className="ant-mk-splitline" style={{borderColor: card.color, borderWidth: _borderWidth}}></div>
        </div>
      )
@@ -140,9 +161,10 @@
        </div>
      )
    } else if (card.eleType === 'video') {
      _style.overflow = 'hidden'
      return (
        <div>
          <Video card={card} value={card.url || 'http://qingqiumarket.cn/mkwms/Content/images/upload/20210104/trailer.mp4'}/>
        <div className="video-wrap">
          <Video card={card} poster={card.posterUrl || ''} value={card.url || 'http://qingqiumarket.cn/mkwms/Content/images/upload/20210104/trailer.mp4'}/>
        </div>
      )
    } else if (card.eleType === 'currentDate') {
@@ -152,7 +174,7 @@
        val = <><span style={_s}>{card.prefix || ''}</span>{moment().format(card.dateFormat)}<span style={_s}>{card.postfix || ''}</span></>
      }
      return (
        <div className="ant-mk-date">
        <div className="ant-mk-text line1" style={{height: card.innerHeight || 'auto'}}>
          {val}
        </div>
      )
@@ -162,10 +184,39 @@
        let _s = {fontSize: card.fixSize, color: card.fixColor, marginLeft: card.fixLeft, marginRight: card.fixRight}
        val = <><span style={_s}>{card.prefix || ''}</span>{card.formula}<span style={_s}>{card.postfix || ''}</span></>
      }
      return (
        <div className="ant-mk-date">
        <div className="ant-mk-text" style={{height: card.innerHeight || 'auto'}}>
          {val}
        </div>
      )
    } else if (card.eleType === 'tag') {
      let vals = []
      if (card.datatype === 'static') {
        vals = card.value.split(',').filter(Boolean)
      } else {
        vals = [card.field || '']
      }
      let _style = resetStyle(card.style)
      return (
        <div className="ant-mk-tag">
          {vals.map((val, index) => <span key={index} className="tag-item" style={_style}>{val}</span>)}
        </div>
      )
    } else if (card.eleType === 'color') {
      _style.overflow = 'hidden'
      let _bgstyle = {backgroundColor: card.value || '#1890ff'}
      if (PicRadio[card.lenWidRadio]) {
        _bgstyle.paddingTop = PicRadio[card.lenWidRadio]
      } else {
        _bgstyle.paddingTop = '100%'
      }
      return (
        <div style={_bgstyle}></div>
      )
    }
  }
@@ -173,14 +224,34 @@
  const clickComponent = (e) => {
    if (sessionStorage.getItem('style-control') === 'true' || sessionStorage.getItem('style-control') === 'cardcell') {
      e.stopPropagation()
      MKEmitter.emit('clickComponent', card, parent, 'cardcell')
      MKEmitter.emit('clickComponent', card.uuid, parent.uuid)
    }
  }
  let able = true
  if ((appType === 'mob' || appType === 'pc') && parent && (parent.setting.click === 'menu' || parent.setting.click === 'menus')) {
  // if ((appType === 'mob' || appType === 'pc') && parent && parent.setting.click === 'menu') {
  if ((appType === 'mob' || appType === 'pc') && parent.setting && (parent.setting.click === 'menu' || parent.setting.click === 'menus')) {
    able = false
  }
  let _style_ = null
  if (card.style && card.style.clear === 'left') {
    _style_ = {clear: 'left'}
  } else if (card.style && card.style.clear === 'right') {
    _style_ = {float: 'right'}
  }
  let mark = ['text', 'number', 'slider', 'sequence', 'formula', 'icon'].includes(card.eleType)
  if (parent.setting && parent.setting.cardRole === 'header') {
    mark = false
  } else if (card.eleType === 'formula' && card.eval === 'func') {
    mark = false
  }
  let className = 'ant-col card-cell ant-col-' + card.width
  if (card.noValue === 'hide') {
    className += ' no-value-hide'
  }
  return (
@@ -190,10 +261,10 @@
        <CopyOutlined className="copy" title="复制" onClick={() => copyCard(id)} />
        <CloseOutlined className="close" title="删除" onClick={() => delCard(id)} />
        <FontColorsOutlined className="style" title="调整样式" onClick={() => changeStyle(id)}/>
        {['text', 'number', 'slider', 'sequence', 'formula'].includes(card.eleType) ? <MarkColumn columns={fields} type={card.eleType} marks={card.marks} onSubmit={(vals) => updateMarks({...card, marks: vals})} /> : null }
        {mark ? <MarkColumn field={card.field || ''} columns={fields} type={card.eleType} marks={card.marks} onSubmit={(vals) => updateMarks({...card, marks: vals})} /> : null }
      </div>
    } trigger="hover">
      <div ref={node => drag(drop(node))} className={'ant-col card-cell ant-col-' + card.width}>
      <div ref={node => drag(drop(node))} style={_style_} className={className}>
        <div style={_style} onClick={clickComponent} onDoubleClick={() => able && editCard(id)} id={card.uuid}>
          {getContent()}
        </div>