Skip to content

Commit 2f3f90d

Browse files
author
uniquexiaobai
committed
add Feed page
1 parent bedf681 commit 2f3f90d

File tree

13 files changed

+133
-64
lines changed

13 files changed

+133
-64
lines changed

app.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"pages/famous/famous",
66
"pages/me/me",
77
"pages/settings/settings",
8-
"pages/logs/logs",
98
"pages/auth/onboard/onboard"
109
],
1110
"window":{

pages/explore/explore.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<view class="container">
2-
<loading hidden="{{loading_hidden}}" bindchange="loadingChange">
2+
<loading hidden="{{loading_hidden}}">
33
玩命加载中...
44
</loading>
55
<view class="col explore">

pages/explore/explore.wxss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.container {
22
height: 100%;
3+
background: rgba(255,255,255,0.8);
34
}
45
.explore {
56
flex: 1;

pages/famous/famous.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<view class="container">
2-
<loading hidden="{{loading_hidden}}" bindchange="loadingChange">
2+
<loading hidden="{{loading_hidden}}">
33
玩命加载中...
44
</loading>
55
<view class="col famous">

pages/famous/famous.wxss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.container {
22
height: 100%;
3+
background: rgba(255,255,255,0.8);
34
}
45
.famous {
56
flex: 1;

pages/helper/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
function formateActionType (type) {
3+
switch (type) {
4+
case 'CreateEvent':
5+
return 'Create';
6+
case 'DeleteEvent':
7+
return 'Delete';
8+
case 'ForkEvent':
9+
return 'Forked';
10+
case 'WatchEvent':
11+
return 'Started';
12+
case 'PushEvent':
13+
return 'Push';
14+
case 'PullRequestEvent':
15+
return 'Pull Request';
16+
case 'IssuesEvent':
17+
return 'Create Issue'
18+
case 'IssueCommentEvent':
19+
return 'Comment Issue';
20+
case 'MemberEvent':
21+
return 'Add Member'
22+
case 'PullRequestReviewCommentEvent':
23+
return 'Pull Request Review';
24+
default:
25+
return 'Started';
26+
}
27+
}
28+
29+
module.exports = {
30+
formateActionType: formateActionType
31+
};

pages/index/index.js

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,63 @@
11
const app = getApp();
2+
const services = require('../../utils/services.js');
3+
const helper = require('../helper/index.js');
24

35
Page({
46
data: {
5-
motto: 'Feed',
7+
loading_hidden: true,
8+
items: [],
9+
page: 1
610
},
711

8-
onLoad() {
12+
onLoad () {
913
const user = wx.getStorageSync('user');
1014
console.log(user);
1115
if(!user) {
1216
wx.navigateTo({
1317
url: '../auth/onboard/onboard'
1418
});
1519
}
20+
this.refreshData();
1621
},
1722

18-
bindViewTap() {
19-
wx.navigateTo({
20-
url: '../logs/logs'
21-
})
23+
_reloadUrl () {
24+
const basic_url = 'https://api.github.com/users/uniquexiaobai/received_events?page=';
25+
return basic_url + this.data.page;
2226
},
2327

24-
goRouteSignIn() {
25-
wx.navigateTo({
26-
url: '../auth/onboard/onboard'
28+
_initData () {
29+
this.setData({
30+
items: [],
31+
page: 1
2732
});
33+
},
34+
35+
fetchEventsData (url) {
36+
services.fetch(url).then(res => {
37+
console.log(res.data);
38+
res.data.forEach(item => {
39+
item.type = helper.formateActionType(item.type);
40+
});
41+
this.setData({
42+
items: this.data.items.concat(res.data),
43+
loading_hidden: true
44+
});
45+
});
46+
},
47+
48+
loadMoreData () {
49+
this.setData({
50+
page: ++this.data.page,
51+
loading_hidden: false
52+
});
53+
this.fetchEventsData(this._reloadUrl());
54+
},
55+
56+
refreshData () {
57+
this.setData({
58+
loading_hidden: false
59+
});
60+
this._initData();
61+
this.fetchEventsData(this._reloadUrl());
2862
}
2963
});

pages/index/index.wxml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
<view class="container col">
2-
<view bindtap="bindViewTap" class="userinfo">
3-
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
4-
<text>{{motto}}</text>
5-
</view>
6-
<view class="routes">
7-
<button bindtap="goRouteSignIn" type="primary" size="mini">SignIn</button>
8-
</view>
2+
<loading hidden="{{loading_hidden}}" bindchange="loadingChange">
3+
玩命加载中...
4+
</loading>
5+
<scroll-view scroll-y="true" bindscrolltolower="loadMoreData" bindscrolltoupper="refreshData">
6+
<block wx:for="{{items}}">
7+
<view class="col received_events">
8+
<view class="row received_event_top">
9+
<image class="actor_avatar" mode="aspectFit" src="{{item.actor.avatar_url}}"></image>
10+
<view class="col">
11+
<view class="actor_name">{{item.actor.display_login}}</view>
12+
<text class="action_time">1 hours ago</text>
13+
</view>
14+
</view>
15+
<view class="row received_event_bottom">
16+
<text class="action_type">{{item.type}}</text>
17+
<view class="action_repo">{{item.repo.name}}</view>
18+
</view>
19+
</view>
20+
</block>
21+
</scroll-view>
922
</view>

pages/index/index.wxss

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
1-
.userinfo {
2-
display: flex;
3-
flex-direction: column;
4-
align-items: center;
1+
.container {
2+
height: 100%;
3+
background: rgba(255,255,255,0.8);
54
}
6-
7-
.userinfo-avatar {
8-
width: 128rpx;
9-
height: 128rpx;
10-
margin: 20rpx;
11-
border-radius: 50%;
5+
scroll-view {
6+
width: 100%;
7+
height: 100%;
8+
}
9+
.received_events {
10+
border-bottom: 1rpx solid #ccc;
11+
padding: 15rpx;
1212
}
1313

14-
.userinfo-nickname {
15-
color: #aaa;
14+
.received_event_top {
15+
color: #5D5D5D;
16+
}
17+
.actor_avatar {
18+
width: 80rpx;
19+
height: 80rpx;
20+
margin-right: 30rpx;
21+
}
22+
.actor_name {
23+
color: #6491CC;
24+
}
25+
.action_time {
26+
color: #B8B8B8;
27+
font-size: 8rpx;
1628
}
1729

18-
.routes {
19-
display: flex;
30+
.received_event_bottom {
31+
margin-top: 10rpx;
32+
}
33+
.action_type {
34+
font-size: 25rpx;
35+
font-weight: bold;
36+
margin-right: 20rpx;
37+
}
38+
.action_repo {
39+
font-size: 16rpx;
40+
color: #6491CC;
2041
}

pages/logs/logs.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)