├── README.md
├── app.js
├── app.json
├── app.wxss
├── image
├── ic_about_blue.png
├── ic_about_gray.png
├── ic_gif_blue.png
├── ic_gif_gray.png
├── ic_joke_blue.png
├── ic_joke_gray.png
└── loading.gif
├── pages
├── about
│ ├── about.js
│ ├── about.json
│ ├── about.wxml
│ └── about.wxss
├── common
│ └── common.wxml
├── joke
│ ├── joke.js
│ ├── joke.json
│ ├── joke.wxml
│ └── joke.wxss
└── picture
│ ├── picture.js
│ ├── picture.json
│ ├── picture.wxml
│ └── picture.wxss
├── project.config.json
├── screenshot
├── joke.png
└── picture.png
└── utils
└── util.js
/README.md:
--------------------------------------------------------------------------------
1 | # 微信小程序开发项目——笑话大全
2 |
3 | ###此项目是学习完微信小程序后实现的一个demo,采用[聚合数据](https://www.juhe.cn/)的免费api获取最新的文本笑话和趣图(图片和gif图)
4 |
5 |
6 |
7 |
8 | 
9 | 
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | globalData:{
4 | appkey:'c39621ea5b825547001f9858a643f182',
5 | pagesize:10,
6 | }
7 | })
--------------------------------------------------------------------------------
/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages":[
3 | "pages/joke/joke",
4 | "pages/picture/picture",
5 | "pages/about/about"
6 | ],
7 | "window":{
8 | "backgroundTextStyle":"light",
9 | "navigationBarBackgroundColor": "#268dcd",
10 | "navigationBarTitleText": "开心一刻",
11 | "navigationBarTextStyle":"white",
12 | "enablePullDownRefresh":true
13 | },
14 | "tabBar": {
15 | "color": "#000000",
16 | "selectedColor": "#268dcd",
17 | "borderStyle": "white",
18 | "backgroundColor": "#ffffff",
19 | "list": [
20 | {
21 | "pagePath": "pages/joke/joke",
22 | "text": "笑话",
23 | "iconPath": "image/ic_joke_gray.png",
24 | "selectedIconPath": "image/ic_joke_blue.png"
25 | },
26 | {
27 | "pagePath": "pages/picture/picture",
28 | "text": "趣图",
29 | "iconPath": "image/ic_gif_gray.png",
30 | "selectedIconPath": "image/ic_gif_blue.png"
31 | },
32 | {
33 | "pagePath": "pages/about/about",
34 | "text": "关于",
35 | "iconPath": "image/ic_about_gray.png",
36 | "selectedIconPath": "image/ic_about_blue.png"
37 | }
38 |
39 | ]
40 | },
41 | "netWorkTimeout": {
42 | "request": 10000,
43 | "connectSocket": 10000,
44 | "uploadFile": 10000,
45 | "downloadFile": 10000
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | .container {
3 | flex: 1;
4 | display: flex;
5 | flex-direction: column;
6 | }
7 |
8 | page{
9 | height: 100%;
10 | }
11 |
12 | .page-body {
13 | display: flex;
14 | flex: 1;
15 | flex-direction: column;
16 | height: 100%;
17 | }
18 |
19 |
20 | .loading-view{
21 | display: flex;
22 | flex-direction: row;
23 | justify-content: center;
24 | align-items: center;
25 | padding: 10px;
26 | }
27 |
28 | .item-view{
29 | padding: 10px;
30 | display: flex;
31 | flex-direction: column;
32 | border-top: 1px solid #DEDEDE;
33 | border-left: 1px solid #DEDEDE;
34 | box-shadow: 2px 2px 2px #C7C7C7;
35 | margin: 10px;
36 | border-radius: 5px;
37 | }
38 |
39 | .item-view .content{
40 | color: black;
41 | }
42 |
43 | .item-view .date{
44 | color: grey;
45 | margin-top: 10px;
46 | }
47 |
48 | .item-view image{
49 | width: 100%;
50 | height: 400rpx;
51 | margin-top: 10px;
52 | }
53 |
--------------------------------------------------------------------------------
/image/ic_about_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhijieeeeee/wechat-app-joke/8e3a3da40a9f9c7a02daec1f2a5aa9ebd2819f2b/image/ic_about_blue.png
--------------------------------------------------------------------------------
/image/ic_about_gray.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhijieeeeee/wechat-app-joke/8e3a3da40a9f9c7a02daec1f2a5aa9ebd2819f2b/image/ic_about_gray.png
--------------------------------------------------------------------------------
/image/ic_gif_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhijieeeeee/wechat-app-joke/8e3a3da40a9f9c7a02daec1f2a5aa9ebd2819f2b/image/ic_gif_blue.png
--------------------------------------------------------------------------------
/image/ic_gif_gray.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhijieeeeee/wechat-app-joke/8e3a3da40a9f9c7a02daec1f2a5aa9ebd2819f2b/image/ic_gif_gray.png
--------------------------------------------------------------------------------
/image/ic_joke_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhijieeeeee/wechat-app-joke/8e3a3da40a9f9c7a02daec1f2a5aa9ebd2819f2b/image/ic_joke_blue.png
--------------------------------------------------------------------------------
/image/ic_joke_gray.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhijieeeeee/wechat-app-joke/8e3a3da40a9f9c7a02daec1f2a5aa9ebd2819f2b/image/ic_joke_gray.png
--------------------------------------------------------------------------------
/image/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhijieeeeee/wechat-app-joke/8e3a3da40a9f9c7a02daec1f2a5aa9ebd2819f2b/image/loading.gif
--------------------------------------------------------------------------------
/pages/about/about.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data:{
3 | // text:"这是一个页面"
4 | },
5 | onLoad:function(options){
6 | // 页面初始化 options为页面跳转所带来的参数
7 | },
8 | onReady:function(){
9 | // 页面渲染完成
10 | },
11 | onShow:function(){
12 | // 页面显示
13 | },
14 | onHide:function(){
15 | // 页面隐藏
16 | },
17 | onUnload:function(){
18 | // 页面关闭
19 | }
20 | })
--------------------------------------------------------------------------------
/pages/about/about.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "关于我"
3 | }
--------------------------------------------------------------------------------
/pages/about/about.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | GitHub:
8 | https://github.com/zhijieeeeee
9 |
10 |
11 | CSDN:
12 | http://blog.csdn.net/u013155862
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/pages/about/about.wxss:
--------------------------------------------------------------------------------
1 | .container{
2 | padding:10px;
3 | display: flex;
4 | justify-content: center;
5 | align-items: center;
6 | }
7 |
8 | .container image{
9 | margin-top: 40px;
10 | width: 150px;
11 | height: 150px;
12 | }
13 |
14 | .container .about{
15 | margin: 10px;
16 | word-break:break-all;
17 | }
18 |
19 | .container .website{
20 | margin-top: 40px;
21 | display: flex;
22 | flex-direction: column;
23 | }
24 |
25 | .container .website .item{
26 | display: flex;
27 | flex-direction: row;
28 | margin-bottom: 10px;
29 | }
30 |
31 | .github{
32 | color: #268dcd;
33 | font-size: 20px;
34 | }
--------------------------------------------------------------------------------
/pages/common/common.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{item.content}}
5 | {{item.updatetime}}
6 |
7 |
8 |
9 |
10 |
11 |
12 | {{item.content}}
13 |
14 | {{item.updatetime}}
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | 正在加载
23 |
24 |
--------------------------------------------------------------------------------
/pages/joke/joke.js:
--------------------------------------------------------------------------------
1 | var http = require( '../../utils/util' )
2 | var app = getApp()
3 | var url = 'http://japi.juhe.cn/joke/content/text.from'
4 |
5 | Page( {
6 | data: {
7 | page: 1,
8 | loadingHide: false,
9 | hideFooter: true,
10 | jokeList: [],
11 | },
12 | onLoad: function( options ) {
13 | // 页面初始化 options为页面跳转所带来的参数
14 | var that = this
15 | //请求笑话列表
16 | http.request( url, this.data.page, function( dataJson ) {
17 | that.setData( {
18 | jokeList: that.data.jokeList.concat( dataJson.result.data ),
19 | loadingHide: true
20 | })
21 | }, function( reason ) {
22 | console.log( reason )
23 | that.setData( {
24 | loadingHide: true
25 | })
26 | })
27 |
28 | },
29 |
30 | /**
31 | * 下拉刷新
32 | */
33 | onPullDownRefresh() {
34 | // var that = this
35 | // this.setData( {
36 | // page: 1,
37 | // jokeList:[]
38 | // })
39 | // http.request( url, this.data.page, function( dataJson ) {
40 | // that.setData( {
41 | // jokeList: that.data.jokeList.concat( dataJson.result.data )
42 | // })
43 | // wx.stopPullDownRefresh()
44 | // }, function( reason ) {
45 | // console.log( reason )
46 | // wx.stopPullDownRefresh()
47 | // })
48 | },
49 |
50 | /**
51 | * 滑动到底部加载更多
52 | */
53 | loadMore() {
54 | //请求笑话列表
55 | var that = this
56 | //显示footer
57 | this.setData( {
58 | hideFooter: !this.data.hideFooter
59 | })
60 | //请求笑话列表
61 | http.request( url, ++this.data.page, function( dataJson ) {
62 | that.setData( {
63 | jokeList: that.data.jokeList.concat( dataJson.result.data ),
64 | hideFooter: !that.data.hideFooter
65 | })
66 |
67 | }, function( reason ) {
68 | console.log( reason )
69 | that.setData( {
70 | hideFooter: !that.data.hideFooter
71 | })
72 | })
73 |
74 |
75 | },
76 |
77 | })
--------------------------------------------------------------------------------
/pages/joke/joke.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "笑话大全"
3 | }
--------------------------------------------------------------------------------
/pages/joke/joke.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | 加载中...
10 |
--------------------------------------------------------------------------------
/pages/joke/joke.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhijieeeeee/wechat-app-joke/8e3a3da40a9f9c7a02daec1f2a5aa9ebd2819f2b/pages/joke/joke.wxss
--------------------------------------------------------------------------------
/pages/picture/picture.js:
--------------------------------------------------------------------------------
1 | var app = getApp()
2 | var http = require( '../../utils/util' )
3 | var url = 'http://japi.juhe.cn/joke/img/text.from'
4 | Page( {
5 | data: {
6 | page: 1,
7 | loadingHide: false,
8 | hideFooter: true,
9 | picList: []
10 | },
11 | onLoad: function( options ) {
12 | // 页面初始化 options为页面跳转所带来的参数
13 | var that = this
14 | //请求笑话列表
15 | http.request( url, this.data.page, function( dataJson ) {
16 | that.setData( {
17 | picList: that.data.picList.concat( dataJson.result.data ),
18 | loadingHide: true
19 | })
20 | }, function( reason ) {
21 | console.log( reason )
22 | that.setData( {
23 | loadingHide: true
24 | })
25 | })
26 | },
27 |
28 | /**
29 | * 滑动到底部加载更多
30 | */
31 | loadMore() {
32 | //请求笑话列表
33 | var that = this
34 | //显示footer
35 | this.setData( {
36 | hideFooter: !this.data.hideFooter
37 | })
38 | http.request( url, ++this.data.page, function( dataJson ) {
39 | that.setData( {
40 | picList: that.data.picList.concat( dataJson.result.data ),
41 | hideFooter: !that.data.hideFooter
42 | })
43 | }, function( reason ) {
44 | console.log( reason )
45 | that.setData( {
46 | hideFooter: !that.data.hideFooter
47 | })
48 | })
49 | },
50 |
51 | preview( e ) {
52 | console.log( e.target.dataset.url )
53 | var urls = []
54 | urls.push( e.target.dataset.url )
55 | wx.previewImage( {
56 | urls: urls // 需要预览的图片http链接列表
57 | })
58 | }
59 |
60 | })
--------------------------------------------------------------------------------
/pages/picture/picture.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "搞笑趣图"
3 | }
--------------------------------------------------------------------------------
/pages/picture/picture.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | 加载中...
10 |
--------------------------------------------------------------------------------
/pages/picture/picture.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhijieeeeee/wechat-app-joke/8e3a3da40a9f9c7a02daec1f2a5aa9ebd2819f2b/pages/picture/picture.wxss
--------------------------------------------------------------------------------
/project.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "项目配置文件。",
3 | "setting": {
4 | "urlCheck": true,
5 | "es6": true,
6 | "postcss": true,
7 | "minified": true,
8 | "newFeature": true
9 | },
10 | "compileType": "miniprogram",
11 | "libVersion": "1.6.4",
12 | "appid": "touristappid",
13 | "projectname": "%E7%AC%91%E8%AF%9D%E5%A4%A7%E5%85%A8",
14 | "condition": {
15 | "search": {
16 | "current": -1,
17 | "list": []
18 | },
19 | "conversation": {
20 | "current": -1,
21 | "list": []
22 | },
23 | "miniprogram": {
24 | "current": -1,
25 | "list": []
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/screenshot/joke.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhijieeeeee/wechat-app-joke/8e3a3da40a9f9c7a02daec1f2a5aa9ebd2819f2b/screenshot/joke.png
--------------------------------------------------------------------------------
/screenshot/picture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhijieeeeee/wechat-app-joke/8e3a3da40a9f9c7a02daec1f2a5aa9ebd2819f2b/screenshot/picture.png
--------------------------------------------------------------------------------
/utils/util.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 请求网络
3 | */
4 | function request( url, page, success, fail ) {
5 | if( typeof success != 'function' || typeof fail != 'function' ) {
6 | return
7 | }
8 | var app = getApp()
9 | wx.request( {
10 | url: url,
11 | data: {
12 | key: app.globalData.appkey,
13 | page: page,
14 | pagesize: app.globalData.pagesize
15 | },
16 | success: function( res ) {
17 | if( res.data.error_code == 0 ) {
18 | success( res.data )
19 | } else {
20 | fail( res.data.reason )
21 | }
22 | },
23 | fail: function() {
24 | fail( '网络错误' )
25 | }
26 |
27 | })
28 | }
29 |
30 | module.exports = {
31 | request: request
32 | }
33 |
--------------------------------------------------------------------------------