| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Modal, Popover, Icon, Col } from 'antd' |
| | | import { Popover, Col } from 'antd' |
| | | import { SwapOutlined, ArrowLeftOutlined, ArrowRightOutlined, EditOutlined, FontColorsOutlined, DeleteOutlined, RightOutlined } from '@ant-design/icons' |
| | | |
| | | import asyncIconComponent from '@/utils/asyncIconComponent' |
| | | import zhCN from '@/locales/zh-CN/model.js' |
| | | import enUS from '@/locales/en-US/model.js' |
| | | import SettingForm from './settingform' |
| | | import Utils from '@/utils/utils.js' |
| | | import getSettingForm from './options' |
| | | import { resetStyle } from '@/utils/utils-custom.js' |
| | | import MkIcon from '@/components/mk-icon' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import './index.scss' |
| | | |
| | | const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent')) |
| | | const NormalForm = asyncIconComponent(() => import('@/components/normalform')) |
| | | |
| | | class MenuBoxComponent extends Component { |
| | | static propTpyes = { |
| | | offset: PropTypes.any, // 偏移量 |
| | | cards: PropTypes.object, // 卡片行配置信息 |
| | | card: PropTypes.object, // 卡片配置信息 |
| | | move: PropTypes.func, // 卡片移动 |
| | |
| | | } |
| | | |
| | | state = { |
| | | dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | card: null, // 卡片信息,包括正反面 |
| | | formlist: null, // 设置表单信息 |
| | | visible: false, // 模态框控制 |
| | | card: null |
| | | } |
| | | |
| | | /** |
| | | * @description 搜索条件初始化 |
| | | */ |
| | | UNSAFE_componentWillMount () { |
| | | const { card } = this.props |
| | | |
| | |
| | | }) |
| | | } |
| | | |
| | | componentDidMount () { |
| | | MKEmitter.addListener('submitStyle', this.getStyle) |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | | const { cards } = this.props |
| | | |
| | | return !is(fromJS(cards.wrap), fromJS(nextProps.cards.wrap)) || !is(fromJS(this.state), fromJS(nextState)) |
| | | return !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | |
| | | /** |
| | |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | MKEmitter.removeListener('submitStyle', this.getStyle) |
| | | } |
| | | |
| | | getStyle = (comIds, style) => { |
| | | const { cards } = this.props |
| | | getStyle = (style) => { |
| | | const { card } = this.state |
| | | |
| | | if (comIds.length !== 2 || comIds[0] !== cards.uuid || comIds[1] !== card.uuid) return |
| | | |
| | | let _card = fromJS(card).toJS() |
| | | _card.style = style |
| | |
| | | } |
| | | |
| | | changeStyle = () => { |
| | | const { cards } = this.props |
| | | const { card } = this.state |
| | | |
| | | let _style = card.style ? fromJS(card.style).toJS() : {} |
| | | let options = ['font', 'border', 'padding'] |
| | | let options = ['font', 'border', 'padding', 'margin', 'background'] |
| | | |
| | | MKEmitter.emit('changeStyle', [cards.uuid, card.uuid], options, _style) |
| | | MKEmitter.emit('changeStyle', options, _style, this.getStyle) |
| | | } |
| | | |
| | | settingSubmit = () => { |
| | | getSettingForms = () => { |
| | | const { cards } = this.props |
| | | const { card } = this.state |
| | | |
| | | this.settingRef.handleConfirm().then(res => { |
| | | this.setState({ |
| | | visible: false, |
| | | card: {...card, setting: res} |
| | | }) |
| | | return getSettingForm(card.setting, cards.columns || []) |
| | | } |
| | | |
| | | this.props.updateElement({...card, setting: res}) |
| | | }) |
| | | updateSetting = (res) => { |
| | | const { card } = this.state |
| | | let _card = {...card, setting: res} |
| | | |
| | | if (card.setting.type === 'menu' && _card.setting.type !== 'menu') { |
| | | _card.oriuuid = _card.uuid |
| | | _card.uuid = Utils.getuuid() |
| | | } |
| | | |
| | | this.setState({ card: _card }) |
| | | this.props.updateElement(_card) |
| | | } |
| | | |
| | | changeMenu = () => { |
| | |
| | | window.open(card.setting.linkurl) |
| | | } else { |
| | | MKEmitter.emit('changeEditMenu', { |
| | | fixed: card.setting.type === 'menu', |
| | | MenuID: card.setting.type === 'linkmenu' ? card.setting.linkMenuId : card.uuid, |
| | | copyMenuId: card.setting.type === 'menu' ? card.setting.copyMenuId : '', |
| | | MenuNo: card.setting.MenuNo || '', |
| | | clearMenu: card.setting.clearMenu || 'true', |
| | | // MenuNo: card.setting.MenuNo || '', |
| | | MenuName: card.setting.name, |
| | | }) |
| | | } |
| | | } |
| | | |
| | | render() { |
| | | const { cards, offset } = this.props |
| | | const { card, visible, dict } = this.state |
| | | const { card } = this.state |
| | | |
| | | let _style = {...card.style} |
| | | |
| | | if (_style.shadow) { |
| | | _style.boxShadow = '0 0 4px ' + _style.shadow |
| | | } |
| | | |
| | | _style = resetStyle(_style) |
| | | |
| | | return ( |
| | | <Col span={card.setting.width || 6} offset={offset || 0}> |
| | | <Col span={card.setting.width || 6}> |
| | | <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ |
| | | <div className="mk-popover-control"> |
| | | <Icon className="edit" title="编辑" type="edit" onClick={() => this.setState({visible: true})} /> |
| | | <NormalForm title="菜单编辑" width={900} update={this.updateSetting} getForms={this.getSettingForms}> |
| | | <EditOutlined style={{color: '#1890ff'}} title="编辑"/> |
| | | </NormalForm> |
| | | <CopyComponent type="menucell" card={card}/> |
| | | <Icon className="style" title="调整样式" onClick={this.changeStyle} type="font-colors" /> |
| | | <FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle}/> |
| | | <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ |
| | | <div className="mk-popover-control"> |
| | | <Icon className="plus" title="左移" type="arrow-left" onClick={() => this.props.move(card, 'left')} /> |
| | | <Icon className="close" title="右移" type="arrow-right" onClick={() => this.props.move(card, 'right')} /> |
| | | <ArrowLeftOutlined className="plus" title="左移" onClick={() => this.props.move(card, 'left')} /> |
| | | <ArrowRightOutlined className="close" title="右移" onClick={() => this.props.move(card, 'right')} /> |
| | | </div> |
| | | } trigger="hover" getPopupContainer={() => document.getElementById(card.uuid + 'swap')}> |
| | | <Icon type="swap" id={card.uuid + 'swap'}/> |
| | | <SwapOutlined id={card.uuid + 'swap'}/> |
| | | </Popover> |
| | | <Icon className="close" title="删除菜单" type="delete" onClick={() => this.props.deleteElement(card)} /> |
| | | <DeleteOutlined className="close" title="删除菜单" onClick={() => this.props.deleteElement(card)} /> |
| | | </div> |
| | | } trigger="hover"> |
| | | <div className="menu-item" onDoubleClick={() => this.changeMenu()} style={_style}> |
| | | {card.setting.sign === 'icon' ? <div className="menu-sign"> |
| | | <Icon style={{ |
| | | <MkIcon style={{ |
| | | fontSize: card.setting.iconFont || 20, |
| | | padding: card.setting.padding, |
| | | background: card.setting.background, |
| | | color: card.setting.color |
| | | }} type={card.setting.icon}/> |
| | | color: card.setting.color, |
| | | borderRadius: card.setting.borderRadius || '15%', |
| | | opacity: !card.setting.icon ? 0 : 1 |
| | | }} type={card.setting.icon || 'cloud'}/> |
| | | {card.setting.tip ? <sup className="am-badge-text"></sup> : null} |
| | | </div> : <div className="menu-sign"> |
| | | <img style={{width: card.setting.imgWidth, height: card.setting.imgWidth}} src={card.setting.url} alt=""/> |
| | | <img style={{width: card.setting.imgWidth, height: card.setting.imgWidth, borderRadius: card.setting.borderRadius || '15%'}} src={card.setting.url} alt=""/> |
| | | {card.setting.tip ? <sup className="am-badge-text"></sup> : null} |
| | | </div>} |
| | | <div className="menu-name">{card.setting.name}</div> |
| | | <div className="menu-name" style={{opacity: !card.setting.name ? 0 : 1}}>{card.setting.name || '明科'}</div> |
| | | <RightOutlined className="menu-right" /> |
| | | {!card.setting.name || (card.setting.type === 'linkmenu' && card.setting.linkMenuId === '') ? <NormalForm title="菜单编辑" width={900} update={this.updateSetting} cancel={() => this.props.deleteElement(card, 'direct')} getForms={this.getSettingForms}> |
| | | <span id={card.uuid}></span> |
| | | </NormalForm> : null} |
| | | </div> |
| | | </Popover> |
| | | <Modal |
| | | wrapClassName="popview-modal" |
| | | title={'菜单设置'} |
| | | visible={visible} |
| | | width={800} |
| | | maskClosable={false} |
| | | okText={dict['model.submit']} |
| | | onOk={this.settingSubmit} |
| | | onCancel={() => { this.setState({ visible: false }) }} |
| | | destroyOnClose |
| | | > |
| | | <SettingForm |
| | | dict={dict} |
| | | cards={cards} |
| | | setting={card.setting} |
| | | inputSubmit={this.settingSubmit} |
| | | wrappedComponentRef={(inst) => this.settingRef = inst} |
| | | /> |
| | | </Modal> |
| | | </Col> |
| | | ) |
| | | } |