king
2022-11-04 3c50bfdd8d605b3dd449adcb54cdf7f7c25d6c16
src/mob/mobshell/index.jsx
@@ -4,8 +4,6 @@
import { Empty, notification, Modal } from 'antd'
import Utils from '@/utils/utils.js'
import MKEmitter from '@/utils/events.js'
import MenuUtils from '@/utils/utils-custom.js'
import Card from './card'
import './index.scss'
@@ -18,6 +16,10 @@
    const _cards = update(cards, { $splice: [[index, 1], [atIndex, 0, card]] })
    handleList({...menu, components: _cards})
    setCards(_cards)
  }
  if (menu.components.length > cards.length) {
    setCards(menu.components)
  }
  
  const findCard = id => {
@@ -46,13 +48,10 @@
      })
    }
    let uuids = MenuUtils.getDelButtonIds(card)
    confirm({
      title: `确定删除《${card.name}》吗?`,
      title: `确定删除${card.name ? `《${card.name}》` : '组件'}吗?`,
      content: hasComponent ? '当前组件中含有子组件!' : '',
      onOk() {
        MKEmitter.emit('delButtons', uuids)
        const _cards = cards.filter(item => item.uuid !== card.uuid)
        handleList({...menu, components: _cards})
        setCards(_cards)
@@ -69,11 +68,54 @@
        return
      }
      let style = null
      if (item.component === 'search') { // 搜索组件不可重复添加
        if (cards.filter(card => card.type === 'topbar' && card.wrap.type !== 'navbar').length > 0) {
          notification.warning({
            top: 92,
            message: '导航栏使用了搜索,不可添加搜索组件!',
            duration: 5
          })
          return
        }
        if (cards.filter(card => card.type === 'search').length > 0) {
          notification.warning({
            top: 92,
            message: '搜索条件不可重复添加!',
            duration: 5
          })
          return
        }
      } else if (item.component === 'navbar') {
        if (cards.filter(card => card.type === 'navbar').length > 0) {
          notification.warning({
            top: 92,
            message: '菜单栏不可重复添加!',
            duration: 5
          })
          return
        }
        if (!menu.style.paddingBottom) {
          style = {...menu.style, paddingBottom: '50px'}
        }
      } else if (item.component === 'topbar') {
        if (cards.filter(card => card.type === 'topbar').length > 0) {
          notification.warning({
            top: 92,
            message: '导航栏不可重复添加!',
            duration: 5
          })
          return
        }
        if (!menu.style.paddingTop) {
          style = {...menu.style, paddingTop: '50px'}
        }
      } else if (item.component === 'officialAccount') {
        if (cards.filter(card => card.type === 'officialAccount').length > 0) {
          notification.warning({
            top: 92,
            message: '关注组件不可重复添加!',
            duration: 5
          })
          return
@@ -92,8 +134,15 @@
        editor: '富文本',
        code: '自定义',
        carousel: '轮播',
        dashboard: '仪表盘',
        form: '表单',
        card: '卡片'
        card: '卡片',
        navbar: '导航栏',
        menubar: '菜单栏',
        balcony: '浮动卡',
        timeline: '时间轴',
        officialAccount: '关注公众号',
        login: '登录'
      }
      let i = 1
      
@@ -111,7 +160,6 @@
        subtype: item.subtype,
        config: item.config,
        width: item.width || 24,
        dataName: Utils.getdataName(),
        name: name,
        floor: 1,   // 组件的层级
        isNew: true // 新添加标志,用于初始化
@@ -127,16 +175,42 @@
      }
      const { index: overIndex } = findCard(`${targetId}`)
      const _cards = update(cards, { $splice: [[overIndex + 1, 0, newcard]] })
      let _cards = update(cards, { $splice: [[overIndex + 1, 0, newcard]] })
      let Topbar = null
      let Navbar = null
      _cards = _cards.filter(item => {
        if (item.type === 'topbar') {
          Topbar = item
        } else if (item.type === 'navbar') {
          Navbar = item
        }
      handleList({...menu, components: _cards})
        return item.type !== 'topbar' && item.type !== 'navbar'
      })
      if (Topbar) {
        _cards.unshift(Topbar)
      }
      if (Navbar) {
        _cards.push(Navbar)
      }
      if (style) {
        handleList({...menu, style, components: _cards})
      } else {
        handleList({...menu, components: _cards})
      }
      setCards(_cards)
    }
  })
  let style = JSON.stringify(menu.style || {})
  style = style.replace(/@mywebsite@\//ig, window.GLOB.baseurl)
  style = JSON.parse(style)
  return (
    <div ref={drop} className="mob-shell-inner" id="menu-shell-inner" style={menu.style}>
      <div className="ant-row">
    <div ref={drop} className="mob-shell-inner" id="menu-shell-inner">
      <div className="ant-row" style={style}>
        {cards.map(card => (
          <Card
            id={card.uuid}
@@ -148,10 +222,10 @@
            updateConfig={updateConfig}
          />
        ))}
        {cards.length === 0 ?
          <Empty description="请添加组件" /> : null
        }
      </div>
      {cards.length === 0 ?
        <Empty description="请添加组件" /> : null
      }
    </div>
  )
}