king
2022-06-18 fe21d23b147ed5cec22b4f76a88840b05495d4ad
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
62
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 : 1
 
  const edit = () => {
    editCard(id)
  }
 
  const close = () => {
    closeCard(id)
  }
 
  let _param = ''
  if (card.type === 'CustomPage') {
    _param = {
      MenuType: 'custom',
      MenuId: card.MenuID,
      ParentId: card.ParentId,
      MenuName: card.MenuName,
      MenuNo: card.MenuNo
    }
    _param = window.btoa(window.encodeURIComponent(JSON.stringify(_param)))
  }
 
  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>
      {/* 自定义模板,在新页面编辑 */}
      {!card.forbidden && card.type !== 'CustomPage' ? <EditOutlined className="edit" onClick={edit} /> : null}
      {!card.forbidden && card.type === 'CustomPage' ? <EditOutlined className="edit" onClick={() => {window.open(`#/menudesign/${_param}`)}}/> : 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