Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijieeeeee committed Oct 13, 2016
0 parents commit 8e44269
Show file tree
Hide file tree
Showing 24 changed files with 343 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//app.js
App({
globalData:{
appkey:'c39621ea5b825547001f9858a643f182',
pagesize:10,
}
})
41 changes: 41 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"pages":[
"pages/joke/joke",
"pages/picture/picture",
"pages/index/index"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#268dcd",
"navigationBarTitleText": "开心一刻",
"navigationBarTextStyle":"white",
"enablePullDownRefresh":true
},
"tabBar": {
"color": "#000000",
"selectedColor": "#268dcd",
"borderStyle": "white",
"backgroundColor": "#ffffff",
"list": [
{
"pagePath": "pages/joke/joke",
"text": "笑话",
"iconPath": "image/ic_joke_gray.png",
"selectedIconPath": "image/ic_joke_blue.png"
},
{
"pagePath": "pages/picture/picture",
"text": "趣图",
"iconPath": "image/ic_gif_gray.png",
"selectedIconPath": "image/ic_gif_blue.png"
}

]
},
"netWorkTimeout": {
"request": 10000,
"connectSocket": 10000,
"uploadFile": 10000,
"downloadFile": 10000
}
}
26 changes: 26 additions & 0 deletions app.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**app.wxss**/
.container {
flex: 1;
display: flex;
flex-direction: column;
}

page{
height: 100%;
}

.page-body {
display: flex;
flex: 1;
flex-direction: column;
height: 100%;
}


.loading-view{
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 10px;
}
Binary file added image/ic_gif_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/ic_gif_gray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/ic_joke_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/ic_joke_gray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added pages/about/about.js
Empty file.
Empty file added pages/about/about.json
Empty file.
Empty file added pages/about/about.wxml
Empty file.
Empty file added pages/about/about.wxss
Empty file.
26 changes: 26 additions & 0 deletions pages/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//index.js
//获取应用实例
var app = getApp()
Page({
data: {
motto: 'Hello World',
userInfo: {}
},
//事件处理函数
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad: function () {
console.log('onLoad')
var that = this
//调用应用实例的方法获取全局数据
app.getUserInfo(function(userInfo){
//更新数据
that.setData({
userInfo:userInfo
})
})
}
})
10 changes: 10 additions & 0 deletions pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--index.wxml-->
<view class="container">
<view bindtap="bindViewTap" class="userinfo">
<image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</view>
<view class="usermotto">
<text class="user-motto">{{motto}}</text>
</view>
</view>
21 changes: 21 additions & 0 deletions pages/index/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**index.wxss**/
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
}

.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}

.userinfo-nickname {
color: #aaa;
}

.usermotto {
margin-top: 200px;
}
57 changes: 57 additions & 0 deletions pages/joke/joke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
var http = require( '../../utils/util' )
var app = getApp()
var url = 'http://japi.juhe.cn/joke/content/text.from'

Page( {
data: {
page: 1,
loadingHide: false,
hideFooter: true,
jokeList: [],
},
onLoad: function( options ) {
// 页面初始化 options为页面跳转所带来的参数
var that = this
//请求笑话列表
http.request( url, this.data.page, function( dataJson ) {
that.setData( {
jokeList: that.data.jokeList.concat( dataJson.result.data ),
loadingHide: true
})
}, function( reason ) {
console.log( reason )
that.setData( {
loadingHide: true
})
})

},

/**
* 滑动到底部加载更多
*/
loadMore() {
//请求笑话列表
var that = this
//显示footer
this.setData( {
hideFooter: !this.data.hideFooter
})
//请求笑话列表
http.request( url, ++this.data.page, function( dataJson ) {
that.setData( {
jokeList: that.data.jokeList.concat( dataJson.result.data ),
hideFooter: !that.data.hideFooter
})

}, function( reason ) {
console.log( reason )
that.setData( {
hideFooter: !that.data.hideFooter
})
})


},

})
3 changes: 3 additions & 0 deletions pages/joke/joke.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"navigationBarTitleText": "笑话大全"
}
14 changes: 14 additions & 0 deletions pages/joke/joke.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<scroll-view scroll-y="true" class="page-body" bindscrolltolower="loadMore">
<view class="item-view" wx:for="{{jokeList}}">
<text class="content">{{item.content}}</text>
<text class="date">{{item.updatetime}}</text>
</view>
<view class="loading-view" hidden="{{hideFooter}}">
<image src="../../image/loading.gif" style="height:26px;width:26px"/>
<text style="font-size:20px">正在加载</text>
</view>
</scroll-view>

