import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Icon, Popover, Menu, Button } from 'antd'
|
|
import asyncIconComponent from '@/utils/asyncIconComponent'
|
|
import MKEmitter from '@/utils/events.js'
|
import zhCN from '@/locales/zh-CN/model.js'
|
import enUS from '@/locales/en-US/model.js'
|
import './index.scss'
|
|
const WrapComponent = asyncIconComponent(() => import('./wrapsetting'))
|
const MenuComponent = asyncIconComponent(() => import('./menusetting'))
|
const LinkComponent = asyncIconComponent(() => import('./linksetting'))
|
|
const { SubMenu } = Menu
|
|
class NormalNavbar extends Component {
|
static propTpyes = {
|
card: PropTypes.object,
|
deletecomponent: PropTypes.func,
|
updateConfig: PropTypes.func,
|
}
|
|
state = {
|
dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
card: null,
|
back: false
|
}
|
|
UNSAFE_componentWillMount () {
|
const { card } = this.props
|
|
if (card.isNew) {
|
let _card = {
|
uuid: card.uuid,
|
type: card.type,
|
floor: card.floor,
|
dataName: card.dataName || '',
|
width: card.width || 24,
|
name: card.name,
|
subtype: card.subtype,
|
wrap: { name: card.name, width: card.width || 1200 },
|
logoStyle: { width: '100px' },
|
style: { },
|
links: [],
|
menus: [],
|
}
|
|
if (card.config) {
|
let config = fromJS(card.config).toJS()
|
|
_card.wrap = config.wrap
|
_card.wrap.name = card.name
|
_card.style = config.style
|
}
|
|
this.setState({
|
card: _card
|
})
|
this.props.updateConfig(_card)
|
} else {
|
this.setState({
|
card: fromJS(card).toJS()
|
})
|
}
|
}
|
|
componentDidMount () {
|
MKEmitter.addListener('submitStyle', this.getStyle)
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
/**
|
* @description 组件销毁,清除state更新,清除快捷键设置
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('submitStyle', this.getStyle)
|
}
|
|
/**
|
* @description 卡片行外层信息更新(数据源,样式等)
|
*/
|
updateComponent = (component) => {
|
this.setState({
|
card: component
|
})
|
|
component.width = component.wrap.width
|
component.name = component.wrap.name
|
|
this.props.updateConfig(component)
|
}
|
|
getStyle = (comIds, style) => {
|
const { card } = this.state
|
|
if (comIds[0] !== card.uuid) return
|
|
let _card = {...card}
|
if (comIds.length === 1) {
|
_card = {...card, style}
|
} else if (comIds[1] === 'logo') {
|
_card = {...card, logoStyle: style}
|
}
|
|
this.setState({
|
card: _card
|
})
|
|
this.props.updateConfig(_card)
|
}
|
|
changeStyle = () => {
|
const { card } = this.state
|
|
MKEmitter.emit('changeStyle', [card.uuid], ['font', 'background', 'shadow'], card.style)
|
}
|
|
changeLogoStyle = () => {
|
const { card } = this.state
|
|
MKEmitter.emit('changeStyle', [card.uuid, 'logo'], ['width', 'margin'], card.logoStyle)
|
}
|
|
clickComponent = (e) => {
|
if (sessionStorage.getItem('style-control') === 'true' || sessionStorage.getItem('style-control') === 'component') {
|
e.stopPropagation()
|
MKEmitter.emit('clickComponent', this.state.card)
|
}
|
}
|
|
changeMenu = (menu) => {
|
if (menu.property === 'link') {
|
window.open(menu.link)
|
return
|
}
|
MKEmitter.emit('changeEditMenu', {
|
MenuID: menu.property === 'linkmenu' ? menu.linkMenuId : menu.MenuID,
|
copyMenuId: menu.property === 'menu' ? menu.copyMenuId : '',
|
MenuNo: menu.MenuNo,
|
MenuName: menu.name,
|
})
|
}
|
|
changeLogoMenu = () => {
|
const { card } = this.state
|
|
if (card.wrap.property === 'linkmenu') {
|
MKEmitter.emit('changeEditMenu', {
|
MenuID: card.wrap.linkmenu,
|
copyMenuId: '',
|
MenuNo: '',
|
MenuName: ''
|
})
|
}
|
}
|
|
render() {
|
const { card } = this.state
|
|
return (
|
<div className="normal-navbar-edit-box" style={card.style} onClick={this.clickComponent} id={card.uuid}>
|
<Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
|
<div className="mk-popover-control">
|
<MenuComponent config={card} updateConfig={this.updateComponent} />
|
<LinkComponent config={card} updateConfig={this.updateComponent} />
|
<WrapComponent config={card} updateConfig={this.updateComponent} />
|
<Icon className="style" title="调整样式" onClick={this.changeStyle} type="font-colors" />
|
<Icon className="close" title="删除组件" type="delete" onClick={() => this.props.deletecomponent(card.uuid)} />
|
</div>
|
} trigger="hover">
|
<Icon type="tool" />
|
</Popover>
|
<div className="navbar-wrap" style={{width: card.wrap.width + 'px', height: card.wrap.height + 'px', lineHeight: card.wrap.height + 'px'}}>
|
{card.wrap.logo ? <Popover overlayClassName="mk-popover-control-wrap top-menu-popover" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
|
<div className="mk-popover-control">
|
<Icon className="style" title="调整样式" onClick={this.changeLogoStyle} type="font-colors" />
|
</div>
|
} trigger="hover">
|
<div className={'logo' + (card.wrap.logolink ? ' pointer' : '')} style={card.logoStyle} onDoubleClick={this.changeLogoMenu}><img src={card.wrap.logo} alt=""/></div>
|
</Popover> : null}
|
<div className="menu">
|
<Menu mode="horizontal">
|
{card.menus.map(fst => {
|
if (fst.property === 'classify' && fst.sublist.length > 0) {
|
return (
|
<SubMenu title={fst.name} key={fst.MenuID} popupClassName="normal-navbar-submenu">
|
{fst.sublist.map(scd => {
|
if (scd.property === 'classify' && scd.sublist.length > 0) {
|
return (
|
<Menu.ItemGroup key={scd.MenuID} title={scd.name}>
|
{scd.sublist.map(thd => {
|
return (
|
<Menu.Item key={thd.MenuID} >
|
<span onClick={(e) => e.stopPropagation()} onDoubleClick={() => this.changeMenu(thd)}>{thd.name}</span>
|
</Menu.Item>
|
)
|
})}
|
</Menu.ItemGroup>
|
)
|
} else {
|
return (
|
<Menu.Item key={scd.MenuID} onClick={(e) => e.stopPropagation()}>
|
<span onClick={(e) => e.stopPropagation()} onDoubleClick={() => this.changeMenu(scd)}>{scd.name}</span>
|
</Menu.Item>
|
)
|
}
|
})}
|
</SubMenu>
|
)
|
} else {
|
return (
|
<Menu.Item key={fst.MenuID}>
|
<span onClick={(e) => e.stopPropagation()} onDoubleClick={() => this.changeMenu(fst)}>{fst.name}</span>
|
</Menu.Item>
|
)
|
}
|
})}
|
</Menu>
|
</div>
|
<div className="link">
|
{card.links.map(link => {
|
return <Button type="link" key={link.MenuID} onDoubleClick={() => this.changeMenu(link)}>{link.name}</Button>
|
})}
|
</div>
|
</div>
|
</div>
|
)
|
}
|
}
|
|
export default NormalNavbar
|