Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

Commit

Permalink
feat(news/search): 增加搜索资讯功能
Browse files Browse the repository at this point in the history
1. 修改 'loadmore' 组件初始化判断;
2. 增加 '搜索资讯功能'
  • Loading branch information
jsonleex committed Feb 27, 2018
1 parent 5279ea5 commit eaafc93
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/loadMore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export default {
if (typeof this.onLoadMore === 'function') {
this.scEl.onscroll = this.handleScrolling();
}
if (!this.fulled()) {
if (typeof this.onRefresh === 'function' && !this.fulled()) {
this.beforeRefresh();
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/page/news/news.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="p-news">
<head-top :go-back='true' title='资讯' :append='true'>
<router-link to='serach' append tag='svg' slot='append'>
<router-link to='search' append tag='svg' slot='append'>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#base-search"></use>
</router-link>
</head-top>
Expand Down
96 changes: 96 additions & 0 deletions src/page/news/newsSearch.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<template>
<div class="p-news-search">
<head-top :go-back='true' :append='true' title='搜索资讯'>
<div slot='append' class="head-top-cancel" @click='beforeSearch'>搜索</div>
<div slot='title' class="p-news-search-input">
<input type="text" v-model='keyword' @keypress='beforeSearch($event)'>
</div>
</head-top>
<div></div>
<load-more
ref='loadmore'
:onRefresh='topEvent'
:onLoadMore='onLoadMore'
class="p-news-search-body">
<news-item
v-for='news in list'
v-if='news.id'
:key='news.id'
:news='news'
/>
</load-more>
</div>
</template>
<script>
import newsItem from './components/newsItem.vue';
export default {
name: 'news-search',
components: {
newsItem
},
data() {
return {
keyword: '',
list: []
};
},
computed: {
after() {
const len = this.list.length;
return len > 0 ? this.list[len - 1].id : 0;
},
topEvent() {
const len = this.keyword.length;
return len > 0 ? this.onRefresh : null;
}
},
methods: {
beforeSearch(e) {
if (!this.keyword) return;
const type = e.type;
switch (type) {
case 'click':
return this.onRefresh();
case 'keypress':
return e.keyCode === 13 && this.onRefresh();
}
},
onRefresh() {
if (!this.keyword) {
return this.$refs.loadmore.topEnd(!1);
}
this.$http
.get(`/news`, {
params: {
limit: 15,
key: this.keyword
}
})
.then(({ data } = []) => {
this.list = data;
this.$refs.loadmore.topEnd(!(data.length < 15));
});
},
onLoadMore() {
if (!this.keyword) {
return this.$refs.loadmore.bottomEnd(true);
}
this.$http
.get(`/news`, {
params: {
limit: 15,
key: this.keyword,
after: this.after
}
})
.then(({ data } = []) => {
data.length > 0 && (this.list = [...this.list, ...this.data]);
this.$refs.loadmore.bottomEnd(data.length < 15);
});
}
}
};
</script>
<style lang='less' src='./style/newsSearch.less'>
</style>
15 changes: 15 additions & 0 deletions src/page/news/style/newsSearch.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.p-news-search {
&-input {
width: 120%;
margin-left: -13%;
input {
color: #59b6d7;
padding: 10px;
width: 530px;
height: 55px;
font-size: 32px;
border-radius: 10px;
background-color: #ebebeb;
}
}
}
11 changes: 11 additions & 0 deletions src/routers/news.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const news = () => import(/* webpackChunkName: 'news' */ '../page/news/news');
const newsSearch = () =>
import(/* webpackChunkName: 'news' */ '../page/news/newsSearch');
export default [
{
path: '/news',
Expand All @@ -8,5 +10,14 @@ export default [
keepAlive: true,
requiresAuth: true
}
},
{
path: '/news/search',
component: newsSearch,
meta: {
title: '搜索',
keepAlive: true,
requiresAuth: true
}
}
];

0 comments on commit eaafc93

Please sign in to comment.