import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Icon, Popover } from 'antd'
|
import { ExpandOutlined, ReloadOutlined } from '@ant-design/icons'
|
|
import asyncIconComponent from '@/utils/asyncIconComponent'
|
import getWrapForm from './options'
|
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 NormalForm = asyncIconComponent(() => import('@/components/normalform'))
|
|
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,
|
width: 24,
|
subtype: card.subtype,
|
wrap: { type: 'navbar', height: 50, title: 'NavBar', back: 'true', search: 'false', logout: 'false' },
|
style: {boxShadow: '0 0 3px #D9D9D9', shadowColor: '#D9D9D9', shadowBlur: '3px', paddingLeft: '10px', paddingRight: '10px', lineHeight: '2.8', fontSize: '18px' },
|
searchStyle: {}
|
}
|
|
if (card.config) {
|
let config = fromJS(card.config).toJS()
|
|
_card.wrap = config.wrap
|
_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)
|
MKEmitter.addListener('submitSearch', this.getSearch)
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
/**
|
* @description 组件销毁,清除state更新,清除快捷键设置
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('submitStyle', this.getStyle)
|
MKEmitter.removeListener('submitSearch', this.getSearch)
|
}
|
|
/**
|
* @description 卡片行外层信息更新(数据源,样式等)
|
*/
|
updateComponent = (component) => {
|
this.setState({
|
card: component
|
})
|
|
this.props.updateConfig(component)
|
}
|
|
getStyle = (comIds, style) => {
|
const { card } = this.state
|
|
if (comIds[0] !== card.uuid) return
|
|
let _card = fromJS(card).toJS()
|
|
if (comIds[1] === 'search') {
|
_card.searchStyle = style
|
} else {
|
_card.style = style
|
}
|
|
this.setState({
|
card: _card
|
})
|
|
this.props.updateConfig(_card)
|
}
|
|
changeStyle = () => {
|
const { card } = this.state
|
|
MKEmitter.emit('changeStyle', [card.uuid], ['font', 'background', 'border', 'padding', 'shadow'], card.style)
|
}
|
|
changeSearchStyle = () => {
|
const { card } = this.state
|
|
MKEmitter.emit('changeStyle', [card.uuid, 'search'], ['font', 'background', 'border'], card.searchStyle || {})
|
}
|
|
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)
|
} else {
|
MKEmitter.emit('changeEditMenu', {
|
MenuID: menu.property === 'linkmenu' ? menu.linkMenuId : menu.MenuID,
|
copyMenuId: menu.property === 'menu' ? menu.copyMenuId : '',
|
MenuNo: menu.MenuNo,
|
MenuName: menu.name,
|
})
|
}
|
}
|
|
getSearch = (config) => {
|
const { card } = this.state
|
|
if (card.uuid !== config.uuid) return
|
|
this.setState({
|
card: config
|
})
|
|
this.props.updateConfig(config)
|
}
|
|
setSearch = () => {
|
let card = fromJS(this.state.card).toJS()
|
|
if (!card.search) {
|
card.search = {
|
floor: 1,
|
setting: { type: 'title', field: '', title: '', focus: 'true', btn: 'hidden' },
|
groups: [],
|
fields: []
|
}
|
}
|
this.props.updateConfig(card)
|
MKEmitter.emit('changeSearch', card)
|
}
|
|
getWrapForms = () => {
|
const { wrap } = this.state.card
|
|
return getWrapForm(wrap)
|
}
|
|
updateWrap = (res) => {
|
this.updateComponent({...this.state.card, wrap: res})
|
}
|
|
render() {
|
const { card } = this.state
|
|
let right = null
|
if (card.wrap.logout === 'true') {
|
right = <Icon type="logout" />
|
}
|
if (card.wrap.scan === 'true') {
|
right = !right ? <ExpandOutlined /> : <Icon type="ellipsis" />
|
}
|
if (card.wrap.refresh === 'true') {
|
right = !right ? <ReloadOutlined /> : <Icon type="ellipsis" />
|
}
|
|
return (
|
<div className="normal-topbar-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">
|
<NormalForm title="导航栏设置" width={750} update={this.updateWrap} getForms={this.getWrapForms}>
|
<Icon type="edit" style={{color: '#1890ff'}} title="编辑"/>
|
</NormalForm>
|
<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="am-navbar">
|
<div className="am-navbar-left">
|
{card.wrap.back !== 'false' ? <Icon type="left" /> : null}
|
</div>
|
{card.wrap.type !== 'search' ?
|
<div className="am-navbar-title">{card.wrap.title || ''}</div> :
|
<div className="am-navbar-search" onDoubleClick={this.setSearch}>
|
<Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
|
<div className="mk-popover-control">
|
<Icon className="style" title="调整样式" onClick={this.changeSearchStyle} type="font-colors" />
|
</div>
|
} trigger="hover">
|
<div style={card.searchStyle} className="search-bar">
|
{card.search && card.search.setting.scan === 'true' ? <Icon type="scan" /> : <Icon type="search" />}
|
</div>
|
</Popover>
|
</div>
|
}
|
<div className="am-navbar-right">
|
{card.wrap.search === 'true' ? <Icon type="search" onDoubleClick={this.setSearch}/> : null}
|
{right}
|
</div>
|
</div>
|
</div>
|
)
|
}
|
}
|
|
export default NormalNavbar
|