|
|
@@ -1,24 +1,104 @@
|
|
|
import React, { Component } from 'react';
|
|
|
+import {PageContext} from './components/context'
|
|
|
|
|
|
import './App.css';
|
|
|
+import {graphqls} from './api/graphql_request'
|
|
|
+import {getStoreByProps} from './api/graphql/store'
|
|
|
+import {getSlidesByProps} from './api/graphql/slides'
|
|
|
|
|
|
-import NavBars from './components/App/NavBar'
|
|
|
import TabBarBottom from './components/App/TabBarBottom'
|
|
|
+import HomePage from './components/HomePage/HomePage'
|
|
|
|
|
|
+import UserPage from './components/UserPage/userPage'
|
|
|
|
|
|
|
|
|
class OrderApp extends Component {
|
|
|
- // constructor(props){
|
|
|
- // super(props)
|
|
|
- // }
|
|
|
-
|
|
|
+
|
|
|
+ constructor(props){
|
|
|
+ super(props)
|
|
|
+ this.state={
|
|
|
+ page:'home',
|
|
|
+ store:[],
|
|
|
+ slide:[]
|
|
|
+ }
|
|
|
+ this.changePage=this.changePage.bind(this)
|
|
|
+ }
|
|
|
+
|
|
|
+ componentDidMount(){
|
|
|
+ this.getStores()
|
|
|
+ this.getSlides()
|
|
|
+ }
|
|
|
+
|
|
|
+ changePage(page){
|
|
|
+ this.setState({page})
|
|
|
+ }
|
|
|
+
|
|
|
+ getStores(){
|
|
|
+ //获取所有商家
|
|
|
+ return graphqls(getStoreByProps,{}).then((e)=>{
|
|
|
+ console.log(e.storebyprops)
|
|
|
+ this.setState({
|
|
|
+ store:e.storebyprops
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ getSlides(){
|
|
|
+ return graphqls(getSlidesByProps,{}).then((e)=>{
|
|
|
+
|
|
|
+ this.setState({ slide:e.slidsbyprops })
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //根据状态渲染页面
|
|
|
+ renderPage(page){
|
|
|
+ switch(page){
|
|
|
+ case ('home'):
|
|
|
+ //console.log('++++1+++++',this.state.store)
|
|
|
+ return(
|
|
|
+ <div className="pageWrap">
|
|
|
+ <div className="scrollPage">
|
|
|
+ <HomePage changePage={this.changePage} store={this.state.store} slide={this.state.slide}/>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+
|
|
|
+ case ('user'):
|
|
|
+ return(
|
|
|
+ <div className="pageWrap">
|
|
|
+ <div className="scrollPage">
|
|
|
+ <UserPage changePage={this.changePage} />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+
|
|
|
+ default:
|
|
|
+ return(
|
|
|
+ <div>页面加载失败,请刷新页面</div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ renderBottom(){
|
|
|
+ let page=this.state.page
|
|
|
+ if(page==='home'||page==='user'){
|
|
|
+ return(<TabBarBottom changePage={this.changePage}/>)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
render() {
|
|
|
+ const changePage=this.changePage
|
|
|
return (
|
|
|
<div className="AppWrap">
|
|
|
<div className="phone6s">
|
|
|
<div className="App">
|
|
|
- <NavBars />
|
|
|
- <TabBarBottom />
|
|
|
+ <div className="App orderApp">
|
|
|
+ <PageContext.Provider value={changePage}>
|
|
|
+ {this.renderPage(this.state.page)}
|
|
|
+ {this.renderBottom()}
|
|
|
+ </PageContext.Provider>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|