diff --git a/app.js b/app.js new file mode 100644 index 0000000..1f5df9a --- /dev/null +++ b/app.js @@ -0,0 +1,7 @@ +//app.js +App({ + globalData:{ + appkey:'c39621ea5b825547001f9858a643f182', + pagesize:10, + } +}) \ No newline at end of file diff --git a/app.json b/app.json new file mode 100644 index 0000000..5b331a7 --- /dev/null +++ b/app.json @@ -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 + } +} diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..606999b --- /dev/null +++ b/app.wxss @@ -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; +} \ No newline at end of file diff --git a/image/ic_gif_blue.png b/image/ic_gif_blue.png new file mode 100644 index 0000000..3eed633 Binary files /dev/null and b/image/ic_gif_blue.png differ diff --git a/image/ic_gif_gray.png b/image/ic_gif_gray.png new file mode 100644 index 0000000..50c9f6d Binary files /dev/null and b/image/ic_gif_gray.png differ diff --git a/image/ic_joke_blue.png b/image/ic_joke_blue.png new file mode 100644 index 0000000..d27a2f9 Binary files /dev/null and b/image/ic_joke_blue.png differ diff --git a/image/ic_joke_gray.png b/image/ic_joke_gray.png new file mode 100644 index 0000000..02591f4 Binary files /dev/null and b/image/ic_joke_gray.png differ diff --git a/image/loading.gif b/image/loading.gif new file mode 100644 index 0000000..5bb505b Binary files /dev/null and b/image/loading.gif differ diff --git a/pages/about/about.js b/pages/about/about.js new file mode 100644 index 0000000..e69de29 diff --git a/pages/about/about.json b/pages/about/about.json new file mode 100644 index 0000000..e69de29 diff --git a/pages/about/about.wxml b/pages/about/about.wxml new file mode 100644 index 0000000..e69de29 diff --git a/pages/about/about.wxss b/pages/about/about.wxss new file mode 100644 index 0000000..e69de29 diff --git a/pages/index/index.js b/pages/index/index.js new file mode 100644 index 0000000..6ae22ca --- /dev/null +++ b/pages/index/index.js @@ -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 + }) + }) + } +}) diff --git a/pages/index/index.wxml b/pages/index/index.wxml new file mode 100644 index 0000000..022ad3b --- /dev/null +++ b/pages/index/index.wxml @@ -0,0 +1,10 @@ + + + + + {{userInfo.nickName}} + + + {{motto}} + + diff --git a/pages/index/index.wxss b/pages/index/index.wxss new file mode 100644 index 0000000..ce30de0 --- /dev/null +++ b/pages/index/index.wxss @@ -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; +} \ No newline at end of file diff --git a/pages/joke/joke.js b/pages/joke/joke.js new file mode 100644 index 0000000..e025fed --- /dev/null +++ b/pages/joke/joke.js @@ -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 + }) + }) + + + }, + +}) \ No newline at end of file diff --git a/pages/joke/joke.json b/pages/joke/joke.json new file mode 100644 index 0000000..dc7439c --- /dev/null +++ b/pages/joke/joke.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "笑话大全" +} \ No newline at end of file diff --git a/pages/joke/joke.wxml b/pages/joke/joke.wxml new file mode 100644 index 0000000..0dbbe65 --- /dev/null +++ b/pages/joke/joke.wxml @@ -0,0 +1,14 @@ + + + {{item.content}} + {{item.updatetime}} + + + + + \ No newline at end of file diff --git a/pages/joke/joke.wxss b/pages/joke/joke.wxss new file mode 100644 index 0000000..52e1820 --- /dev/null +++ b/pages/joke/joke.wxss @@ -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; +} + + diff --git a/pages/picture/picture.js b/pages/picture/picture.js new file mode 100644 index 0000000..ea47d47 --- /dev/null +++ b/pages/picture/picture.js @@ -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链接列表 + }) + } + +}) \ No newline at end of file diff --git a/pages/picture/picture.json b/pages/picture/picture.json new file mode 100644 index 0000000..2617026 --- /dev/null +++ b/pages/picture/picture.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "搞笑趣图" +} \ No newline at end of file diff --git a/pages/picture/picture.wxml b/pages/picture/picture.wxml new file mode 100644 index 0000000..77e4974 --- /dev/null +++ b/pages/picture/picture.wxml @@ -0,0 +1,11 @@ + + + {{item.content}} + + {{item.updatetime}} + + + + \ No newline at end of file diff --git a/pages/picture/picture.wxss b/pages/picture/picture.wxss new file mode 100644 index 0000000..6b659ce --- /dev/null +++ b/pages/picture/picture.wxss @@ -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; +} \ No newline at end of file diff --git a/utils/util.js b/utils/util.js new file mode 100644 index 0000000..7d375e4 --- /dev/null +++ b/utils/util.js @@ -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 +}