Authored by 郭成尧

'listScroll'

@@ -23,7 +23,6 @@ module.exports = { @@ -23,7 +23,6 @@ module.exports = {
23 getNewsList: (req, res, next) => { 23 getNewsList: (req, res, next) => {
24 let params = { 24 let params = {
25 page: req.body.page, 25 page: req.body.page,
26 - limit: req.body.limit,  
27 gender: req.body.gender, 26 gender: req.body.gender,
28 uid: req.user.uid 27 uid: req.user.uid
29 }; 28 };
@@ -17,7 +17,7 @@ module.exports = { @@ -17,7 +17,7 @@ module.exports = {
17 gender: params.gender, 17 gender: params.gender,
18 uid: params.uid || '0', 18 uid: params.uid || '0',
19 page: params.page, 19 page: params.page,
20 - limit: params.limit, 20 + limit: '5',
21 app_type: '1' 21 app_type: '1'
22 }); 22 });
23 } 23 }
@@ -22,8 +22,14 @@ const newsList = params => { @@ -22,8 +22,14 @@ const newsList = params => {
22 return api.all([ 22 return api.all([
23 newsListApi.getNewsListData(params) 23 newsListApi.getNewsListData(params)
24 ]).then(result => { 24 ]).then(result => {
25 - if (result[0].code === 200) {  
26 - Object.assign(finalResult, result[0].data.list.artList); 25 + if (result[0].code === 200 && result[0].data.list) {
  26 + Object.assign(finalResult, {
  27 + data: {
  28 + list: result[0].data.list.artList,
  29 + totalPage: result[0].data.totalPage
  30 + },
  31 + code: 200
  32 + });
27 } else { 33 } else {
28 logger.error('getNewsListData api code no 200'); 34 logger.error('getNewsListData api code no 200');
29 } 35 }
1 <template> 1 <template>
2 <resources v-bind:content-code.sync="contentCode"></resources> 2 <resources v-bind:content-code.sync="contentCode"></resources>
3 - <div v-for="news in newsList" class="news-box"> 3 + <div v-for="news in newsList" class="news-box" v-infinite-scroll="getNewsList()">
4 <span v-if='news.categoryName !== "最新"' class="tag">{{news.categoryName}}</span> 4 <span v-if='news.categoryName !== "最新"' class="tag">{{news.categoryName}}</span>
5 <div class="img"> 5 <div class="img">
6 <a href='{{"/news/" + news.id}}'> 6 <a href='{{"/news/" + news.id}}'>
@@ -87,8 +87,9 @@ @@ -87,8 +87,9 @@
87 contentCode: contentCode.news[qs.cate || 'new'], 87 contentCode: contentCode.news[qs.cate || 'new'],
88 newsList: [], 88 newsList: [],
89 gender: qs.gender, 89 gender: qs.gender,
90 - page: 1,  
91 - limit: 10, 90 + page: 0,
  91 + busy: false,
  92 + scrollDisabled: false
92 }; 93 };
93 }, 94 },
94 watch: { 95 watch: {
@@ -100,21 +101,30 @@ @@ -100,21 +101,30 @@
100 101
101 /* 获取资讯列表数据 */ 102 /* 获取资讯列表数据 */
102 getNewsList() { 103 getNewsList() {
103 - $.post({  
104 - url: '/news/get-news-list',  
105 - data: {  
106 - sortId: this.crntCateId,  
107 - page: this.page,  
108 - limit: this.limit,  
109 - gender: this.gender || '1,2,3'  
110 - }  
111 - }).done(result => {  
112 - if (result) {  
113 - this.newsList = result;  
114 - } else {  
115 - tip('服务端无数据返回');  
116 - }  
117 - }).fail(); 104 + if (this.busy === false) {
  105 + this.busy = true;
  106 + $.post({
  107 + url: '/news/get-news-list',
  108 + data: {
  109 + sortId: this.crntCateId,
  110 + page: this.page++,
  111 + gender: this.gender || '1,2,3'
  112 + }
  113 + }).done(result => {
  114 + if (result.code === 200) {
  115 + if (this.newsList.length > 0 && result.data.list.length > 0) {
  116 + Array.prototype.push.apply(this.newsList, result.data.list);
  117 + } else {
  118 + this.newsList = result.data.list;
  119 + }
  120 + } else {
  121 + this.scrollDisabled = true;
  122 + }
  123 + this.busy = false;
  124 + }).fail(() => {
  125 + tip('服务器错误');
  126 + });
  127 + }
118 }, 128 },
119 129
120 /* 分享资讯 */ 130 /* 分享资讯 */