├── LICENSE
├── README.md
├── chaptor_01
├── README.md
├── app.js
├── app.json
├── app.wxss
├── images
│ ├── 1应用生命周期.png
│ ├── 2页面生命周期.png
│ ├── 3应用与页面生命周期.png
│ └── 小程序生命周期.gif
├── pages
│ ├── index
│ │ ├── index.js
│ │ ├── index.wxml
│ │ └── index.wxss
│ └── logs
│ │ ├── logs.js
│ │ ├── logs.json
│ │ ├── logs.wxml
│ │ └── logs.wxss
└── utils
│ └── util.js
├── chaptor_02
├── README.md
├── app.js
├── app.json
├── app.wxss
├── images
│ ├── click.gif
│ ├── code1.png
│ ├── code2.png
│ ├── coor.png
│ ├── dbclick.gif
│ ├── longtap.gif
│ └── shoushi.gif
├── pages
│ ├── index
│ │ ├── index.js
│ │ ├── index.json
│ │ ├── index.wxml
│ │ └── index.wxss
│ └── logs
│ │ ├── logs.js
│ │ ├── logs.json
│ │ ├── logs.wxml
│ │ └── logs.wxss
└── utils
│ └── util.js
├── chaptor_03
├── app.js
├── app.json
├── app.wxss
├── pages
│ ├── chat
│ │ ├── chat.js
│ │ ├── chat.json
│ │ ├── chat.wxml
│ │ └── chat.wxss
│ ├── index
│ │ ├── index.js
│ │ ├── index.wxml
│ │ └── index.wxss
│ └── logs
│ │ ├── logs.js
│ │ ├── logs.json
│ │ ├── logs.wxml
│ │ └── logs.wxss
└── utils
│ └── util.js
├── chaptor_04
├── app.js
├── app.json
├── app.wxss
├── fonts
│ ├── ionicons.eot
│ ├── ionicons.svg
│ ├── ionicons.ttf
│ └── ionicons.woff
├── media
│ └── test.mp4
├── pages
│ ├── index
│ │ ├── index.js
│ │ ├── index.wxml
│ │ └── index.wxss
│ └── logs
│ │ ├── logs.js
│ │ ├── logs.json
│ │ ├── logs.wxml
│ │ └── logs.wxss
└── utils
│ └── util.js
├── chaptor_05
├── .gitignore
├── README.md
├── app.js
├── app.json
├── app.wxss
├── pages
│ ├── index
│ │ ├── index.js
│ │ ├── index.json
│ │ ├── index.wxml
│ │ └── index.wxss
│ └── logs
│ │ ├── logs.js
│ │ ├── logs.json
│ │ ├── logs.wxml
│ │ └── logs.wxss
├── utils
│ ├── httpclient.js
│ └── util.js
└── weui.wxss
├── chaptor_06
├── .gitignore
├── app.js
├── app.json
├── app.wxss
├── pages
│ ├── index
│ │ ├── index.js
│ │ ├── index.json
│ │ ├── index.wxml
│ │ └── index.wxss
│ ├── logs
│ │ ├── logs.js
│ │ ├── logs.json
│ │ ├── logs.wxml
│ │ └── logs.wxss
│ ├── route1
│ │ ├── route1.js
│ │ ├── route1.json
│ │ ├── route1.wxml
│ │ └── route1.wxss
│ ├── route2
│ │ ├── route2.js
│ │ ├── route2.json
│ │ ├── route2.wxml
│ │ └── route2.wxss
│ ├── route3
│ │ ├── route3.js
│ │ ├── route3.json
│ │ ├── route3.wxml
│ │ └── route3.wxss
│ ├── route4
│ │ ├── route4.js
│ │ ├── route4.json
│ │ ├── route4.wxml
│ │ └── route4.wxss
│ └── route5
│ │ ├── route5.js
│ │ ├── route5.json
│ │ ├── route5.wxml
│ │ └── route5.wxss
├── utils
│ └── util.js
└── weui.wxss
├── chaptor_07
├── .gitignore
├── app.js
├── app.json
├── app.wxss
├── images
│ ├── 1.png
│ ├── 2.jpg
│ ├── 3.png
│ ├── 4.png
│ ├── 5.png
│ ├── 6.jpg
│ ├── 7.jpg
│ ├── 8.jpg
│ └── 9.png
├── pages
│ ├── article
│ │ ├── list.js
│ │ ├── list.json
│ │ ├── list.wxml
│ │ └── list.wxss
│ ├── articledetail
│ │ ├── detail.js
│ │ ├── detail.json
│ │ ├── detail.wxml
│ │ └── detail.wxss
│ ├── index
│ │ ├── index.js
│ │ ├── index.json
│ │ ├── index.wxml
│ │ └── index.wxss
│ └── logs
│ │ ├── logs.js
│ │ ├── logs.json
│ │ ├── logs.wxml
│ │ └── logs.wxss
├── utils
│ ├── httpclient.js
│ └── util.js
├── weui.wxss
└── wxParse
│ ├── emojis
│ ├── 00.gif
│ ├── 01.gif
│ ├── 02.gif
│ ├── 03.gif
│ ├── 04.gif
│ ├── 05.gif
│ ├── 06.gif
│ ├── 07.gif
│ ├── 08.gif
│ ├── 09.gif
│ ├── 10.gif
│ ├── 100.gif
│ ├── 101.gif
│ ├── 102.gif
│ ├── 103.gif
│ ├── 104.gif
│ ├── 105.gif
│ ├── 106.gif
│ ├── 107.gif
│ ├── 108.gif
│ ├── 109.gif
│ ├── 11.gif
│ ├── 110.gif
│ ├── 111.gif
│ ├── 112.gif
│ ├── 113.gif
│ ├── 114.gif
│ ├── 115.gif
│ ├── 116.gif
│ ├── 117.gif
│ ├── 118.gif
│ ├── 119.gif
│ ├── 12.gif
│ ├── 120.gif
│ ├── 121.gif
│ ├── 122.gif
│ ├── 123.gif
│ ├── 124.gif
│ ├── 125.gif
│ ├── 126.gif
│ ├── 127.gif
│ ├── 128.gif
│ ├── 129.gif
│ ├── 13.gif
│ ├── 130.gif
│ ├── 131.gif
│ ├── 132.gif
│ ├── 133.gif
│ ├── 134.gif
│ ├── 14.gif
│ ├── 15.gif
│ ├── 16.gif
│ ├── 17.gif
│ ├── 18.gif
│ ├── 19.gif
│ ├── 20.gif
│ ├── 21.gif
│ ├── 22.gif
│ ├── 23.gif
│ ├── 24.gif
│ ├── 25.gif
│ ├── 26.gif
│ ├── 27.gif
│ ├── 28.gif
│ ├── 29.gif
│ ├── 30.gif
│ ├── 31.gif
│ ├── 32.gif
│ ├── 33.gif
│ ├── 34.gif
│ ├── 35.gif
│ ├── 36.gif
│ ├── 37.gif
│ ├── 38.gif
│ ├── 39.gif
│ ├── 40.gif
│ ├── 41.gif
│ ├── 42.gif
│ ├── 43.gif
│ ├── 44.gif
│ ├── 45.gif
│ ├── 46.gif
│ ├── 47.gif
│ ├── 48.gif
│ ├── 49.gif
│ ├── 50.gif
│ ├── 51.gif
│ ├── 52.gif
│ ├── 53.gif
│ ├── 54.gif
│ ├── 55.gif
│ ├── 56.gif
│ ├── 57.gif
│ ├── 58.gif
│ ├── 59.gif
│ ├── 60.gif
│ ├── 61.gif
│ ├── 62.gif
│ ├── 63.gif
│ ├── 64.gif
│ ├── 65.gif
│ ├── 66.gif
│ ├── 67.gif
│ ├── 68.gif
│ ├── 69.gif
│ ├── 70.gif
│ ├── 71.gif
│ ├── 72.gif
│ ├── 73.gif
│ ├── 74.gif
│ ├── 75.gif
│ ├── 76.gif
│ ├── 77.gif
│ ├── 78.gif
│ ├── 79.gif
│ ├── 80.gif
│ ├── 81.gif
│ ├── 82.gif
│ ├── 83.gif
│ ├── 84.gif
│ ├── 85.gif
│ ├── 86.gif
│ ├── 87.gif
│ ├── 88.gif
│ ├── 89.gif
│ ├── 90.gif
│ ├── 91.gif
│ ├── 92.gif
│ ├── 93.gif
│ ├── 94.gif
│ ├── 95.gif
│ ├── 96.gif
│ ├── 97.gif
│ ├── 98.gif
│ └── 99.gif
│ ├── html2json.js
│ ├── htmlparser.js
│ ├── showdown.js
│ ├── wxDiscode.js
│ ├── wxParse.js
│ ├── wxParse.wxml
│ └── wxParse.wxss
├── chaptor_08
├── .gitignore
├── app.js
├── app.json
├── app.wxss
├── pages
│ ├── index
│ │ ├── index.js
│ │ ├── index.wxml
│ │ └── index.wxss
│ └── logs
│ │ ├── logs.js
│ │ ├── logs.json
│ │ ├── logs.wxml
│ │ └── logs.wxss
└── utils
│ ├── localStorage.js
│ └── util.js
├── chaptor_10
├── .gitignore
├── README.md
├── app.js
├── app.json
├── app.wxss
├── images
│ ├── test.gif
│ └── test.jpeg
├── pages
│ ├── canvas1
│ │ ├── canvas1.js
│ │ ├── canvas1.json
│ │ ├── canvas1.wxml
│ │ └── canvas1.wxss
│ ├── canvas2
│ │ ├── canvas2.js
│ │ ├── canvas2.json
│ │ ├── canvas2.wxml
│ │ └── canvas2.wxss
│ ├── canvas3
│ │ ├── canvas3.js
│ │ ├── canvas3.json
│ │ ├── canvas3.wxml
│ │ └── canvas3.wxss
│ ├── canvas4
│ │ ├── canvas4.js
│ │ ├── canvas4.json
│ │ ├── canvas4.wxml
│ │ └── canvas4.wxss
│ ├── canvas5
│ │ ├── canvas5.js
│ │ ├── canvas5.json
│ │ ├── canvas5.wxml
│ │ └── canvas5.wxss
│ └── index
│ │ ├── index.js
│ │ ├── index.json
│ │ ├── index.wxml
│ │ └── index.wxss
├── utils
│ └── util.js
└── xiaohuangxiang.png
├── chaptor_11
├── .gitignore
├── app.js
├── app.json
├── app.wxss
├── pages
│ ├── index
│ │ ├── index.js
│ │ ├── index.json
│ │ ├── index.wxml
│ │ └── index.wxss
│ ├── logs
│ │ ├── logs.js
│ │ ├── logs.json
│ │ ├── logs.wxml
│ │ └── logs.wxss
│ └── share
│ │ ├── share.js
│ │ ├── share.json
│ │ ├── share.wxml
│ │ └── share.wxss
└── utils
│ └── util.js
├── screenshot
├── chaptor_07-01.gif
├── dingyuhao.JPG
└── mapjietu.gif
├── weixin_demo
├── app.js
├── app.json
├── app.wxss
├── pages
│ ├── component
│ │ ├── button
│ │ │ ├── buttons.js
│ │ │ ├── buttons.json
│ │ │ ├── buttons.wxml
│ │ │ └── buttons.wxss
│ │ ├── flex
│ │ │ ├── myflex.js
│ │ │ ├── myflex.json
│ │ │ ├── myflex.wxml
│ │ │ └── myflex.wxss
│ │ ├── labels
│ │ │ ├── labels.js
│ │ │ ├── labels.json
│ │ │ ├── labels.wxml
│ │ │ └── labels.wxss
│ │ ├── map
│ │ │ ├── map.js
│ │ │ ├── map.json
│ │ │ ├── map.wxml
│ │ │ └── map.wxss
│ │ ├── myrequest
│ │ │ ├── myreq.js
│ │ │ ├── myreq.json
│ │ │ ├── myreq.wxml
│ │ │ └── myreq.wxss
│ │ ├── swiper
│ │ │ ├── myswiper.js
│ │ │ ├── myswiper.json
│ │ │ ├── myswiper.wxml
│ │ │ └── myswiper.wxss
│ │ └── uploadfile
│ │ │ ├── uploadfile.js
│ │ │ ├── uploadfile.json
│ │ │ ├── uploadfile.wxml
│ │ │ └── uploadfile.wxss
│ ├── index
│ │ ├── index.js
│ │ ├── index.wxml
│ │ └── index.wxss
│ └── logs
│ │ ├── logs.js
│ │ ├── logs.json
│ │ ├── logs.wxml
│ │ └── logs.wxss
├── utils
│ └── util.js
└── weui.min.css
└── wschat.html
/README.md:
--------------------------------------------------------------------------------
1 | # wechat-mini-program-learning
2 | 微信小程序学习系列
3 |
4 | 作者博客:[http://www.cnblogs.com/nosqlcoco](http://www.cnblogs.com/nosqlcoco)
5 |
6 | # 快速入门
7 |
8 | 1. [微信小程序入门正确姿势(一)](http://www.cnblogs.com/nosqlcoco/p/5927249.html)
9 | * [微信小程序开发工具使用与设计规范(二)](http://www.cnblogs.com/nosqlcoco/p/5931952.html)
10 |
11 | # 案例
12 | - chaptor_01: [微信小程序之生命周期(三)](http://www.cnblogs.com/nosqlcoco/p/wxsmallcycle.html)
13 | - chaptor_02: 小程序触控事件
14 | - chaptor_03: 小程序websocket长连接
15 | - chaptor_04: 音乐播放控制
16 | - chaptor_05: 用户敏感数据解密
17 | - chaptor_06: 页面路由
18 | - chaptor_07: 小程序DEMO-小黄象社区
19 | - chaptor_08: 本地缓存
20 | - chaptor_10: canvas
21 | - chaptor_11: 小程序扫码、分享、客服消息
22 | - weixin_Demo: UI组件
23 |
24 | 图片上传和长连接依赖后台接口,请参照另一个项目[springboot-weapp-demo](https://github.com/cocoli/springboot-weapp-demo)
25 |
26 | 小程序交流群:594342242
27 |
28 | 我的订阅号:
29 | 
30 |
--------------------------------------------------------------------------------
/chaptor_01/README.md:
--------------------------------------------------------------------------------
1 | 这一章节介绍微信小程序的生命周期,什么是生命周期呢?
2 |
3 | > 通俗的讲,生命周期就是指一个对象的生老病死。
4 | > 从软件的角度来看,生命周期指程序从创建、到开始、暂停、唤起、停止、卸载的过程。
5 |
6 | 下面从一下三个方面介绍微信小程序的生命周期:
7 |
8 | - 应用生命周期
9 | - 页面生命周期
10 | - 应用与页面生命周期
11 |
12 | 》》》应用生命周期
13 |
14 | ![enter description here][1]
15 |
16 | 1. 用户首次打开小程序,触发 onLaunch(全局只触发一次)。
17 | * 小程序初始化完成后,触发onShow方法,监听小程序显示。
18 | * 小程序从前台进入后台,触发 onHide方法。
19 | * 小程序从后台进入前台显示,触发 onShow方法。
20 | * 小程序后台运行一定时间,或系统资源占用过高,会被销毁。
21 |
22 | 前台、后台定义: 当用户点击左上角关闭,或者按了设备 Home 键离开微信,小程序并没有直接销毁,而是进入了后台;当再次进入微信或再次打开小程序,又会从后台进入前台。
23 |
24 | 在整理本文资料的时候,有点不解,为什么不把小程序监听『销毁』方法开放给开发者,我猜测是因为IOS系统限制『按下Home键时,app从活动状态转入后台,会被挂起』;微信也不例外,只要运行一段时间或把微信客户端进程杀掉,就无法通知小程序应用被销毁。
25 |
26 | 》》》页面生命周期
27 |
28 | ![enter description here][2]
29 |
30 | 1. 小程序注册完成后,加载页面,触发onLoad方法。
31 | * 页面载入后触发onShow方法,显示页面。
32 | * 首次显示页面,会触发onReady方法,渲染页面元素和样式,一个页面只会调用一次。
33 | * 当小程序后台运行或跳转到其他页面时,触发onHide方法。
34 | * 当小程序有后台进入到前台运行或重新进入页面时,触发onShow方法。
35 | * 当使用重定向方法wx.redirectTo(OBJECT)或关闭当前页返回上一页wx.navigateBack(),触发onUnload
36 |
37 | 》》》应用生命周期影响页面生命周期
38 |
39 | ![enter description here][3]
40 |
41 | 1. 小程序初始化完成后,页面首次加载触发onLoad,只会触发一次。
42 | * 当小程序进入到后台,先执行页面onHide方法再执行应用onHide方法。
43 | * 当小程序从后台进入到前台,先执行应用onShow方法再执行页面onShow方法。
44 |
45 | 下图是小程序从注册到页面加入,前后台切换流程。
46 | ![enter description here][4]
47 |
48 |
49 |
50 | [1]: ./images/1%E5%BA%94%E7%94%A8%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F.png "1应用生命周期.png"
51 | [2]: ./images/2%E9%A1%B5%E9%9D%A2%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F.png "2页面生命周期.png"
52 | [3]: ./images/3%E5%BA%94%E7%94%A8%E4%B8%8E%E9%A1%B5%E9%9D%A2%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F.png "3应用与页面生命周期.png"
53 | [4]: ./images/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F.gif "小程序生命周期.gif"
54 |
--------------------------------------------------------------------------------
/chaptor_01/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | onLaunch: function () {
4 | //调用API从本地缓存中获取数据
5 | var logs = wx.getStorageSync('logs') || []
6 | logs.unshift(Date.now())
7 | wx.setStorageSync('logs', logs)
8 | console.log('小程序正在启动...')
9 | },
10 | onShow: function(){
11 | console.log('进入小程序')
12 | },
13 | onHide: function(){
14 | console.log('小程序隐藏了...')
15 | },
16 | getUserInfo:function(cb){
17 | var that = this;
18 | if(this.globalData.userInfo){
19 | typeof cb == "function" && cb(this.globalData.userInfo)
20 | }else{
21 | //调用登录接口
22 | wx.login({
23 | success: function () {
24 | wx.getUserInfo({
25 | success: function (res) {
26 | that.globalData.userInfo = res.userInfo;
27 | typeof cb == "function" && cb(that.globalData.userInfo)
28 | }
29 | })
30 | }
31 | });
32 | }
33 | },
34 | globalData:{
35 | userInfo:null,
36 | lastStartTime: new Date()
37 | }
38 | })
39 |
--------------------------------------------------------------------------------
/chaptor_01/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages":[
3 | "pages/index/index",
4 | "pages/logs/logs"
5 | ],
6 | "window":{
7 | "backgroundTextStyle":"light",
8 | "navigationBarBackgroundColor": "#fff",
9 | "navigationBarTitleText": "WeChat",
10 | "navigationBarTextStyle":"black",
11 | "enablePullDownRefresh": true
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/chaptor_01/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | .container {
3 | height: 100%;
4 | display: flex;
5 | flex-direction: column;
6 | align-items: center;
7 | justify-content: space-between;
8 | padding: 200rpx 0;
9 | box-sizing: border-box;
10 | }
11 |
--------------------------------------------------------------------------------
/chaptor_01/images/1应用生命周期.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_01/images/1应用生命周期.png
--------------------------------------------------------------------------------
/chaptor_01/images/2页面生命周期.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_01/images/2页面生命周期.png
--------------------------------------------------------------------------------
/chaptor_01/images/3应用与页面生命周期.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_01/images/3应用与页面生命周期.png
--------------------------------------------------------------------------------
/chaptor_01/images/小程序生命周期.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_01/images/小程序生命周期.gif
--------------------------------------------------------------------------------
/chaptor_01/pages/index/index.js:
--------------------------------------------------------------------------------
1 | //index.js
2 | //获取应用实例
3 | var app = getApp()
4 | Page({
5 | data: {
6 | motto: 'Hello World',
7 | userInfo: {}
8 | },
9 | //事件处理函数
10 | bindViewTap: function() {
11 | wx.navigateTo({
12 | url: '../logs/logs'
13 | })
14 | },
15 | onLoad: function () {
16 | console.log('载入页面')
17 | var that = this
18 | //调用应用实例的方法获取全局数据
19 | app.getUserInfo(function(userInfo){
20 | //更新数据
21 | that.setData({
22 | userInfo:userInfo
23 | })
24 | })
25 | },
26 | onReady: function(){
27 | console.log('页面首次渲染完成')
28 | },
29 | onShow: function () {
30 | console.log('显示页面')
31 | //console.log(getApp().globalData.lastStartTime)
32 | },
33 | onHide: function () {
34 | console.log('隐藏页面')
35 | },
36 | onUnload: function(){
37 | console.log('卸载页面')
38 | },
39 | onPullDownRefreash: function(){
40 | console.log('页面下拉刷新')
41 | }
42 | })
43 |
--------------------------------------------------------------------------------
/chaptor_01/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {{userInfo.nickName}}
6 |
7 |
8 | {{motto}}
9 |
10 |
11 |
--------------------------------------------------------------------------------
/chaptor_01/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /**index.wxss**/
2 | .userinfo {
3 | display: flex;
4 | flex-direction: column;
5 | align-items: center;
6 | }
7 |
8 | .userinfo-avatar {
9 | width: 128rpx;
10 | height: 128rpx;
11 | margin: 20rpx;
12 | border-radius: 50%;
13 | }
14 |
15 | .userinfo-nickname {
16 | color: #aaa;
17 | }
18 |
19 | .usermotto {
20 | margin-top: 200px;
21 | }
--------------------------------------------------------------------------------
/chaptor_01/pages/logs/logs.js:
--------------------------------------------------------------------------------
1 | //logs.js
2 | var util = require('../../utils/util.js')
3 | Page({
4 | data: {
5 | logs: []
6 | },
7 | onLoad: function () {
8 | this.setData({
9 | logs: (wx.getStorageSync('logs') || []).map(function (log) {
10 | return util.formatTime(new Date(log))
11 | })
12 | })
13 | },
14 | unLoad: function(){
15 | console.log("log unmout");
16 | }
17 | })
18 |
--------------------------------------------------------------------------------
/chaptor_01/pages/logs/logs.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "查看启动日志"
3 | }
--------------------------------------------------------------------------------
/chaptor_01/pages/logs/logs.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{index + 1}}. {{log}}
5 |
6 |
7 |
--------------------------------------------------------------------------------
/chaptor_01/pages/logs/logs.wxss:
--------------------------------------------------------------------------------
1 | .log-list {
2 | display: flex;
3 | flex-direction: column;
4 | padding: 40rpx;
5 | }
6 | .log-item {
7 | margin: 10rpx;
8 | }
9 |
--------------------------------------------------------------------------------
/chaptor_01/utils/util.js:
--------------------------------------------------------------------------------
1 | function formatTime(date) {
2 | var year = date.getFullYear()
3 | var month = date.getMonth() + 1
4 | var day = date.getDate()
5 |
6 | var hour = date.getHours()
7 | var minute = date.getMinutes()
8 | var second = date.getSeconds();
9 |
10 |
11 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
12 | }
13 |
14 | function formatNumber(n) {
15 | n = n.toString()
16 | return n[1] ? n : '0' + n
17 | }
18 |
19 | module.exports = {
20 | formatTime: formatTime
21 | }
22 |
--------------------------------------------------------------------------------
/chaptor_02/README.md:
--------------------------------------------------------------------------------
1 | ## 微信小程序之事件绑定
2 |
3 | ### 》》》什么是事件
4 | - 事件是视图层到逻辑层的通讯方式。
5 | - 事件可以将用户的行为反馈到逻辑层进行处理。
6 | - 事件可以绑定在组件上,当达到触发事件,就会执行逻辑层中对应的事件处理函数。
7 | - 事件对象可以携带额外信息,如id, dataset, touches。
8 |
9 | ### 》》》事件分类
10 | - touchstart 手指触摸
11 | - touchmove 手指触摸后移动
12 | - touchcancel 手指触摸动作被打断,如弹窗和来电提醒
13 | - touchend 手指触摸动作结束
14 | - tap 手指触摸后离开
15 | - longtap 手指触摸后后,超过350ms离开
16 |
17 | ### 》》》事件绑定
18 |
19 | 事件绑定的写法同组件的属性,以 key、value 的形式。
20 |
21 | - key 以bind或catch开头,然后跟上事件的类型,如bindtap, catchtouchstart
22 | - value 是一个字符串,需要在对应的 Page 中定义同名的函数。不然当触发事件的时候会报错。
23 | bind事件绑定不会阻止冒泡事件向上冒泡,catch事件绑定可以阻止冒泡事件向上冒泡。
24 |
25 | 上面简单介绍了小程序事件基础,是时候彰显"事件"的威力:
26 | - 单击(tap)
27 | - 双击(dbtap)
28 | - 长按(longtap)
29 | - 滑动
30 | - 多点触控
31 |
32 | #### 1.单击
33 | 单击事件由touchstart、touchend组成,touchend后触发tap事件。
34 |
35 | 
36 |
37 | ```html
38 |
39 |
40 |
41 | ```
42 |
43 | ```javascript
44 | mytouchstart: function(e){
45 | console.log(e.timeStamp + '- touch start')
46 | },
47 | mytouchend: function(e){
48 | console.log(e.timeStamp + '- touch end')
49 | },
50 | mytap: function(e){
51 | console.log(e.timeStamp + '- tap')
52 | }
53 | ```
54 |
55 | #### 2.双击
56 | 双击事件由两个单击事件组成,两次间隔时间小于300ms认为是双击;微信官方文档没有双击事件,需要开发者自己定义处理。
57 |
58 | 
59 |
60 | ```html
61 |
62 |
63 |
64 | ```
65 |
66 | ```javascript
67 | Page({
68 | data: {
69 | //上一次触摸距离页面打开时间毫秒数,默认为为0
70 | lastTapDiffTime: 0
71 | },
72 | //触摸事件,判断单击还是双击
73 | mytap: function(e){
74 | //触摸时间距离页面打开时间毫秒数
75 | var curTime = e.timeStamp;
76 | //上一次触摸距离页面打开时间毫秒数
77 | var lastTime = this.data.lastTapDiffTime;
78 | if(lastTime > 0){
79 | //如果两次单击间隔小于300毫秒,认为是双击
80 | if(curTime - lastTime < 300){
81 | console.log(e.timeStamp + '- db tap')
82 | }else{
83 | console.log(e.timeStamp + '- tap')
84 | }
85 | }else{
86 | console.log(e.timeStamp + '- first tap')
87 | }
88 | //将本次点击触摸时间设置为上一次触摸时间
89 | this.setData({lastTapDiffTime: curTime});
90 | }
91 | })
92 | ```
93 |
94 | #### 3.长按
95 | 长按事件手指触摸后,超过350ms再离开。
96 |
97 | 
98 |
99 | ```html
100 |
101 |
103 |
104 | ```
105 |
106 | ```javascript
107 | mytouchstart: function(e){
108 | console.log(e.timeStamp + '- touch start')
109 | },
110 | //长按事件
111 | mylongtap: function(e){
112 | console.log(e.timeStamp + '- long tap')
113 | },
114 | mytouchend: function(e){
115 | console.log(e.timeStamp + '- touch end')
116 | },
117 | mytap: function(e){
118 | console.log(e.timeStamp + '- tap')
119 | }
120 | ```
121 |
122 | 单击、双击、长按属于点触事件,会触发touchstart、touchend、tap事件,touchcancel事件只能在真机模拟,不多说了。
123 |
124 |
125 | 事件 |
126 | 触发顺序 |
127 |
128 |
129 | 单击 |
130 | touchstart → touchend → tap |
131 |
132 |
133 | 双击 |
134 | touchstart → touchend → tap → touchstart → touchend → tap |
135 |
136 |
137 | 长按 |
138 | touchstart → longtap → touchend → tap |
139 |
140 |
141 |
142 | #### 4.滑动
143 |
144 | 手指触摸屏幕并移动,为了简化起见,下面以水平滑动和垂直滑动为例。
145 | 滑动事件由touchstart、touchmove、touchend组成。
146 |
147 | 
148 |
149 | 坐标图:
150 | 
151 |
152 | 1. 以屏幕左上角为原点建立直角坐标系。第四象限为手机屏幕,Y轴越往下坐标值越大(注意跟数学象限的区别)。
153 | 2. 假设A点为touchstart事件触摸点,坐标为A(ax,ay),然后手指向上滑动到点B(bx,by),就满足条件by < ay;
154 | 3. 同理,向右滑动到C(cx,cy),满足cx > ax;向下滑动到D(dx,dy),满足dy > ay;向左移动到E(ex,ey)满足ex < ax.
155 | 4. 计算线段AB在Y轴上投影长度为m,在X轴上的投影长度为n
156 | 5. 计算r = m/n,如果r > 1,视为向上滑动。
157 | 6. 同理计算线段AC,AD,AE在Y轴投影长度与X轴的投影长度之比,得出向右向下向左的滑动。
158 |
159 | 以上没考虑r为1的情况。
160 |
161 | ```html
162 |
163 |
164 |
165 | ```
166 |
167 | ```javascript
168 | Page({
169 | data: {
170 | //初始化touchstart坐标
171 | startPoint: [0,0]
172 | },
173 | mytouchstart: function(e){
174 | //开始触摸,获取触摸点坐标并放入数组中
175 | this.setData({startPoint: [e.touches[0].pageX, e.touches[0].pageY]});
176 | },
177 | //触摸点移动
178 | mytouchmove: function(e){
179 | //当前触摸点坐标
180 | var curPoint = [e.touches[0].pageX,e.touches[0].pageY];
181 | var startPoint = this.data.startPoint;
182 | //比较pageX值
183 | if(curPoint[0] <= startPoint[0]){
184 | if(Math.abs(curPoint[0] - startPoint[0]) >= Math.abs(curPoint[1] - startPoint[1])){
185 | console.log(e.timeStamp + '- touch left move')
186 | }else{
187 | if(curPoint[1] >= startPoint[1]){
188 | console.log(e.timeStamp + '- touch down move')
189 | }else{
190 | console.log(e.timeStamp + '- touch up move')
191 | }
192 | }
193 | }else{
194 | if(Math.abs(curPoint[0] - startPoint[0]) >= Math.abs(curPoint[1] - startPoint[1])){
195 | console.log(e.timeStamp + '- touch right move')
196 | }else{
197 | if(curPoint[1] >= startPoint[1]){
198 | console.log(e.timeStamp + '- touch down move')
199 | }else{
200 | console.log(e.timeStamp + '- touch up move')
201 | }
202 | }
203 | }
204 | }
205 | })
206 | ```
207 |
208 | #### 5.多点触控
209 |
210 | 由于模拟器尚不支持多点触控,内测开放后,继续补充。
--------------------------------------------------------------------------------
/chaptor_02/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | onLaunch: function () {
4 | //调用API从本地缓存中获取数据
5 | var logs = wx.getStorageSync('logs') || []
6 | logs.unshift(Date.now())
7 | wx.setStorageSync('logs', logs)
8 | },
9 | getUserInfo:function(cb){
10 | var that = this;
11 | if(this.globalData.userInfo){
12 | typeof cb == "function" && cb(this.globalData.userInfo)
13 | }else{
14 | //调用登录接口
15 | wx.login({
16 | success: function () {
17 | wx.getUserInfo({
18 | success: function (res) {
19 | that.globalData.userInfo = res.userInfo;
20 | typeof cb == "function" && cb(that.globalData.userInfo)
21 | }
22 | })
23 | }
24 | });
25 | }
26 | },
27 | globalData:{
28 | userInfo:null
29 | }
30 | })
31 |
--------------------------------------------------------------------------------
/chaptor_02/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages":[
3 | "pages/index/index",
4 | "pages/logs/logs"
5 | ],
6 | "window":{
7 | "backgroundTextStyle":"dark",
8 | "navigationBarBackgroundColor": "#fff",
9 | "navigationBarTitleText": "WeChat",
10 | "navigationBarTextStyle":"black",
11 | "backgroundColor": "red",
12 | "enablePullDownRefresh": true
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/chaptor_02/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | .container {
3 | height: 100%;
4 | display: flex;
5 | flex-direction: column;
6 | align-items: center;
7 | justify-content: space-between;
8 | padding: 200rpx 0;
9 | box-sizing: border-box;
10 | }
11 |
--------------------------------------------------------------------------------
/chaptor_02/images/click.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_02/images/click.gif
--------------------------------------------------------------------------------
/chaptor_02/images/code1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_02/images/code1.png
--------------------------------------------------------------------------------
/chaptor_02/images/code2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_02/images/code2.png
--------------------------------------------------------------------------------
/chaptor_02/images/coor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_02/images/coor.png
--------------------------------------------------------------------------------
/chaptor_02/images/dbclick.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_02/images/dbclick.gif
--------------------------------------------------------------------------------
/chaptor_02/images/longtap.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_02/images/longtap.gif
--------------------------------------------------------------------------------
/chaptor_02/images/shoushi.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_02/images/shoushi.gif
--------------------------------------------------------------------------------
/chaptor_02/pages/index/index.js:
--------------------------------------------------------------------------------
1 | //index.js
2 | //获取应用实例
3 | var app = getApp()
4 | Page({
5 | data: {
6 | btnWidth: 200,
7 | touchLog:"",
8 | lastTapDiffTime: 0,
9 | startPoint: [0,0]
10 | },
11 | //事件处理函数
12 | bindViewTap: function() {
13 | wx.navigateTo({
14 | url: '../logs/logs'
15 | })
16 | },
17 | onLoad: function () {
18 | var that = this
19 | //调用应用实例的方法获取全局数据
20 | app.getUserInfo(function(userInfo){
21 | //更新数据
22 | that.setData({
23 | userInfo:userInfo
24 | })
25 | })
26 | },
27 | ////触摸事件,判断单击还是双击
28 | mytap: function(e){
29 | var curTime = e.timeStamp;
30 | var lastTime = this.data.lastTapDiffTime;
31 | if(lastTime > 0){
32 | //如果两次单击间隔小于300毫秒,认为是双击
33 | if(curTime - lastTime < 300){
34 | console.log(e.timeStamp + '- db tap')
35 | }else{
36 | console.log(e.timeStamp + '- tap')
37 | }
38 | }else{
39 | console.log(e.timeStamp + '- first tap')
40 | }
41 | this.setData({lastTapDiffTime: curTime});
42 | },
43 | //识别长按
44 | mylongtap: function(e){
45 | console.log(e.timeStamp + '- long tap')
46 | },
47 | //触摸开始
48 | mytouchstart: function(e){
49 | console.log(e.timeStamp + '- touch start')
50 | console.log(e.touches.length);
51 | this.setData({startPoint: [e.touches[0].pageX, e.touches[0].pageY]});
52 | },
53 | //触摸点移动
54 | mytouchmove: function(e){
55 | //当前触摸点坐标
56 | var curPoint = [e.touches[0].pageX,e.touches[0].pageY];
57 | var startPoint = this.data.startPoint;
58 | if(curPoint[0] <= this.data.startPoint[0]){
59 | if(Math.abs(curPoint[0]-startPoint[0])>= Math.abs(curPoint[1]-startPoint[1])){
60 | console.log(e.timeStamp + '- touch left move')
61 | }else{
62 | if(curPoint[1]>= startPoint[1]){
63 | this.setData({btnWidth: this.data.btnWidth-1})
64 | console.log(e.timeStamp + '- touch down move')
65 | }else{
66 | this.setData({btnWidth: this.data.btnWidth+1})
67 | console.log(e.timeStamp + '- touch up move')
68 | }
69 | }
70 | }else{
71 | if(Math.abs(curPoint[0]-startPoint[0])>= Math.abs(curPoint[1]-startPoint[1])){
72 | console.log(e.timeStamp + '- touch right move')
73 | }else{
74 | if(curPoint[1]>= startPoint[1]){
75 | this.setData({btnWidth: this.data.btnWidth-1})
76 | console.log(e.timeStamp + '- touch down move')
77 | }else{
78 | this.setData({btnWidth: this.data.btnWidth+1})
79 | console.log(e.timeStamp + '- touch up move')
80 | }
81 | }
82 | }
83 | },
84 | //触摸被中断
85 | mytouchcacel: function(e){
86 | console.log(e.timeStamp + '- touch cancel')
87 |
88 | },
89 | //触摸结束
90 | mytouchend: function(e){
91 | console.log(e.timeStamp + '- touch end')
92 |
93 | },
94 | onPullDownRefresh: function(e){
95 | console.log('onPullDownRefresh')
96 | }
97 | })
98 |
--------------------------------------------------------------------------------
/chaptor_02/pages/index/index.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_02/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {{item}}
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/chaptor_02/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /**index.wxss**/
2 | .userinfo {
3 | display: flex;
4 | flex-direction: column;
5 | align-items: center;
6 | }
7 |
8 | .userinfo-avatar {
9 | width: 128rpx;
10 | height: 128rpx;
11 | margin: 20rpx;
12 | border-radius: 50%;
13 | }
14 |
15 | .userinfo-nickname {
16 | color: #aaa;
17 | }
18 |
19 | .usermotto {
20 | margin-top: 200px;
21 | }
--------------------------------------------------------------------------------
/chaptor_02/pages/logs/logs.js:
--------------------------------------------------------------------------------
1 | //logs.js
2 | var util = require('../../utils/util.js')
3 | Page({
4 | data: {
5 | logs: []
6 | },
7 | onLoad: function () {
8 | this.setData({
9 | logs: (wx.getStorageSync('logs') || []).map(function (log) {
10 | return util.formatTime(new Date(log))
11 | })
12 | })
13 | }
14 | })
15 |
--------------------------------------------------------------------------------
/chaptor_02/pages/logs/logs.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "查看启动日志"
3 | }
--------------------------------------------------------------------------------
/chaptor_02/pages/logs/logs.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{index + 1}}. {{log}}
5 |
6 |
7 |
--------------------------------------------------------------------------------
/chaptor_02/pages/logs/logs.wxss:
--------------------------------------------------------------------------------
1 | .log-list {
2 | display: flex;
3 | flex-direction: column;
4 | padding: 40rpx;
5 | }
6 | .log-item {
7 | margin: 10rpx;
8 | }
9 |
--------------------------------------------------------------------------------
/chaptor_02/utils/util.js:
--------------------------------------------------------------------------------
1 | function formatTime(date) {
2 | var year = date.getFullYear()
3 | var month = date.getMonth() + 1
4 | var day = date.getDate()
5 |
6 | var hour = date.getHours()
7 | var minute = date.getMinutes()
8 | var second = date.getSeconds();
9 |
10 |
11 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
12 | }
13 |
14 | function formatNumber(n) {
15 | n = n.toString()
16 | return n[1] ? n : '0' + n
17 | }
18 |
19 | module.exports = {
20 | formatTime: formatTime
21 | }
22 |
--------------------------------------------------------------------------------
/chaptor_03/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | onLaunch: function () {
4 | //调用API从本地缓存中获取数据
5 | var logs = wx.getStorageSync('logs') || []
6 | logs.unshift(Date.now())
7 | wx.setStorageSync('logs', logs)
8 | },
9 | getUserInfo:function(cb){
10 | var that = this;
11 | if(this.globalData.userInfo){
12 | typeof cb == "function" && cb(this.globalData.userInfo)
13 | }else{
14 | //调用登录接口
15 | wx.login({
16 | success: function () {
17 | wx.getUserInfo({
18 | success: function (res) {
19 | that.globalData.userInfo = res.userInfo;
20 | typeof cb == "function" && cb(that.globalData.userInfo)
21 | }
22 | })
23 | }
24 | });
25 | }
26 | },
27 | globalData:{
28 | userInfo:null,
29 | ws:'wss://localhost:8443'
30 | }
31 | })
32 |
--------------------------------------------------------------------------------
/chaptor_03/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages":[
3 | "pages/index/index",
4 | "pages/chat/chat",
5 | "pages/logs/logs"
6 | ],
7 | "window":{
8 | "backgroundTextStyle":"light",
9 | "navigationBarBackgroundColor": "#fff",
10 | "navigationBarTitleText": "聊天",
11 | "navigationBarTextStyle":"black"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/chaptor_03/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | .container {
3 | height: 100%;
4 | display: flex;
5 | flex-direction: column;
6 | align-items: center;
7 | justify-content: space-between;
8 | padding: 200rpx 0;
9 | box-sizing: border-box;
10 | }
11 |
--------------------------------------------------------------------------------
/chaptor_03/pages/chat/chat.js:
--------------------------------------------------------------------------------
1 | var app = getApp();
2 | var socketOpen = false;
3 | Page({
4 | data:{
5 | // text:"这是一个页面"
6 | inputValue: '',
7 | //消息记录
8 | historyMsgList:[]
9 | },
10 | onLoad:function(options){
11 | // 页面初始化 options为页面跳转所带来的参数
12 | this.setData({user: options.user})
13 | },
14 | bindKeyInput: function(e) {
15 | this.setData({
16 | inputValue: e.detail.value
17 | })
18 | },
19 | //发送消息
20 | sendtap: function(e){
21 | var $this = this;
22 | if(socketOpen){
23 | wx.sendSocketMessage({
24 | data: JSON.stringify({
25 | user: $this.data.user,
26 | content:$this.data.inputValue
27 | }),
28 | success: function(res){
29 | var arr = $this.data.historyMsgList;
30 | arr.push('发送消息登录:' + $this.data.inputValue)
31 | $this.setData({historyMsgList:arr});
32 | }
33 | })
34 | }
35 | },
36 | onReady:function(){
37 | var $this = this;
38 | var user = this.data.user;
39 | //发起websocket连接
40 | wx.connectSocket({
41 | url: app.globalData.ws + '/weappservice/websocket?name=' + user,
42 | data: {
43 | x: 'x'
44 | },
45 | method: 'POST',
46 | header:{
47 | 'content-type': 'application/text'
48 | }
49 |
50 | })
51 | wx.onSocketOpen(function(res) {
52 | socketOpen = true;
53 |
54 | var arr = $this.data.historyMsgList;
55 | arr.push(user + '登录成功');
56 | $this.setData({historyMsgList:arr});
57 |
58 | console.log('WebSocket连接已打开!');
59 | })
60 | wx.onSocketError(function(res){
61 | console.log('WebSocket连接打开失败,请检查!')
62 | }),
63 | //接收消息
64 | wx.onSocketMessage(function(res){
65 | var data = JSON.parse(res.data);
66 | var arr = $this.data.historyMsgList;
67 | arr.push('接收到'+data.user+'的消息,Ta说:' + data.content)
68 | $this.setData({historyMsgList:arr});
69 | })
70 | },
71 | onShow:function(){
72 | // 页面显示
73 | },
74 | onHide:function(){
75 | // 页面隐藏
76 | },
77 | onUnload:function(){
78 | // 页面关闭
79 | }
80 | })
--------------------------------------------------------------------------------
/chaptor_03/pages/chat/chat.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_03/pages/chat/chat.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | {{item}}
7 |
8 |
--------------------------------------------------------------------------------
/chaptor_03/pages/chat/chat.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_03/pages/chat/chat.wxss
--------------------------------------------------------------------------------
/chaptor_03/pages/index/index.js:
--------------------------------------------------------------------------------
1 | //index.js
2 | //获取应用实例
3 | var app = getApp()
4 | Page({
5 | data: {
6 | motto: 'Hello 小程序',
7 | userInfo: {},
8 | inputValue: ''
9 | },
10 | //事件处理函数
11 | bindViewTap: function() {
12 | wx.navigateTo({
13 | url: '../logs/logs'
14 | })
15 | },
16 | onLoad: function () {
17 | console.log('onLoad')
18 | var that = this
19 | //调用应用实例的方法获取全局数据
20 | app.getUserInfo(function(userInfo){
21 | //更新数据
22 | that.setData({
23 | userInfo:userInfo
24 | })
25 | })
26 | },
27 | bindKeyInput: function(e) {
28 | this.setData({
29 | inputValue: e.detail.value
30 | })
31 | },
32 | logintap: function(e){
33 | wx.redirectTo({
34 | url: '/pages/chat/chat?user=' + this.data.inputValue
35 | })
36 | }
37 | })
38 |
--------------------------------------------------------------------------------
/chaptor_03/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/chaptor_03/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /**index.wxss**/
2 | page{
3 | background-color: #FBF9FE;
4 | }
5 | .userinfo {
6 | display: flex;
7 | flex-direction: column;
8 | align-items: center;
9 | }
10 |
11 | .userinfo-avatar {
12 | width: 128rpx;
13 | height: 128rpx;
14 | margin: 20rpx;
15 | border-radius: 50%;
16 | }
17 |
18 | .userinfo-nickname {
19 | color: #aaa;
20 | }
21 |
22 | .usermotto {
23 | margin-top: 200px;
24 | }
25 | .ipt-cls{
26 | background-color: #fff;
27 | width: 80%;
28 | height: 40px;
29 | }
30 | .btn-login{
31 | margin-top: 10px;
32 | width: 80%;
33 | }
--------------------------------------------------------------------------------
/chaptor_03/pages/logs/logs.js:
--------------------------------------------------------------------------------
1 | //logs.js
2 | var util = require('../../utils/util.js')
3 | Page({
4 | data: {
5 | logs: []
6 | },
7 | onLoad: function () {
8 | this.setData({
9 | logs: (wx.getStorageSync('logs') || []).map(function (log) {
10 | return util.formatTime(new Date(log))
11 | })
12 | })
13 | }
14 | })
15 |
--------------------------------------------------------------------------------
/chaptor_03/pages/logs/logs.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "查看启动日志"
3 | }
--------------------------------------------------------------------------------
/chaptor_03/pages/logs/logs.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{index + 1}}. {{log}}
5 |
6 |
7 |
--------------------------------------------------------------------------------
/chaptor_03/pages/logs/logs.wxss:
--------------------------------------------------------------------------------
1 | .log-list {
2 | display: flex;
3 | flex-direction: column;
4 | padding: 40rpx;
5 | }
6 | .log-item {
7 | margin: 10rpx;
8 | }
9 |
--------------------------------------------------------------------------------
/chaptor_03/utils/util.js:
--------------------------------------------------------------------------------
1 | function formatTime(date) {
2 | var year = date.getFullYear()
3 | var month = date.getMonth() + 1
4 | var day = date.getDate()
5 |
6 | var hour = date.getHours()
7 | var minute = date.getMinutes()
8 | var second = date.getSeconds();
9 |
10 |
11 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
12 | }
13 |
14 | function formatNumber(n) {
15 | n = n.toString()
16 | return n[1] ? n : '0' + n
17 | }
18 |
19 | module.exports = {
20 | formatTime: formatTime
21 | }
22 |
--------------------------------------------------------------------------------
/chaptor_04/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | onLaunch: function () {
4 | //调用API从本地缓存中获取数据
5 | var logs = wx.getStorageSync('logs') || []
6 | logs.unshift(Date.now())
7 | wx.setStorageSync('logs', logs)
8 | },
9 | getUserInfo:function(cb){
10 | var that = this;
11 | if(this.globalData.userInfo){
12 | typeof cb == "function" && cb(this.globalData.userInfo)
13 | }else{
14 | //调用登录接口
15 | wx.login({
16 | success: function () {
17 | wx.getUserInfo({
18 | success: function (res) {
19 | that.globalData.userInfo = res.userInfo;
20 | typeof cb == "function" && cb(that.globalData.userInfo)
21 | }
22 | })
23 | }
24 | });
25 | }
26 | },
27 | globalData:{
28 | userInfo:null
29 | }
30 | })
31 |
--------------------------------------------------------------------------------
/chaptor_04/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages":[
3 | "pages/index/index",
4 | "pages/logs/logs"
5 | ],
6 | "window":{
7 | "backgroundTextStyle":"light",
8 | "navigationBarBackgroundColor": "#fff",
9 | "navigationBarTitleText": "音乐播放",
10 | "navigationBarTextStyle":"black"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chaptor_04/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | .container {
3 | height: 100%;
4 | display: flex;
5 | flex-direction: row;
6 | align-items: center;
7 | justify-content: space-between;
8 | padding: 200rpx 0;
9 | box-sizing: border-box;
10 | }
11 |
--------------------------------------------------------------------------------
/chaptor_04/fonts/ionicons.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_04/fonts/ionicons.eot
--------------------------------------------------------------------------------
/chaptor_04/fonts/ionicons.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_04/fonts/ionicons.ttf
--------------------------------------------------------------------------------
/chaptor_04/fonts/ionicons.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_04/fonts/ionicons.woff
--------------------------------------------------------------------------------
/chaptor_04/media/test.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_04/media/test.mp4
--------------------------------------------------------------------------------
/chaptor_04/pages/index/index.js:
--------------------------------------------------------------------------------
1 | //index.js
2 | //获取应用实例
3 | var app = getApp()
4 | Page({
5 | data: {
6 | motto: 'Hello 小程序',
7 | userInfo: {},
8 | progressWith: 0,
9 | currenduration: 0,
10 | duration: 0,
11 | //视频路径
12 | videoSrc: '../../media/test.mp4',
13 | intervalId: ''
14 | },
15 | //事件处理函数
16 | bindViewTap: function() {
17 | wx.navigateTo({
18 | url: '../logs/logs'
19 | })
20 | },
21 | onLoad: function () {
22 | console.log('onLoad')
23 | var that = this
24 | //调用应用实例的方法获取全局数据
25 | app.getUserInfo(function(userInfo){
26 | //更新数据
27 | that.setData({
28 | userInfo:userInfo
29 | })
30 | })
31 | },
32 | //开始播放
33 | startplay: function(e){
34 | var $this = this;
35 | console.log('paly')
36 |
37 | wx.getBackgroundAudioPlayerState({
38 | success: function(res){
39 | var s = res.status;
40 | if(s == 0){
41 | wx.playVoice()
42 | }
43 | $this.setData({duration:Math.ceil(res.duration)});
44 | }
45 | })
46 |
47 | wx.playBackgroundAudio({
48 | dataUrl: 'http://yinyueshiting.baidu.com/data2/music/239833557/739948431476324061128.mp3?xcode=37d73fc57b0c55ac31189f16455400eb',
49 | title: '悟空',
50 | coverImgUrl: 'http://musicdata.baidu.com/data2/pic/89838191/89838191.jpg',
51 | success: function(res){
52 | var id = $this.setMusicInterval();
53 | $this.setData({intervalId: id})
54 | }
55 | })
56 | },
57 | //暂停
58 | pauseplay: function(e){
59 | console.log('pause')
60 | wx.pauseBackgroundAudio()
61 | clearInterval(this.data.intervalId)
62 | },
63 | //停止播放
64 | stopplay: function(e){
65 | console.log('stop')
66 | wx.stopBackgroundAudio()
67 | this.setData({currenduration:0, progressWith:0})
68 | clearInterval(this.data.intervalId)
69 | },
70 | //快进
71 | forward: function(e){
72 | var $this = this;
73 | wx.getBackgroundAudioPlayerState({
74 | success: function(res){
75 | var duration = res.currentPosition;
76 |
77 | if(duration > $this.data.duration + 5){
78 | duration = $this.data.duration;
79 | }
80 | wx.seekBackgroundAudio({
81 | position: duration
82 | })
83 | }
84 | })
85 | },
86 | //快退
87 | backward: function(e){
88 | wx.getBackgroundAudioPlayerState({
89 | success: function(res){
90 | var currentposition = res.currentPosition;
91 | if(currentposition <= 5){
92 | currentposition = 0;
93 | }else{
94 | currentposition -= 5;
95 | }
96 | wx.seekBackgroundAudio({
97 | position: currentposition
98 | })
99 | }
100 | })
101 | },
102 | setMusicInterval: function(){
103 | var $this = this;
104 | var id = setInterval(function(){
105 | wx.getBackgroundAudioPlayerState({
106 | success: function(res){
107 | console.log(res)
108 | var prog = parseInt(res.currentPosition) / parseInt(res.duration);
109 | console.log(prog)
110 | $this.setData({progressWith:prog * 100,currenduration:Math.ceil(res.currentPosition)});
111 | }
112 | })
113 | },1000);
114 | return id;
115 | }
116 | })
117 |
--------------------------------------------------------------------------------
/chaptor_04/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | 当前:{{currenduration}}/{{duration}}
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/chaptor_04/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /**index.wxss**/
2 | .userinfo {
3 | display: flex;
4 | flex-direction: column;
5 | align-items: center;
6 | }
7 |
8 | .userinfo-avatar {
9 | width: 128rpx;
10 | height: 128rpx;
11 | margin: 20rpx;
12 | border-radius: 50%;
13 | }
14 |
15 | .userinfo-nickname {
16 | color: #aaa;
17 | }
18 |
19 | .usermotto {
20 | margin-top: 200px;
21 | }
22 | .mycontainer {
23 | flex-direction:row;
24 | flex-wrap: wrap;
25 | justify-content:space-around;
26 | align-items:center;
27 | }
28 | .btncls{
29 | margin-top: 10px;
30 | }
31 | .weui-progress__bar{
32 | background-color: 'gray'
33 | }
34 | .myprogress{
35 | height:5px;
36 | background-color:#1AAD19;
37 | }
--------------------------------------------------------------------------------
/chaptor_04/pages/logs/logs.js:
--------------------------------------------------------------------------------
1 | //logs.js
2 | var util = require('../../utils/util.js')
3 | Page({
4 | data: {
5 | logs: []
6 | },
7 | onLoad: function () {
8 | this.setData({
9 | logs: (wx.getStorageSync('logs') || []).map(function (log) {
10 | return util.formatTime(new Date(log))
11 | })
12 | })
13 | }
14 | })
15 |
--------------------------------------------------------------------------------
/chaptor_04/pages/logs/logs.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "查看启动日志"
3 | }
--------------------------------------------------------------------------------
/chaptor_04/pages/logs/logs.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{index + 1}}. {{log}}
5 |
6 |
7 |
--------------------------------------------------------------------------------
/chaptor_04/pages/logs/logs.wxss:
--------------------------------------------------------------------------------
1 | .log-list {
2 | display: flex;
3 | flex-direction: column;
4 | padding: 40rpx;
5 | }
6 | .log-item {
7 | margin: 10rpx;
8 | }
9 |
--------------------------------------------------------------------------------
/chaptor_04/utils/util.js:
--------------------------------------------------------------------------------
1 | function formatTime(date) {
2 | var year = date.getFullYear()
3 | var month = date.getMonth() + 1
4 | var day = date.getDate()
5 |
6 | var hour = date.getHours()
7 | var minute = date.getMinutes()
8 | var second = date.getSeconds();
9 |
10 |
11 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
12 | }
13 |
14 | function formatNumber(n) {
15 | n = n.toString()
16 | return n[1] ? n : '0' + n
17 | }
18 |
19 | module.exports = {
20 | formatTime: formatTime
21 | }
22 |
--------------------------------------------------------------------------------
/chaptor_05/.gitignore:
--------------------------------------------------------------------------------
1 | *swp
2 |
--------------------------------------------------------------------------------
/chaptor_05/README.md:
--------------------------------------------------------------------------------
1 | ### 微信小程序用户数据解密(2016-11-24)
2 | - 根据code换取sessionsession_key和openid
3 | - 用户敏感数据解密
--------------------------------------------------------------------------------
/chaptor_05/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | onLaunch: function () {
4 | //调用API从本地缓存中获取数据
5 | var logs = wx.getStorageSync('logs') || []
6 | logs.unshift(Date.now())
7 | wx.setStorageSync('logs', logs)
8 | },
9 | getUserInfo:function(cb){
10 | var that = this
11 | if(this.globalData.userInfo){
12 | typeof cb == "function" && cb(this.globalData.userInfo)
13 | }else{
14 | //调用登录接口
15 | wx.login({
16 | success: function (res) {
17 | that.globalData.loginCode = res.code
18 | wx.getUserInfo({
19 | success: function (res) {
20 | that.globalData.userInfo = res.userInfo
21 | that.globalData.iv=res.iv
22 | that.globalData.encryptedData=res.encryptedData
23 | typeof cb == "function" && cb(that.globalData.userInfo)
24 |
25 | }
26 | })
27 | }
28 | })
29 | }
30 | },
31 | globalData:{
32 | userInfo:null,
33 | loginCode: null,
34 | encryptedData: null,
35 | iv: null,
36 | server: 'https://localhost:8443/weappservice/api/v1',
37 | appId: 'JWEJIJ345QHWJKENVKF',
38 | apiNames : ['WX_CODE','WX_CHECK_USER','WX_DECODE_USERINFO']
39 | }
40 | })
--------------------------------------------------------------------------------
/chaptor_05/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages":[
3 | "pages/index/index",
4 | "pages/logs/logs"
5 | ],
6 | "window":{
7 | "backgroundTextStyle":"light",
8 | "navigationBarBackgroundColor": "#fff",
9 | "navigationBarTitleText": "用户信息解密案例",
10 | "navigationBarTextStyle":"black"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chaptor_05/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | @import 'weui.wxss';
3 | .container {
4 | height: 100%;
5 | display: flex;
6 | flex-direction: column;
7 | align-items: center;
8 | justify-content: space-between;
9 | padding: 200rpx 0;
10 | box-sizing: border-box;
11 | }
12 |
--------------------------------------------------------------------------------
/chaptor_05/pages/index/index.js:
--------------------------------------------------------------------------------
1 | //index.js
2 | //获取应用实例
3 | var app = getApp()
4 | var httpclient = require('../../utils/httpclient.js')
5 | Page({
6 | data: {
7 | btnType: 'primary',
8 | btnSize: 'default',
9 | btnPlain: false,
10 |
11 | nickname: '',
12 | city: '',
13 | loginCode: '',
14 |
15 | encryptedData:'',
16 | iv:'',
17 | userInfo: {},
18 | sessionId: '',
19 | openId: '',
20 | unionId: '',
21 | nickname1: ''
22 | },
23 | //事件处理函数
24 | bindViewTap: function() {
25 | wx.navigateTo({
26 | url: '../logs/logs'
27 | })
28 | },
29 | onLoad: function () {
30 |
31 | },
32 | //登录
33 | wxlogin: function(e){
34 | var that = this
35 |
36 | //调用应用实例的方法获取全局数据
37 | app.getUserInfo(function(userInfo){
38 | //更新数据
39 | that.setData({
40 | userInfo: userInfo,
41 | nickname: userInfo.nickName,
42 | city: userInfo.city,
43 | loginCode: app.globalData.loginCode,
44 | encryptedData: app.globalData.encryptedData,
45 | iv: app.globalData.iv
46 | })
47 | })
48 | },
49 | // 从服务端获取sessionId
50 | get3rdSessionId: function(e){
51 | var that = this;
52 | //根据code获取sessionsession_key和openid
53 | wx.showToast({
54 | title: '正在请求',
55 | icon: 'loading',
56 | duration: 10000
57 | });
58 |
59 | httpclient.req(
60 | '/wx/getSession',
61 | {
62 | apiName: 'WX_CODE',
63 | code: this.data.loginCode
64 | },
65 | 'GET',
66 | function(result){
67 | wx.hideToast()
68 | var sessionId = result.data.data.sessionId;
69 | that.setData({sessionId: sessionId})
70 | wx.setStorageSync('sessionId', sessionId)
71 | },
72 | function(result){
73 | console.log(result)
74 | }
75 | );
76 | },
77 | //解密用户敏感数据
78 | getUserAllData: function(e){
79 | var that = this;
80 | wx.showToast({
81 | title: '正在请求',
82 | icon: 'loading',
83 | duration: 10000
84 | })
85 | httpclient.req(
86 | '/wx/decodeUserInfo',
87 | {
88 | apiName: 'WX_DECODE_USERINFO',
89 | encryptedData: this.data.encryptedData,
90 | iv: this.data.iv,
91 | sessionId: wx.getStorageSync('sessionId')
92 | },
93 | 'GET',
94 | function(result){
95 | wx.hideToast()
96 | var data = JSON.parse(result.data.data);
97 | that.setData({
98 | openId: data.openId,
99 | unionId: data.unionId,
100 | nickname1: data.nickName
101 | })
102 | },
103 | function(result){
104 | console.log(result)
105 | }
106 | );
107 | }
108 | })
109 |
--------------------------------------------------------------------------------
/chaptor_05/pages/index/index.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_05/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | 昵称:
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | 城市:
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | js_code:
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | sessionId:
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | 昵称:
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | openId
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | unionId
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/chaptor_05/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /**index.wxss**/
2 | page{
3 | background-color: 'gray';
4 | }
5 | .wrap-item button{
6 | margin: 10px 0 10px 0;
7 | }
--------------------------------------------------------------------------------
/chaptor_05/pages/logs/logs.js:
--------------------------------------------------------------------------------
1 | //logs.js
2 | var util = require('../../utils/util.js')
3 | Page({
4 | data: {
5 | logs: []
6 | },
7 | onLoad: function () {
8 | this.setData({
9 | logs: (wx.getStorageSync('logs') || []).map(function (log) {
10 | return util.formatTime(new Date(log))
11 | })
12 | })
13 | }
14 | })
15 |
--------------------------------------------------------------------------------
/chaptor_05/pages/logs/logs.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "查看启动日志"
3 | }
--------------------------------------------------------------------------------
/chaptor_05/pages/logs/logs.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{index + 1}}. {{log}}
5 |
6 |
7 |
--------------------------------------------------------------------------------
/chaptor_05/pages/logs/logs.wxss:
--------------------------------------------------------------------------------
1 | .log-list {
2 | display: flex;
3 | flex-direction: column;
4 | padding: 40rpx;
5 | }
6 | .log-item {
7 | margin: 10rpx;
8 | }
9 |
--------------------------------------------------------------------------------
/chaptor_05/utils/httpclient.js:
--------------------------------------------------------------------------------
1 | var app = getApp();
2 | function req(url, data, method, success, fail){
3 | var mydata = data || {};
4 | mydata['appId'] = app.globalData.appId;
5 | wx.request({
6 | url: app.globalData.server + url,
7 | data: mydata,
8 | method: method,
9 | success: success,
10 | fail: fail,
11 | complete: function() {
12 | // complete
13 | }
14 | })
15 | }
16 | module.exports = {
17 | req: req
18 | }
--------------------------------------------------------------------------------
/chaptor_05/utils/util.js:
--------------------------------------------------------------------------------
1 | function formatTime(date) {
2 | var year = date.getFullYear()
3 | var month = date.getMonth() + 1
4 | var day = date.getDate()
5 |
6 | var hour = date.getHours()
7 | var minute = date.getMinutes()
8 | var second = date.getSeconds()
9 |
10 |
11 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
12 | }
13 |
14 | function formatNumber(n) {
15 | n = n.toString()
16 | return n[1] ? n : '0' + n
17 | }
18 |
19 | module.exports = {
20 | formatTime: formatTime
21 | }
22 |
--------------------------------------------------------------------------------
/chaptor_06/.gitignore:
--------------------------------------------------------------------------------
1 | *swp
2 |
--------------------------------------------------------------------------------
/chaptor_06/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 |
3 | var host = 'baidu.com'
4 | App({
5 | onLaunch: function () {
6 | //调用API从本地缓存中获取数据
7 | var logs = wx.getStorageSync('logs') || []
8 | logs.unshift(Date.now())
9 | wx.setStorageSync('logs', logs)
10 | },
11 | getUserInfo:function(cb){
12 | var that = this
13 | if(this.globalData.userInfo){
14 | typeof cb == "function" && cb(this.globalData.userInfo)
15 | }else{
16 | //调用登录接口
17 | wx.login({
18 | success: function () {
19 | wx.getUserInfo({
20 | success: function (res) {
21 | that.globalData.userInfo = res.userInfo
22 | typeof cb == "function" && cb(that.globalData.userInfo)
23 | }
24 | })
25 | }
26 | })
27 | }
28 | },
29 | globalData:{
30 | userInfo:null,
31 | url: host + 'baidu.com'
32 | }
33 | })
--------------------------------------------------------------------------------
/chaptor_06/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages":[
3 | "pages/index/index",
4 | "pages/logs/logs",
5 | "pages/route1/route1",
6 | "pages/route2/route2",
7 | "pages/route3/route3",
8 | "pages/route4/route4",
9 | "pages/route5/route5"
10 | ],
11 | "window":{
12 | "backgroundTextStyle":"light",
13 | "navigationBarBackgroundColor": "#fff",
14 | "navigationBarTitleText": "页面路由",
15 | "navigationBarTextStyle":"black"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/chaptor_06/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | @import 'weui.wxss';
3 | .container {
4 | height: 100%;
5 | display: flex;
6 | flex-direction: column;
7 | align-items: center;
8 | justify-content: space-between;
9 | padding: 200rpx 0;
10 | box-sizing: border-box;
11 | }
12 |
--------------------------------------------------------------------------------
/chaptor_06/pages/index/index.js:
--------------------------------------------------------------------------------
1 | //index.js
2 | //获取应用实例
3 | var app = getApp()
4 | Page({
5 | data: {
6 |
7 | },
8 | //事件处理函数
9 | bindViewTap: function () {
10 | wx.navigateTo({
11 | url: '../logs/logs'
12 | })
13 | },
14 | onLoad: function () {
15 |
16 | },
17 | toPage1: function (e) {
18 | console.log(e)
19 | wx.navigateTo({
20 | url: '../route1/route1',
21 | success: function (res) {
22 | console.log(res)
23 | }
24 | })
25 | }
26 | })
27 |
--------------------------------------------------------------------------------
/chaptor_06/pages/index/index.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_06/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/chaptor_06/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /**index.wxss**/
2 | .redbutton{
3 | color: #ff0000;
4 | }
5 |
6 | .yellowbutton{
7 | color: #ffff00;
8 | }
--------------------------------------------------------------------------------
/chaptor_06/pages/logs/logs.js:
--------------------------------------------------------------------------------
1 | //logs.js
2 | var util = require('../../utils/util.js')
3 | Page({
4 | data: {
5 | logs: []
6 | },
7 | onLoad: function () {
8 | this.setData({
9 | logs: (wx.getStorageSync('logs') || []).map(function (log) {
10 | return util.formatTime(new Date(log))
11 | })
12 | })
13 | }
14 | })
15 |
--------------------------------------------------------------------------------
/chaptor_06/pages/logs/logs.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "查看启动日志"
3 | }
--------------------------------------------------------------------------------
/chaptor_06/pages/logs/logs.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{index + 1}}. {{log}}
5 |
6 |
7 |
--------------------------------------------------------------------------------
/chaptor_06/pages/logs/logs.wxss:
--------------------------------------------------------------------------------
1 | .log-list {
2 | display: flex;
3 | flex-direction: column;
4 | padding: 40rpx;
5 | }
6 | .log-item {
7 | margin: 10rpx;
8 | }
9 |
--------------------------------------------------------------------------------
/chaptor_06/pages/route1/route1.js:
--------------------------------------------------------------------------------
1 | // pages/route1/route1.js
2 | Page({
3 | data:{},
4 | onLoad:function(options){
5 | // 页面初始化 options为页面跳转所带来的参数
6 | },
7 | onReady:function(){
8 | // 页面渲染完成
9 | var pages = getCurrentPages();
10 | },
11 | onShow:function(){
12 | // 页面显示
13 | },
14 | onHide:function(){
15 | // 页面隐藏
16 | },
17 | onUnload:function(){
18 | // 页面关闭
19 | },
20 | toPage2: function (e) {
21 | console.log(e)
22 | wx.navigateTo({
23 | url: '../route2/route2',
24 | success: function (res) {
25 | console.log(res)
26 | }
27 | })
28 | }
29 | })
--------------------------------------------------------------------------------
/chaptor_06/pages/route1/route1.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_06/pages/route1/route1.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/chaptor_06/pages/route1/route1.wxss:
--------------------------------------------------------------------------------
1 | /* pages/route1/route1.wxss */
--------------------------------------------------------------------------------
/chaptor_06/pages/route2/route2.js:
--------------------------------------------------------------------------------
1 | // pages/route2/route2.js
2 | Page({
3 | data:{
4 | total : 0
5 | },
6 | onLoad:function(options){
7 | var that = this
8 | // 页面初始化 options为页面跳转所带来的参数
9 | setInterval(function(){
10 |
11 | that.setData({total: that.data.total + 1})
12 | console.log(that.data.total)
13 | },1000 )
14 | },
15 | onReady:function(){
16 | // 页面渲染完成
17 | console.log(this.data.name)
18 | },
19 | onShow:function(){
20 | // 页面显示
21 | },
22 | onHide:function(){
23 | // 页面隐藏
24 | },
25 | onUnload:function(){
26 | // 页面关闭
27 | },
28 | toPage3: function (e) {
29 | console.log(e)
30 | wx.navigateTo({
31 | url: '../route4/route4',
32 | success: function (res) {
33 | console.log(res)
34 | }
35 | })
36 | },
37 | backPage: function(e){
38 | wx.navigateBack({
39 | delta: 1, // 回退前 delta(默认为1) 页面
40 | success: function(res){
41 | // success
42 | },
43 | fail: function() {
44 | // fail
45 | },
46 | complete: function() {
47 | // complete
48 | }
49 | })
50 | }
51 | })
--------------------------------------------------------------------------------
/chaptor_06/pages/route2/route2.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_06/pages/route2/route2.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/chaptor_06/pages/route2/route2.wxss:
--------------------------------------------------------------------------------
1 | /* pages/route2/route2.wxss */
--------------------------------------------------------------------------------
/chaptor_06/pages/route3/route3.js:
--------------------------------------------------------------------------------
1 | // pages/route3/route3.js
2 | Page({
3 | data:{},
4 | onLoad:function(options){
5 | // 页面初始化 options为页面跳转所带来的参数
6 | },
7 | onReady:function(){
8 | // 页面渲染完成
9 | },
10 | onShow:function(){
11 | // 页面显示
12 | },
13 | onHide:function(){
14 | // 页面隐藏
15 | },
16 | onUnload:function(){
17 | // 页面关闭
18 | },
19 | toPage4: function (e) {
20 | console.log(e)
21 | wx.navigateTo({
22 | url: '../route4/route4',
23 | success: function (res) {
24 | console.log(res)
25 | }
26 | })
27 | }
28 | })
--------------------------------------------------------------------------------
/chaptor_06/pages/route3/route3.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_06/pages/route3/route3.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/chaptor_06/pages/route3/route3.wxss:
--------------------------------------------------------------------------------
1 | /* pages/route3/route3.wxss */
--------------------------------------------------------------------------------
/chaptor_06/pages/route4/route4.js:
--------------------------------------------------------------------------------
1 | // pages/route4/route4.js
2 | Page({
3 | data:{},
4 | onLoad:function(options){
5 | // 页面初始化 options为页面跳转所带来的参数
6 | console.log(options.url)
7 | console.log(options.name)
8 | },
9 | onReady:function(){
10 | // 页面渲染完成
11 | },
12 | onShow:function(){
13 | // 页面显示
14 | },
15 | onHide:function(){
16 | // 页面隐藏
17 | },
18 | onUnload:function(){
19 | // 页面关闭
20 | },
21 | toPage5: function(e){
22 | wx.navigateTo({
23 | url: '../route5/route5',
24 | success: function (res) {
25 | console.log(res)
26 | }
27 | })
28 | },
29 | navigateBackPage: function(e){
30 | wx.navigateBack({
31 | delta: 2, // 回退前 delta(默认为1) 页面
32 | success: function(res){
33 | // success
34 | }
35 | })
36 | },
37 | redirectPage: function(e){
38 | wx.redirectTo({
39 | url: '../route1/route1',
40 | success: function(res){
41 | // success
42 | }
43 | })
44 | },
45 | navigateToPage: function(e){
46 | wx.navigateTo({
47 | url: '../route2/route2',
48 | success: function(res){
49 | // success
50 | }
51 | })
52 | }
53 | })
--------------------------------------------------------------------------------
/chaptor_06/pages/route4/route4.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_06/pages/route4/route4.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/chaptor_06/pages/route4/route4.wxss:
--------------------------------------------------------------------------------
1 | /* pages/route4/route4.wxss */
--------------------------------------------------------------------------------
/chaptor_06/pages/route5/route5.js:
--------------------------------------------------------------------------------
1 | // pages/route5/route5.js
2 | Page({
3 | data:{},
4 | onLoad:function(options){
5 | // 页面初始化 options为页面跳转所带来的参数
6 | },
7 | onReady:function(){
8 | // 页面渲染完成
9 | },
10 | onShow:function(){
11 | // 页面显示
12 | },
13 | onHide:function(){
14 | // 页面隐藏
15 | },
16 | onUnload:function(){
17 | // 页面关闭
18 | }
19 | })
--------------------------------------------------------------------------------
/chaptor_06/pages/route5/route5.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_06/pages/route5/route5.wxml:
--------------------------------------------------------------------------------
1 |
2 | pages/route5/route5.wxml
3 |
--------------------------------------------------------------------------------
/chaptor_06/pages/route5/route5.wxss:
--------------------------------------------------------------------------------
1 | /* pages/route5/route5.wxss */
--------------------------------------------------------------------------------
/chaptor_06/utils/util.js:
--------------------------------------------------------------------------------
1 | function formatTime(date) {
2 | var year = date.getFullYear()
3 | var month = date.getMonth() + 1
4 | var day = date.getDate()
5 |
6 | var hour = date.getHours()
7 | var minute = date.getMinutes()
8 | var second = date.getSeconds()
9 |
10 |
11 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
12 | }
13 |
14 | function formatNumber(n) {
15 | n = n.toString()
16 | return n[1] ? n : '0' + n
17 | }
18 |
19 | module.exports = {
20 | formatTime: formatTime
21 | }
22 |
--------------------------------------------------------------------------------
/chaptor_07/.gitignore:
--------------------------------------------------------------------------------
1 | *swp
2 |
--------------------------------------------------------------------------------
/chaptor_07/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | onLaunch: function () {
4 | //调用API从本地缓存中获取数据
5 | var logs = wx.getStorageSync('logs') || []
6 | logs.unshift(Date.now())
7 | wx.setStorageSync('logs', logs)
8 | },
9 | getUserInfo:function(cb){
10 | var that = this
11 | if(this.globalData.userInfo){
12 | typeof cb == "function" && cb(this.globalData.userInfo)
13 | }else{
14 | //调用登录接口
15 | wx.login({
16 | success: function () {
17 | wx.getUserInfo({
18 | success: function (res) {
19 | that.globalData.userInfo = res.userInfo
20 | typeof cb == "function" && cb(that.globalData.userInfo)
21 | }
22 | })
23 | }
24 | })
25 | }
26 | },
27 | globalData:{
28 | server: 'https://localhost:8443/weappservice/api/v1',
29 | appId: 'JWEJIJ345QHWJKENVKF'
30 | }
31 | })
--------------------------------------------------------------------------------
/chaptor_07/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages":[
3 | "pages/index/index",
4 | "pages/logs/logs",
5 | "pages/article/list",
6 | "pages/articledetail/detail"
7 | ],
8 | "window":{
9 | "backgroundTextStyle":"light",
10 | "navigationBarBackgroundColor": "#fff",
11 | "navigationBarTitleText": "小黄象-精品专栏",
12 | "navigationBarTextStyle":"black"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/chaptor_07/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | @import 'weui.wxss';
3 | .container {
4 | height: 100%;
5 | display: flex;
6 | flex-direction: column;
7 | align-items: center;
8 | justify-content: space-between;
9 | padding: 200rpx 0;
10 | box-sizing: border-box;
11 | }
12 |
--------------------------------------------------------------------------------
/chaptor_07/images/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/images/1.png
--------------------------------------------------------------------------------
/chaptor_07/images/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/images/2.jpg
--------------------------------------------------------------------------------
/chaptor_07/images/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/images/3.png
--------------------------------------------------------------------------------
/chaptor_07/images/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/images/4.png
--------------------------------------------------------------------------------
/chaptor_07/images/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/images/5.png
--------------------------------------------------------------------------------
/chaptor_07/images/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/images/6.jpg
--------------------------------------------------------------------------------
/chaptor_07/images/7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/images/7.jpg
--------------------------------------------------------------------------------
/chaptor_07/images/8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/images/8.jpg
--------------------------------------------------------------------------------
/chaptor_07/images/9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/images/9.png
--------------------------------------------------------------------------------
/chaptor_07/pages/article/list.js:
--------------------------------------------------------------------------------
1 | // pages/article/list.js
2 | var app = getApp()
3 | var httpclient = require('../../utils/httpclient.js')
4 | Page({
5 | data:{
6 | //分页当前页
7 | pageIdx: 0,
8 | //文章列表
9 | articles: []
10 | },
11 | onLoad:function(options){
12 | //传入类型
13 | var type = options.type;
14 | //专栏文章
15 | if(type === 'column'){
16 | var path = options.path;
17 | this.setData({desc: options.desc})
18 | //查询数据
19 | this.getColumnArticle(path);
20 | }else if(type === 'search'){//搜索文章
21 | this.setData({desc: options.text})
22 | //查询数据
23 | this.searchArticle(options.text);
24 | }
25 | },
26 | onReady:function(){
27 | // 页面渲染完成
28 | },
29 | onShow:function(){
30 | // 页面显示
31 | },
32 | onHide:function(){
33 | // 页面隐藏
34 | },
35 | onUnload:function(){
36 | // 页面关闭
37 | },
38 | //根据专栏路径查询
39 | getColumnArticle: function(path){
40 | var that = this;
41 | httpclient.req(
42 | '/wxclub' + path + '/' + that.data.pageIdx,
43 | {
44 | apiName: 'WX_CLUB_ARTICLES',
45 | },
46 | 'GET',
47 | function(res){
48 | var datalist = res.data.data || [];
49 | that.setData({articles: datalist})
50 |
51 | for(var i = 0; i < datalist.length; i++){
52 | //将文章放到本地缓存
53 | wx.setStorage({
54 | key: datalist[i]['id'],
55 | data: datalist[i]
56 | });
57 | }
58 | }
59 | )
60 | },
61 | //根据文章标题查询
62 | searchArticle: function(text){
63 | var that = this;
64 | httpclient.req(
65 | '/wxclub/column/search/' + that.data.pageIdx,
66 | {
67 | apiName : 'WX_CLUB_SEARCH',
68 | text: text
69 | },
70 | 'GET',
71 | function(res){
72 | var datalist = res.data.data || [];
73 | that.setData({articles: datalist})
74 |
75 | for(var i = 0; i < datalist.length; i++){
76 | //将文章放到本地缓存
77 | wx.setStorage({
78 | key: datalist[i]['id'],
79 | data: datalist[i]
80 | });
81 | }
82 | }
83 | )
84 | }
85 | })
--------------------------------------------------------------------------------
/chaptor_07/pages/article/list.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_07/pages/article/list.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | {{desc}}
4 |
5 |
6 |
7 |
8 |
9 |
10 | {{item.title}}
11 | {{item.createTime}}
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/chaptor_07/pages/article/list.wxss:
--------------------------------------------------------------------------------
1 | /* pages/article/list.wxss */
2 | .page__bd{
3 | margin-top: 100rpx;
4 | }
--------------------------------------------------------------------------------
/chaptor_07/pages/articledetail/detail.js:
--------------------------------------------------------------------------------
1 | // pages/articledetail/detail.js
2 | var WxParse = require('../../wxParse/wxParse.js');
3 | Page({
4 | data:{
5 | avatarUrl: '',
6 | nickName: '',
7 | remark: ''
8 |
9 | },
10 | onLoad:function(options){
11 | var that = this;
12 | var id = options.id;
13 | //根据文章ID,从本地缓存中获取文章
14 | wx.getStorage({
15 | key: id,
16 | success: function(res){
17 | var data =res.data;
18 | //将标题栏设置为文章标题
19 | wx.setNavigationBarTitle({
20 | title: data.title,
21 | success: function(res) {
22 |
23 | }
24 | })
25 | that.setData({
26 | avatarUrl: data.author.headimg,
27 | nickName: data.author.nickname,
28 | remark: data.author.remark
29 | //content: data.content
30 | })
31 | //使用wxParse将html转为wxml,请在github上自行参考wxParse
32 | WxParse.wxParse('content', 'html', data.content, that,5);
33 | }
34 | })
35 | },
36 | onReady:function(){
37 | // 页面渲染完成
38 | },
39 | onShow:function(){
40 | // 页面显示
41 | },
42 | onHide:function(){
43 | // 页面隐藏
44 | },
45 | onUnload:function(){
46 | // 页面关闭
47 | }
48 | })
--------------------------------------------------------------------------------
/chaptor_07/pages/articledetail/detail.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_07/pages/articledetail/detail.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | {{nickName}}\n
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/chaptor_07/pages/articledetail/detail.wxss:
--------------------------------------------------------------------------------
1 | /* pages/articledetail/detail.wxss */
2 | @import "../../wxParse/wxParse.wxss";
3 | .userinfo {
4 | display: flex;
5 | border-bottom: 1px solid #aaa;
6 | }
7 |
8 | .userinfo-avatar {
9 | width: 128rpx;
10 | height: 128rpx;
11 | margin: 20rpx;
12 | border-radius: 50%;
13 | }
14 | .userinfo-mark{
15 | display: flex;
16 | flex-direction: column;
17 | margin-top: 20rpx;
18 |
19 | }
20 | .userinfo-nickname {
21 | color: #aaa;
22 | }
23 | .userinfo-remark{
24 | font-size: 15px;
25 | }
26 | .fixed-bottom{
27 | background-color: yellow;
28 | }
--------------------------------------------------------------------------------
/chaptor_07/pages/index/index.js:
--------------------------------------------------------------------------------
1 | //index.js
2 | //获取应用实例
3 | var app = getApp()
4 | Page({
5 | data: {
6 | gridIcons: [
7 | {icon:'1.png',text:'新手训练营',path:'/column/1',desc:'这是新手上路的专栏,辅助新手0基础开始上路'},
8 | {icon:'2.jpg',text:'深度思考',path:'/column/2',desc:'小程序深度思考,技术、商业、未来的一切'},
9 | {icon:'3.png',text:'精品问答',path:'/column/3',desc:'这里汇总了的技术问答问题,看看你的问题能否解决'},
10 | {icon:'4.png',text:'社区攻略',path:'/column/4',desc:'玩转社区,你需要了解的规则都在这里'},
11 | {icon:'5.png',text:'填坑系列',path:'/column/5',desc:'toBeMN的填坑之路系列,带你跳过开发中的那些坑'},
12 | {icon:'6.jpg',text:'JS新手学习',path:'/column/7',desc:'丁小柒JavaScript新手学习系列,带你从零入门快上车'},
13 | {icon:'7.jpg',text:'小程序基础篇',path:'/column/10',desc:'JeremyLu的高品质基础篇,对生命周期、数据解密、数据绑定等做深度分析'},
14 | {icon:'8.jpg',text:'框架细节',path:'/column/6',desc:'Roluce 框架细节系列,带你解密那些容易忽略的细节'},
15 | {icon:'9.png',text:'IDE心得',path:'/column/8',desc:'微信Web开发者工具使用心得,工欲善其事必先利其器'}
16 | ],
17 | inputShowed: false,
18 | inputVal: ""
19 | },
20 | onLoad: function () {
21 |
22 | },
23 | showInput: function () {
24 | this.setData({
25 | inputShowed: true
26 | });
27 | },
28 | clearInput: function () {
29 | this.setData({
30 | inputVal: ""
31 | });
32 | },
33 | inputTyping: function (e) {
34 | this.setData({
35 | inputVal: e.detail.value
36 | });
37 | },
38 | search: function(e){
39 | wx.navigateTo({
40 | url: '/pages/article/list?type=search&text=' + this.data.inputVal,
41 | success: function(res){
42 | // success
43 | },
44 | fail: function() {
45 | // fail
46 | },
47 | complete: function() {
48 | // complete
49 | }
50 | })
51 | },
52 | scancode: function(e){
53 | wx.scanCode({
54 | success: function(res){
55 | console.log(res)
56 | var result = res.result;
57 | console.log(result)
58 | var url = result.replace('wa://','').replace('http://','');
59 | console.log(url)
60 | wx.navigateTo({
61 | url: url,
62 | success: function(res){
63 | // success
64 | }
65 | })
66 |
67 | },
68 | fail: function() {
69 | // fail
70 | },
71 | complete: function() {
72 | // complete
73 | }
74 | })
75 | }
76 | })
77 |
--------------------------------------------------------------------------------
/chaptor_07/pages/index/index.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_07/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
16 |
17 | 搜索
18 | 扫码
19 |
20 |
21 |
22 |
23 |
24 | {{item.text}}
25 |
26 |
27 |
28 |
29 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/chaptor_07/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /**index.wxss**/
2 | .page__desc{
3 | font-size: 0.7rem;
4 | }
5 |
6 | .searchbar-result{
7 | margin-top: 0;
8 | font-size: 14px;
9 | }
10 | .searchbar-result:before{
11 | display: none;
12 | }
13 | .weui-cell{
14 | padding: 12px 15px 12px 35px;
15 | }
16 |
17 | .weui-footer{
18 | margin-bottom: 50px;
19 | }
20 | .weui-footer_fixed-bottom{
21 | margin-bottom: 0;
22 | }
--------------------------------------------------------------------------------
/chaptor_07/pages/logs/logs.js:
--------------------------------------------------------------------------------
1 | //logs.js
2 | var util = require('../../utils/util.js')
3 | Page({
4 | data: {
5 | logs: []
6 | },
7 | onLoad: function () {
8 | this.setData({
9 | logs: (wx.getStorageSync('logs') || []).map(function (log) {
10 | return util.formatTime(new Date(log))
11 | })
12 | })
13 | }
14 | })
15 |
--------------------------------------------------------------------------------
/chaptor_07/pages/logs/logs.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "查看启动日志"
3 | }
--------------------------------------------------------------------------------
/chaptor_07/pages/logs/logs.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{index + 1}}. {{log}}
5 |
6 |
7 |
--------------------------------------------------------------------------------
/chaptor_07/pages/logs/logs.wxss:
--------------------------------------------------------------------------------
1 | .log-list {
2 | display: flex;
3 | flex-direction: column;
4 | padding: 40rpx;
5 | }
6 | .log-item {
7 | margin: 10rpx;
8 | }
9 |
--------------------------------------------------------------------------------
/chaptor_07/utils/httpclient.js:
--------------------------------------------------------------------------------
1 | var app = getApp();
2 | function req(url, data, method, success, fail){
3 | var mydata = data || {};
4 | mydata['appId'] = app.globalData.appId;
5 | wx.request({
6 | url: app.globalData.server + url,
7 | data: mydata,
8 | method: method,
9 | success: success,
10 | fail: fail,
11 | complete: function() {
12 | // complete
13 | }
14 | })
15 | }
16 | module.exports = {
17 | req: req
18 | }
--------------------------------------------------------------------------------
/chaptor_07/utils/util.js:
--------------------------------------------------------------------------------
1 | function formatTime(date) {
2 | var year = date.getFullYear()
3 | var month = date.getMonth() + 1
4 | var day = date.getDate()
5 |
6 | var hour = date.getHours()
7 | var minute = date.getMinutes()
8 | var second = date.getSeconds()
9 |
10 |
11 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
12 | }
13 |
14 | function formatNumber(n) {
15 | n = n.toString()
16 | return n[1] ? n : '0' + n
17 | }
18 |
19 | module.exports = {
20 | formatTime: formatTime
21 | }
22 |
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/00.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/00.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/01.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/01.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/02.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/02.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/03.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/03.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/04.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/04.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/05.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/05.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/06.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/06.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/07.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/07.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/08.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/08.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/09.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/09.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/10.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/10.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/100.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/100.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/101.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/101.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/102.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/102.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/103.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/103.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/104.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/104.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/105.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/105.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/106.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/106.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/107.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/107.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/108.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/108.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/109.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/109.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/11.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/11.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/110.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/110.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/111.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/111.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/112.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/112.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/113.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/113.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/114.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/114.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/115.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/115.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/116.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/116.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/117.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/117.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/118.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/118.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/119.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/119.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/12.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/12.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/120.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/120.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/121.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/121.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/122.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/122.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/123.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/123.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/124.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/124.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/125.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/125.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/126.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/126.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/127.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/127.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/128.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/128.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/129.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/129.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/13.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/13.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/130.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/130.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/131.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/131.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/132.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/132.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/133.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/133.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/134.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/134.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/14.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/14.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/15.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/15.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/16.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/16.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/17.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/17.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/18.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/18.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/19.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/19.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/20.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/20.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/21.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/21.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/22.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/22.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/23.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/23.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/24.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/24.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/25.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/25.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/26.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/26.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/27.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/27.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/28.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/28.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/29.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/29.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/30.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/30.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/31.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/31.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/32.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/32.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/33.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/33.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/34.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/34.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/35.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/35.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/36.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/36.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/37.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/37.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/38.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/38.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/39.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/39.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/40.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/40.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/41.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/41.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/42.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/42.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/43.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/43.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/44.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/44.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/45.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/45.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/46.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/46.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/47.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/47.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/48.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/48.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/49.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/49.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/50.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/50.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/51.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/51.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/52.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/52.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/53.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/53.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/54.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/54.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/55.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/55.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/56.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/56.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/57.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/57.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/58.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/58.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/59.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/59.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/60.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/60.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/61.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/61.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/62.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/62.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/63.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/63.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/64.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/64.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/65.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/65.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/66.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/66.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/67.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/67.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/68.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/68.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/69.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/69.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/70.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/70.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/71.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/71.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/72.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/72.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/73.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/73.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/74.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/74.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/75.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/75.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/76.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/76.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/77.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/77.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/78.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/78.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/79.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/79.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/80.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/80.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/81.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/81.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/82.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/82.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/83.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/83.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/84.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/84.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/85.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/85.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/86.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/86.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/87.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/87.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/88.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/88.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/89.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/89.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/90.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/90.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/91.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/91.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/92.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/92.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/93.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/93.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/94.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/94.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/95.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/95.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/96.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/96.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/97.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/97.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/98.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/98.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/emojis/99.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_07/wxParse/emojis/99.gif
--------------------------------------------------------------------------------
/chaptor_07/wxParse/html2json.js:
--------------------------------------------------------------------------------
1 | /**
2 | * author: Di (微信小程序开发工程师)
3 | * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
4 | * 垂直微信小程序开发交流社区
5 | *
6 | * github地址: https://github.com/icindy/wxParse
7 | *
8 | * for: 微信小程序富文本解析
9 | * detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
10 | */
11 |
12 | var __placeImgeUrlHttps = "https";
13 | var __emojisReg = '';
14 | var __emojisBaseSrc = '';
15 | var __emojis = {};
16 | var wxDiscode = require('wxDiscode.js');
17 | var HTMLParser = require('htmlparser.js');
18 | // Empty Elements - HTML 5
19 | var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr");
20 | // Block Elements - HTML 5
21 | var block = makeMap("br,a,code,address,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video");
22 |
23 | // Inline Elements - HTML 5
24 | var inline = makeMap("abbr,acronym,applet,b,basefont,bdo,big,button,cite,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var");
25 |
26 | // Elements that you can, intentionally, leave open
27 | // (and which close themselves)
28 | var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");
29 |
30 | // Attributes that have their values filled in disabled="disabled"
31 | var fillAttrs = makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");
32 |
33 | // Special Elements (can contain anything)
34 | var special = makeMap("wxxxcode-style,script,style,view,scroll-view,block");
35 | function makeMap(str) {
36 | var obj = {}, items = str.split(",");
37 | for (var i = 0; i < items.length; i++)
38 | obj[items[i]] = true;
39 | return obj;
40 | }
41 |
42 | function q(v) {
43 | return '"' + v + '"';
44 | }
45 |
46 | function removeDOCTYPE(html) {
47 | return html
48 | .replace(/<\?xml.*\?>\n/, '')
49 | .replace(/\n/, '')
50 | .replace(/\n/, '');
51 | }
52 |
53 |
54 | function html2json(html, bindName) {
55 | //处理字符串
56 | html = removeDOCTYPE(html);
57 | html = wxDiscode.strDiscode(html);
58 | //生成node节点
59 | var bufArray = [];
60 | var results = {
61 | node: bindName,
62 | nodes: [],
63 | images:[],
64 | imageUrls:[]
65 | };
66 | HTMLParser(html, {
67 | start: function (tag, attrs, unary) {
68 | //debug(tag, attrs, unary);
69 | // node for this element
70 | var node = {
71 | node: 'element',
72 | tag: tag,
73 | };
74 |
75 | if (block[tag]) {
76 | node.tagType = "block";
77 | } else if (inline[tag]) {
78 | node.tagType = "inline";
79 | } else if (closeSelf[tag]) {
80 | node.tagType = "closeSelf";
81 | }
82 |
83 | if (attrs.length !== 0) {
84 | node.attr = attrs.reduce(function (pre, attr) {
85 | var name = attr.name;
86 | var value = attr.value;
87 | if (name == 'class') {
88 | console.dir(value);
89 | // value = value.join("")
90 | node.classStr = value;
91 | }
92 | // has multi attibutes
93 | // make it array of attribute
94 | if (name == 'style') {
95 | console.dir(value);
96 | // value = value.join("")
97 | node.styleStr = value;
98 | }
99 | if (value.match(/ /)) {
100 | value = value.split(' ');
101 | }
102 |
103 |
104 | // if attr already exists
105 | // merge it
106 | if (pre[name]) {
107 | if (Array.isArray(pre[name])) {
108 | // already array, push to last
109 | pre[name].push(value);
110 | } else {
111 | // single value, make it array
112 | pre[name] = [pre[name], value];
113 | }
114 | } else {
115 | // not exist, put it
116 | pre[name] = value;
117 | }
118 |
119 | return pre;
120 | }, {});
121 | }
122 |
123 | //对img添加额外数据
124 | if (node.tag === 'img') {
125 | node.imgIndex = results.images.length;
126 | var imgUrl = node.attr.src;
127 | imgUrl = wxDiscode.urlToHttpUrl(imgUrl, __placeImgeUrlHttps);
128 | node.attr.src = imgUrl;
129 | node.from = bindName;
130 | results.images.push(node);
131 | results.imageUrls.push(imgUrl);
132 | }
133 |
134 | if (unary) {
135 | // if this tag dosen't have end tag
136 | // like
137 | // add to parents
138 | var parent = bufArray[0] || results;
139 | if (parent.nodes === undefined) {
140 | parent.nodes = [];
141 | }
142 | parent.nodes.push(node);
143 | } else {
144 | bufArray.unshift(node);
145 | }
146 | },
147 | end: function (tag) {
148 | //debug(tag);
149 | // merge into parent tag
150 | var node = bufArray.shift();
151 | if (node.tag !== tag) console.error('invalid state: mismatch end tag');
152 |
153 | if (bufArray.length === 0) {
154 | results.nodes.push(node);
155 | } else {
156 | var parent = bufArray[0];
157 | if (parent.nodes === undefined) {
158 | parent.nodes = [];
159 | }
160 | parent.nodes.push(node);
161 | }
162 | },
163 | chars: function (text) {
164 | //debug(text);
165 | var node = {
166 | node: 'text',
167 | text: text,
168 | textArray:transEmojiStr(text)
169 | };
170 |
171 | if (bufArray.length === 0) {
172 | results.nodes.push(node);
173 | } else {
174 | var parent = bufArray[0];
175 | if (parent.nodes === undefined) {
176 | parent.nodes = [];
177 | }
178 | parent.nodes.push(node);
179 | }
180 | },
181 | comment: function (text) {
182 | //debug(text);
183 | var node = {
184 | node: 'comment',
185 | text: text,
186 | };
187 | var parent = bufArray[0];
188 | if (parent.nodes === undefined) {
189 | parent.nodes = [];
190 | }
191 | parent.nodes.push(node);
192 | },
193 | });
194 | return results;
195 | };
196 |
197 | function transEmojiStr(str){
198 | // var eReg = new RegExp("["+__reg+' '+"]");
199 | // str = str.replace(/\[([^\[\]]+)\]/g,':$1:')
200 |
201 | var emojiObjs = [];
202 | //如果正则表达式为空
203 | if(__emojisReg.length == 0 || !__emojis){
204 | var emojiObj = {}
205 | emojiObj.node = "text";
206 | emojiObj.text = str;
207 | array = [emojiObj];
208 | return array;
209 | }
210 | //这个地方需要调整
211 | str = str.replace(/\[([^\[\]]+)\]/g,':$1:')
212 | var eReg = new RegExp("[:]");
213 | var array = str.split(eReg);
214 | for(var i = 0; i < array.length; i++){
215 | var ele = array[i];
216 | var emojiObj = {};
217 | if(__emojis[ele]){
218 | emojiObj.node = "element";
219 | emojiObj.tag = "emoji";
220 | emojiObj.text = __emojis[ele];
221 | emojiObj.baseSrc= __emojisBaseSrc;
222 | }else{
223 | emojiObj.node = "text";
224 | emojiObj.text = ele;
225 | }
226 | emojiObjs.push(emojiObj);
227 | }
228 |
229 | return emojiObjs;
230 | }
231 |
232 | function emojisInit(reg='',baseSrc="/wxParse/emojis/",emojis){
233 | __emojisReg = reg;
234 | __emojisBaseSrc=baseSrc;
235 | __emojis=emojis;
236 | }
237 |
238 | module.exports = {
239 | html2json: html2json,
240 | emojisInit:emojisInit
241 | };
242 |
243 |
--------------------------------------------------------------------------------
/chaptor_07/wxParse/htmlparser.js:
--------------------------------------------------------------------------------
1 | /**
2 | * author: Di (微信小程序开发工程师)
3 | * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
4 | * 垂直微信小程序开发交流社区
5 | *
6 | * github地址: https://github.com/icindy/wxParse
7 | *
8 | * for: 微信小程序富文本解析
9 | * detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
10 | */
11 | // Regular Expressions for parsing tags and attributes
12 | var startTag = /^<([-A-Za-z0-9_]+)((?:\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,
13 | endTag = /^<\/([-A-Za-z0-9_]+)[^>]*>/,
14 | attr = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;
15 |
16 | // Empty Elements - HTML 5
17 | var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr");
18 |
19 | // Block Elements - HTML 5
20 | var block = makeMap("a,address,code,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video");
21 |
22 | // Inline Elements - HTML 5
23 | var inline = makeMap("abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var");
24 |
25 | // Elements that you can, intentionally, leave open
26 | // (and which close themselves)
27 | var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");
28 |
29 | // Attributes that have their values filled in disabled="disabled"
30 | var fillAttrs = makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");
31 |
32 | // Special Elements (can contain anything)
33 | var special = makeMap("wxxxcode-style,script,style,view,scroll-view,block");
34 |
35 | function HTMLParser(html, handler) {
36 | var index, chars, match, stack = [], last = html;
37 | stack.last = function () {
38 | return this[this.length - 1];
39 | };
40 |
41 | while (html) {
42 | chars = true;
43 |
44 | // Make sure we're not in a script or style element
45 | if (!stack.last() || !special[stack.last()]) {
46 |
47 | // Comment
48 | if (html.indexOf("");
50 |
51 | if (index >= 0) {
52 | if (handler.comment)
53 | handler.comment(html.substring(4, index));
54 | html = html.substring(index + 3);
55 | chars = false;
56 | }
57 |
58 | // end tag
59 | } else if (html.indexOf("") == 0) {
60 | match = html.match(endTag);
61 |
62 | if (match) {
63 | html = html.substring(match[0].length);
64 | match[0].replace(endTag, parseEndTag);
65 | chars = false;
66 | }
67 |
68 | // start tag
69 | } else if (html.indexOf("<") == 0) {
70 | match = html.match(startTag);
71 |
72 | if (match) {
73 | html = html.substring(match[0].length);
74 | match[0].replace(startTag, parseStartTag);
75 | chars = false;
76 | }
77 | }
78 |
79 | if (chars) {
80 | index = html.indexOf("<");
81 |
82 | var text = index < 0 ? html : html.substring(0, index);
83 | html = index < 0 ? "" : html.substring(index);
84 |
85 | if (handler.chars)
86 | handler.chars(text);
87 | }
88 |
89 | } else {
90 |
91 | html = html.replace(new RegExp("([\\s\\S]*?)<\/" + stack.last() + "[^>]*>"), function (all, text) {
92 | text = text.replace(/|/g, "$1$2");
93 | if (handler.chars)
94 | handler.chars(text);
95 |
96 | return "";
97 | });
98 |
99 |
100 | parseEndTag("", stack.last());
101 | }
102 |
103 | if (html == last)
104 | throw "Parse Error: " + html;
105 | last = html;
106 | }
107 |
108 | // Clean up any remaining tags
109 | parseEndTag();
110 |
111 | function parseStartTag(tag, tagName, rest, unary) {
112 | tagName = tagName.toLowerCase();
113 |
114 | if (block[tagName]) {
115 | while (stack.last() && inline[stack.last()]) {
116 | parseEndTag("", stack.last());
117 | }
118 | }
119 |
120 | if (closeSelf[tagName] && stack.last() == tagName) {
121 | parseEndTag("", tagName);
122 | }
123 |
124 | unary = empty[tagName] || !!unary;
125 |
126 | if (!unary)
127 | stack.push(tagName);
128 |
129 | if (handler.start) {
130 | var attrs = [];
131 |
132 | rest.replace(attr, function (match, name) {
133 | var value = arguments[2] ? arguments[2] :
134 | arguments[3] ? arguments[3] :
135 | arguments[4] ? arguments[4] :
136 | fillAttrs[name] ? name : "";
137 |
138 | attrs.push({
139 | name: name,
140 | value: value,
141 | escaped: value.replace(/(^|[^\\])"/g, '$1\\\"') //"
142 | });
143 | });
144 |
145 | if (handler.start) {
146 | handler.start(tagName, attrs, unary);
147 | }
148 |
149 | }
150 | }
151 |
152 | function parseEndTag(tag, tagName) {
153 | // If no tag name is provided, clean shop
154 | if (!tagName)
155 | var pos = 0;
156 |
157 | // Find the closest opened tag of the same type
158 | else
159 | for (var pos = stack.length - 1; pos >= 0; pos--)
160 | if (stack[pos] == tagName)
161 | break;
162 |
163 | if (pos >= 0) {
164 | // Close all the open elements, up the stack
165 | for (var i = stack.length - 1; i >= pos; i--)
166 | if (handler.end)
167 | handler.end(stack[i]);
168 |
169 | // Remove the open elements from the stack
170 | stack.length = pos;
171 | }
172 | }
173 | };
174 |
175 | function makeMap(str) {
176 | var obj = {}, items = str.split(",");
177 | for (var i = 0; i < items.length; i++)
178 | obj[items[i]] = true;
179 | return obj;
180 | }
181 |
182 | module.exports = HTMLParser;
183 |
--------------------------------------------------------------------------------
/chaptor_07/wxParse/wxDiscode.js:
--------------------------------------------------------------------------------
1 | // HTML 支持的数学符号
2 | function strNumDiscode(str){
3 | str = str.replace(/∀/g, '∀');
4 | str = str.replace(/∂/g, '∂');
5 | str = str.replace(/&exists;/g, '∃');
6 | str = str.replace(/∅/g, '∅');
7 | str = str.replace(/∇/g, '∇');
8 | str = str.replace(/∈/g, '∈');
9 | str = str.replace(/∉/g, '∉');
10 | str = str.replace(/∋/g, '∋');
11 | str = str.replace(/∏/g, '∏');
12 | str = str.replace(/∑/g, '∑');
13 | str = str.replace(/−/g, '−');
14 | str = str.replace(/∗/g, '∗');
15 | str = str.replace(/√/g, '√');
16 | str = str.replace(/∝/g, '∝');
17 | str = str.replace(/∞/g, '∞');
18 | str = str.replace(/∠/g, '∠');
19 | str = str.replace(/∧/g, '∧');
20 | str = str.replace(/∨/g, '∨');
21 | str = str.replace(/∩/g, '∩');
22 | str = str.replace(/∩/g, '∪');
23 | str = str.replace(/∫/g, '∫');
24 | str = str.replace(/∴/g, '∴');
25 | str = str.replace(/∼/g, '∼');
26 | str = str.replace(/≅/g, '≅');
27 | str = str.replace(/≈/g, '≈');
28 | str = str.replace(/≠/g, '≠');
29 | str = str.replace(/≤/g, '≤');
30 | str = str.replace(/≥/g, '≥');
31 | str = str.replace(/⊂/g, '⊂');
32 | str = str.replace(/⊃/g, '⊃');
33 | str = str.replace(/⊄/g, '⊄');
34 | str = str.replace(/⊆/g, '⊆');
35 | str = str.replace(/⊇/g, '⊇');
36 | str = str.replace(/⊕/g, '⊕');
37 | str = str.replace(/⊗/g, '⊗');
38 | str = str.replace(/⊥/g, '⊥');
39 | str = str.replace(/⋅/g, '⋅');
40 | return str;
41 | }
42 |
43 | //HTML 支持的希腊字母
44 | function strGreeceDiscode(str){
45 | str = str.replace(/Α/g, 'Α');
46 | str = str.replace(/Β/g, 'Β');
47 | str = str.replace(/Γ/g, 'Γ');
48 | str = str.replace(/Δ/g, 'Δ');
49 | str = str.replace(/Ε/g, 'Ε');
50 | str = str.replace(/Ζ/g, 'Ζ');
51 | str = str.replace(/Η/g, 'Η');
52 | str = str.replace(/Θ/g, 'Θ');
53 | str = str.replace(/Ι/g, 'Ι');
54 | str = str.replace(/Κ/g, 'Κ');
55 | str = str.replace(/Λ/g, 'Λ');
56 | str = str.replace(/Μ/g, 'Μ');
57 | str = str.replace(/Ν/g, 'Ν');
58 | str = str.replace(/Ξ/g, 'Ν');
59 | str = str.replace(/Ο/g, 'Ο');
60 | str = str.replace(/Π/g, 'Π');
61 | str = str.replace(/Ρ/g, 'Ρ');
62 | str = str.replace(/Σ/g, 'Σ');
63 | str = str.replace(/Τ/g, 'Τ');
64 | str = str.replace(/Υ/g, 'Υ');
65 | str = str.replace(/Φ/g, 'Φ');
66 | str = str.replace(/Χ/g, 'Χ');
67 | str = str.replace(/Ψ/g, 'Ψ');
68 | str = str.replace(/Ω/g, 'Ω');
69 |
70 | str = str.replace(/α/g, 'α');
71 | str = str.replace(/β/g, 'β');
72 | str = str.replace(/γ/g, 'γ');
73 | str = str.replace(/δ/g, 'δ');
74 | str = str.replace(/ε/g, 'ε');
75 | str = str.replace(/ζ/g, 'ζ');
76 | str = str.replace(/η/g, 'η');
77 | str = str.replace(/θ/g, 'θ');
78 | str = str.replace(/ι/g, 'ι');
79 | str = str.replace(/κ/g, 'κ');
80 | str = str.replace(/λ/g, 'λ');
81 | str = str.replace(/μ/g, 'μ');
82 | str = str.replace(/ν/g, 'ν');
83 | str = str.replace(/ξ/g, 'ξ');
84 | str = str.replace(/ο/g, 'ο');
85 | str = str.replace(/π/g, 'π');
86 | str = str.replace(/ρ/g, 'ρ');
87 | str = str.replace(/ς/g, 'ς');
88 | str = str.replace(/σ/g, 'σ');
89 | str = str.replace(/τ/g, 'τ');
90 | str = str.replace(/υ/g, 'υ');
91 | str = str.replace(/φ/g, 'φ');
92 | str = str.replace(/χ/g, 'χ');
93 | str = str.replace(/ψ/g, 'ψ');
94 | str = str.replace(/ω/g, 'ω');
95 | str = str.replace(/ϑ/g, 'ϑ');
96 | str = str.replace(/ϒ/g, 'ϒ');
97 | str = str.replace(/ϖ/g, 'ϖ');
98 | str = str.replace(/·/g, '·');
99 | return str;
100 | }
101 |
102 | //
103 |
104 | function strcharacterDiscode(str){
105 | // 加入常用解析
106 | str = str.replace(/ /g, ' ');
107 | str = str.replace(/"/g, '"');
108 | str = str.replace(/&/g, '&');
109 | // str = str.replace(/</g, '‹');
110 | // str = str.replace(/>/g, '›');
111 |
112 | str = str.replace(/</g, '<');
113 | str = str.replace(/>/g, '>');
114 |
115 | return str;
116 | }
117 |
118 | // HTML 支持的其他实体
119 | function strOtherDiscode(str){
120 | str = str.replace(/Œ/g, 'Œ');
121 | str = str.replace(/œ/g, 'œ');
122 | str = str.replace(/Š/g, 'Š');
123 | str = str.replace(/š/g, 'š');
124 | str = str.replace(/Ÿ/g, 'Ÿ');
125 | str = str.replace(/ƒ/g, 'ƒ');
126 | str = str.replace(/ˆ/g, 'ˆ');
127 | str = str.replace(/˜/g, '˜');
128 | str = str.replace(/ /g, '');
129 | str = str.replace(/ /g, '');
130 | str = str.replace(/ /g, '');
131 | str = str.replace(//g, '');
132 | str = str.replace(//g, '');
133 | str = str.replace(//g, '');
134 | str = str.replace(//g, '');
135 | str = str.replace(/–/g, '–');
136 | str = str.replace(/—/g, '—');
137 | str = str.replace(/‘/g, '‘');
138 | str = str.replace(/’/g, '’');
139 | str = str.replace(/‚/g, '‚');
140 | str = str.replace(/“/g, '“');
141 | str = str.replace(/”/g, '”');
142 | str = str.replace(/„/g, '„');
143 | str = str.replace(/†/g, '†');
144 | str = str.replace(/‡/g, '‡');
145 | str = str.replace(/•/g, '•');
146 | str = str.replace(/…/g, '…');
147 | str = str.replace(/‰/g, '‰');
148 | str = str.replace(/′/g, '′');
149 | str = str.replace(/″/g, '″');
150 | str = str.replace(/‹/g, '‹');
151 | str = str.replace(/›/g, '›');
152 | str = str.replace(/‾/g, '‾');
153 | str = str.replace(/€/g, '€');
154 | str = str.replace(/™/g, '™');
155 |
156 | str = str.replace(/←/g, '←');
157 | str = str.replace(/↑/g, '↑');
158 | str = str.replace(/→/g, '→');
159 | str = str.replace(/↓/g, '↓');
160 | str = str.replace(/↔/g, '↔');
161 | str = str.replace(/↵/g, '↵');
162 | str = str.replace(/⌈/g, '⌈');
163 | str = str.replace(/⌉/g, '⌉');
164 |
165 | str = str.replace(/⌊/g, '⌊');
166 | str = str.replace(/⌋/g, '⌋');
167 | str = str.replace(/◊/g, '◊');
168 | str = str.replace(/♠/g, '♠');
169 | str = str.replace(/♣/g, '♣');
170 | str = str.replace(/♥/g, '♥');
171 |
172 | str = str.replace(/♦/g, '♦');
173 |
174 | return str;
175 | }
176 |
177 | function strMoreDiscode(str){
178 | str = str.replace(/\r\n/g,"");
179 | str = str.replace(/\n/g,"");
180 |
181 | str = str.replace(/code/g,"wxxxcode-style");
182 | return str;
183 | }
184 |
185 | function strDiscode(str){
186 | str = strNumDiscode(str);
187 | str = strGreeceDiscode(str);
188 | str = strcharacterDiscode(str);
189 | str = strOtherDiscode(str);
190 | str = strMoreDiscode(str);
191 | return str;
192 | }
193 | function urlToHttpUrl(url,rep){
194 |
195 | var patt1 = new RegExp("^//");
196 | var result = patt1.test(url);
197 | if(result){
198 | url = rep+":"+url;
199 | }
200 | return url;
201 | }
202 |
203 | module.exports = {
204 | strDiscode:strDiscode,
205 | urlToHttpUrl:urlToHttpUrl
206 | }
--------------------------------------------------------------------------------
/chaptor_07/wxParse/wxParse.js:
--------------------------------------------------------------------------------
1 | /**
2 | * author: Di (微信小程序开发工程师)
3 | * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
4 | * 垂直微信小程序开发交流社区
5 | *
6 | * github地址: https://github.com/icindy/wxParse
7 | *
8 | * for: 微信小程序富文本解析
9 | * detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
10 | */
11 |
12 | /**
13 | * utils函数引入
14 | **/
15 | import showdown from 'showdown.js';
16 | import HtmlToJson from 'html2json.js';
17 | /**
18 | * 配置及公有属性
19 | **/
20 | /**
21 | * 主函数入口区
22 | **/
23 | function wxParse(bindName = 'wxParseData', type='html', data='数据不能为空
', target,imagePadding) {
24 | var that = target;
25 | var transData = {};//存放转化后的数据
26 | if (type == 'html') {
27 | transData = HtmlToJson.html2json(data, bindName);
28 | console.log(JSON.stringify(transData, ' ', ' '));
29 | } else if (type == 'md' || type == 'markdown') {
30 | var converter = new showdown.Converter();
31 | var html = converter.makeHtml(data);
32 | transData = HtmlToJson.html2json(html, bindName);
33 | console.log(JSON.stringify(transData, ' ', ' '));
34 | }
35 | transData.view = {};
36 | transData.view.imagePadding = 0;
37 | if(typeof(imagePadding) != 'undefined'){
38 | transData.view.imagePadding = imagePadding
39 | }
40 | var bindData = {};
41 | bindData[bindName] = transData;
42 | that.setData(bindData)
43 | that.wxParseImgLoad = wxParseImgLoad;
44 | that.wxParseImgTap = wxParseImgTap;
45 | }
46 | // 图片点击事件
47 | function wxParseImgTap(e) {
48 | var that = this;
49 | var nowImgUrl = e.target.dataset.src;
50 | var tagFrom = e.target.dataset.from;
51 | if (typeof (tagFrom) != 'undefined' && tagFrom.length > 0) {
52 | wx.previewImage({
53 | current: nowImgUrl, // 当前显示图片的http链接
54 | urls: that.data[tagFrom].imageUrls // 需要预览的图片http链接列表
55 | })
56 | }
57 | }
58 |
59 | /**
60 | * 图片视觉宽高计算函数区
61 | **/
62 | function wxParseImgLoad(e) {
63 | var that = this;
64 | var tagFrom = e.target.dataset.from;
65 | var idx = e.target.dataset.idx;
66 | if (typeof (tagFrom) != 'undefined' && tagFrom.length > 0) {
67 | calMoreImageInfo(e, idx, that, tagFrom)
68 | }
69 | }
70 | // 假循环获取计算图片视觉最佳宽高
71 | function calMoreImageInfo(e, idx, that, bindName) {
72 | var temData = that.data[bindName];
73 | if (temData.images.length == 0) {
74 | return;
75 | }
76 | var temImages = temData.images;
77 | //因为无法获取view宽度 需要自定义padding进行计算,稍后处理
78 | var recal = wxAutoImageCal(e.detail.width, e.detail.height,that,bindName);
79 | temImages[idx].width = recal.imageWidth;
80 | temImages[idx].height = recal.imageheight;
81 | temData.images = temImages;
82 | var bindData = {};
83 | bindData[bindName] = temData;
84 | that.setData(bindData);
85 | }
86 |
87 | // 计算视觉优先的图片宽高
88 | function wxAutoImageCal(originalWidth, originalHeight,that,bindName) {
89 | //获取图片的原始长宽
90 | var windowWidth = 0, windowHeight = 0;
91 | var autoWidth = 0, autoHeight = 0;
92 | var results = {};
93 | wx.getSystemInfo({
94 | success: function (res) {
95 | var padding = that.data[bindName].view.imagePadding;
96 | windowWidth = res.windowWidth-2*padding;
97 | windowHeight = res.windowHeight;
98 | //判断按照那种方式进行缩放
99 | console.log("windowWidth" + windowWidth);
100 | if (originalWidth > windowWidth) {//在图片width大于手机屏幕width时候
101 | autoWidth = windowWidth;
102 | console.log("autoWidth" + autoWidth);
103 | autoHeight = (autoWidth * originalHeight) / originalWidth;
104 | console.log("autoHeight" + autoHeight);
105 | results.imageWidth = autoWidth;
106 | results.imageheight = autoHeight;
107 | } else {//否则展示原来的数据
108 | results.imageWidth = originalWidth;
109 | results.imageheight = originalHeight;
110 | }
111 | }
112 | })
113 | return results;
114 | }
115 |
116 | function wxParseTemArray(temArrayName,bindNameReg,total,that){
117 | var array = [];
118 | var temData = that.data;
119 | var obj = null;
120 | for(var i = 0; i < total; i++){
121 | var simArr = temData[bindNameReg+i].nodes;
122 | array.push(simArr);
123 | }
124 |
125 | temArrayName = temArrayName || 'wxParseTemArray';
126 | obj = JSON.parse('{"'+ temArrayName +'":""}');
127 | obj[temArrayName] = array;
128 | that.setData(obj);
129 | }
130 |
131 | /**
132 | * 配置emojis
133 | *
134 | */
135 |
136 | function emojisInit(reg='',baseSrc="/wxParse/emojis/",emojis){
137 | HtmlToJson.emojisInit(reg,baseSrc,emojis);
138 | }
139 |
140 | module.exports = {
141 | wxParse: wxParse,
142 | wxParseTemArray:wxParseTemArray,
143 | emojisInit:emojisInit
144 | }
145 |
146 |
147 |
--------------------------------------------------------------------------------
/chaptor_07/wxParse/wxParse.wxss:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * author: Di (微信小程序开发工程师)
4 | * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
5 | * 垂直微信小程序开发交流社区
6 | *
7 | * github地址: https://github.com/icindy/wxParse
8 | *
9 | * for: 微信小程序富文本解析
10 | * detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
11 | */
12 |
13 | .wxParse{
14 | margin: 0 5px;
15 | font-family: Helvetica,sans-serif;
16 | font-size: 28rpx;
17 | color: #666;
18 | line-height: 1.8;
19 | }
20 | view{
21 | word-break:break-all; overflow:auto;
22 | }
23 | .wxParse-inline{
24 | display: inline;
25 | margin: 0;
26 | padding: 0;
27 | }
28 | /*//标题 */
29 | .wxParse-div{margin: 0;padding: 0;}
30 | .wxParse-h1{ font-size:2em; margin: .67em 0 }
31 | .wxParse-h2{ font-size:1.5em; margin: .75em 0 }
32 | .wxParse-h3{ font-size:1.17em; margin: .83em 0 }
33 | .wxParse-h4{ margin: 1.12em 0}
34 | .wxParse-h5 { font-size:.83em; margin: 1.5em 0 }
35 | .wxParse-h6{ font-size:.75em; margin: 1.67em 0 }
36 |
37 | .wxParse-h1 {
38 | font-size: 18px;
39 | font-weight: 400;
40 | margin-bottom: .9em;
41 | }
42 | .wxParse-h2 {
43 | font-size: 16px;
44 | font-weight: 400;
45 | margin-bottom: .34em;
46 | }
47 | .wxParse-h3 {
48 | font-weight: 400;
49 | font-size: 15px;
50 | margin-bottom: .34em;
51 | }
52 | .wxParse-h4 {
53 | font-weight: 400;
54 | font-size: 14px;
55 | margin-bottom: .24em;
56 | }
57 | .wxParse-h5 {
58 | font-weight: 400;
59 | font-size: 13px;
60 | margin-bottom: .14em;
61 | }
62 | .wxParse-h6 {
63 | font-weight: 400;
64 | font-size: 12px;
65 | margin-bottom: .04em;
66 | }
67 |
68 | .wxParse-h1, .wxParse-h2, .wxParse-h3, .wxParse-h4, .wxParse-h5, .wxParse-h6, .wxParse-b, .wxParse-strong { font-weight: bolder }
69 |
70 | .wxParse-i,.wxParse-cite,.wxParse-em,.wxParse-var,.wxParse-address{font-style:italic}
71 | .wxParse-pre,.wxParse-tt,.wxParse-code,.wxParse-kbd,.wxParse-samp{font-family:monospace}
72 | .wxParse-pre{white-space:pre}
73 | .wxParse-big{font-size:1.17em}
74 | .wxParse-small,.wxParse-sub,.wxParse-sup{font-size:.83em}
75 | .wxParse-sub{vertical-align:sub}
76 | .wxParse-sup{vertical-align:super}
77 | .wxParse-s,.wxParse-strike,.wxParse-del{text-decoration:line-through}
78 | /*wxparse-自定义个性化的css样式*/
79 | /*增加video的css样式*/
80 | .wxParse-strong,wxParse-s{display: inline}
81 | .wxParse-a{
82 | color: deepskyblue;
83 | word-break:break-all;
84 | overflow:auto;
85 | }
86 |
87 | .wxParse-video{
88 | text-align: center;
89 | margin: 10px 0;
90 | }
91 |
92 | .wxParse-video-video{
93 | width:100%;
94 | }
95 |
96 | .wxParse-img{
97 | background-color: #efefef;
98 | overflow: hidden;
99 | width:40px;
100 | height: 40px;
101 | }
102 |
103 | .wxParse-blockquote {
104 | margin: 0;
105 | padding:10px 0 10px 5px;
106 | font-family:Courier, Calibri,"宋体";
107 | background:#f5f5f5;
108 | border-left: 3px solid #dbdbdb;
109 | }
110 |
111 | .wxParse-code,.wxParse-wxxxcode-style{
112 | display: inline;
113 | background:#f5f5f5;
114 | }
115 | .wxParse-ul{
116 | margin: 20rpx 10rpx;
117 | }
118 |
119 | .wxParse-li,.wxParse-li-inner{
120 | display: flex;
121 | align-items: baseline;
122 | margin: 10rpx 0;
123 | }
124 | .wxParse-li-text{
125 |
126 | align-items: center;
127 | line-height: 20px;
128 | }
129 |
130 | .wxParse-li-circle{
131 | display: inline-flex;
132 | width: 5px;
133 | height: 5px;
134 | background-color: #333;
135 | margin-right: 5px;
136 | }
137 |
138 | .wxParse-li-square{
139 | display: inline-flex;
140 | width: 10rpx;
141 | height: 10rpx;
142 | background-color: #333;
143 | margin-right: 5px;
144 | }
145 | .wxParse-li-ring{
146 | display: inline-flex;
147 | width: 10rpx;
148 | height: 10rpx;
149 | border: 2rpx solid #333;
150 | border-radius: 50%;
151 | background-color: #fff;
152 | margin-right: 5px;
153 | }
154 |
155 | /*.wxParse-table{
156 | width: 100%;
157 | height: 400px;
158 | }
159 | .wxParse-thead,.wxParse-tfoot,.wxParse-tr{
160 | display: flex;
161 | flex-direction: row;
162 | }
163 | .wxParse-th,.wxParse-td{
164 | display: flex;
165 | width: 580px;
166 | overflow: auto;
167 | }*/
168 |
169 | .wxParse-u {
170 | text-decoration: underline;
171 | }
172 | .wxParse-hide{
173 | display: none;
174 | }
175 | .WxEmojiView{
176 | align-items: center;
177 | }
178 | .wxEmoji{
179 | width: 16px;
180 | height:16px;
181 | }
182 |
--------------------------------------------------------------------------------
/chaptor_08/.gitignore:
--------------------------------------------------------------------------------
1 | *swp
2 |
--------------------------------------------------------------------------------
/chaptor_08/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | onLaunch: function () {
4 | //调用API从本地缓存中获取数据
5 | var logs = wx.getStorageSync('logs') || []
6 | logs.unshift(Date.now())
7 | wx.setStorageSync('logs', logs)
8 | },
9 | getUserInfo:function(cb){
10 | var that = this
11 | if(this.globalData.userInfo){
12 | typeof cb == "function" && cb(this.globalData.userInfo)
13 | }else{
14 | //调用登录接口
15 | wx.login({
16 | success: function () {
17 | wx.getUserInfo({
18 | success: function (res) {
19 | that.globalData.userInfo = res.userInfo
20 | typeof cb == "function" && cb(that.globalData.userInfo)
21 | }
22 | })
23 | }
24 | })
25 | }
26 | },
27 | globalData:{
28 | userInfo:null
29 | }
30 | })
--------------------------------------------------------------------------------
/chaptor_08/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages":[
3 | "pages/index/index",
4 | "pages/logs/logs"
5 | ],
6 | "window":{
7 | "backgroundTextStyle":"light",
8 | "navigationBarBackgroundColor": "#fff",
9 | "navigationBarTitleText": "WeChat",
10 | "navigationBarTextStyle":"black"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chaptor_08/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | .container {
3 | height: 100%;
4 | display: flex;
5 | flex-direction: column;
6 | align-items: center;
7 | justify-content: space-between;
8 | padding: 200rpx 0;
9 | box-sizing: border-box;
10 | }
11 |
--------------------------------------------------------------------------------
/chaptor_08/pages/index/index.js:
--------------------------------------------------------------------------------
1 | //index.js
2 | var local = require('../../utils/localStorage')
3 | //获取应用实例
4 | var app = getApp()
5 | Page({
6 | data: {
7 | storageKey: '',
8 | storageValue: ''
9 | },
10 | //事件处理函数
11 | bindViewTap: function() {
12 | wx.navigateTo({
13 | url: '../logs/logs'
14 | })
15 | },
16 | onLoad: function () {
17 |
18 | },
19 | keyIpt: function(e){
20 | this.setData({
21 | storageKey: e.detail.value
22 | })
23 | },
24 | valueIpt: function(e){
25 | this.setData({
26 | storageValue: e.detail.value
27 | })
28 | },
29 |
30 | save: function(e){
31 | console.log('开始保存')
32 | wx.setStorageSync(this.data.storageKey + '2', this.data.storageValue)
33 | console.log('同步保存成功')
34 | wx.setStorage({
35 | key: this.data.storageKey + '1',
36 | data: this.data.storageValue,
37 | success: function(res){
38 | console.log('异步保存成功')
39 | }
40 | })
41 |
42 | },
43 | getData: function(e){
44 | //异步获取
45 | wx.getStorage({
46 | key: this.data.storageKey + '1',
47 | success: function(res){
48 | console.log('我是异步获取的内容: ' + res.data)
49 | }
50 | })
51 | //同步获取
52 | var valueData = wx.getStorageSync(this.data.storageKey + '1');
53 | console.log('我是同步获取的内容: ' + valueData);
54 | },
55 | getDataInfo: function(e){
56 | //异步获取
57 | var storageInfo = wx.getStorageInfoSync();
58 | console.log("异步获取缓存信息")
59 | console.log(storageInfo)
60 | //同步获取
61 | wx.getStorageInfo({
62 | success: function(res){
63 | console.log("同步获取缓存信息")
64 | console.log(res)
65 | }
66 | })
67 | },
68 | removeData: function(e){
69 | //异步删除
70 | wx.removeStorageSync('String');
71 | //同步删除
72 | wx.removeStorage({
73 | key: 'String',
74 | success: function(res){
75 | // success
76 | },
77 | fail: function() {
78 | // fail
79 | },
80 | complete: function() {
81 | // complete
82 | }
83 | })
84 | },
85 | clearData: function(e){
86 | //异步删除
87 | wx.clearStorageSync()
88 | //同步删除
89 | wx.clearStorage({
90 | success: function(res){
91 | // success
92 | },
93 | fail: function() {
94 | // fail
95 | },
96 | complete: function() {
97 | // complete
98 | }
99 | })
100 | }
101 | })
102 |
--------------------------------------------------------------------------------
/chaptor_08/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/chaptor_08/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /**index.wxss**/
2 |
--------------------------------------------------------------------------------
/chaptor_08/pages/logs/logs.js:
--------------------------------------------------------------------------------
1 | //logs.js
2 | var util = require('../../utils/util.js')
3 | Page({
4 | data: {
5 | logs: []
6 | },
7 | onLoad: function () {
8 | this.setData({
9 | logs: (wx.getStorageSync('logs') || []).map(function (log) {
10 | return util.formatTime(new Date(log))
11 | })
12 | })
13 | }
14 | })
15 |
--------------------------------------------------------------------------------
/chaptor_08/pages/logs/logs.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "查看启动日志"
3 | }
--------------------------------------------------------------------------------
/chaptor_08/pages/logs/logs.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{index + 1}}. {{log}}
5 |
6 |
7 |
--------------------------------------------------------------------------------
/chaptor_08/pages/logs/logs.wxss:
--------------------------------------------------------------------------------
1 | .log-list {
2 | display: flex;
3 | flex-direction: column;
4 | padding: 40rpx;
5 | }
6 | .log-item {
7 | margin: 10rpx;
8 | }
9 |
--------------------------------------------------------------------------------
/chaptor_08/utils/localStorage.js:
--------------------------------------------------------------------------------
1 | var add = function(key, data, expires){
2 | var timestamp=new Date().getTime();
3 | return timestamp;
4 | }
5 | module.exports = {
6 | add: add
7 | }
--------------------------------------------------------------------------------
/chaptor_08/utils/util.js:
--------------------------------------------------------------------------------
1 | function formatTime(date) {
2 | var year = date.getFullYear()
3 | var month = date.getMonth() + 1
4 | var day = date.getDate()
5 |
6 | var hour = date.getHours()
7 | var minute = date.getMinutes()
8 | var second = date.getSeconds()
9 |
10 |
11 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
12 | }
13 |
14 | function formatNumber(n) {
15 | n = n.toString()
16 | return n[1] ? n : '0' + n
17 | }
18 |
19 | module.exports = {
20 | formatTime: formatTime
21 | }
22 |
--------------------------------------------------------------------------------
/chaptor_10/.gitignore:
--------------------------------------------------------------------------------
1 | *swp
2 |
--------------------------------------------------------------------------------
/chaptor_10/README.md:
--------------------------------------------------------------------------------
1 | ### Canvas
--------------------------------------------------------------------------------
/chaptor_10/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | onLaunch: function () {
4 |
5 | },
6 | globalData:{
7 | userInfo:null
8 | }
9 | })
--------------------------------------------------------------------------------
/chaptor_10/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages":[
3 | "pages/index/index",
4 | "pages/canvas1/canvas1",
5 | "pages/canvas2/canvas2",
6 | "pages/canvas3/canvas3",
7 | "pages/canvas4/canvas4",
8 | "pages/canvas5/canvas5"
9 | ],
10 | "window":{
11 | "backgroundTextStyle":"light",
12 | "navigationBarBackgroundColor": "#fff",
13 | "navigationBarTitleText": "Canvas学习",
14 | "navigationBarTextStyle":"black"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/chaptor_10/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | .container {
3 | height: 100%;
4 | display: flex;
5 | flex-direction: column;
6 | align-items: center;
7 | justify-content: space-between;
8 | padding: 200rpx 0;
9 | box-sizing: border-box;
10 | }
11 |
--------------------------------------------------------------------------------
/chaptor_10/images/test.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_10/images/test.gif
--------------------------------------------------------------------------------
/chaptor_10/images/test.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_10/images/test.jpeg
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas1/canvas1.js:
--------------------------------------------------------------------------------
1 | // pages/canvas1/canvas1.js
2 | Page({
3 | data:{},
4 | onLoad:function(options){
5 | // 页面初始化 options为页面跳转所带来的参数
6 | },
7 | onReady:function(){
8 | // 页面渲染完成
9 |
10 | var context = wx.createContext();
11 | },
12 | onShow:function(){
13 | // 页面显示
14 | },
15 | onHide:function(){
16 | // 页面隐藏
17 | },
18 | onUnload:function(){
19 | // 页面关闭
20 | },
21 | mytouchstart: function(e){
22 | console.log('touchstart in canvas')
23 | },
24 | mytouchmove: function(e){
25 | console.log('touchmove in canvas')
26 | },
27 | mytouchend: function(e){
28 | console.log('touchend')
29 | }
30 | })
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas1/canvas1.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas1/canvas1.wxml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas1/canvas1.wxss:
--------------------------------------------------------------------------------
1 | .canvas1 {
2 | background-color: #E0E0E0;
3 | }
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas2/canvas2.js:
--------------------------------------------------------------------------------
1 | // pages/canvas2/canvas2.js
2 | Page({
3 | data:{},
4 | onLoad:function(options){
5 | // 页面初始化 options为页面跳转所带来的参数
6 | },
7 | onReady:function(){
8 | var context = wx.createContext()
9 |
10 | //缩放
11 | context.rect(5, 5, 30, 30)
12 | context.stroke()
13 | context.scale(2,2)
14 | context.stroke()
15 | context.scale(2,2)
16 | context.stroke()
17 | wx.drawCanvas({
18 | canvasId: 'canvas_scale',
19 | actions: context.getActions()
20 | })
21 | context.clearActions()
22 |
23 | //旋转
24 | context.rect(30, 30, 100, 100)
25 | context.stroke()
26 | context.rotate(0.15)
27 | context.stroke()
28 | wx.drawCanvas({
29 | canvasId: 'canvas_rotate',
30 | actions: context.getActions()
31 | })
32 | context.clearActions()
33 |
34 | //平移
35 | context.rect(30, 30, 100, 100)
36 | context.stroke()
37 | context.translate(10, 10)
38 | context.stroke()
39 | wx.drawCanvas({
40 | canvasId: 'canvas_translate',
41 | actions: context.getActions()
42 | })
43 | },
44 | onShow:function(){
45 | // 页面显示
46 | },
47 | onHide:function(){
48 | // 页面隐藏
49 | },
50 | onUnload:function(){
51 | // 页面关闭
52 | }
53 | })
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas2/canvas2.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas2/canvas2.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas2/canvas2.wxss:
--------------------------------------------------------------------------------
1 | canvas{
2 | border: 1px solid #E0E0E0;
3 | margin-top: 10px;
4 | }
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas3/canvas3.js:
--------------------------------------------------------------------------------
1 | // pages/canvas3/canvas3.js
2 | Page({
3 | data:{},
4 | onLoad:function(options){
5 | // 页面初始化 options为页面跳转所带来的参数
6 | },
7 | onReady:function(){
8 | var context = wx.createContext()
9 | context.rect(15, 15, 100, 100)
10 | context.fill()
11 | context.stroke()
12 | context.clearRect(25, 25, 80, 80)
13 |
14 | context.fillText('Text', 40, 40)
15 | wx.drawCanvas({
16 | canvasId: 'canvas1',
17 | actions: context.getActions()
18 | })
19 |
20 | context.clearActions()
21 |
22 | wx.chooseImage({
23 | success: function(res) {
24 | context.drawImage(res.tempFilePaths[0], 0, 0)
25 | wx.drawCanvas({
26 | canvasId: 'canvas2',
27 | actions: context.getActions()
28 | })
29 | }
30 | })
31 | },
32 | onShow:function(){
33 | // 页面显示
34 | },
35 | onHide:function(){
36 | // 页面隐藏
37 | },
38 | onUnload:function(){
39 | // 页面关闭
40 | }
41 | })
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas3/canvas3.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas3/canvas3.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas3/canvas3.wxss:
--------------------------------------------------------------------------------
1 | canvas{
2 | border: 1px solid lightgray;
3 | margin-top: 10px;
4 | }
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas4/canvas4.js:
--------------------------------------------------------------------------------
1 | // pages/canvas4/canvas4.js
2 | Page({
3 | data:{},
4 | onLoad:function(options){
5 | // 页面初始化 options为页面跳转所带来的参数
6 | },
7 | onReady:function(){
8 | // 使用 wx.createContext 获取绘图上下文 context
9 | var context = wx.createContext()
10 |
11 | context.setStrokeStyle("#00ff00")
12 | context.setLineWidth(5)
13 | context.rect(0, 0, 200, 200)
14 | context.stroke()
15 | context.setStrokeStyle("#ff0000")
16 | context.setLineWidth(2)
17 | context.moveTo(160, 100)
18 | context.arc(100, 100, 60, 0, 2 * Math.PI, true)
19 | context.moveTo(140, 100)
20 | context.arc(100, 100, 40, 0, Math.PI, false)
21 | context.moveTo(85, 80)
22 | context.arc(80, 80, 5, 0, 2 * Math.PI, true)
23 | context.moveTo(125, 80)
24 | context.arc(120, 80, 5, 0, 2 * Math.PI, true)
25 | context.stroke()
26 | wx.drawCanvas({
27 | canvasId: 'canvas1',
28 | actions: context.getActions()
29 | })
30 | },
31 | onShow:function(){
32 | // 页面显示
33 | },
34 | onHide:function(){
35 | // 页面隐藏
36 | },
37 | onUnload:function(){
38 | // 页面关闭
39 | }
40 | })
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas4/canvas4.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas4/canvas4.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas4/canvas4.wxss:
--------------------------------------------------------------------------------
1 | canvas{
2 | height: 500px;
3 | }
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas5/canvas5.js:
--------------------------------------------------------------------------------
1 | // pages/canvas5/canvas5.js
2 | Page({
3 | data:{},
4 | onLoad:function(options){
5 | // 页面初始化 options为页面跳转所带来的参数
6 | },
7 | onReady:function(){
8 | var context = wx.createContext()
9 |
10 | context.setFillStyle("#FF00FF")
11 | context.setStrokeStyle("#00FFFF")
12 | context.setGlobalAlpha(1)
13 | context.setShadow(10,10,10, '#000000')
14 | context.setFontSize(18)
15 | context.setLineWidth(3)
16 | context.setLineCap('round');
17 | context.setLineJoin('round')
18 | context.rect(50, 50, 100, 100)
19 | context.fill()
20 | context.stroke()
21 | wx.drawCanvas({
22 | canvasId: 'canvas1',
23 | actions: context.getActions()
24 | })
25 | },
26 | onShow:function(){
27 | // 页面显示
28 | },
29 | onHide:function(){
30 | // 页面隐藏
31 | },
32 | onUnload:function(){
33 | // 页面关闭
34 | },
35 | saveas: function(e){
36 | wx.canvasToTempFilePath({
37 | canvasId: 'canvas1',
38 | success: function(res){
39 | wx.saveFile({
40 | tempFilePath: res.tempFilePath,
41 | success: function(res){
42 | wx.getSavedFileList({
43 | success: function(res){
44 | console.log(res.fileList)
45 | },
46 | fail: function() {
47 | // fail
48 | },
49 | complete: function() {
50 | // complete
51 | }
52 | })
53 | },
54 | fail: function() {
55 | // fail
56 | },
57 | complete: function() {
58 | // complete
59 | }
60 | })
61 | },
62 | fail: function() {
63 | console.log('fail')
64 | },
65 | complete: function() {
66 | // complete
67 | }
68 | })
69 | }
70 | })
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas5/canvas5.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas5/canvas5.wxml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/chaptor_10/pages/canvas5/canvas5.wxss:
--------------------------------------------------------------------------------
1 | canvas{
2 | height: 250px;
3 | }
--------------------------------------------------------------------------------
/chaptor_10/pages/index/index.js:
--------------------------------------------------------------------------------
1 | //index.js
2 | //获取应用实例
3 | var app = getApp()
4 | Page({
5 | data: {
6 | motto: 'Hello World',
7 | userInfo: {}
8 | },
9 | //事件处理函数
10 | bindViewTap: function() {
11 | wx.navigateTo({
12 | url: '../logs/logs'
13 | })
14 | },
15 | onLoad: function () {
16 |
17 | },
18 | toCanvas1Page: function(e){
19 | wx.navigateTo({
20 | url: '../canvas1/canvas1'
21 | })
22 | },
23 | toCanvas2Page: function(e){
24 | wx.navigateTo({
25 | url: '../canvas2/canvas2'
26 | })
27 | },
28 | toCanvas3Page: function(e){
29 | wx.navigateTo({
30 | url: '../canvas3/canvas3'
31 | })
32 | },
33 | toCanvas4Page: function(e){
34 | wx.navigateTo({
35 | url: '../canvas4/canvas4'
36 | })
37 | },
38 | toCanvas5Page: function(e){
39 | wx.navigateTo({
40 | url: '../canvas5/canvas5'
41 | })
42 | }
43 | })
44 |
--------------------------------------------------------------------------------
/chaptor_10/pages/index/index.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_10/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/chaptor_10/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /**index.wxss**/
2 |
--------------------------------------------------------------------------------
/chaptor_10/utils/util.js:
--------------------------------------------------------------------------------
1 | function formatTime(date) {
2 | var year = date.getFullYear()
3 | var month = date.getMonth() + 1
4 | var day = date.getDate()
5 |
6 | var hour = date.getHours()
7 | var minute = date.getMinutes()
8 | var second = date.getSeconds()
9 |
10 |
11 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
12 | }
13 |
14 | function formatNumber(n) {
15 | n = n.toString()
16 | return n[1] ? n : '0' + n
17 | }
18 |
19 | module.exports = {
20 | formatTime: formatTime
21 | }
22 |
--------------------------------------------------------------------------------
/chaptor_10/xiaohuangxiang.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/chaptor_10/xiaohuangxiang.png
--------------------------------------------------------------------------------
/chaptor_11/.gitignore:
--------------------------------------------------------------------------------
1 | *swp
2 |
--------------------------------------------------------------------------------
/chaptor_11/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | onLaunch: function () {
4 | //调用API从本地缓存中获取数据
5 | var logs = wx.getStorageSync('logs') || []
6 | logs.unshift(Date.now())
7 | wx.setStorageSync('logs', logs)
8 | },
9 | getUserInfo:function(cb){
10 | var that = this
11 | if(this.globalData.userInfo){
12 | typeof cb == "function" && cb(this.globalData.userInfo)
13 | }else{
14 | //调用登录接口
15 | wx.login({
16 | success: function () {
17 | wx.getUserInfo({
18 | success: function (res) {
19 | that.globalData.userInfo = res.userInfo
20 | typeof cb == "function" && cb(that.globalData.userInfo)
21 | }
22 | })
23 | }
24 | })
25 | }
26 | },
27 | globalData:{
28 | userInfo:null
29 | }
30 | })
--------------------------------------------------------------------------------
/chaptor_11/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages":[
3 | "pages/index/index",
4 | "pages/logs/logs",
5 | "pages/share/share"
6 | ],
7 | "window":{
8 | "backgroundTextStyle":"light",
9 | "navigationBarBackgroundColor": "#fff",
10 | "navigationBarTitleText": "WeChat",
11 | "navigationBarTextStyle":"black"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/chaptor_11/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | .container {
3 | height: 100%;
4 | display: flex;
5 | flex-direction: column;
6 | align-items: center;
7 | justify-content: space-between;
8 | padding: 200rpx 0;
9 | box-sizing: border-box;
10 | }
11 |
--------------------------------------------------------------------------------
/chaptor_11/pages/index/index.js:
--------------------------------------------------------------------------------
1 | //index.js
2 | //获取应用实例
3 | var app = getApp()
4 | Page({
5 | data: {
6 | motto: 'Hello World',
7 | userInfo: {}
8 | },
9 | //事件处理函数
10 | bindViewTap: function() {
11 | wx.navigateTo({
12 | url: '../logs/logs'
13 | })
14 | },
15 | onLoad: function () {
16 | console.log('onLoad')
17 | var that = this
18 | //调用应用实例的方法获取全局数据
19 | app.getUserInfo(function(userInfo){
20 | //更新数据
21 | that.setData({
22 | userInfo:userInfo
23 | })
24 | })
25 | },
26 | onShareAppMessage: function(){
27 | return {
28 | title: 'Hello World',
29 | desc: '小程序分享',
30 | path: '/pages/share/share?id=123'
31 | }
32 | },
33 | scanqr: function(e){
34 | wx.scanCode({
35 | success: function(res){
36 | // success
37 | console.log(res)
38 | },
39 | fail: function() {
40 | // fail
41 | },
42 | complete: function() {
43 | // complete
44 | }
45 | })
46 | }
47 | })
48 |
--------------------------------------------------------------------------------
/chaptor_11/pages/index/index.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_11/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {{userInfo.nickName}}
6 |
7 |
8 |
9 | 客服消息
10 |
11 |
12 |
--------------------------------------------------------------------------------
/chaptor_11/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /**index.wxss**/
2 | .userinfo {
3 | display: flex;
4 | flex-direction: column;
5 | align-items: center;
6 | }
7 |
8 | .userinfo-avatar {
9 | width: 128rpx;
10 | height: 128rpx;
11 | margin: 20rpx;
12 | border-radius: 50%;
13 | }
14 |
15 | .userinfo-nickname {
16 | color: #aaa;
17 | }
18 |
19 | .usermotto {
20 | margin-top: 200px;
21 | }
--------------------------------------------------------------------------------
/chaptor_11/pages/logs/logs.js:
--------------------------------------------------------------------------------
1 | //logs.js
2 | var util = require('../../utils/util.js')
3 | Page({
4 | data: {
5 | logs: []
6 | },
7 | onLoad: function () {
8 | this.setData({
9 | logs: (wx.getStorageSync('logs') || []).map(function (log) {
10 | return util.formatTime(new Date(log))
11 | })
12 | })
13 | }
14 | })
15 |
--------------------------------------------------------------------------------
/chaptor_11/pages/logs/logs.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "查看启动日志"
3 | }
--------------------------------------------------------------------------------
/chaptor_11/pages/logs/logs.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{index + 1}}. {{log}}
5 |
6 |
7 |
--------------------------------------------------------------------------------
/chaptor_11/pages/logs/logs.wxss:
--------------------------------------------------------------------------------
1 | .log-list {
2 | display: flex;
3 | flex-direction: column;
4 | padding: 40rpx;
5 | }
6 | .log-item {
7 | margin: 10rpx;
8 | }
9 |
--------------------------------------------------------------------------------
/chaptor_11/pages/share/share.js:
--------------------------------------------------------------------------------
1 | // pages/share/share.js
2 | Page({
3 | data:{},
4 | onLoad:function(options){
5 | console.log(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 | })
--------------------------------------------------------------------------------
/chaptor_11/pages/share/share.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/chaptor_11/pages/share/share.wxml:
--------------------------------------------------------------------------------
1 |
2 | 我是分享出来的页面
3 |
--------------------------------------------------------------------------------
/chaptor_11/pages/share/share.wxss:
--------------------------------------------------------------------------------
1 | /* pages/share/share.wxss */
--------------------------------------------------------------------------------
/chaptor_11/utils/util.js:
--------------------------------------------------------------------------------
1 | function formatTime(date) {
2 | var year = date.getFullYear()
3 | var month = date.getMonth() + 1
4 | var day = date.getDate()
5 |
6 | var hour = date.getHours()
7 | var minute = date.getMinutes()
8 | var second = date.getSeconds()
9 |
10 |
11 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
12 | }
13 |
14 | function formatNumber(n) {
15 | n = n.toString()
16 | return n[1] ? n : '0' + n
17 | }
18 |
19 | module.exports = {
20 | formatTime: formatTime
21 | }
22 |
--------------------------------------------------------------------------------
/screenshot/chaptor_07-01.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/screenshot/chaptor_07-01.gif
--------------------------------------------------------------------------------
/screenshot/dingyuhao.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/screenshot/dingyuhao.JPG
--------------------------------------------------------------------------------
/screenshot/mapjietu.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/screenshot/mapjietu.gif
--------------------------------------------------------------------------------
/weixin_demo/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | onLaunch: function () {
4 | //调用API从本地缓存中获取数据
5 | var logs = wx.getStorageSync('logs') || []
6 | logs.unshift(Date.now())
7 | wx.setStorageSync('logs', logs)
8 | },
9 | getUserInfo:function(cb){
10 | var that = this
11 | if(this.globalData.userInfo){
12 | typeof cb == "function" && cb(this.globalData.userInfo)
13 | }else{
14 | //调用登录接口
15 | wx.login({
16 | success: function () {
17 | wx.getUserInfo({
18 | success: function (res) {
19 | that.globalData.userInfo = res.userInfo
20 | typeof cb == "function" && cb(that.globalData.userInfo)
21 | }
22 | })
23 | }
24 | })
25 | }
26 | },
27 | globalData:{
28 | userInfo:null,
29 | server: 'http://localhost:9090/weappservice'
30 | }
31 | })
--------------------------------------------------------------------------------
/weixin_demo/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages":[
3 | "pages/index/index",
4 | "pages/logs/logs",
5 | "pages/component/labels/labels",
6 | "pages/component/map/map",
7 | "pages/component/button/buttons",
8 | "pages/component/flex/myflex",
9 | "pages/component/uploadfile/uploadfile",
10 | "pages/component/myrequest/myreq"
11 | ],
12 | "window":{
13 | "backgroundTextStyle":"dark",
14 | "navigationBarBackgroundColor": "#585858",
15 | "navigationBarTitleText": "WeChat",
16 | "navigationBarTextStyle":"white",
17 | "enablePullDownRefresh": true
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/weixin_demo/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | .container {
3 | height: 100%;
4 | display: flex;
5 | flex-direction: column;
6 | align-items: center;
7 | justify-content: space-between;
8 | padding: 200rpx 0;
9 | box-sizing: border-box;
10 | }
11 |
--------------------------------------------------------------------------------
/weixin_demo/pages/component/button/buttons.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data:{
3 | btnType: 'primary',
4 | defaultSize: 'default',
5 | miniSize: 'mini',
6 | warnSize: 'default',
7 | btnPlain: true,
8 | btnHidden: true,
9 | disabled: true,
10 | loading: true,
11 | formreset: 'reset',
12 | toastHidden: true
13 | },
14 | clickMe: function(){
15 | this.setData({toastHidden: false});
16 | },
17 | toastChange: function(){
18 | this.setData({toastHidden: true});
19 | },
20 | onLoad:function(options){
21 | // 页面初始化 options为页面跳转所带来的参数
22 | },
23 | onReady:function(){
24 | // 页面渲染完成
25 | },
26 | onShow:function(){
27 | // 页面显示
28 | },
29 | onHide:function(){
30 | // 页面隐藏
31 | },
32 | onUnload:function(){
33 | // 页面关闭
34 | },
35 | onPullDownRefresh: function(e){
36 | console.log('onPullDownRefresh')
37 | }
38 | })
--------------------------------------------------------------------------------
/weixin_demo/pages/component/button/buttons.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/weixin_demo/pages/component/button/buttons.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Thanks Click
12 |
--------------------------------------------------------------------------------
/weixin_demo/pages/component/button/buttons.wxss:
--------------------------------------------------------------------------------
1 | .btn_hover{
2 | width: 320px;
3 | }
--------------------------------------------------------------------------------
/weixin_demo/pages/component/flex/myflex.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 | })
--------------------------------------------------------------------------------
/weixin_demo/pages/component/flex/myflex.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/weixin_demo/pages/component/flex/myflex.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1
4 | 2
5 | 3
6 |
7 |
8 |
--------------------------------------------------------------------------------
/weixin_demo/pages/component/flex/myflex.wxss:
--------------------------------------------------------------------------------
1 | .mycontainer {
2 | flex-direction:row;
3 | flex-wrap: wrap;
4 | justify-content:space-around;
5 | align-items:center;
6 | }
7 | .mycontainer view{
8 | width: 50px;
9 | text-align: center;
10 | }
11 |
12 | .c2{
13 | /*flex-grow: 1;*/
14 | background-color: yellowgreen;
15 | }
16 | .c3{
17 | background-color: gray;
18 | /*flex-grow: 1;*/
19 | }
--------------------------------------------------------------------------------
/weixin_demo/pages/component/labels/labels.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 | })
--------------------------------------------------------------------------------
/weixin_demo/pages/component/labels/labels.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/weixin_demo/pages/component/labels/labels.wxml:
--------------------------------------------------------------------------------
1 |
2 | My Label
3 |
--------------------------------------------------------------------------------
/weixin_demo/pages/component/labels/labels.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/weixin_demo/pages/component/labels/labels.wxss
--------------------------------------------------------------------------------
/weixin_demo/pages/component/map/map.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | markers: [{
4 | latitude: 40.124463,
5 | longitude: 116.942965,
6 | name: '京平高速',
7 | desc: '我现在的位置'
8 | }],
9 | covers: [{
10 | latitude: 23.099794,
11 | longitude: 113.324520,
12 | iconPath: '../images/car.png',
13 | rotate: 10
14 | }, {
15 | latitude: 23.099298,
16 | longitude: 113.324129,
17 | iconPath: '../images/car.png',
18 | rotate: 90
19 | }]
20 | }
21 | })
--------------------------------------------------------------------------------
/weixin_demo/pages/component/map/map.json:
--------------------------------------------------------------------------------
1 | {
2 |
3 | }
--------------------------------------------------------------------------------
/weixin_demo/pages/component/map/map.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/weixin_demo/pages/component/map/map.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/weixin_demo/pages/component/map/map.wxss
--------------------------------------------------------------------------------
/weixin_demo/pages/component/myrequest/myreq.js:
--------------------------------------------------------------------------------
1 | var util = require('../../../utils/util');
2 | Page({
3 | data:{
4 | // text:"这是一个页面"
5 | loadingText: '加载中...',
6 | loadingHidden: true,
7 | toastHidden: true
8 | },
9 | onPullDownRefresh: function(e){
10 | console.log( util.getDate())
11 | var that = this;
12 | this.setData({"loadingHidden": false});
13 | wx.setNavigationBarTitle({
14 | title: '微信小程序Demo'
15 | });
16 | wx.showNavigationBarLoading();
17 | util.request({name:'xiaoqiang'},getApp().globalData.server + '/test',function(res){
18 | wx.stopPullDownRefresh()
19 | console.log(res.data)
20 | that.setData({loadingHidden: true,toastHidden: false});
21 | wx.hideNavigationBarLoading()
22 | })
23 | },
24 | getServerDataByyClick: function(e){
25 | wx.request({
26 | url: 'http://appservice.3chunhui.com/chunhui/m/user@login.do',
27 | header: {'Accept-language':'en_US'},
28 | data: {user:'13125052494',pwd:'E10ADC3949BA59ABBE56E057F20F883E'},
29 | method: 'GET',
30 | fail: function(res){
31 |
32 | },
33 | success: function(res){
34 | console.log(res)
35 | }
36 | });
37 | },
38 | //完成提示
39 | toast1Change: function(event){
40 | this.setData({toastHidden: true});
41 | },
42 | onLoad:function(options){
43 | // 页面初始化 options为页面跳转所带来的参数
44 | },
45 | onReady:function(){
46 | // 页面渲染完成
47 | },
48 | onShow:function(){
49 | // 页面显示
50 | },
51 | onHide:function(){
52 | // 页面隐藏
53 | },
54 | onUnload:function(){
55 | // 页面关闭
56 | }
57 | })
--------------------------------------------------------------------------------
/weixin_demo/pages/component/myrequest/myreq.json:
--------------------------------------------------------------------------------
1 | {
2 | "windows":{
3 | "enablePullDownRefresh": false
4 | }
5 | }
--------------------------------------------------------------------------------
/weixin_demo/pages/component/myrequest/myreq.wxml:
--------------------------------------------------------------------------------
1 |
2 | {{loadingText}}
3 | 获取成功
4 |
5 |
6 |
--------------------------------------------------------------------------------
/weixin_demo/pages/component/myrequest/myreq.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/weixin_demo/pages/component/myrequest/myreq.wxss
--------------------------------------------------------------------------------
/weixin_demo/pages/component/swiper/myswiper.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/weixin_demo/pages/component/swiper/myswiper.js
--------------------------------------------------------------------------------
/weixin_demo/pages/component/swiper/myswiper.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/weixin_demo/pages/component/swiper/myswiper.wxml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/weixin_demo/pages/component/swiper/myswiper.wxml
--------------------------------------------------------------------------------
/weixin_demo/pages/component/swiper/myswiper.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nosqlcoco/wechat-mini-program-learning/41fb2fffe5f4f5ef15823d02d44505f369137a83/weixin_demo/pages/component/swiper/myswiper.wxss
--------------------------------------------------------------------------------
/weixin_demo/pages/component/uploadfile/uploadfile.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data:{
3 | modalHidden: true,
4 | toastHidden: true,
5 | imgShow: false,
6 | imgPaths: [],
7 | downloadPath: ''
8 | },
9 | onLoad:function(options){
10 | // 页面初始化 options为页面跳转所带来的参数
11 | },
12 | onReady:function(){
13 | // 页面渲染完成
14 | },
15 | onShow:function(){
16 | // 页面显示
17 | },
18 | onHide:function(){
19 | // 页面隐藏
20 | },
21 | onUnload:function(){
22 | // 页面关闭
23 | },
24 |
25 | chooseImage: function(e){
26 | var $this = this;
27 | wx.chooseImage({
28 | count: 1,
29 | sizeType: ['original', 'compressed '],
30 | sourceType: ['album', 'camera'], //album 从相册选图,camera 使用相机,默认二者都有
31 | success:function(res){
32 | $this.setData({imgPaths:res.tempFilePaths})
33 | console.log(res)
34 | }
35 | })
36 | },
37 | uploadImage: function(e){
38 | var $this = this;
39 | if(this.data.imgPaths.length == 0){
40 | this.setData({modalHidden:false});
41 | }
42 | wx.uploadFile({
43 | url: getApp().globalData.server + '/uploadfile',
44 | filePath: this.data.imgPaths[0],
45 | name: 'file',
46 | header: {},
47 | formData: {
48 | 'user': 'kesq'
49 | },
50 | success: function(res){
51 | console.log('success')
52 | $this.setData({toastHidden: false})
53 | console.log(JSON.parse(res.data))
54 | },
55 | fail: function(res){
56 | console.log(res)
57 | console.log('fail')
58 | },
59 | complete: function(res){
60 | console.log(res)
61 | console.log('complete')
62 | }
63 | })
64 | },
65 | myconfirm: function(e){
66 | this.setData({modalHidden: true})
67 | },
68 | //完成提示
69 | toast1Change: function(event){
70 | this.setData({toastHidden: true});
71 | },
72 | downloadImage: function(e){
73 | var $this = this;
74 | wx.downloadFile({
75 | url: 'http://img.3chunhui.com/headimg/kesq-crede.png',
76 | type: 'image',
77 | success: function(res){
78 | $this.setData({downloadPath:res.tempFilePath,imgShow: true})
79 |
80 | }
81 | })
82 | },
83 | previewImage: function(e){
84 | wx.previewImage({
85 | urls:['http://img.3chunhui.com/headimg/kesq-crede.png'],
86 | success: function(e){
87 | console.log('success')
88 | },
89 | fail: function(e){
90 | console.log('fail')
91 | },
92 | complete: function(e){
93 | console.log('complete')
94 | }
95 | })
96 | },
97 | previewImage: function(e){
98 | console.log('eee')
99 | wx.previewImage({
100 | //current: 'http://img.3chunhui.com/headimg/kesq-crede.png',
101 | urls: ['http://img.3chunhui.com/headimg/kesq-crede.png'],
102 | success: function(res){
103 | console.log(res)
104 | },
105 | fail: function(res){
106 | console.log(res)
107 | },
108 | complete: function(res){
109 | console.log(res)
110 | }
111 | })
112 | }
113 | })
--------------------------------------------------------------------------------
/weixin_demo/pages/component/uploadfile/uploadfile.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/weixin_demo/pages/component/uploadfile/uploadfile.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | 上传成功
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/weixin_demo/pages/component/uploadfile/uploadfile.wxss:
--------------------------------------------------------------------------------
1 | .btn1cls{
2 | margin-top: 50px;
3 | }
--------------------------------------------------------------------------------
/weixin_demo/pages/index/index.js:
--------------------------------------------------------------------------------
1 | var componentpath = "/pages/component";
2 | Page({
3 | data:{
4 | btnType: 'primary',
5 | btnSize: 'default',
6 | loading: true,
7 | btnPlain: false,
8 | btnHidden: true,
9 | loadingHidden: true,
10 | toastHidden: true,
11 | loadingText: '加载中...',
12 | textHidden: false
13 | },
14 | //容器布局
15 | openFlexPage: function(event){
16 | wx.navigateTo({
17 | url: componentpath + '/flex/myflex'
18 | });
19 | },
20 | //按钮
21 | openBtnPage: function(event){
22 | wx.navigateTo({
23 | url: componentpath + '/button/buttons'
24 | });
25 | },
26 | //完成提示
27 | toast1Change: function(event){
28 | this.setData({toastHidden: true});
29 | },
30 | //开关
31 | redirectToPage: function(event){
32 |
33 | },
34 | //获取网络数据
35 | getAjaxData: function(event){
36 | wx.navigateTo({
37 | url: componentpath + '/myrequest/myreq'
38 | });
39 |
40 |
41 | },
42 | //跳转标签页面
43 | toLabelPage: function(event){
44 | wx.navigateTo({
45 | url: componentpath + '/labels/labels'
46 | });
47 | },
48 | //跳转地图页面
49 | toMapPage: function(event){
50 | /*wx.getLocation({
51 | type: 'wgs84',
52 | success:function(res){
53 | wx.openLocation({
54 | latitude: res.latitude,
55 | longitude: res.longitude,
56 | })
57 | }
58 | })*/
59 | wx.navigateTo({
60 | url: componentpath + '/map/map'
61 | });
62 | },
63 | toUploadFilePage: function(){
64 | wx.navigateTo({
65 | url: componentpath + '/uploadfile/uploadfile'
66 | });
67 | },
68 | onPullDownRefresh: function(e){
69 | console.log("onPullDownRefresh")
70 | },
71 | onLoad:function(options){
72 | // 页面初始化 options为页面跳转所带来的参数
73 | },
74 | onReady:function(){
75 | // 页面渲染完成
76 | },
77 | onShow:function(){
78 | // 页面显示
79 | },
80 | onHide:function(){
81 | // 页面隐藏
82 | },
83 | onUnload:function(){
84 | // 页面关闭
85 | }
86 | })
--------------------------------------------------------------------------------
/weixin_demo/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | {{loadingText}}
15 | 获取成功
16 |
17 |
18 |
19 |
20 |
21 | ssss
22 |
23 |
24 |
--------------------------------------------------------------------------------
/weixin_demo/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | page{
2 | background-color: 'gray';
3 | }
4 | .wrap-item button{
5 | margin: 10px 0 10px 0;
6 | }
--------------------------------------------------------------------------------
/weixin_demo/pages/logs/logs.js:
--------------------------------------------------------------------------------
1 | //logs.js
2 | var util = require('../../utils/util.js')
3 | Page({
4 | data: {
5 | logs: []
6 | },
7 | onLoad: function () {
8 | this.setData({
9 | logs: (wx.getStorageSync('logs') || []).map(function (log) {
10 | return util.formatTime(new Date(log))
11 | })
12 | })
13 | }
14 | })
15 |
--------------------------------------------------------------------------------
/weixin_demo/pages/logs/logs.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "查看启动日志"
3 | }
--------------------------------------------------------------------------------
/weixin_demo/pages/logs/logs.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{index + 1}}. {{log}}
5 |
6 |
7 |
--------------------------------------------------------------------------------
/weixin_demo/pages/logs/logs.wxss:
--------------------------------------------------------------------------------
1 | .log-list {
2 | display: flex;
3 | flex-direction: column;
4 | padding: 40rpx;
5 | }
6 | .log-item {
7 | margin: 10rpx;
8 | }
9 |
--------------------------------------------------------------------------------
/weixin_demo/utils/util.js:
--------------------------------------------------------------------------------
1 | function formatTime(date) {
2 | var year = date.getFullYear()
3 | var month = date.getMonth() + 1
4 | var day = date.getDate()
5 |
6 | var hour = date.getHours()
7 | var minute = date.getMinutes()
8 | var second = date.getSeconds()
9 |
10 |
11 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
12 | }
13 |
14 | function formatNumber(n) {
15 | n = n.toString()
16 | return n[1] ? n : '0' + n
17 | }
18 |
19 | function getDate(){
20 | return new Date();
21 | }
22 |
23 | function myrequest(data,url,callback){
24 | wx.request({
25 | url: url,
26 | data: data,
27 | method: 'GET',
28 | fail: function(){
29 |
30 | },
31 | success: callback
32 | });
33 | }
34 | module.exports = {
35 | formatTime: formatTime,
36 | getDate : getDate,
37 | request : myrequest
38 | }
39 |
--------------------------------------------------------------------------------
/wschat.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | 聊天
10 |
34 |
35 | 聊天记录
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------