import React, {Component} from 'react'
|
import { Toast } from 'antd-mobile'
|
|
import Api from '@/api'
|
import asyncComponent from '@/utils/asyncPage'
|
import '@/assets/css/iconfont.css'
|
import '@/assets/css/style.css'
|
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 Main extends Component {
|
state = {
|
// viewId: this.props.match.params.viewId,
|
config: ''
|
}
|
|
UNSAFE_componentWillMount () {
|
// const { viewId } = this.state
|
|
// if (!this.props.location.state) {
|
// this.props.history.replace({pathname: `/loading/${this.props.match.params.viewId}`})
|
// return
|
// }
|
|
// this.setState({
|
// config: this.props.location.state.config
|
// })
|
Api.getMockData({
|
func: 'sPC_Get_LongParam',
|
MenuID: this.props.match.params.viewId,
|
TypeCharOne: 'mob'
|
}).then((res) => {
|
if (res.status) {
|
let config = ''
|
|
try {
|
// config = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
|
config = res.LongParam
|
} catch {
|
config = ''
|
}
|
|
if (!config) {
|
Toast.fail('配置解析错误!', 3)
|
return
|
}
|
|
this.setState({
|
config: config
|
})
|
} else {
|
Toast.fail(res.message, 3)
|
}
|
})
|
}
|
|
renderContent = () => {
|
const { config } = this.state
|
|
if (!config || !config.subcomponents) return null
|
let components = []
|
config.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 () {
|
return (
|
<div className="tab-view-wrap">
|
{this.renderContent()}
|
</div>
|
)
|
}
|
}
|
|
export default Main
|