| | |
| | | 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' |
| | | |
| | |
| | | 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 => { |
| | |
| | | }) |
| | | } |
| | | |
| | | 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) |
| | |
| | | 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 |
| | |
| | | editor: '富文本', |
| | | code: '自定义', |
| | | carousel: '轮播', |
| | | dashboard: '仪表盘', |
| | | form: '表单', |
| | | card: '卡片' |
| | | card: '卡片', |
| | | navbar: '导航栏', |
| | | menubar: '菜单栏', |
| | | balcony: '浮动卡', |
| | | timeline: '时间轴', |
| | | officialAccount: '关注公众号', |
| | | login: '登录' |
| | | } |
| | | let i = 1 |
| | | |
| | |
| | | subtype: item.subtype, |
| | | config: item.config, |
| | | width: item.width || 24, |
| | | dataName: Utils.getdataName(), |
| | | name: name, |
| | | floor: 1, // 组件的层级 |
| | | isNew: true // 新添加标志,用于初始化 |
| | |
| | | } |
| | | |
| | | 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} |
| | |
| | | updateConfig={updateConfig} |
| | | /> |
| | | ))} |
| | | {cards.length === 0 ? |
| | | <Empty description="请添加组件" /> : null |
| | | } |
| | | </div> |
| | | {cards.length === 0 ? |
| | | <Empty description="请添加组件" /> : null |
| | | } |
| | | </div> |
| | | ) |
| | | } |