Authored by QC-L

优化搜索逻辑 review by 黄敬囿

... ... @@ -36,6 +36,14 @@ export default class Search extends Component {
})
}
componentDidShow() {
const list = Taro.getStorageSync('latelySearch');
this.setState({
latelySearch: list || []
})
}
onScroll(e) {
if (e.detail.scrollTop > 48) {
this.setState({
... ... @@ -55,6 +63,9 @@ export default class Search extends Component {
}
onComplate(e) {
if (e.detail.value === '') {
return;
}
this.savaLateSearch(e);
router.go('productList', {
query: e.detail.value
... ... @@ -90,6 +101,7 @@ export default class Search extends Component {
render () {
let {hotSearchTitle, hotSearch, latelySearchTitle, latelySearch} = this.state;
let value = '';
return (
<ScrollView
... ... @@ -104,7 +116,7 @@ export default class Search extends Component {
<PageTitle pageTitle="搜索"></PageTitle>
<View className={this.fixed ? 'fixed search-out-box' : 'search-out-box'}>
<SearchBar onComplate={this.onComplate}></SearchBar>
<SearchBar onComplate={this.onComplate} value={value}></SearchBar>
</View>
{
... ...
... ... @@ -273,7 +273,9 @@ export default class SearchList extends Component {
if (latelySearch) {
searchList = latelySearch || []
}
console.log(searchList);
if (e.detail.value === '') {
return;
}
if (searchList.length >= 10) {
searchList.pop();
}
... ...