author.js
4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// 逛编辑(作者)列表
import { API_HOST, SERVICE_HOST } from '../../../../libs/config';
import { GET, POST } from '../../../../libs/request';
import objectAssign from '../../../../vendors/object-assign';
import guangUtil from './util';
import Promise from '../../../../vendors/es6-promise';
import util from '../../../../utils/util';
import {
logEvent,
YB_PAGE_OPEN_L,
} from '../../../../libs/analytics.js'
//获取应用实例
let app = getApp();
let PV_ID = new Date().getTime() + '';
const screenHeight = app.globalData.systemInfo.screenHeight;
const windowWidth = app.globalData.systemInfo.windowWidth;
const windowHeight = app.globalData.systemInfo.windowHeight;
Page({
data: {
options: {},
windowHeight: windowHeight,
screenHeight: screenHeight - 60,
scrollTop: 0,
isShowIndicator: false,
isLoading: true,
yasParam: '',
from_page_name: '',
from_page_param: '',
current_page_name: 'guangAuthor',
current_page_param: '',
authorResult: [],
authorInfo: {},
page: 0,
end: false
},
onLoad: function(options) {
this.setData({
options,
yasParam: `&page_name=${this.data.current_page_name}&page_param=${options.author_id || ''}`,
current_page_param: options.author_id || '',
from_page_name: options.page_name || '',
from_page_param: options.page_param || '',
});
this._init();
var pages = getCurrentPages();
var currentPage = pages[pages.length - 1];
var url = currentPage.route;
let params = {
PAGE_NAME: this.data.current_page_name,
PAGE_PARAM: this.data.current_page_param,
FROM_PAGE_NAME: this.data.from_page_name,
FROM_PAGE_PARAM: this.data.from_page_param,
PV_ID: PV_ID,
PAGE_PATH: url,
};
logEvent(YB_PAGE_OPEN_L, params);
},
_init: function() {
return Promise.all([
this._getAuthor(),
this.loadMore()
]);
},
_getAuthor: function() {
guangUtil._getAuthor({
author_id: this.data.options.author_id
}, GET, API_HOST).then(rdata => {
if (rdata.avatar) {
rdata.avatar = util.formatImageUrl(rdata.avatar, 80, 80);
}
this.setData({authorInfo: rdata});
});
},
loadMore: function() {
let authorResult = this.data.authorResult;
let page = this.data.page + 1;
let end = this.data.end;
if (end) {
this.setData({isLoading: false});
return;
}
// 设置请求页+1,防止请求数据重复
this.setData({page});
let loadData;
guangUtil._getList(objectAssign({
page: page,
author_id: this.data.options.author_id,
gender: app.globalData.selectedChannel === 'boy' ? '1,3' : '2,3'
}), GET, API_HOST).then(rdata => {
loadData = rdata;
return guangUtil._getSimpleArticleList((rdata.list.artList || []).map(item => {
return item.id;
}), GET, API_HOST);
}).then(result => {
let artList = loadData.list && loadData.list.artList || [];
artList.map(item => {
(result.artList || []).map(sub => {
if (item.id === sub.articleId) {
objectAssign(item, sub);
}
});
});
if (!end) {
end = loadData.page >= loadData.totalPage;
}
authorResult = authorResult.concat(guangUtil._formatArticle(artList));
loadData = [];
result = [];
this.setData({authorResult: authorResult, isLoading: !end});
});
},
onScroll: function(e) {
var { scrollTop } = e.detail;
var isShow = scrollTop > windowHeight * 2 ? true : false;
if (isShow != this.data.isShowIndicator) {
this.setData({
isShowIndicator: isShow
});
}
},
backToTop: function () {
this.setData({
scrollTop: 0
});
}
});