king
2020-11-26 89fb1308d92e10a27cf8f91f4dd766eb38976e12
src/templates/formtabconfig/dragelement/index.jsx
@@ -8,8 +8,7 @@
import ItemTypes from './itemtypes'
import './index.scss'
const Container = ({list, type, groupId, setting, placeholder, handleList, handleMenu, deleteMenu, copyElement, profileMenu }) => {
  let target = null
const Container = ({list, type, groupId, setting, placeholder, handleList, handleMenu, deleteMenu, profileMenu }) => {
  const [cards, setCards] = useState(list)
  const moveCard = (id, atIndex) => {
    const { card, index } = findCard(id)
@@ -40,6 +39,36 @@
    const { card } = findCard(id)
    handleMenu(card)
  }
  const copyCard = id => {
    const { card } = findCard(id)
    let _card = JSON.parse(JSON.stringify(card))
    _card.originUuid = _card.uuid
    _card.uuid = Utils.getuuid()
    _card.iscopy = true
    _card.focus = true
    // 复制到剪切板
    let oInput = document.createElement('input')
    let val = JSON.parse(JSON.stringify(_card))
    val.copyType = 'form'
    val.uuid = Utils.getuuid()
    delete val.originUuid
    delete val.iscopy
    oInput.value = window.btoa(window.encodeURIComponent(JSON.stringify(val)))
    document.body.appendChild(oInput)
    oInput.select()
    document.execCommand('Copy')
    oInput.className = 'oInput'
    oInput.style.display = 'none'
    document.body.removeChild(oInput)
    handleMenu(_card)
  }
  
  const profileCard = id => {
    const { card } = findCard(id)
@@ -49,21 +78,6 @@
  const delCard = id => {
    const { card } = findCard(id)
    deleteMenu({card: card, type: type})
  }
  const copyCard = id => {
    const { card } = findCard(id)
    let copycard = JSON.parse(JSON.stringify(card))
    copycard.uuid = Utils.getuuid()
    copycard.origin = false
    copycard.label = copycard.label + '(copy)'
    copycard.focus = true
    copyElement(copycard)
  }
  const hasDrop = (item) => {
    target = item
  }
  const [, drop] = useDrop({
@@ -113,7 +127,6 @@
        newcard.linkTab = ''
        newcard.class = 'default'
        newcard.intertype = 'inner'
        newcard.method = 'POST'
        newcard.position = 'toolbar'
        newcard.execSuccess = 'grid'
        newcard.execError = 'never'
@@ -122,24 +135,26 @@
        newcard.verify = null
      }
      
      let targetId = cards.length > 0 ? cards[cards.length - 1].uuid : 0
      if (target) {
        targetId = target.uuid
      let targetId = ''
      if (item.dropTargetId) {
        targetId = item.dropTargetId
        delete item.dropTargetId
      } else if (cards.length > 0) {
        targetId = cards[cards.length - 1].uuid
      }
      const { index: overIndex } = findCard(`${targetId}`)
      let targetIndex = overIndex
      const _cards = update(cards, { $splice: [[overIndex + 1, 0, newcard]] })
      targetIndex++
      const _cards = update(cards, { $splice: [[targetIndex, 0, newcard]] })
      handleList(type, _cards, newcard, groupId)
      target = null
    }
  })
  let _width = (setting && setting.width) || 100
  
  return (
    <div ref={drop} className="ant-row">
    <div ref={drop} className="ant-row" style={type === 'search' ? {margin: '0 auto', width: _width + '%'} : {}}>
      {type === 'action' && cards.map(card => (
        <Card
          key={card.uuid}
@@ -149,10 +164,8 @@
          moveCard={moveCard}
          editCard={editCard}
          delCard={delCard}
          copyCard={copyCard}
          profileCard={profileCard}
          findCard={findCard}
          hasDrop={hasDrop}
        />
      ))}
      {type === 'search' && cards.map(card => (
@@ -166,8 +179,8 @@
            moveCard={moveCard}
            editCard={editCard}
            delCard={delCard}
            copyCard={copyCard}
            findCard={findCard}
            hasDrop={hasDrop}
          />
        </Col>
      ))}