king
2022-12-09 cb9ade2afd2a367ad767bc605ab7086c695dd010
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
 
import asyncComponent from '@/utils/asyncComponent'
import './index.scss'
 
const SearchComponent = asyncComponent(() => import('@/tabviews/zshare/topSearch'))
 
class NormalHeader extends Component {
  static propTpyes = {
    BID: PropTypes.any,        // 上级主键值
    config: PropTypes.object,  // 配置信息
    refresh: PropTypes.func    // 条件刷新
  }
 
  state = {
    title: '',     // 标题
    show: false,   // 是否显示搜索
  }
 
  UNSAFE_componentWillMount () {
    const { config } = this.props
 
    this.setState({
      title: config.plot ? config.plot.title : config.wrap.title,
      show: !['normaltable', 'propcard', 'editable'].includes(config.subtype) && config.search && config.search.length > 0
    })
  }
 
  shouldComponentUpdate (nextProps, nextState) { return false }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  render() {
    const { config, BID } = this.props
    const { title, show } = this.state
 
    if (!title && !show) return null
 
    return (
      <div className={'normal-header' + (show ? ' header-search' : '')} style={config.headerStyle}>
        <span className="title">{title}</span>
        {show ? <SearchComponent config={config} BID={BID} refreshdata={this.props.refresh}/> : null}
      </div>
    )
  }
}
 
export default NormalHeader