king
2019-12-08 8c14d194348465710826ed5740173e64bd803f71
src/templates/modalconfig/dragelement/index.jsx
@@ -7,14 +7,22 @@
import ItemTypes from './itemtypes'
import './index.scss'
const Container = ({list, setting, placeholder, handleList, handleForm, closeForm }) => {
const Container = ({list, group, setting, placeholder, handleList, handleForm, closeForm }) => {
  let target = null
  const [cards, setCards] = useState(list)
  const moveCard = (id, atIndex) => {
    const { card, index } = findCard(id)
    if (!card) return
    const _cards = update(cards, { $splice: [[index, 1], [atIndex, 0, card]] })
    setCards(_cards)
    handleList(_cards)
    if (!group) {
      handleList(_cards)
    } else {
      handleList(_cards, group)
    }
  }
  const findCard = id => {
@@ -42,6 +50,13 @@
  const [, drop] = useDrop({
    accept: ItemTypes.form,
    drop(item) {
      if (item.hasOwnProperty('originalIndex') && group) {
        const { card } = findCard(item.id)
        if (!card) {
          handleList(cards, group, item.id)
        }
      }
      if (item.hasOwnProperty('originalIndex')) {
        return
      }
@@ -62,14 +77,14 @@
      newcard.orderBy = ''
      newcard.orderType = 'asc'
      
      let indexes = cards.map(car => {return car.id})
      let newid = 0
      while (indexes.includes(newid)) {
        newid++
      }
      newcard.id = newid
      // let indexes = cards.map(car => {return car.id})
      // let newid = 0
      // while (indexes.includes(newid)) {
      //   newid++
      // }
      newcard.id = Utils.getuuid()
      let targetId = indexes.length > 0 ? indexes[indexes.length - 1] : 0
      let targetId = cards.length > 0 ? cards[cards.length - 1].id : 0
      if (target) {
        targetId = target.id
      }
@@ -85,7 +100,13 @@
      const _cards = update(cards, { $splice: [[targetIndex, 0, newcard]] })
      setCards(_cards)
      handleList(_cards)
      if (!group) {
        handleList(_cards)
      } else {
        handleList(_cards, group)
      }
      target = null
    }
  })