Skip to content

Commit 5f478d1

Browse files
committed
update: optimize home page fetch data
1 parent e610e04 commit 5f478d1

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/pages/index/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,19 @@ Page({
5353
'oTopicListReqParams.page': this.data.oTopicListReqParams.page
5454
});
5555
// 追加主题列表数据
56-
this.fnNetRTopicList(true);
56+
this.fnNetRTopicList(1);
5757
},
5858
// 切换tab选项卡
5959
fnTapSwitchTab(e) {
6060
let oDataSet = e.currentTarget.dataset;
61-
// 更新为当前活动的tab
61+
// 更新tab相关数据
6262
this.setData({
6363
nActiveTabIndex: oDataSet.index,
64-
'oTopicListReqParams.tab': oDataSet.tab
64+
'oTopicListReqParams.tab': oDataSet.tab,
65+
'oTopicListReqParams.page': 1
6566
});
6667
// 更新主题列表数据
67-
this.fnNetRTopicList();
68+
this.fnNetRTopicList(2);
6869
},
6970
// 过滤html标签
7071
fnFilterHtmlTag(sText = '') {
@@ -79,23 +80,29 @@ Page({
7980
},
8081
/**
8182
* 获取主题列表
82-
* @param {Boolean} bIsAppendTopicList 是否追加主题列表数据
83+
* @param {Number} nFetchScene 列表数据获取的场景值
84+
* 0 => 正常获取 1 => 页面触底后获取 2 => 切换tab后获取
8385
*/
84-
fnNetRTopicList(bIsAppendTopicList = false) {
86+
fnNetRTopicList(nFetchScene = 0) {
8587
// 显示标题栏加载效果
8688
wx.showNavigationBarLoading();
8789
wx.dc.topic
8890
.list(this.data.oTopicListReqParams, this.fnTopicListDataModel)
8991
.then(res => {
9092
if (res) {
9193
let aNewTopicList = res;
92-
if (bIsAppendTopicList) {
94+
// 根据场景值不同做不同的处理
95+
if (nFetchScene === 1) {
9396
// 将现有主题列表与刚获取到主题列表数据合并
9497
aNewTopicList = this.data.aTopicList.concat(aNewTopicList);
9598
}
9699
this.setData({
97100
aTopicList: aNewTopicList
98101
});
102+
if (nFetchScene === 2) {
103+
// 切换tab后,页面滚动到顶部
104+
wx.pageScrollTo({ scrollTop: 0, duration: 0 });
105+
}
99106
}
100107
// 停止加载效果
101108
wx.stopPullDownRefresh();

src/pages/login/login.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Page({
2323
fnTapLoginByScanCode() {
2424
wx.scanCode({
2525
success: res => {
26-
console.log(res);
2726
if (res.result) {
2827
this.fnNetUserLogin(res.result);
2928
}

0 commit comments

Comments
 (0)