king
2019-09-07 c2a10e60d47895a58007201fd1fa88e453ddd653
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import {connect} from 'react-redux'
import { is, fromJS } from 'immutable'
import {Tabs, Icon} from 'antd'
import {modifyTabview} from '@/store/action'
import './tabview.scss'
 
class Header extends Component {
  static propTpyes = {
    tabviews: PropTypes.array
  }
 
  state = {
    selectedTabId: '',
    iFrameHeight: 0
  }
 
  handleTabview (menu) {
    let tabs = JSON.parse(JSON.stringify(this.props.tabviews))
    tabs = tabs.filter(tab => {
      if (tab.MenuID === this.state.selectedTabId) {
        tab.selected = true
      } else {
        tab.selected = false
      }
      return tab.MenuID !== menu.MenuID
    })
    if (menu.MenuID === this.state.selectedTabId) {
      tabs[0] && (tabs[0].selected = true)
    }
    this.props.modifyTabview(tabs)
  }
 
  changeTab (menu) {
    this.setState({
      selectedTabId: menu.MenuID
    })
  }
  
  UNSAFE_componentWillMount () {
 
  }
 
  componentDidMount () {
    console.log(this.props)
  }
 
  UNSAFE_componentWillReceiveProps (nextProps) {
    if (nextProps.tabviews && !is(fromJS(this.props.tabviews), fromJS(nextProps.tabviews))) {
      let view = nextProps.tabviews.filter(tab => tab.selected)[0]
      this.setState({
        selectedTabId: view ? view.MenuID : ''
      })
    }
  }
 
  shouldComponentUpdate(nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
 
  componentDidUpdate () {
 
  }
 
  render () {
    return (
      <section className="flex-container content-box">
        <div className="content-header">
          {this.props.tabviews && this.props.tabviews.length > 0 &&
            <Tabs activeKey={this.state.selectedTabId}>
              {this.props.tabviews.map(view => {
                return (
                  <Tabs.TabPane
                    className="test"
                    tab={
                      <span>
                        <span className="tab-name" onClick={() => {this.changeTab(view)}}>
                          {view.MenuName}
                        </span>
                        <Icon type="close" onClick={() => {this.handleTabview(view)}}/>
                      </span>
                    }
                    key={view.MenuID}
                  >
                    <iframe
                      title={view.MenuName}
                      src={'http://qingqiumarket.cn/MKWMS/zh-CN/' + view.LinkUrl}
                    />
                  </Tabs.TabPane>
                )
              })}
            </Tabs>
          }
        </div>
      </section>
    )
  }
}
 
const mapStateToProps = (state) => {
  return {
    tabviews: state.tabviews
  }
}
 
const mapDispatchToProps = (dispatch) => {
  return {
    modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews))
  }
}
 
export default connect(mapStateToProps, mapDispatchToProps)(Header)