king
4 天以前 047dbd742341e268ca772eda8d2ff0b6ba09cb44
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React from 'react'
import { useDrag, useDrop } from 'react-dnd'
import { EditOutlined, CloseOutlined } from '@ant-design/icons'
import ItemTypes from './itemtypes'
import MkIcon from '@/components/mk-icon'
import './index.scss'
 
const Card = ({ id, card, moveCard, findCard, editCard, closeCard }) => {
  const originalIndex = findCard(id).index
  const [{ isDragging }, drag] = useDrag({
    item: { type: ItemTypes.CARD, id, originalIndex },
    collect: monitor => ({
      isDragging: monitor.isDragging(),
    }),
  })
  const [, drop] = useDrop({
    accept: ItemTypes.CARD,
    canDrop: () => true,
    drop({ id: draggedId }) {
      if (draggedId !== id) {
        const { index: overIndex } = findCard(id)
        moveCard(draggedId, overIndex)
      }
    },
  })
  const opacity = isDragging ? 0.5 : 1
 
  const edit = () => {
    editCard(id)
  }
 
  const close = () => {
    closeCard(id)
  }
 
  if (card.level === 'second') {
    return (
      <div className="side-card" style={{ opacity }}>
        <div ref={node => drag(drop(node))}>
          {card.PageParam && card.PageParam.Icon && <MkIcon type={card.PageParam.Icon} />}
          {card.MenuName}
        </div>
        <EditOutlined className="edit" onClick={edit} />
        <CloseOutlined className="close" onClick={close} />
      </div>
    )
  } else {
    return (
      <div className="side-card" style={{ opacity }}>
        <div ref={node => drag(drop(node))}>
          {card.MenuName}
        </div>
        {/* 自定义模板,在新页面编辑 */}
        {!card.forbidden ? <EditOutlined className="edit" onClick={edit} /> : null}
        {card.forbidden && card.type === 'CustomPage' ? <EditOutlined className="edit" style={{color: '#959595', cursor: 'not-allowed'}} title="会员等级不够,无开发权限。"/> : null}
        <CloseOutlined className="close" onClick={close} />
      </div>
    )
  }
}
export default Card