05-综合应用
15
刘冠军
开始于 2020-10-24 23:11
0 2 109
已截止

任务尚未发布或者你没有权限查看任务内容。

任务讨论
4-贺爽
import React,{useEffect} from 'react' import {connect} from 'react-redux' import './Home.css';
import Car from './Car' import Cart from './Cart' import Mytab from './Mytab' import { ActivityIndicator } from 'antd-mobile' import {Shuju} from './Actioncreator' // function xianshi(props){ //     props.dispatch(Shuju()); // } // window.onload=xianshi; const Home=(props)=>{

    
    useEffect(() => {
        props.dispatch(Shuju())
    }, [])
    console.log(props.datalist) // if(props.datalist.length!=='undefined'){ //     props.history.push('/login') // } return ( <div class="container" > {/* 搜索框 */} <header class="head"> <i class="tao iconfont icon-taobao1"></i> <div class='header-bd' > <a class="placeholder" onClick={()=>props.history.push('/cart')}> <span class="text inconfont icon-taobaosousuo">寻找宝贝店铺</span> </a> </div> </header> {/* 轮播图 */} <div class='lunbotu'> <Car/> </div> {/* 商品 */} <div class='shangpin'>{
            props.datalist.map((item,index)=>{
                return( <div class='list' onClick={()=>props.history.push('/goods',{id:props.datalist[index].id,img:props.datalist[index].img})}> <img key={index} src={props.datalist[index].img}/> <p class='p1'>{props.datalist[index].title}</p> <p class='p2'><span class='span1'>¥</span>{props.datalist[index].price}<span class='span2'>666人已购买</span></p> </div> )
            })} </div> <Mytab/> </div> )
}
const mapStateToProps=(state)=>({
    datalist:state.homereducer.datalist
})
export default connect(mapStateToProps)(Home);
//import img from '../assets/banner.jpg'
// iconfont.cn官网搜选图标,加入购物车
// 点击页面右上角购物车,将图标添加进项目(没有项目就新建)
// 点击“下载到本地”
// 解压压缩包,全部复制到项目public文件夹下,
// 在index.html中通过link引入iconfont.css
// 使用时,<i className='iconfont icon-具体名字'></i> // export default withRouter(Home);
//安装:node(npm) npm i(install) packageName
//npm react-router-dom 
//npm i antd-mobile
//npm i redux react-redux redux-thunk

//(npx)create-react-app proName
//组件化(
// UI组件:只展示结构,展示用的(通过属性props传递数据)
// 智能组件:状态(state、setstate)、生命周期(componentDidMount,render(更新阶段))
// )
//hooks:函数组建内,也可以声明状态,更新状态(useState)
//套到组件的最外层import {BrowerRouter as Route,Link}from 'react-router-dom"和import {HashRouter}from“react——router-dom”
{/* <Router>关于路由
    //在每一页都显示,可以这样写 <div>title</div> //对于切换的,进行匹配 <Switch> <Route exact path='/' component={}/> <Route path='/doc' component={Doc}/> <Route path='doc:id' component={Doc1}/> <Route path='/' component={NOtFound}/> </Switch> </Router> */}
//第二次作业在pages文件夹里
// const Home=(props)=>{
//     return(
// <div style={{textAlign:'center'}}> // <h2>React</h2> // <p>用户构建用户界面的 JavaScript库</p> // <div> // <button onClick={ //                     ()=>props.history.push('/doc')
//                 }>快速开始</button> // <button onClick={ //                     ()=>props.history.push('/tuto')
//                 }>入门教程</button> // </div> // </div> //     )
// } 
// let datalist=[]; const homereducer=(state={datalist:[]},action)=>{ switch(action.type){ case 'Get': //return  return {datalist:action.datalist} default: return state;
    }
}
export default homereducer
import { createStore, compose, combineReducers, applyMiddleware } from 'redux'; import homereducer from './homereducer'; import cartreducer from './cartreducer' // import thunk from 'redux-thunk' let rootReducer = combineReducers({
    homereducer,cartreducer
}); // let createStoreWithMiddleware = applyMiddleware(thunk)(createStore); // let store = createStoreWithMiddleware(rootReducer); function logger({ getState }) { return (next) => (action) => { console.log('will dispatch', action) // 调用 middleware 链中下一个 middleware 的 dispatch。 let returnValue = next(action) console.log('state after dispatch', getState()) // 一般会是 action 本身,除非 // 后面的 middleware 修改了它。 return returnValue
    }
} const thunk = ({ dispatch, getState }) => (next) => (action) => { console.log('thunk'); if (typeof action === 'function') { return action(dispatch, getState);
    } return next(action);
}; const store=createStore(
    rootReducer,
    compose(
        applyMiddleware(logger, thunk), // //window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
    )
    ); export {store}
