Commit d07c2bc6 by zhanghaozhe

search-result

parent 8cf60829
...@@ -3,6 +3,7 @@ import SearchHead from './searchHead' ...@@ -3,6 +3,7 @@ import SearchHead from './searchHead'
import Tag from '@common/Tag/index.js' import Tag from '@common/Tag/index.js'
import { http, api } from '@/utils' import { http, api } from '@/utils'
import './index.scss'; import './index.scss';
import { Link } from 'react-router-dom'
class Search extends PureComponent { class Search extends PureComponent {
...@@ -10,14 +11,22 @@ class Search extends PureComponent { ...@@ -10,14 +11,22 @@ class Search extends PureComponent {
super(props); super(props);
this.state = { this.state = {
history: JSON.parse(localStorage.getItem('history')) || [], history: JSON.parse(localStorage.getItem('history')) || [],
searchHot: ['rec', '电脑', '照片扫描仪', '智能手表', '功夫茶杯', '广角镜头手机'], hot_words: [],
searchList: [] searchList: []
} }
} }
async componentDidMount() { async componentDidMount() {
const data = await http.get(`${api['search-api']}/search_hot_word`) const res = await http.get(`${api['search-api']}/search_hot_word`)
console.log(data) if (res.data.errno === 0) {
this.setState({
hot_words: res.data.data.info.hot_words
})
}
}
search = text => {
} }
render() { render() {
...@@ -47,9 +56,13 @@ class Search extends PureComponent { ...@@ -47,9 +56,13 @@ class Search extends PureComponent {
</label> </label>
<div className="search-tag"> <div className="search-tag">
{ {
this.state.searchHot.length > 0 ? this.state['hot_words'].length > 0 ?
this.state.searchHot.map((v, i) => { this.state['hot_words'].map((v, i) => {
return (<Tag key={i}>{v}</Tag>) return (
<Link key={i} to={`/search-result?word=${v}`}>
<Tag>{v}</Tag>
</Link>
)
}) })
: <div style={{textAlign: 'center', padding: '20px'}}>暂无热门</div> : <div style={{textAlign: 'center', padding: '20px'}}>暂无热门</div>
} }
......
import React, { PureComponent } from 'react';
import SearchHeader from './searchHead'
class SearchResult extends PureComponent {
componentDidMount(){
}
render() {
return (
<div className='search-result'>
<SearchHeader/>
</div>
);
}
}
export default SearchResult;
\ No newline at end of file
.search-result {
}
\ No newline at end of file
export const CHANGEVAL = 'CHANGEVAL'
\ No newline at end of file
import reducer from './reducer';
import * as constants from './constants';
export { reducer, constants };
\ No newline at end of file
const initState = {
}
export default (state = initState, actions) => {
switch (actions.type) {
default:
return state
}
}
\ No newline at end of file
...@@ -6,6 +6,7 @@ import CourseList from '@/components/classify/courselist'; ...@@ -6,6 +6,7 @@ import CourseList from '@/components/classify/courselist';
import Order from '@/components/order/index'; import Order from '@/components/order/index';
import Preferential from '@/components/preferential/index'; import Preferential from '@/components/preferential/index';
import Search from '@/components/search/index' import Search from '@/components/search/index'
import SearchResult from '@/components/search/search-result'
import Detail from '@/components/detail/index' import Detail from '@/components/detail/index'
import Examination from '@/components/examination' import Examination from '@/components/examination'
import ExchangeCoupons from '@/components/coupons/exchange-coupons' import ExchangeCoupons from '@/components/coupons/exchange-coupons'
...@@ -43,9 +44,14 @@ export default [ ...@@ -43,9 +44,14 @@ export default [
}, },
{ {
path: '/search', path: '/search',
exact: true,
component: Search component: Search
}, },
{ {
path: '/search-result',
component: SearchResult
},
{
path: '/order', path: '/order',
component: Order component: Order
}, },
......
import { combineReducers } from 'redux'; import { combineReducers } from 'redux';
import searchReducer from '@/components/search/store/reducer';
import myCourses from '@/components/study/myCourses/reducers' import myCourses from '@/components/study/myCourses/reducers'
const reducer = combineReducers({ const reducer = combineReducers({
searchReducer,
myCourses myCourses
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment