king
2021-09-18 d3a618f09ab510de5c4ca772c44f60c218b61964
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Popover, Icon } from 'antd'
 
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 = {
    defaultshow: PropTypes.any,      // 标题与搜索条件不存在时隐藏
    hideSearch: PropTypes.any,       // 隐藏搜索条件
    config: PropTypes.object,        // 配置信息
    updateComponent: PropTypes.func  // 配置更新
  }
 
  state = {
    appType: sessionStorage.getItem('appType')
  }
 
  componentDidMount () {
    MKEmitter.addListener('submitStyle', this.getStyle)
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props.config), fromJS(nextProps.config))
  }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('submitStyle', this.getStyle)
  }
 
  getStyle = (comIds, style) => {
    const { config } = this.props
 
    if (comIds[0] !== config.uuid || comIds[1] !== 'header') return
 
    let _config = {...config, headerStyle: style}
    
    this.props.updateComponent(_config)
  }
 
  changeStyle = () => {
    const { config } = this.props
 
    // MKEmitter.emit('changeStyle', [config.uuid, 'header'], ['font', 'height', 'border'], config.headerStyle)
    MKEmitter.emit('changeStyle', [config.uuid, 'header'], ['font', 'border'], config.headerStyle)
  }
 
  render() {
    const { config, defaultshow, hideSearch } = this.props
    const { appType } = this.state
 
    let title = config.plot ? config.plot.title : config.wrap.title
    let show = true
 
    if (!title && appType === 'mob' && config.type === 'card' && config.subtype === 'datacard' && config.action && config.action.length) {
      title = ' '
    }
 
    if (defaultshow === 'hidden') {
      if (!title && (!config.search || config.search.length === 0)) {
        show = false
      }
    }
    let _style = resetStyle(config.headerStyle)
 
    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">
            <Icon className="style" title="调整样式" onClick={this.changeStyle} type="font-colors" />
          </div>
        } trigger="hover">
          <span className="title">{title}</span>
        </Popover>
        {config.wrap && config.wrap.searchable === 'true' ? <span className="ant-input-search ant-input-affix-wrapper"><span className="ant-input-suffix"><Icon type="search" /></span></span> : null}
        {hideSearch !== 'true' && config.search ? <SearchComponent config={config} updatesearch={this.props.updateComponent}/> : null}
      </div>
    )
  }
}
 
export default NormalHeader