import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
// import { is, fromJS } from 'immutable'
|
import { TabBar } from 'antd-mobile'
|
|
import asyncComponent from '@/utils/asyncPage'
|
// import Api from '@/api'
|
import './index.scss'
|
|
const StabList = asyncComponent(() => import('@/components/list/stab-list'))
|
const TopSearch = asyncComponent(() => import('@/components/search/topsearch'))
|
const CardList = asyncComponent(() => import('@/components/list/card-list'))
|
const CarList1 = asyncComponent(() => import('@/components/list/carousel'))
|
const NoticeBar = asyncComponent(() => import('@/components/list/noticebar'))
|
|
class NavBar1 extends Component {
|
static propTpyes = {
|
config: PropTypes.object
|
}
|
|
state = {
|
selectedTab: ''
|
}
|
|
UNSAFE_componentWillMount () {
|
const { config } = this.props
|
|
if (config.sublist && config.sublist[0]) {
|
this.setState({
|
selectedTab: config.sublist[0].field
|
})
|
}
|
}
|
|
// shouldComponentUpdate (nextProps, nextState) {
|
// return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
|
// }
|
|
changeTab = (val) => {
|
this.setState({
|
selectedTab: val
|
})
|
}
|
|
renderContent = (item) => {
|
let components = []
|
|
item.subcomponents.forEach(cell => {
|
if (cell.type === 'list') {
|
if (cell.subtype === 'stab-list') {
|
components.push(<StabList key={cell.uuid} history={this.props.history} config={cell} />)
|
} else if (cell.subtype === 'card-list') {
|
components.push(<CardList key={cell.uuid} history={this.props.history} config={cell} />)
|
} else if (cell.subtype === 'carousel') {
|
components.push(<CarList1 key={cell.uuid} history={this.props.history} config={cell} />)
|
} else if (cell.subtype === 'noticebar') {
|
components.push(<NoticeBar key={cell.uuid} history={this.props.history} config={cell} />)
|
}
|
} else if (cell.type === 'search') {
|
if (cell.subtype === 'top-search') {
|
components.push(<TopSearch key={cell.uuid} history={this.props.history} config={cell} />)
|
}
|
}
|
})
|
|
return components
|
}
|
|
|
render () {
|
const { config } = this.props
|
const { selectedTab } = this.state
|
|
return (
|
<div className="nav-bar-1">
|
<TabBar
|
unselectedTintColor="#949494"
|
tintColor="#33A3F4"
|
barTintColor="white"
|
>
|
{config.sublist.map(item => (
|
<TabBar.Item
|
title={item.label}
|
key={item.field}
|
dot={item.dot}
|
icon={<i className={item.icon} />}
|
selectedIcon={<i className={item.icon} />}
|
selected={selectedTab === item.field}
|
onPress={() => {this.changeTab(item.field)}}
|
>
|
{this.renderContent(item)}
|
</TabBar.Item>
|
))}
|
</TabBar>
|
</div>
|
)
|
}
|
}
|
|
export default NavBar1
|