import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Popover } from 'antd'
|
import { FontColorsOutlined, SearchOutlined } from '@ant-design/icons'
|
|
import asyncComponent from '@/utils/asyncComponent'
|
import MKEmitter from '@/utils/events.js'
|
import { resetStyle } from '@/utils/utils-custom.js'
|
import './index.scss'
|
|
const SearchComponent = asyncComponent(() => import('@/menu/components/share/searchcomponent'))
|
|
class NormalHeader extends Component {
|
static propTpyes = {
|
hideSearch: PropTypes.any, // 隐藏搜索条件
|
config: PropTypes.object, // 配置信息
|
updateComponent: PropTypes.func // 配置更新
|
}
|
|
state = {
|
appType: sessionStorage.getItem('appType')
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.props.config), fromJS(nextProps.config))
|
}
|
|
/**
|
* @description 组件销毁,清除state更新,清除快捷键设置
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
getStyle = (style) => {
|
if (!style.borderBottomWidth) {
|
style.borderBottomWidth = '0px'
|
}
|
|
let _config = {...this.props.config, headerStyle: style}
|
|
this.props.updateComponent(_config)
|
}
|
|
changeStyle = () => {
|
const { config } = this.props
|
|
let options = ['font', 'border', 'background', 'padding']
|
|
MKEmitter.emit('changeStyle', options, config.headerStyle, this.getStyle)
|
}
|
|
render() {
|
const { config, hideSearch } = this.props
|
|
let title = ''
|
let show = true
|
|
if (config.plot) {
|
title = config.plot.title
|
} else if (config.type === 'group') {
|
title = config.setting.title || ''
|
} else if (config.wrap) {
|
title = config.wrap.title || ''
|
}
|
|
if (!title && (!config.search || config.search.length === 0 || hideSearch === 'true')) {
|
show = false
|
}
|
let _style = resetStyle(config.headerStyle)
|
|
let _s = {display: 'block', flex: 1}
|
if (show && ((config.wrap && config.wrap.searchable === 'true') || (hideSearch !== 'true' && config.search && config.search.length))) {
|
_s = null
|
}
|
|
return (
|
<div className={'normal-header' + (!show ? ' hidden' : '') + (config.wrap && config.wrap.searchable === 'true' ? ' tree-search' : '')} style={_style}>
|
<Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
|
<div className="mk-popover-control">
|
<FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle}/>
|
</div>
|
} trigger="hover">
|
<span className="title" style={_s}>{title}</span>
|
</Popover>
|
{config.wrap && config.wrap.searchable === 'true' ? <span className="ant-input-search ant-input-affix-wrapper"><span className="ant-input-suffix"><SearchOutlined /></span></span> : null}
|
{hideSearch !== 'true' && config.search ? <SearchComponent config={config} updatesearch={this.props.updateComponent}/> : null}
|
</div>
|
)
|
}
|
}
|
|
export default NormalHeader
|