import React,{useEffect} from 'react' import {Shuju} from './Actioncreator' import { connect } from 'react-redux' import './detailshow.css' const Goods = (props) => {
    useEffect(() => {
        props.dispatch(Shuju())
    }, []) console.log(props) let id=props.location.state.id return(
        props.datalist.map((item,index)=>{ if(props.datalist[index].id===id){ console.log(props.datalist[index].img) return(
                    <div class='dcontainer'>
                    <div class='navi-bar' onClick={()=>props.history.goBack()}>
                    <botton class="back">
                        <span class='back-i'><</span>
                    </botton>
                    </div>
                    <div class='con-img'>
                        <img src={props.datalist[index].img} class='tupian'/>
                    </div>
                    <div className='dmcontainer'>
                        <div class='dianpu'>
                            <i className='iconfont icon-taobaodianpu'></i>
                            <span>店铺</span>
                        </div>
                        <div class='kefu'>
                            <i className='iconfont icon-taobaokefu-01'></i>
                            <span>客服</span>
                        </div>
                        <div class='shoucang' onClick={props.history.push('/cart'),()=>{ if(document.getElementById('shoucang').className!=='iconfont icon-shoucang2')
                            { document.getElementById('shoucang').className='iconfont icon-shoucang2' props.dispatch({
                                    type:"ADD_TODO",
                                    id:id,
                                    title:props.datalist[index].title,
                                    shoucang:[{id,title}]
                                })
                            }else(document.getElementById('shoucang')==="iconfont icon-shoucang2"){
                                props.dispatch({
                                    type:"DEL_TODO",
                                    id:id,
                                    title:props.datalist[index].title,
                                    shoucang:[{id,title}]
                                })
                            }
                        }}>
                            <i className='iconfont icon-shoucang2' id='shoucang'></i>
                            <span>收藏</span>
                        </div>
                        <div class='jiaru'>
                            <span>加入购物车</span>
                        </div>
                        <div class='liji'>
                            <span>立即购买</span>
                        </div>
                    </div>
                </div>
                )
            }
        })
    ) } const mapStateToProps = (state)=>({ datalist:state.homereducer.datalist
}) export default connect(mapStateToProps)( Goods)
const Shuju=()=>{ return (dispatch)=>{ let url='https://www.fastmock.site/mock/9e4bbf9e35ad15942010865690c87ac6/api/getgoodslist';
        fetch(url,{
            method:'GET',
            headers:{ 'Content-TYpe':'application/json' },
        })
        .then(res=>res.json())
        .then(res=>{
            dispatch({
                type:'Get',
                datalist:res.data
            })
        })
    }
}
export {Shuju}
import React,{useEffect} from 'react' import Mytab from './Mytab' import { connect } from 'react-redux' import {Shuju} from './Actioncreator' const Cart = (props) => {
    useEffect(() => {
        props.dispatch(Shuju())
    }, []) return ( <div> props.shoucang.map((item,index)=> <li key={index}>{item} <button onClick={ ()=>{
                    props.dispatch({
                        type: "DEL_TODO",
                        index: id
                    })
            }
            }>删除</button>></li> ) <Mytab /> </div> )
}
const mapStateToProps = (state)=>({
    shoucang:state.cartreducer,
    datalist:state.homereducer.datalist
})
export default connect(mapStateToProps)(Cart)
import { scryRenderedComponentsWithType } from "react-dom/test-utils"; let srr=new Object(); let shoucang=[]; function cartreducer(state=shoucang,action){ if(action.type=='ADD_TODO'){ let i=0;
        srr.id=action.id;
        srr.title=action.title;
        shoucang[i]=srr; return {...state,shoucang:action.shoucang}
    } if(action.type=='DEL_TODO'){ // action.index let arr = [...state];
        arr.splice(action.id,1); return arr;
    } return state;
}
export default cartreducer
// import React,{useState,useEffect} from 'react'; // import { BrowserRouter as Router, Redirect, Route, NavLink, Switch } from 'react-router-dom' // import store from './ReduxDemo/store'; // import { Provider } from 'react-redux' // import Todos from './ReduxDemo/Todos'; // import Input from './ReduxDemo/input' // // redux react-redux // // webpack // // umi框架 // // Router(react-router)怎么实现的(源码) // //action是更新状态唯一的途径,就是一个普通的对象,包含一个type属性 // const App = ()=>{ // 	return <Provider store={store}> // 		<Router> // 			<Todos/> // 			<Input/> // 		</Router> // 	</Provider> // } // export default App; //作业 //第三次作业 import React from 'react';
import { BrowserRouter as Router, Redirect, Route, NavLink, Switch } from 'react-router-dom' import Header from './pages/myHeader';
import routes from './router.config';
import {Button,TabBar} from 'antd-mobile' import Home from './Taobao/Home';
import Cart from './Taobao/Cart';
import List from './Taobao/List';
import Search from './Taobao/Search' import {store} from './Taobao/Store' import { Provider } from 'react-redux';
import Login from './Taobao/Login';
import Goods from './Taobao/Goods'; // https://aecpm.alicdn.com/simba/img/TB15tIjGVXXXXcoapXXSutbFXXX.jpg const App = ()=>{ return <Provider store={store}>
			<Router>
				<Switch>
					<Route exact path='/' component={Home} />
					<Route path='/cart' component={Cart} />
					<Route path='/list' component={List}/>
					<Route path='/search' component={Search}/>
					<Route path='/service' component={Login}/>
					<Route path='/goods' component={Goods}/>

					{/* <Route component={Home} /> */}
					<Route render={()=><Redirect to='/'/>} />
					
				</Switch>
			{/* <Mytab /> */}		
		</Router>
	</Provider>
	
} const RouteWithSubRoutes=(props)=>{ return <Route
	path={props.path}
	render={
		()=><props.component routes={props.routes}/>
	}/>
}
export default App;
export {RouteWithSubRoutes}; // function PrivateRoute({ routes,component: Com, ...rest }) { // 	return ( // 		<Route // 			{ ...rest } // 			render={ ({ location }) => // 				localStorage.getItem('userinfo') // 					? <Com routes={routes}/> // 					: ( // 						<Redirect // 							to={ { // 								pathname: "/login", // 								state: location // 							} } // 						/> // 					) // 			} // 		/> // 	); // } //  const RouteWithSubRoute = (props)=>{ // 	if(props.pri){ // 		return <PrivateRoute {...props}/> // 	} // 	return <Route  // 				path={props.path}  // 				render={ // 					(pro)=><props.component {...pro} routes={props.routes}/> // 				} // 			/> // } // 1、搜索框(点击跳转搜索页面,顶部是searchBar, // 点取消,返回首页) // 2、轮播图 // 3、商品列表(10个)(点击跳转商品详情页, // 详情页写上面的图片和返回箭头,点返回箭头返回首页 // 和底部按钮(店铺、客服、收藏、加入购物车和立即购买) // ) // 路由基本配置 // 路由传参(以及获取参数-props) // 动态路由(/:page) // js跳转 // 权限路由 // npm i antd-mobile --registry https:// // function Core(){ //     return <h2>Core</h2>; // } // function Guide(){ //     return <h2>Guide</h2>; // } // function Api(){ //     return <h2>Api</h2>; // } // function Hooks(){ //     return <h2>Hooks</h2>; // } //  function RouteWithSubRoutes(route,i){ // 	return ( // 		<Route key={i} path={route.path}  // 			render={(props)=>{ // 				if(route.routes){ // 					return( // 						<div> // 							<Switch> // 								{ // 									route.routes.map((routes,i)=>(<Route key={i} path={routes.path} component={routes.component}/>)) // 								} // 								<Redirect to={route.routes[0].path}></Redirect> // 							</Switch> // 						</div> // 					) // 				}else{ // 					return ( // 						<div> // 							<route.component props={props}></route.component> // 						</div> // 					) // 				} // 			}} // 		/> // 	) // } // function PrivateRoute({ component: Com, ...rest }) { // 		return ( // 			<Route // 				{ ...rest } // 				render={ ({ location }) => // 					localStorage.getItem('userinfo') // 						? <Com routes={routes} // 						: ( // 							<Redirect // 								to={ { // 									pathname: "/login", // 									state: location // 								} } // 							/> // 						) // 				} // 			/> // 		); // 	} //老师的代码: // const RouteWithSubRoutes=(props)=>{ // 	if(props.pri){ // 		return <PrivateRoute {...props}/> // 	} // 	return <Route // 	path={props.path} // 	render={ // 		()=><props.component routes={props.routes}/> // 	} // } // const App = () => { // 	return <Router> // 		<Header /> // 		<Switch> // 			{ // 				routes.map(({pri,...rest})=>{ // 					if(pri){ // 						return <PrivateRoute {...rest} /> // 					} // 					return <RouteWithSubRoutes {...rest}/> // 				}) // 			} // 		</Switch> // 	</Router> // } // export default App; // export {RouteWithSubRoutes} // home组件这种配置方式会在 // Home组件的props内注入四个属性 // <Route exact path='/' component={ Home } /> // <PrivateRoute path='/doc' component={ Doc } />  // <Route path='/doc/:id' component={ Doc } />  // <PrivateRoute path='/tuto' component={ Tuto } /> // <PrivateRoute path='/blog' component={ Blog } /> // <Route path='/comm' component={ Comm } /> // <Route path='/login' component={ Login } />  // no-match  // <Route component={()=><div>404</div>} />  // <Route path='*' component={ () => <div>404</div> } />
刘冠军

任务已更新

刘冠军

任务已更新