<loading hidden="{{loadingHide}}">
加载中...
</loading>
17 changes: 17 additions & 0 deletions pages/joke/joke.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.item-view{
padding: 10px;
display: flex;
flex-direction: column;
border-bottom: 1px solid gray;
}

.item-view .content{
color: black;
}

.item-view .date{
color: grey;
margin-top: 10px;
}


55 changes: 55 additions & 0 deletions pages/picture/picture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
var app = getApp()
var http = require( '../../utils/util' )
var url = 'http://japi.juhe.cn/joke/img/text.from'
Page( {
data: {
page: 1,
loadingHide: false,
picList: []
},
onLoad: function( options ) {
// 页面初始化 options为页面跳转所带来的参数
var that = this
//请求笑话列表
http.request( url, this.data.page, function( dataJson ) {
that.setData( {
picList: that.data.picList.concat( dataJson.result.data ),
loadingHide: true
})
}, function( reason ) {
console.log( reason )
that.setData( {
loadingHide: true
})
})
},

/**
* 滑动到底部加载更多
*/
loadMore() {
//请求笑话列表
var that = this
http.request( url, ++this.data.page, function( dataJson ) {
that.setData( {
picList: that.data.picList.concat( dataJson.result.data ),

})
}, function( reason ) {
console.log( reason )
that.setData( {

})
})
},

preview( e ) {
console.log( e.target.dataset.url )
var urls = []
urls.push( e.target.dataset.url )
wx.previewImage( {
urls: urls // 需要预览的图片http链接列表
})
}

})
3 changes: 3 additions & 0 deletions pages/picture/picture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"navigationBarTitleText": "搞笑趣图"
}
11 changes: 11 additions & 0 deletions pages/picture/picture.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<scroll-view scroll-y="true" class="page-body" bindscrolltolower="loadMore">
<view class="item-view" wx:for="{{picList}}">
<text class="content">{{item.content}}</text>
<image src="{{item.url}}" mode="aspectFit" catchtap="preview" data-url="{{item.url}}"/>
<text class="date">{{item.updatetime}}</text>
</view>
</scroll-view>

<loading hidden="{{loadingHide}}">
加载中...
</loading>
17 changes: 17 additions & 0 deletions pages/picture/picture.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.item-view{
padding: 10px;
display: flex;
flex-direction: column;
border-bottom: 1px solid gray;
}

.item-view image{
width: 100%;
height: 400rpx;
margin-top: 10px;
}

.item-view .date{
color: grey;
margin-top: 10px;
}
35 changes: 35 additions & 0 deletions utils/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* 请求网络
*/
function request( url, page, success, fail ) {
if( typeof success != 'function' || typeof fail != 'function' ) {
return
}
var app = getApp()
wx.request( {
url: url,
data: {
key: app.globalData.appkey,
page: page,
pagesize: app.globalData.pagesize
},
header: {
'Content-Type': 'application/json'
},
success: function( res ) {
if( res.data.error_code == 0 ) {
success( res.data )
} else {
fail( res.data.reason )
}
},
fail: function() {
fail( '网络错误' )
}

})
}

module.exports = {
request: request
}

0 comments on commit 8e44269

Please sign in to comment.