Skip to content

Commit 230d324

Browse files
committed
update: add collect topic list in the user profile
1 parent 9c3917c commit 230d324

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

src/dc/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class TopicCollect extends Base {
6565
return fnDataProcess(
6666
{
6767
url: this.sListUrl,
68-
method: 'post',
68+
method: 'get',
6969
...oOption
7070
},
7171
fnDataModel

src/pages/user/user.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Page({
22
data: {
33
bIsReady: false, // 页面是否准备就绪
4+
bIsFetchingUserCollectTopicList: false, // 是否正在获取用户收藏话题列表
45
nActiveTabIndex: 0,
56
aTabBar: [
67
{
@@ -14,11 +15,13 @@ Page({
1415
text: '话题收藏'
1516
}
1617
],
18+
aUserCollectTopicList: [], // 用户收藏话题列表
1719
oUserProfile: {}
1820
},
1921
onLoad(options) {
2022
if (options.name) {
2123
this.fnGetUserProfile(options.name);
24+
this.fnGetUserCollectTopicList(options.name);
2225
}
2326
},
2427
// 点击切换tab
@@ -28,6 +31,39 @@ Page({
2831
nActiveTabIndex: oDataSet.index
2932
});
3033
},
34+
// 获取用户收藏话题
35+
fnGetUserCollectTopicList(sUserName) {
36+
// 显示标题栏加载效果
37+
wx.showNavigationBarLoading();
38+
this.setData({
39+
bIsFetchingUserCollectTopicList: true
40+
});
41+
wx.dc.topicCollect
42+
.list(
43+
{
44+
urlData: {
45+
loginname: sUserName
46+
}
47+
},
48+
this.fnUserCollectTopicListDataModel
49+
)
50+
.then(res => {
51+
// 停止加载效果
52+
this.setData({
53+
aUserCollectTopicList: res.aTopicList,
54+
bIsFetchingUserCollectTopicList: false
55+
});
56+
wx.hideNavigationBarLoading();
57+
})
58+
.catch(err => {
59+
console.log(err);
60+
// 停止加载效果
61+
wx.hideNavigationBarLoading();
62+
this.setData({
63+
bIsFetchingUserCollectTopicList: false
64+
});
65+
});
66+
},
3167
// 获取用户资料
3268
fnGetUserProfile(sUserName) {
3369
// 显示标题栏加载效果
@@ -57,6 +93,19 @@ Page({
5793
wx.hideNavigationBarLoading();
5894
});
5995
},
96+
fnUserCollectTopicListDataModel(aData) {
97+
let oResult = {};
98+
if (!Array.isArray(aData)) {
99+
aData = [];
100+
}
101+
oResult.aTopicList = aData.map(oItem => {
102+
return {
103+
...oItem,
104+
last_reply_at: wx.moment(oItem.last_reply_at).fromNow()
105+
};
106+
});
107+
return oResult;
108+
},
60109
fnUserProfileDataModel(oData) {
61110
let oResult = {
62111
...oData,

src/pages/user/user.wxml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
<block wx:elif="{{nActiveTabIndex === 1}}">
3333
<topic-list list="{{oUserProfile.recent_topics}}"></topic-list>
3434
</block>
35-
<!-- TODO: 话题收藏列表 -->
35+
<!-- 话题收藏列表 -->
3636
<block wx:elif="{{nActiveTabIndex === 2}}">
37-
<view class="topic-collection-list ta-c">
38-
<view>敬请期待</view>
37+
<topic-list wx:if="{{!bIsFetchingUserCollectTopicList}}" list="{{aUserCollectTopicList}}"></topic-list>
38+
<view wx:else class="topic-collection-list ta-c">
39+
<view>正在加载...</view>
3940
</view>
4041
</block>
4142
</view>

0 commit comments

Comments
 (0)