├── README.md
├── app.js
├── app.json
├── app.wxss
├── demo.png
├── fix.md
├── image
├── arrowright.png
├── fix
│ ├── bgm01.png
│ ├── bgm02.png
│ ├── bgm03.png
│ ├── bgm11.png
│ ├── bgm12.png
│ ├── bgm13.png
│ ├── bgm14.png
│ ├── bgm15.png
│ └── scroll-view.png
├── icon64_appwx_logo.png
├── pause.png
├── play.png
├── plus.png
├── record.png
├── stop.png
├── trash.png
├── wechat.png
└── wechatHL.png
├── page
├── API
│ ├── animation
│ │ ├── animation.js
│ │ ├── animation.json
│ │ ├── animation.wxml
│ │ └── animation.wxss
│ ├── background-audio
│ │ ├── background-audio.js
│ │ ├── background-audio.json
│ │ ├── background-audio.wxml
│ │ └── background-audio.wxss
│ ├── canvas
│ │ ├── canvas.js
│ │ ├── canvas.json
│ │ ├── canvas.wxml
│ │ └── canvas.wxss
│ ├── common
│ │ ├── footer.wxml
│ │ └── header.wxml
│ ├── download-file
│ │ ├── download-file.js
│ │ ├── download-file.json
│ │ ├── download-file.wxml
│ │ └── download-file.wxss
│ ├── file
│ │ ├── file.js
│ │ ├── file.json
│ │ ├── file.wxml
│ │ └── file.wxss
│ ├── generate.sh
│ ├── get-location
│ │ ├── format-location.js
│ │ ├── get-location.js
│ │ ├── get-location.json
│ │ ├── get-location.wxml
│ │ └── get-location.wxss
│ ├── get-network-type
│ │ ├── get-network-type.js
│ │ ├── get-network-type.json
│ │ ├── get-network-type.wxml
│ │ └── get-network-type.wxss
│ ├── get-system-info
│ │ ├── get-system-info.js
│ │ ├── get-system-info.json
│ │ ├── get-system-info.wxml
│ │ └── get-system-info.wxss
│ ├── get-user-info
│ │ ├── get-user-info.js
│ │ ├── get-user-info.json
│ │ ├── get-user-info.wxml
│ │ └── get-user-info.wxss
│ ├── image
│ │ ├── image.js
│ │ ├── image.json
│ │ ├── image.wxml
│ │ └── image.wxss
│ ├── index
│ │ ├── index.js
│ │ ├── index.wxml
│ │ └── index.wxss
│ ├── login
│ │ ├── login.js
│ │ ├── login.json
│ │ ├── login.wxml
│ │ └── login.wxss
│ ├── navigation-bar-loading
│ │ ├── navigation-bar-loading.js
│ │ ├── navigation-bar-loading.json
│ │ ├── navigation-bar-loading.wxml
│ │ └── navigation-bar-loading.wxss
│ ├── navigator
│ │ ├── navigator.js
│ │ ├── navigator.json
│ │ ├── navigator.wxml
│ │ └── navigator.wxss
│ ├── on-accelerometer-change
│ │ ├── on-accelerometer-change.js
│ │ ├── on-accelerometer-change.json
│ │ ├── on-accelerometer-change.wxml
│ │ └── on-accelerometer-change.wxss
│ ├── on-compass-change
│ │ ├── on-compass-change.js
│ │ ├── on-compass-change.json
│ │ ├── on-compass-change.wxml
│ │ └── on-compass-change.wxss
│ ├── open-location
│ │ ├── open-location.js
│ │ ├── open-location.json
│ │ ├── open-location.wxml
│ │ └── open-location.wxss
│ ├── pull-down-refresh
│ │ ├── pull-down-refresh.js
│ │ ├── pull-down-refresh.json
│ │ ├── pull-down-refresh.wxml
│ │ └── pull-down-refresh.wxss
│ ├── request-payment
│ │ ├── request-payment.js
│ │ ├── request-payment.json
│ │ ├── request-payment.wxml
│ │ └── request-payment.wxss
│ ├── request
│ │ ├── request.js
│ │ ├── request.json
│ │ ├── request.wxml
│ │ └── request.wxss
│ ├── set-navigation-bar-title
│ │ ├── set-navigation-bar-title.js
│ │ ├── set-navigation-bar-title.json
│ │ ├── set-navigation-bar-title.wxml
│ │ └── set-navigation-bar-title.wxss
│ ├── storage
│ │ ├── storage.js
│ │ ├── storage.json
│ │ ├── storage.wxml
│ │ └── storage.wxss
│ ├── upload-file
│ │ ├── upload-file.js
│ │ ├── upload-file.json
│ │ ├── upload-file.wxml
│ │ └── upload-file.wxss
│ ├── voice
│ │ ├── voice.js
│ │ ├── voice.json
│ │ ├── voice.wxml
│ │ └── voice.wxss
│ └── web-socket
│ │ ├── web-socket.js
│ │ ├── web-socket.json
│ │ ├── web-socket.wxml
│ │ └── web-socket.wxss
└── component
│ ├── component-pages
│ ├── wx-action-sheet
│ │ ├── wx-action-sheet.js
│ │ ├── wx-action-sheet.wxml
│ │ └── wx-action-sheet.wxss
│ ├── wx-audio
│ │ ├── wx-audio.js
│ │ └── wx-audio.wxml
│ ├── wx-button
│ │ ├── wx-button.js
│ │ ├── wx-button.wxml
│ │ └── wx-button.wxss
│ ├── wx-checkbox
│ │ ├── wx-checkbox.js
│ │ ├── wx-checkbox.wxml
│ │ └── wx-checkbox.wxss
│ ├── wx-form
│ │ ├── wx-form.js
│ │ ├── wx-form.wxml
│ │ └── wx-form.wxss
│ ├── wx-icon
│ │ ├── wx-icon.js
│ │ ├── wx-icon.wxml
│ │ └── wx-icon.wxss
│ ├── wx-image
│ │ ├── wx-image.js
│ │ ├── wx-image.wxml
│ │ └── wx-image.wxss
│ ├── wx-input
│ │ ├── wx-input.js
│ │ ├── wx-input.wxml
│ │ └── wx-input.wxss
│ ├── wx-label
│ │ ├── wx-label.js
│ │ ├── wx-label.wxml
│ │ └── wx-label.wxss
│ ├── wx-mask
│ │ ├── wx-mask.js
│ │ └── wx-mask.wxml
│ ├── wx-modal
│ │ ├── wx-modal.js
│ │ └── wx-modal.wxml
│ ├── wx-navigator
│ │ ├── navigate.js
│ │ ├── navigate.wxml
│ │ ├── redirect.js
│ │ ├── redirect.wxml
│ │ ├── wx-navigator.js
│ │ ├── wx-navigator.wxml
│ │ └── wx-navigator.wxss
│ ├── wx-picker
│ │ ├── wx-picker.js
│ │ ├── wx-picker.wxml
│ │ └── wx-picker.wxss
│ ├── wx-progress
│ │ ├── wx-progress.js
│ │ ├── wx-progress.wxml
│ │ └── wx-progress.wxss
│ ├── wx-radio
│ │ ├── wx-radio.js
│ │ ├── wx-radio.wxml
│ │ └── wx-radio.wxss
│ ├── wx-scroll-view
│ │ ├── wx-scroll-view.js
│ │ ├── wx-scroll-view.wxml
│ │ └── wx-scroll-view.wxss
│ ├── wx-slide-tab
│ │ ├── wx-slide-tab.js
│ │ ├── wx-slide-tab.wxml
│ │ └── wx-slide-tab.wxss
│ ├── wx-slider
│ │ ├── wx-slider.js
│ │ └── wx-slider.wxml
│ ├── wx-swiper
│ │ ├── wx-swiper.js
│ │ ├── wx-swiper.wxml
│ │ └── wx-swiper.wxss
│ ├── wx-switch
│ │ ├── wx-switch.js
│ │ └── wx-switch.wxml
│ ├── wx-text
│ │ ├── wx-text.js
│ │ └── wx-text.wxml
│ ├── wx-toast
│ │ ├── wx-toast.js
│ │ └── wx-toast.wxml
│ ├── wx-video
│ │ ├── wx-video.js
│ │ └── wx-video.wxml
│ └── wx-view
│ │ ├── wx-view.js
│ │ ├── wx-view.wxml
│ │ └── wx-view.wxss
│ ├── index.js
│ ├── index.wxml
│ ├── index.wxss
│ ├── navigation-pages
│ ├── controller
│ │ ├── controller.js
│ │ └── controller.wxml
│ ├── form
│ │ ├── form.js
│ │ └── form.wxml
│ ├── media
│ │ ├── media.js
│ │ └── media.wxml
│ └── view
│ │ ├── view.js
│ │ └── view.wxml
│ └── resources
│ ├── arrow.png
│ ├── kind
│ ├── canvas.png
│ ├── content.png
│ ├── form.png
│ ├── interact.png
│ ├── map.png
│ ├── media.png
│ ├── nav.png
│ └── view.png
│ └── pic.jpg
└── util
└── util.js
/README.md:
--------------------------------------------------------------------------------
1 | ## webApp-demo
2 |
3 | 
4 |
5 | 微信小程序 demo / 开发工具 / 文档资源
6 |
7 | 为了方便更新, 后续资源全部更新到 [wiki](https://github.com/xwartz/wechatApp-demo/wiki)
8 |
9 |
10 | ### 资源
11 |
12 | *官方已经提供了,无需破解了,具体看以下链接。*
13 |
14 | 官方文档: https://mp.weixin.qq.com/debug/wxadoc/dev/?t=1474643026176
15 |
16 | 开发工具: https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html?t=1474644089359
17 |
18 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | App({
2 | onLaunch: function () {
3 | console.log('App Launch')
4 | },
5 | onShow: function () {
6 | console.log('App Show')
7 | },
8 | onHide: function () {
9 | console.log('App Hide')
10 | },
11 | globalData: {
12 | hasLogin: false
13 | }
14 | })
15 |
--------------------------------------------------------------------------------
/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages": [
3 | "page/component/index",
4 | "page/component/navigation-pages/controller/controller",
5 | "page/component/navigation-pages/form/form",
6 | "page/component/navigation-pages/media/media",
7 | "page/component/navigation-pages/view/view",
8 | "page/component/component-pages/wx-action-sheet/wx-action-sheet",
9 | "page/component/component-pages/wx-audio/wx-audio",
10 | "page/component/component-pages/wx-button/wx-button",
11 | "page/component/component-pages/wx-checkbox/wx-checkbox",
12 | "page/component/component-pages/wx-form/wx-form",
13 | "page/component/component-pages/wx-icon/wx-icon",
14 | "page/component/component-pages/wx-image/wx-image",
15 | "page/component/component-pages/wx-input/wx-input",
16 | "page/component/component-pages/wx-mask/wx-mask",
17 | "page/component/component-pages/wx-modal/wx-modal",
18 | "page/component/component-pages/wx-navigator/wx-navigator",
19 | "page/component/component-pages/wx-progress/wx-progress",
20 | "page/component/component-pages/wx-radio/wx-radio",
21 | "page/component/component-pages/wx-scroll-view/wx-scroll-view",
22 | "page/component/component-pages/wx-slider/wx-slider",
23 | "page/component/component-pages/wx-switch/wx-switch",
24 | "page/component/component-pages/wx-text/wx-text",
25 | "page/component/component-pages/wx-toast/wx-toast",
26 | "page/component/component-pages/wx-video/wx-video",
27 | "page/component/component-pages/wx-view/wx-view",
28 | "page/component/component-pages/wx-swiper/wx-swiper",
29 | "page/component/component-pages/wx-slide-tab/wx-slide-tab",
30 | "page/component/component-pages/wx-label/wx-label",
31 | "page/component/component-pages/wx-navigator/navigate",
32 | "page/component/component-pages/wx-navigator/redirect",
33 | "page/component/component-pages/wx-picker/wx-picker",
34 |
35 | "page/API/index/index",
36 | "page/API/storage/storage",
37 |
38 | "page/API/login/login",
39 | "page/API/get-user-info/get-user-info",
40 | "page/API/request-payment/request-payment",
41 |
42 | "page/API/set-navigation-bar-title/set-navigation-bar-title",
43 | "page/API/navigation-bar-loading/navigation-bar-loading",
44 | "page/API/navigator/navigator",
45 | "page/API/pull-down-refresh/pull-down-refresh",
46 | "page/API/animation/animation",
47 |
48 | "page/API/get-network-type/get-network-type",
49 | "page/API/get-system-info/get-system-info",
50 | "page/API/on-compass-change/on-compass-change",
51 |
52 | "page/API/request/request",
53 | "page/API/web-socket/web-socket",
54 | "page/API/upload-file/upload-file",
55 | "page/API/download-file/download-file",
56 |
57 |
58 | "page/API/image/image",
59 | "page/API/voice/voice",
60 | "page/API/file/file",
61 | "page/API/on-accelerometer-change/on-accelerometer-change",
62 | "page/API/canvas/canvas",
63 | "page/API/background-audio/background-audio",
64 |
65 | "page/API/get-location/get-location",
66 | "page/API/open-location/open-location"
67 |
68 | ],
69 | "window": {
70 | "navigationBarTextStyle": "black",
71 | "navigationBarTitleText": "小程序演示",
72 | "navigationBarBackgroundColor": "#fbf9fe",
73 | "backgroundColor": "#fbf9fe"
74 | },
75 | "tabBar": {
76 | "color": "#dddddd",
77 | "selectedColor": "#3cc51f",
78 | "borderStyle": "black",
79 | "backgroundColor": "#ffffff",
80 | "list": [{
81 | "pagePath": "page/component/index",
82 | "iconPath": "image/wechat.png",
83 | "selectedIconPath": "image/wechatHL.png",
84 | "text": "组件"
85 | }, {
86 | "pagePath": "page/API/index/index",
87 | "iconPath": "image/wechat.png",
88 | "selectedIconPath": "image/wechatHL.png",
89 | "text": "接口"
90 | }]
91 | },
92 | "networkTimeout": {
93 | "request": 10000,
94 | "connectSocket": 10000,
95 | "uploadFile": 10000,
96 | "downloadFile": 10000
97 | },
98 | "debug": true
99 | }
100 |
--------------------------------------------------------------------------------
/app.wxss:
--------------------------------------------------------------------------------
1 | page {
2 | background-color: #fbf9fe;
3 | height: 100%;
4 | }
5 | .container {
6 | display: flex;
7 | flex-direction: column;
8 | min-height: 100%;
9 | justify-content: space-between;
10 | }
11 | .page-header {
12 | display: flex;
13 | font-size: 32rpx;
14 | color: #aaa;
15 | justify-content: center;
16 | margin-top: 50rpx;
17 | }
18 | .page-header-text {
19 | padding: 20rpx 40rpx;
20 | border-bottom: 1px solid #ccc;
21 | }
22 |
23 | .page-body {
24 | width: 100%;
25 | display: flex;
26 | flex-direction: column;
27 | align-items: center;
28 | flex-grow: 1;
29 | overflow-x: hidden;
30 | }
31 | .page-body-wrapper {
32 | margin-top: 100rpx;
33 | display: flex;
34 | flex-direction: column;
35 | align-items: center;
36 | width: 100%;
37 | }
38 | .page-body-wrapper form {
39 | width: 100%;
40 | }
41 | .page-body-wording {
42 | text-align: center;
43 | padding: 200rpx 100rpx;
44 | }
45 | .page-body-info {
46 | display: flex;
47 | flex-direction: column;
48 | align-items: center;
49 | background-color: #fff;
50 | margin-bottom: 50rpx;
51 | width: 100%;
52 | padding: 50rpx 0 150rpx 0;
53 | }
54 | .page-body-title {
55 | margin-bottom: 100rpx;
56 | font-size: 32rpx;
57 | }
58 | .page-body-text {
59 | font-size: 30rpx;
60 | line-height: 26px;
61 | color: #ccc;
62 | }
63 | .page-body-text-small {
64 | font-size: 24rpx;
65 | color: #000;
66 | margin-bottom: 100rpx;
67 | }
68 | .page-body-form {
69 | width: 100%;
70 | background-color: #fff;
71 | display: flex;
72 | flex-direction: column;
73 | width: 100%;
74 | border: 1px solid #eee;
75 | }
76 | .page-body-form-item {
77 | display: flex;
78 | align-items: center;
79 | margin-left: 10rpx;
80 | border-bottom: 1px solid #eee;
81 | height: 80rpx;
82 | }
83 | .page-body-form-key {
84 | width: 180rpx;
85 | }
86 | .page-body-form-value {
87 | flex-grow: 1;
88 | }
89 |
90 | .page-body-form-picker {
91 | display: flex;
92 | justify-content: space-between;
93 | height: 100rpx;
94 | align-items: center;
95 | font-size: 36rpx;
96 | margin-left: 20rpx;
97 | padding-right: 20rpx;
98 | border-bottom: 1px solid #eee;
99 | }
100 | .page-body-form-picker-value {
101 | color: #ccc;
102 | }
103 |
104 | .page-body-buttons {
105 | width: 100%;
106 | }
107 | .page-body-button {
108 | margin: 25rpx;
109 | }
110 | .page-body-button image {
111 | width: 150rpx;
112 | height: 150rpx;
113 | }
114 | .page-footer {
115 | text-align: center;
116 | color: #1aad19;
117 | font-size: 24rpx;
118 | margin: 20rpx 0;
119 | }
120 |
121 | .green{
122 | color: #09BB07;
123 | }
124 | .red{
125 | color: #F76260;
126 | }
127 | .blue{
128 | color: #10AEFF;
129 | }
130 | .yellow{
131 | color: #FFBE00;
132 | }
133 | .gray{
134 | color: #C9C9C9;
135 | }
136 |
137 | .strong{
138 | font-weight: bold;
139 | }
140 |
141 | .bc_green{
142 | background-color: #09BB07;
143 | }
144 | .bc_red{
145 | background-color: #F76260;
146 | }
147 | .bc_blue{
148 | background-color: #10AEFF;
149 | }
150 | .bc_yellow{
151 | background-color: #FFBE00;
152 | }
153 | .bc_gray{
154 | background-color: #C9C9C9;
155 | }
156 |
157 | .tc{
158 | text-align: center;
159 | }
160 |
161 | .page input{
162 | padding: 10px 15px;
163 | background-color: #fff;
164 | }
165 | checkbox, radio{
166 | margin-right: 5px;
167 | }
168 |
169 | .btn-area{
170 | padding: 0 15px;
171 | }
172 | .btn-area button{
173 | margin-top: 10px;
174 | margin-bottom: 10px;
175 | }
176 |
177 | .page {
178 | min-height: 100%;
179 | flex: 1;
180 | background-color: #FBF9FE;
181 | font-size: 16px;
182 | font-family: -apple-system-font,Helvetica Neue,Helvetica,sans-serif;
183 | overflow: hidden;
184 | }
185 | .page__hd{
186 | padding: 40px;
187 | }
188 | .page__title{
189 | display: block;
190 | font-size: 20px;
191 | }
192 | .page__desc{
193 | margin-top: 5px;
194 | font-size: 14px;
195 | color: #888888;
196 | }
197 |
198 | .section{
199 | margin-bottom: 40px;
200 | }
201 | .section_gap{
202 | padding: 0 15px;
203 | }
204 | .section__title{
205 | margin-bottom: 8px;
206 | padding-left: 15px;
207 | padding-right: 15px;
208 | }
209 | .section_gap .section__title{
210 | padding-left: 0;
211 | padding-right: 0;
212 | }
213 | .section__ctn{
214 |
215 | }
216 |
--------------------------------------------------------------------------------
/demo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/demo.png
--------------------------------------------------------------------------------
/fix.md:
--------------------------------------------------------------------------------
1 | ### updated 2016-09-24 20:51
2 | #### bug:
3 | 组件中:
4 | - 内容分区/scroll-view中,click me to top按钮无效(done)
5 |
6 | 接口中:
7 | - 录音功能展示中,无法停止录音。(可能问题只存在电脑调试器中)(done)
8 | - 录音功能展示中,若直接返回上一级页面,原页面的定时器未被回收(done)
9 | - 背景音乐功能展示中,首先播放音乐并返回上级,然后再进入播放音乐页面,音乐播放进度会丢失
10 |
11 | #### 不算bug但是美中不足的地方
12 | 组件中:
13 | - 内容分区/swipe 中,swipe最后一张图片后会反方向到第一张图片(to be improved)
14 | - 内容/Text 中,text默认的line删不掉,一开始体验‘remove’方法的话会产生“程序是不是有问题的错觉”
15 | - 内容/picker 中,时间和日期选择器无效(开始以为是bug,后来发现是demo源码中没有实现这里的选择器)(to be improved)
16 |
17 | 接口中:
18 |
19 | 注:这些在接口栏目中,能在PC上测试的所有的接口都是在PC上测试的,所以可能参考意义并不是那么大
20 |
21 | #### 修复:
22 | 1. 内容分区/scroll-view
23 | 
24 | 方法:
25 | /page/component/component-pages/wx-scroll-view/wx-scroll-view.js 16L 将setAction 改为 setData
26 | ```javascript
27 | scrollToTop: function(e) {
28 | this.setData({
29 | scrollTop: 0
30 | })
31 | }
32 | ```
33 | 2. 录音功能
34 | 方法:
35 | /page/API/voice/voice.js
36 | 1) 将录音定时器放在全局。
37 | 2) 在stop record中清除定时器
38 | 3) onUnload触发时也要清除定时器并还原初始数据
39 | ```javascript
40 | var util = require('../../../util/util.js')
41 | var playTimeInterval,interval
42 |
43 | Page({
44 | data: {
45 | ...
46 | },
47 | startRecord: function () {
48 | ...
49 | },
50 | stopRecord: function () {
51 | wx.stopRecord()
52 | this.setData({recording:false,recordTime:0,formatedRecordTime: '00:00:00'})
53 | clearInterval(interval)
54 | },
55 | ...
56 | onUnload:function(){
57 | this.stopRecord()
58 | console.log("voice page has been unloaded!")
59 | }
60 | })
61 | ```
62 |
63 | 3. 播放背景音乐进度丢失问题
64 | 
65 | 方法:
66 | /page/API/background-audio/background-audio.js 重写了一些方法
67 | 1) 该page生命周期中的onLoad过程中,先通过api获取是否有背景音乐正在播放,获取其进度,然后将data里的数据更新,在onLoad中增加checkPlaying方法
68 | ```javascript
69 | Page({
70 | onLoad: function () {
71 | var that = this
72 | ...
73 | // 进入的时候应该检测后台是否有音乐正在播放
74 | checkPlaying()
75 | function checkPlaying() {
76 | wx.getBackgroundAudioPlayerState({
77 | success: function (res) {
78 | console.log("播放器状态:",res)
79 | console.log("初始化时的webview",that.data.__webviewId__)
80 | var _isPlaying,_playTime
81 | res.status === 1?
82 | _isPlaying = true:_isPlaying = false
83 | res.currentPosition/res.duration > 0.95?
84 | _playTime = 0:_playTime = res.currentPosition
85 | that.setData({
86 | playing:_isPlaying,
87 | playTime: _playTime,
88 | formatedPlayTime: util.formatTime(_playTime)
89 | })
90 | if(_isPlaying)
91 | that._enableInterval()
92 | }
93 | })
94 | }
95 | },
96 | ...
97 | })
98 | ```
99 | 2) 增加了resume方法,用于继续播放(play方法是从头开始播放)
100 | ```javascript
101 | Pager({
102 | ...
103 | resume:function(){
104 | var that = this
105 | if(this.updateInterval != '')
106 | clearInterval(this.updateInterval)
107 | wx.playBackgroundAudio({
108 | dataUrl: dataUrl,
109 | title: 'Lost Stars',
110 | coverImgUrl: 'http://y.gtimg.cn/music/photo_new/T002R150x150M000000Jhxf24CFL06.jpg?max_age=2592000',
111 | complete: function () {
112 | that.setData({
113 | playing:true
114 | })
115 | wx.seekBackgroundAudio({
116 | position: that.data.playTime,
117 | complete:function(){
118 | console.log("resume ok")
119 | }
120 | })
121 | }
122 | })
123 | },
124 | ...
125 | })
126 | ```
127 | 3) 在onLoad中增加了背景音乐的两个状态的监听器,用于同步背景音乐状态的变化和UI的变化
128 | ```javascript
129 | Page({
130 | onLoad: function () {
131 | ...
132 |
133 | // 设置播放停止监听事件
134 | wx.onBackgroundAudioStop(function () {
135 | console.log("音乐停止了,当前webview: ",that.data.__webviewId__)
136 | that.setData({
137 | playing: false,
138 | playTime: 0,
139 | formatedPlayTime: '00:00:00'
140 | })
141 | })
142 | // 设置播放开始监听事件
143 | wx.onBackgroundAudioPlay(function(){
144 | console.log("音乐开始了,当前webview: ",that.data.__webviewId__)
145 | // 开始后需要更新当前歌曲的秒数
146 | if(that.data.playing === false)
147 | that.setData({
148 | playing:true
149 | })
150 | if(that.updateInterval >= 0)
151 | return
152 | that._enableInterval()
153 | })
154 | // 设置播放暂停监听事件
155 | wx.onBackgroundAudioPause(function(){
156 | console.log("音乐暂停了,当前webview: ",that.data.__webviewId__)
157 | // 暂停后,不需要继续更新歌曲秒数
158 | if(that.data.playing === true)
159 | that.setData({
160 | playing:false
161 | })
162 | if(that.updateInterval >= 0)
163 | clearInterval(that.updateInterval)
164 | })
165 | ...
166 | },
167 | ```
168 | 4) 同时在wxml中增加了重播的按键(文字的形式),简单的在两个block中加入
169 | ```xml
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 | 重播
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 | 重播
188 |
189 |
190 | ```
191 | 5) 再加一个样式在wxss
192 | ```css
193 | .page-body-button .restart{
194 | line-height: 80px;
195 | }
196 | ```
197 | #### 仍然存在的问题
198 | 在修复背景音乐一些小bug的过程中,我发现,首先进入播放音乐界面播放歌曲,再返回上一个界面,这时候如果再进入播放音乐界面,那么播放器的功能没有问题,但是在该页面中用于更新UI的定时器会按进出次数递增。
199 | 
200 |
201 | ####一些想法:
202 | 为了解决上面的问题,我有下面几个想法:
203 | - 在这个pager的onUnload阶段,对背景音乐的监听器进行手动的清除(问题是目前的文档中并没有合适的api)
204 | - 不使用背景音乐变化的监听器(包括"wx.onBackgroundAudioPause|wx.onBackgroundAudioStop|wx.onBackgroundAudioPlay"),直接手动管理定时器。(我尝试过这样做,但是没有效果,定时器个数还是会随着进出次数的增加而增加,希望是我的实现错了)
--------------------------------------------------------------------------------
/image/arrowright.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/arrowright.png
--------------------------------------------------------------------------------
/image/fix/bgm01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/fix/bgm01.png
--------------------------------------------------------------------------------
/image/fix/bgm02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/fix/bgm02.png
--------------------------------------------------------------------------------
/image/fix/bgm03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/fix/bgm03.png
--------------------------------------------------------------------------------
/image/fix/bgm11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/fix/bgm11.png
--------------------------------------------------------------------------------
/image/fix/bgm12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/fix/bgm12.png
--------------------------------------------------------------------------------
/image/fix/bgm13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/fix/bgm13.png
--------------------------------------------------------------------------------
/image/fix/bgm14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/fix/bgm14.png
--------------------------------------------------------------------------------
/image/fix/bgm15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/fix/bgm15.png
--------------------------------------------------------------------------------
/image/fix/scroll-view.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/fix/scroll-view.png
--------------------------------------------------------------------------------
/image/icon64_appwx_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/icon64_appwx_logo.png
--------------------------------------------------------------------------------
/image/pause.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/pause.png
--------------------------------------------------------------------------------
/image/play.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/play.png
--------------------------------------------------------------------------------
/image/plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/plus.png
--------------------------------------------------------------------------------
/image/record.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/record.png
--------------------------------------------------------------------------------
/image/stop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/stop.png
--------------------------------------------------------------------------------
/image/trash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/trash.png
--------------------------------------------------------------------------------
/image/wechat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/wechat.png
--------------------------------------------------------------------------------
/image/wechatHL.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/image/wechatHL.png
--------------------------------------------------------------------------------
/page/API/animation/animation.js:
--------------------------------------------------------------------------------
1 | Page({
2 | onReady: function () {
3 | this.animation = wx.createAnimation()
4 |
5 | },
6 | rotate: function () {
7 | this.animation.rotate(Math.random() * 720 - 360).step()
8 | this.setData({ animation: this.animation.export() })
9 | },
10 | scale: function () {
11 | this.animation.scale(Math.random() * 2).step()
12 | this.setData({ animation: this.animation.export() })
13 | },
14 | translate: function () {
15 | this.animation.translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step()
16 | this.setData({ animation: this.animation.export() })
17 | },
18 | skew: function () {
19 | this.animation.skew(Math.random() * 90, Math.random() * 90).step()
20 | this.setData({ animation: this.animation.export() })
21 | },
22 | rotateAndScale: function () {
23 | this.animation.rotate(Math.random() * 720 - 360)
24 | .scale(Math.random() * 2)
25 | .step()
26 | this.setData({ animation: this.animation.export() })
27 | },
28 | rotateThenScale: function () {
29 | this.animation.rotate(Math.random() * 720 - 360).step()
30 | .scale(Math.random() * 2).step()
31 | this.setData({ animation: this.animation.export() })
32 | },
33 | all: function () {
34 | this.animation.rotate(Math.random() * 720 - 360)
35 | .scale(Math.random() * 2)
36 | .translate(Math.random() * 100 - 50, Math.random() * 100 - 50)
37 | .skew(Math.random() * 90, Math.random() * 90)
38 | .step()
39 | this.setData({ animation: this.animation.export() })
40 | },
41 | allInQueue: function () {
42 | this.animation.rotate(Math.random() * 720 - 360).step()
43 | .scale(Math.random() * 2).step()
44 | .translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step()
45 | .skew(Math.random() * 90, Math.random() * 90).step()
46 | this.setData({ animation: this.animation.export() })
47 | },
48 | reset: function () {
49 | this.animation.rotate(0, 0)
50 | .scale(1)
51 | .translate(0, 0)
52 | .skew(0, 0)
53 | .step({ duration: 0 })
54 | this.setData({ animation: this.animation.export() })
55 | }
56 | })
57 |
--------------------------------------------------------------------------------
/page/API/animation/animation.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "动画"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/animation/animation.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 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/page/API/animation/animation.wxss:
--------------------------------------------------------------------------------
1 | .page-body-wrapper {
2 | flex-grow: 1;
3 | }
4 | .animation-element-wrapper {
5 | display: block;
6 | margin-bottom: 100rpx;
7 | }
8 | .animation-element {
9 | width: 200rpx;
10 | height: 200rpx;
11 | background-color: #1AAD19;
12 | }
13 | .animation-buttons {
14 | padding: 50rpx 50rpx 10rpx;
15 | border-top: 1px solid #ccc;
16 | display: flex;
17 | flex-grow: 1;
18 | overflow-y: scroll;
19 | flex-direction: row;
20 | flex-wrap: wrap;
21 | width: 100%;
22 | height: 400rpx;
23 | box-sizing: border-box;
24 | }
25 | .animation-button {
26 | width: 290rpx;
27 | margin: 20rpx auto;
28 | }
29 | .animation-button-reset {
30 | width: 610rpx;
31 | margin: 20rpx auto;
32 | }
33 |
--------------------------------------------------------------------------------
/page/API/background-audio/background-audio.js:
--------------------------------------------------------------------------------
1 | var util = require('../../../util/util.js')
2 | var dataUrl = 'http://ws.stream.qqmusic.qq.com/C100001wmp4t06stlC.m4a?fromtag=38'
3 | Page({
4 | onLoad: function () {
5 | var that = this
6 |
7 | // 设置播放停止监听事件
8 | wx.onBackgroundAudioStop(function () {
9 | console.log("音乐停止了,当前webview: ",that.data.__webviewId__)
10 | that.setData({
11 | playing: false,
12 | playTime: 0,
13 | formatedPlayTime: '00:00:00'
14 | })
15 | })
16 | // 设置播放开始监听事件
17 | wx.onBackgroundAudioPlay(function(){
18 | console.log("音乐开始了,当前webview: ",that.data.__webviewId__)
19 | // 开始后需要更新当前歌曲的秒数
20 | if(that.data.playing === false)
21 | that.setData({
22 | playing:true
23 | })
24 | if(that.updateInterval >= 0)
25 | return
26 | that._enableInterval()
27 | })
28 | // 设置播放暂停监听事件
29 | wx.onBackgroundAudioPause(function(){
30 | console.log("音乐暂停了,当前webview: ",that.data.__webviewId__)
31 | // 暂停后,不需要继续更新歌曲秒数
32 | if(that.data.playing === true)
33 | that.setData({
34 | playing:false
35 | })
36 | if(that.updateInterval >= 0)
37 | clearInterval(that.updateInterval)
38 | })
39 |
40 | // 进入的时候应该检测后台是否有音乐正在播放
41 | checkPlaying()
42 | function checkPlaying() {
43 | wx.getBackgroundAudioPlayerState({
44 | success: function (res) {
45 | console.log("播放器状态:",res)
46 | console.log("初始化时的webview",that.data.__webviewId__)
47 | var _isPlaying,_playTime
48 | res.status === 1?
49 | _isPlaying = true:_isPlaying = false
50 | res.currentPosition/res.duration > 0.95?
51 | _playTime = 0:_playTime = res.currentPosition
52 | that.setData({
53 | playing:_isPlaying,
54 | playTime: _playTime,
55 | formatedPlayTime: util.formatTime(_playTime)
56 | })
57 | if(_isPlaying)
58 | that._enableInterval()
59 | }
60 | })
61 | }
62 | },
63 | data: {
64 | playing: false,
65 | playTime: 0,
66 | formatedPlayTime: '00:00:00'
67 | },
68 | play: function () {
69 | var that = this
70 | if(this.updateInterval >= 0)
71 | clearInterval(this.updateInterval)
72 | wx.playBackgroundAudio({
73 | dataUrl: dataUrl,
74 | title: 'Lost Stars',
75 | coverImgUrl: 'http://y.gtimg.cn/music/photo_new/T002R150x150M000000Jhxf24CFL06.jpg?max_age=2592000',
76 | complete: function () {
77 | that.setData({
78 | playing : true
79 | })
80 | that._enableInterval()
81 | }
82 | })
83 | },
84 | resume:function(){
85 | var that = this
86 | if(this.updateInterval != '')
87 | clearInterval(this.updateInterval)
88 | wx.playBackgroundAudio({
89 | dataUrl: dataUrl,
90 | title: 'Lost Stars',
91 | coverImgUrl: 'http://y.gtimg.cn/music/photo_new/T002R150x150M000000Jhxf24CFL06.jpg?max_age=2592000',
92 | complete: function () {
93 | that.setData({
94 | playing:true
95 | })
96 | wx.seekBackgroundAudio({
97 | position: that.data.playTime,
98 | complete:function(){
99 | console.log("resume ok")
100 | }
101 | })
102 | }
103 | })
104 | },
105 | seek: function (e) {
106 | var that = this
107 | clearInterval(this.updateInterval)
108 | // 此时正在播放
109 | if(this.data.playing === true)
110 | wx.seekBackgroundAudio({
111 | position: e.detail.value,
112 | complete: function(){
113 | that._enableInterval()
114 | }
115 | })
116 | // 此时是暂停状态
117 | else
118 | wx.playBackgroundAudio({
119 | dataUrl: dataUrl,
120 | title: 'Lost Stars',
121 | coverImgUrl: 'http://y.gtimg.cn/music/photo_new/T002R150x150M000000Jhxf24CFL06.jpg?max_age=2592000',
122 | complete: function () {
123 | that.setData({
124 | playing:true
125 | })
126 | wx.seekBackgroundAudio({
127 | position: e.detail.value,
128 | complete:function(){
129 | console.log("seek and play ok")
130 | that._enableInterval()
131 | }
132 | })
133 | }
134 | })
135 | },
136 | pause: function () {
137 | var that = this
138 | wx.pauseBackgroundAudio({
139 | success: function () {
140 | // 清除定时器
141 | that.setData({
142 | playing:false
143 | })
144 | clearInterval(that.updateInterval)
145 | }
146 | })
147 | },
148 | stop: function () {
149 | var that = this
150 | wx.stopBackgroundAudio({
151 | success: function (res) {
152 | // 清除定时器
153 | clearInterval(that.updateInterval)
154 | // 设置初始数据
155 | that.setData({
156 | playing: false,
157 | playTime: 0,
158 | formatedPlayTime: util.formatTime(0)
159 | })
160 | }
161 | })
162 | },
163 | _enableInterval: function () {
164 | var that = this
165 | update()
166 | this.updateInterval = setInterval(update, 500)
167 | function update() {
168 | wx.getBackgroundAudioPlayerState({
169 | success: function (res) {
170 | that.setData({
171 | // 正在播放
172 | playing:true,
173 | playTime: res.currentPosition,
174 | formatedPlayTime: util.formatTime(res.currentPosition + 1)
175 | })
176 | }
177 | })
178 | }
179 | },
180 | onUnload: function () {
181 | clearInterval(this.updateInterval)
182 | }
183 | })
184 |
--------------------------------------------------------------------------------
/page/API/background-audio/background-audio.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "背景音乐"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/background-audio/background-audio.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | {{formatedPlayTime}}
10 |
11 |
12 | 00:00
13 | 04:29
14 |
15 |
16 | 离开应用后音乐也可保持播放
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | 重播
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | 重播
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/page/API/background-audio/background-audio.wxss:
--------------------------------------------------------------------------------
1 | .page-body-wrapper {
2 | margin-top: 0;
3 | }
4 | .page-body-info {
5 | padding-bottom: 50rpx;
6 | }
7 | .time-big {
8 | font-size: 60rpx;
9 | margin: 20rpx;
10 | }
11 | .slider {
12 | width: 650rpx;
13 | }
14 | .play-time {
15 | font-size: 28rpx;
16 | width: 700rpx;
17 | padding: 20rpx 0;
18 | display: flex;
19 | justify-content: space-between;
20 | box-sizing: border-box;
21 | }
22 | .page-body-buttons {
23 | display: flex;
24 | justify-content: space-around;
25 | margin-top: 100rpx;
26 | }
27 | .page-body-button {
28 | width: 250rpx;
29 | text-align: center;
30 | }
31 | .page-body-button .restart{
32 | line-height: 80px;
33 | }
--------------------------------------------------------------------------------
/page/API/canvas/canvas.js:
--------------------------------------------------------------------------------
1 | Page({
2 | onReady: function () {
3 | this.position = {
4 | x: 150,
5 | y: 150,
6 | vx: 2,
7 | vy: 2
8 | }
9 |
10 | this.drawBall()
11 | this.interval = setInterval(this.drawBall, 17)
12 | },
13 | drawBall: function () {
14 | var p = this.position
15 | p.x += p.vx
16 | p.y += p.vy
17 | if (p.x >= 300) {
18 | p.vx = -2
19 | }
20 | if (p.x <= 7) {
21 | p.vx = 2
22 | }
23 | if (p.y >= 300) {
24 | p.vy = -2
25 | }
26 | if (p.y <= 7) {
27 | p.vy = 2
28 | }
29 |
30 | var context = wx.createContext()
31 |
32 | ball(p.x, 150)
33 | ball(150, p.y)
34 | ball(300 - p.x, 150)
35 | ball(150, 300 - p.y)
36 | ball(p.x, p.y)
37 | ball(300 - p.x, 300 - p.y)
38 | ball(p.x, 300 - p.y)
39 | ball(300 - p.x, p.y)
40 |
41 |
42 | wx.drawCanvas({
43 | canvasId: 'canvas',
44 | actions: context.getActions()
45 | })
46 |
47 | function ball(x, y) {
48 | context.beginPath(0)
49 | context.arc(x, y, 5, 0, Math.PI * 2)
50 | context.setFillStyle('#1aad19')
51 | context.setStrokeStyle('rgba(1,1,1,0)')
52 | context.fill()
53 | context.stroke()
54 | }
55 | },
56 | onUnload: function () {
57 | clearInterval(this.interval)
58 | }
59 | })
60 |
--------------------------------------------------------------------------------
/page/API/canvas/canvas.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "创建画布"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/canvas/canvas.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/page/API/canvas/canvas.wxss:
--------------------------------------------------------------------------------
1 | .canvas {
2 | width: 305px;
3 | height: 305px;
4 | background-color: #fff;
5 | }
6 |
--------------------------------------------------------------------------------
/page/API/common/footer.wxml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/page/API/common/header.wxml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/page/API/download-file/download-file.js:
--------------------------------------------------------------------------------
1 | Page({})
2 |
--------------------------------------------------------------------------------
/page/API/download-file/download-file.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "下载文件"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/download-file/download-file.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | 搭建好自己的后台服务器后,可以将服务器上的图片视频等资源下载到手机上。
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/page/API/download-file/download-file.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/API/download-file/download-file.wxss
--------------------------------------------------------------------------------
/page/API/file/file.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | tempFilePath: '',
4 | savedFilePath: wx.getStorageSync('savedFilePath') || '',
5 | dialog: {
6 | hidden: true
7 | }
8 | },
9 | chooseImage: function () {
10 | var that = this
11 | wx.chooseImage({
12 | count: 1,
13 | success: function (res) {
14 | that.setData({
15 | tempFilePath: res.tempFilePaths[0]
16 | })
17 | }
18 | })
19 | },
20 | saveFile: function () {
21 | if (this.data.tempFilePath.length > 0) {
22 | var that = this
23 | wx.saveFile({
24 | tempFilePath: this.data.tempFilePath,
25 | success: function (res) {
26 | that.setData({
27 | savedFilePath: res.savedFilePath
28 | })
29 | wx.setStorageSync('savedFilePath', res.savedFilePath)
30 | that.setData({
31 | dialog: {
32 | title: '保存成功',
33 | content: '下次进入应用时,此文件仍可用',
34 | hidden: false
35 | }
36 | })
37 | },
38 | fail: function (res) {
39 | that.setData({
40 | dialog: {
41 | title: '保存失败',
42 | content: '应该是有 bug 吧',
43 | hidden: false
44 | }
45 | })
46 | }
47 | })
48 | }
49 | },
50 | clear: function () {
51 | wx.setStorageSync('savedFilePath', '')
52 | this.setData({
53 | tempFilePath: '',
54 | savedFilePath: ''
55 | })
56 | },
57 | confirm: function () {
58 | this.setData({
59 | 'dialog.hidden': true
60 | })
61 | }
62 | })
63 |
--------------------------------------------------------------------------------
/page/API/file/file.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "文件"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/file/file.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 |
26 |
27 |
28 | {{dialog.content}}
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/page/API/file/file.wxss:
--------------------------------------------------------------------------------
1 | .image {
2 | width: 300rpx;
3 | height: 300rpx;
4 | }
5 | .image-plus {
6 | width: 150rpx;
7 | height: 150rpx;
8 | border: 1px solid #bbb;
9 | }
10 |
--------------------------------------------------------------------------------
/page/API/generate.sh:
--------------------------------------------------------------------------------
1 | mkdir $1
2 | touch $1/$1.js
3 | touch $1/$1.wxss
4 | touch $1/$1.wxml
5 | touch $1/$1.json
6 |
--------------------------------------------------------------------------------
/page/API/get-location/format-location.js:
--------------------------------------------------------------------------------
1 | function formatLocation(longitude, latitude) {
2 | longitude = longitude.toFixed(2)
3 | latitude = latitude.toFixed(2)
4 |
5 | return {
6 | longitude: longitude.toString().split('.'),
7 | latitude: latitude.toString().split('.')
8 | }
9 | }
10 |
11 | module.exports = formatLocation
12 |
--------------------------------------------------------------------------------
/page/API/get-location/get-location.js:
--------------------------------------------------------------------------------
1 | var formatLocation = require('./format-location.js')
2 |
3 | Page({
4 | data: {
5 | hasLocation: false,
6 | },
7 | getLocation: function () {
8 | var that = this
9 | wx.getLocation({
10 | success: function (res) {
11 | console.log(res)
12 | that.setData({
13 | hasLocation: true,
14 | location: formatLocation(res.longitude, res.latitude)
15 | })
16 | }
17 | })
18 | },
19 | clear: function () {
20 | this.setData({
21 | hasLocation: false
22 | })
23 | }
24 | })
25 |
--------------------------------------------------------------------------------
/page/API/get-location/get-location.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "获取位置"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/get-location/get-location.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | 当前位置经纬度
11 |
12 | 未获取
13 |
14 |
15 |
16 | E{{location.longitude[0]}}°{{location.longitude[1]}}′
17 | N{{location.latitude[0]}}°{{location.latitude[1]}}′
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/page/API/get-location/get-location.wxss:
--------------------------------------------------------------------------------
1 | .page-body-text-small {
2 | font-size: 24rpx;
3 | color: #000;
4 | margin-bottom: 100rpx;
5 | }
6 | .page-body-text-location {
7 | display: flex;
8 | font-size: 50rpx;
9 | }
10 | .page-body-text-location text {
11 | margin: 10rpx;
12 | }
13 |
--------------------------------------------------------------------------------
/page/API/get-network-type/get-network-type.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | hasNetworkType: false
4 | },
5 | getNetworkType: function () {
6 | var that = this
7 | wx.getNetworkType({
8 | success: function (res) {
9 | console.log(res)
10 | that.setData({
11 | hasNetworkType: true,
12 | networkType: res.subtype || res.networkType
13 | })
14 | that.update()
15 | }
16 | })
17 | },
18 | clear: function () {
19 | this.setData({
20 | hasNetworkType: false,
21 | networkType: ''
22 | })
23 | }
24 | })
25 |
--------------------------------------------------------------------------------
/page/API/get-network-type/get-network-type.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "获取手机网络状态"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/get-network-type/get-network-type.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | 网络状态
11 |
12 | 未获取
13 | 点击绿色按钮可获取网络状态
14 |
15 |
16 | {{networkType}}
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/page/API/get-network-type/get-network-type.wxss:
--------------------------------------------------------------------------------
1 | .page-body-text-network-type {
2 | font-size: 80rpx;
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/get-system-info/get-system-info.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | systemInfo: {}
4 | },
5 | getSystemInfo: function () {
6 | var that = this
7 | wx.getSystemInfo({
8 | success: function (res) {
9 | that.setData({
10 | systemInfo: res
11 | })
12 | that.update()
13 | }
14 | })
15 | }
16 | })
17 |
--------------------------------------------------------------------------------
/page/API/get-system-info/get-system-info.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "获取手机系统信息"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/get-system-info/get-system-info.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 |
26 |
27 | 屏幕高度
28 |
29 |
30 |
31 | DPI
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/page/API/get-system-info/get-system-info.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/API/get-system-info/get-system-info.wxss
--------------------------------------------------------------------------------
/page/API/get-user-info/get-user-info.js:
--------------------------------------------------------------------------------
1 | var app = getApp()
2 | Page({
3 | data: {
4 | hasUserInfo: false
5 | },
6 | getUserInfo: function () {
7 | var that = this
8 |
9 | if (app.globalData.hasLogin === false) {
10 | wx.login({
11 | success: _getUserInfo
12 | })
13 | } else {
14 | _getUserInfo()
15 | }
16 |
17 | function _getUserInfo() {
18 | wx.getUserInfo({
19 | success: function (res) {
20 | that.setData({
21 | hasUserInfo: true,
22 | userInfo: res.userInfo
23 | })
24 | that.update()
25 | }
26 | })
27 | }
28 | },
29 | clear: function () {
30 | this.setData({
31 | hasUserInfo: false,
32 | userInfo: {}
33 | })
34 | }
35 | })
36 |
--------------------------------------------------------------------------------
/page/API/get-user-info/get-user-info.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "获取用户信息"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/get-user-info/get-user-info.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | 用户信息
11 |
12 | 未获取
13 | 点击绿色按钮可获取用户头像及昵称
14 |
15 |
16 |
17 | {{userInfo.nickName}}
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/page/API/get-user-info/get-user-info.wxss:
--------------------------------------------------------------------------------
1 | .userinfo-avatar {
2 | border-radius: 128rpx;
3 | width: 128rpx;
4 | height: 128rpx;
5 | }
6 | .userinfo-nickname {
7 | margin-top: 20rpx;
8 | font-size: 38rpx;
9 | }
10 |
--------------------------------------------------------------------------------
/page/API/image/image.js:
--------------------------------------------------------------------------------
1 | var sourceType = [ ['camera'], ['album'], ['camera', 'album'] ]
2 | var sizeType = [ ['compressed'], ['original'], ['compressed', 'original'] ]
3 |
4 | Page({
5 | data: {
6 | sourceTypeIndex: 0,
7 | sourceType: ['拍照', '相册', '拍照或相册'],
8 |
9 | sizeTypeIndex: 0,
10 | sizeType: ['压缩', '原图', '压缩或原图'],
11 |
12 | countIndex: 0,
13 | count: [1, 2, 3, 4, 5, 6, 7, 8, 9]
14 | },
15 | sourceTypeChange: function (e) {
16 | this.setData({
17 | sourceTypeIndex: e.detail.value
18 | })
19 | },
20 | sizeTypeChange: function (e) {
21 | this.setData({
22 | sizeTypeIndex: e.detail.value
23 | })
24 | },
25 | countChange: function (e) {
26 | this.setData({
27 | countIndex: e.detail.value
28 | })
29 | },
30 | chooseImage: function () {
31 | var that = this
32 | wx.chooseImage({
33 | sourceType: sourceType[this.data.sourceTypeIndex],
34 | sizeType: sizeType[this.data.sizeTypeIndex],
35 | count: this.data.count[this.data.countIndex],
36 | success: function (res) {
37 | console.log(res)
38 | that.setData({
39 | imageList: res.tempFilePaths
40 | })
41 | }
42 | })
43 | },
44 | previewImage: function (e) {
45 | var current = e.target.dataset.src
46 |
47 | wx.previewImage({
48 | current: current,
49 | urls: this.data.imageList
50 | })
51 | }
52 | })
53 |
--------------------------------------------------------------------------------
/page/API/image/image.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "图片"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/image/image.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/page/API/image/image.wxss:
--------------------------------------------------------------------------------
1 | .images-wrapper {
2 | padding: 20rpx;
3 | background-color: #fff;
4 | margin-top: 20rpx;
5 | }
6 | .images-wrapper-text {
7 | font-size: 28rpx;
8 | }
9 | .images-list {
10 | display: flex;
11 | margin-top: 20rpx;
12 | flex-wrap: wrap;
13 | }
14 | .images-image {
15 | width: 150rpx;
16 | height: 150rpx;
17 | margin: 10rpx;
18 | }
19 | .images-image-plus {
20 | border: 1px solid #999;
21 | }
22 |
--------------------------------------------------------------------------------
/page/API/index/index.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | menuList: [{
4 | name: '基础能力',
5 | APIList: [{
6 | zhName: '微信登录',
7 | enName: 'login',
8 | url: '../login/login'
9 | }, {
10 | zhName: '获取用户信息',
11 | enName: 'getUserInfo',
12 | url: '../get-user-info/get-user-info'
13 | }, {
14 | zhName: '发起支付',
15 | enName: 'RequestPayment',
16 | url: '../request-payment/request-payment'
17 | }],
18 | opened: false
19 | }, {
20 | name: '界面跳转、监听和加载',
21 | opened: false,
22 | APIList: [{
23 | zhName: '设置界面标题',
24 | enName: 'setNavigationBarTitle',
25 | url: '../set-navigation-bar-title/set-navigation-bar-title'
26 | }, {
27 | zhName: '标题栏加载动画',
28 | enName: 'navigationBarLoading',
29 | url: '../navigation-bar-loading/navigation-bar-loading'
30 | }, {
31 | zhName: '页面跳转',
32 | enName: 'navigateTo, navigateBack, redirectTo',
33 | url: '../navigator/navigator'
34 | }, {
35 | zhName: '下拉刷新',
36 | enName: 'pullDownRefresh',
37 | url: '../pull-down-refresh/pull-down-refresh'
38 | }, {
39 | zhName: '创建动画',
40 | enName: 'createAnimation',
41 | url: '../animation/animation'
42 | }, {
43 | zhName: '创建绘画',
44 | enName: 'createContext',
45 | url: '../canvas/canvas'
46 | }]
47 | }, {
48 | name: '设备相关',
49 | opened: false,
50 | APIList: [{
51 | zhName: '获取手机网络状态',
52 | enName: 'getNetworkType',
53 | url: '../get-network-type/get-network-type'
54 | }, {
55 | zhName: '获取手机系统信息',
56 | enName: 'getSystemInfo',
57 | url: '../get-system-info/get-system-info'
58 | }, {
59 | zhName: '监听重力感应数据',
60 | enName: 'onAccelerometerChange',
61 | url: '../on-accelerometer-change/on-accelerometer-change'
62 | }, {
63 | zhName: '监听罗盘数据',
64 | enName: 'onCompassChange',
65 | url: '../on-compass-change/on-compass-change'
66 | }]
67 | }, {
68 | name: '网络相关',
69 | opened: false,
70 | APIList: [{
71 | zhName: '发起一个请求',
72 | enName: 'request',
73 | url: '../request/request'
74 | }, {
75 | zhName: 'Web Socket',
76 | enName: 'Web Socket',
77 | url: '../web-socket/web-socket'
78 | }, {
79 | zhName: '上传文件',
80 | enName: 'Upload File',
81 | url: '../upload-file/upload-file'
82 | }, {
83 | zhName: '下载文件',
84 | enName: 'Download File',
85 | url: '../download-file/download-file'
86 | }]
87 | }, {
88 | name: '多媒体',
89 | opened: false,
90 | APIList: [{
91 | zhName: '图片',
92 | enName: 'chooseImage/previewImage',
93 | url: '../image/image'
94 | }, {
95 | zhName: '录音',
96 | enName: 'start/stopRecord, play/pause/stopVoice',
97 | url: '../voice/voice'
98 | }, {
99 | zhName: '背景音频',
100 | enName: 'play/pause/stopAudio',
101 | url: '../background-audio/background-audio'
102 | }, {
103 | zhName: '文件',
104 | enName: 'saveFile',
105 | url: '../file/file'
106 | }]
107 | }, {
108 | name: '数据',
109 | opened: false,
110 | url: '../storage/storage'
111 | }, {
112 | name: '地理位置',
113 | opened: false,
114 | APIList: [{
115 | zhName: '获取当前位置',
116 | enName: 'getLocation',
117 | url: '../get-location/get-location'
118 | }, {
119 | zhName: '使用原生地图查看位置',
120 | enName: 'openLocation',
121 | url: '../open-location/open-location'
122 | }]
123 | }]
124 | },
125 | tapMenuItem: function (e) {
126 | var menuItem = this.data.menuList[parseInt(e.currentTarget.id)]
127 | if (menuItem.url) {
128 | wx.navigateTo({ url: menuItem.url })
129 | } else {
130 | var changeData = {}
131 | var opened = menuItem.opened
132 |
133 | changeData['menuList[' + e.currentTarget.id + '].opened'] = !opened
134 | this.setData(changeData)
135 | }
136 | }
137 | })
138 |
--------------------------------------------------------------------------------
/page/API/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
33 |
34 |
--------------------------------------------------------------------------------
/page/API/index/index.wxss:
--------------------------------------------------------------------------------
1 | .header {
2 | padding: 40px;
3 | }
4 | .title {
5 | font-size: 30px;
6 | }
7 | .desc {
8 | margin-top: 5px;
9 | color: #888888;
10 | font-size: 14px;
11 | line-height: 1.4;
12 | }
13 | .menu-list {
14 | display: flex;
15 | flex-direction: column;
16 | background-color: #fbf9fe;
17 | }
18 | .menu-item {
19 | color: #000000;
20 | display: flex;
21 | background-color: #fff;
22 | margin: 10rpx 40rpx;
23 | flex-direction: column;
24 | }
25 | .menu-item-main {
26 | display: flex;
27 | height: 100rpx;
28 | padding: 20rpx;
29 | border-radius: 10rpx;
30 | align-items: center;
31 | font-size: 32rpx;
32 | justify-content: space-between;
33 | }
34 | .menu-item-arrow {
35 | width: 32rpx;
36 | height: 32rpx;
37 | transition: 400ms;
38 | }
39 | .menu-item-arrow.open {
40 | transform: rotate(-90deg);
41 | }
42 | .menu-item-arrow.close {
43 | transform: rotate(90deg);
44 | }
45 | .menu-item-arrow.url {
46 | transform: rotate(0deg);
47 | }
48 |
49 | .menu-item-api-list {
50 | transition: 200ms;
51 | height: auto;
52 | border-top: 1px solid #d8d8d8;
53 | }
54 | .menu-item-api-list.close {
55 | display: none;
56 | height: 0;
57 | }
58 | .menu-item-api-item {
59 | display: flex;
60 | justify-content: space-between;
61 | height: 80rpx;
62 | padding: 20rpx 20rpx 20rpx 0;
63 | margin-left: 20rpx;
64 | align-items: center;
65 | border-top: 1px solid #f0f0f0;
66 | }
67 | .menu-item-api-item-text {
68 | display: flex;
69 | flex-direction: column;
70 | justify-content: space-between;
71 | height: 100%;
72 | }
73 | .menu-item-api-item-text-zhname {
74 | font-size: 30rpx;
75 | }
76 | .menu-item-api-item-text-enname {
77 | font-size: 26rpx;
78 | color: #6b6b6b;
79 | }
80 | .menu-item-api-item-arrow {
81 | width: 32rpx;
82 | height: 32rpx;
83 | }
84 |
--------------------------------------------------------------------------------
/page/API/login/login.js:
--------------------------------------------------------------------------------
1 | var app = getApp()
2 | Page({
3 | onLoad: function () {
4 | this.setData({
5 | hasLogin: app.globalData.hasLogin
6 | })
7 | },
8 | data: {},
9 | login: function () {
10 | var that = this
11 | wx.login({
12 | success: function (res) {
13 | app.globalData.hasLogin = true
14 | that.setData({
15 | hasLogin: true
16 | })
17 | that.update()
18 | }
19 | })
20 | }
21 | })
22 |
--------------------------------------------------------------------------------
/page/API/login/login.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "微信登录"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/login/login.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | 已登录
11 | 每个微信号中仅需登录 1 次,后续每次进入页面即可根据微信 id 自动拉取用户信息
12 |
13 |
14 | 每个微信号中仅需登录一次
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/page/API/login/login.wxss:
--------------------------------------------------------------------------------
1 | .page-body-wrapper {
2 | margin-top: 200rpx;
3 | display: flex;
4 | flex-direction: column;
5 | align-items: center;
6 | justify-content: center;
7 | width: 100%;
8 | padding: 0 50rpx;
9 | box-sizing: border-box;
10 | }
11 | .page-body-title {
12 | font-size: 60rpx;
13 | /*TODO 使用 rpx */
14 | line-height: 100px;
15 | }
16 | .page-body-text {
17 | color: #bbb;
18 | font-size: 28rpx;
19 | /*TODO 使用 rpx */
20 | line-height: 20px;
21 | margin: 0 0 100rpx 0;
22 | text-align: center;
23 | }
24 | .page-body-button {
25 | width: 100%;
26 | }
27 |
--------------------------------------------------------------------------------
/page/API/navigation-bar-loading/navigation-bar-loading.js:
--------------------------------------------------------------------------------
1 | Page({
2 | showNavigationBarLoading: function () {
3 | wx.showNavigationBarLoading()
4 | },
5 | hideNavigationBarLoading: function () {
6 | wx.hideNavigationBarLoading()
7 | }
8 | })
9 |
--------------------------------------------------------------------------------
/page/API/navigation-bar-loading/navigation-bar-loading.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "标题栏加载动画"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/navigation-bar-loading/navigation-bar-loading.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/page/API/navigation-bar-loading/navigation-bar-loading.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/API/navigation-bar-loading/navigation-bar-loading.wxss
--------------------------------------------------------------------------------
/page/API/navigator/navigator.js:
--------------------------------------------------------------------------------
1 | Page({
2 | navigateTo: function () {
3 | wx.navigateTo({ url: './navigator' })
4 | },
5 | navigateBack: function () {
6 | wx.navigateBack()
7 | },
8 | redirectTo: function () {
9 | wx.redirectTo({ url: './navigator' })
10 | }
11 | })
12 |
--------------------------------------------------------------------------------
/page/API/navigator/navigator.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "页面跳转"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/navigator/navigator.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/page/API/navigator/navigator.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/API/navigator/navigator.wxss
--------------------------------------------------------------------------------
/page/API/on-accelerometer-change/on-accelerometer-change.js:
--------------------------------------------------------------------------------
1 | Page({
2 | onReady: function () {
3 | this.drawBigBall()
4 | var that = this
5 |
6 | this.position = {
7 | x: 151,
8 | y: 151,
9 | vx: 0,
10 | vy: 0,
11 | ax: 0,
12 | ay: 0
13 | }
14 | wx.onAccelerometerChange(function (res) {
15 | that.setData({
16 | x: res.x.toFixed(2),
17 | y: res.y.toFixed(2),
18 | z: res.z.toFixed(2)
19 | })
20 | that.position.ax = Math.sin(res.x * Math.PI / 2)
21 | that.position.ay = -Math.sin(res.y * Math.PI / 2)
22 | //that.drawSmallBall()
23 | })
24 |
25 | this.interval = setInterval(function () {
26 | that.drawSmallBall()
27 | }, 17)
28 |
29 | },
30 | drawBigBall: function () {
31 | var context = wx.createContext()
32 | context.beginPath(0)
33 | context.arc(151, 151, 140, 0, Math.PI * 2)
34 | context.setFillStyle('#ffffff')
35 | context.setStrokeStyle('#aaaaaa')
36 | context.fill()
37 | context.stroke()
38 | wx.drawCanvas({
39 | canvasId: 'big-ball',
40 | actions: context.getActions()
41 | })
42 | },
43 | drawSmallBall: function () {
44 | var p = this.position
45 | var strokeStyle = 'rgba(1,1,1,0)'
46 |
47 | p.x = p.x + p.vx
48 | p.y = p.y + p.vy
49 | p.vx = p.vx + p.ax
50 | p.vy = p.vy + p.ay
51 |
52 | if (Math.sqrt(Math.pow(Math.abs(p.x) - 151, 2) + Math.pow(Math.abs(p.y) - 151, 2)) >= 115) {
53 | if (p.x > 151 && p.vx > 0) {
54 | p.vx = 0
55 | }
56 | if (p.x < 151 && p.vx < 0) {
57 | p.vx = 0
58 | }
59 | if (p.y > 151 && p.vy > 0) {
60 | p.vy = 0
61 | }
62 | if (p.y < 151 && p.vy < 0) {
63 | p.vy = 0
64 | }
65 | strokeStyle = '#ff0000'
66 | }
67 |
68 | var context = wx.createContext()
69 | context.beginPath(0)
70 | context.arc(p.x, p.y, 15, 0, Math.PI * 2)
71 | context.setFillStyle('#1aad19')
72 | context.setStrokeStyle(strokeStyle)
73 | context.fill()
74 | context.stroke()
75 | wx.drawCanvas({
76 | canvasId: 'small-ball',
77 | actions: context.getActions()
78 | })
79 | },
80 | data: {
81 | x: 0,
82 | y: 0,
83 | z: 0
84 | },
85 | onUnload: function () {
86 | clearInterval(this.interval)
87 | }
88 | })
89 |
--------------------------------------------------------------------------------
/page/API/on-accelerometer-change/on-accelerometer-change.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "监听重力感应数据"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/on-accelerometer-change/on-accelerometer-change.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | 旋转手机即可移动以下小球
10 |
11 |
12 |
13 |
14 |
15 | X: {{x}}
16 | Y: {{y}}
17 | Z: {{z}}
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/page/API/on-accelerometer-change/on-accelerometer-change.wxss:
--------------------------------------------------------------------------------
1 | .page-body-xyz {
2 | display: flex;
3 | justify-content: space-around;
4 | width: 700rpx;
5 | margin-top: 50rpx;
6 | box-sizing: border-box;
7 | }
8 | .page-body-canvas {
9 | width: 302px;
10 | height: 302px;
11 | position: relative;
12 | }
13 | .page-body-ball {
14 | position: absolute;
15 | top: 0;
16 | left: 0;
17 | width: 302px;
18 | height: 302px;
19 | }
20 | .page-body-title {
21 | font-size: 50rpx;
22 | width: 250rpx;
23 | }
24 |
--------------------------------------------------------------------------------
/page/API/on-compass-change/on-compass-change.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | direction: 0
4 | },
5 | onReady: function () {
6 | var that = this
7 | wx.onCompassChange(function (res) {
8 | that.setData({
9 | direction: parseInt(res.direction)
10 | })
11 | })
12 | }
13 | })
14 |
--------------------------------------------------------------------------------
/page/API/on-compass-change/on-compass-change.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "监听罗盘数据"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/on-compass-change/on-compass-change.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | 选中手机即可获取方位信息
10 |
11 | {{direction}}
12 | o
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/page/API/on-compass-change/on-compass-change.wxss:
--------------------------------------------------------------------------------
1 | .direction {
2 | margin-top: 100rpx;
3 | display: flex;
4 | }
5 | .direction-value {
6 | font-size: 200rpx;
7 | }
8 | .direction-degree {
9 | font-size: 40rpx;
10 | }
11 |
--------------------------------------------------------------------------------
/page/API/open-location/open-location.js:
--------------------------------------------------------------------------------
1 | Page({
2 | openLocation: function (e) {
3 | console.log(e)
4 | var value = e.detail.value
5 | console.log(value)
6 | wx.openLocation({
7 | longitude: Number(value.longitude),
8 | latitude: Number(value.latitude),
9 | name: value.name,
10 | address: value.address
11 | })
12 | }
13 | })
14 |
--------------------------------------------------------------------------------
/page/API/open-location/open-location.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "查看位置"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/open-location/open-location.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/page/API/open-location/open-location.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/API/open-location/open-location.wxss
--------------------------------------------------------------------------------
/page/API/pull-down-refresh/pull-down-refresh.js:
--------------------------------------------------------------------------------
1 | Page({
2 | onPullDownRefresh: function () {
3 | console.log('onPullDownRefresh', new Date())
4 | },
5 | stopPullDownRefresh: function () {
6 | wx.stopPullDownRefresh({
7 | complete: function (res) {
8 | console.log(res, new Date())
9 | }
10 | })
11 | }
12 | })
13 |
--------------------------------------------------------------------------------
/page/API/pull-down-refresh/pull-down-refresh.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "下拉刷新",
3 | "enablePullDownRefresh": true
4 | }
5 |
--------------------------------------------------------------------------------
/page/API/pull-down-refresh/pull-down-refresh.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | 下滑页面即可刷新
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/page/API/pull-down-refresh/pull-down-refresh.wxss:
--------------------------------------------------------------------------------
1 | .page-body-info {
2 | background-color: transparent;
3 | }
4 | .page-body-buttons button {
5 | color: #21c932;
6 | margin: 0 100rpx;
7 | }
8 | .page-body-buttons button:after {
9 | border-color: #21c932;
10 | }
11 |
--------------------------------------------------------------------------------
/page/API/request-payment/request-payment.js:
--------------------------------------------------------------------------------
1 | Page({
2 | })
3 |
--------------------------------------------------------------------------------
/page/API/request-payment/request-payment.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "发起支付"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/request-payment/request-payment.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | 自主接入微信支付后,可以让用户在页面上快捷完成下单购买。
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/page/API/request-payment/request-payment.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/API/request-payment/request-payment.wxss
--------------------------------------------------------------------------------
/page/API/request/request.js:
--------------------------------------------------------------------------------
1 | Page({})
2 |
--------------------------------------------------------------------------------
/page/API/request/request.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "网络请求"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/request/request.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | 搭建好自己的后台服务器后,可以跟服务器互通数据,为用户提供个性化服务。
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/page/API/request/request.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/API/request/request.wxss
--------------------------------------------------------------------------------
/page/API/set-navigation-bar-title/set-navigation-bar-title.js:
--------------------------------------------------------------------------------
1 | Page({
2 | setNaivgationBarTitle: function (e) {
3 | var title = e.detail.value.title
4 | console.log(title)
5 | wx.setNavigationBarTitle({
6 | title: title
7 | })
8 | }
9 | })
10 |
--------------------------------------------------------------------------------
/page/API/set-navigation-bar-title/set-navigation-bar-title.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "设置页面标题"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/set-navigation-bar-title/set-navigation-bar-title.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/page/API/set-navigation-bar-title/set-navigation-bar-title.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/API/set-navigation-bar-title/set-navigation-bar-title.wxss
--------------------------------------------------------------------------------
/page/API/storage/storage.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | toast: {
4 | hidden: true
5 | }
6 | },
7 | submitForm: function (e) {
8 | var type = e.detail.target.id
9 | var key = e.detail.value.key
10 | var data = e.detail.value.data
11 |
12 | if (key.length === 0 && type !== 'clear') {
13 | this.setData({
14 | key: key,
15 | data: data,
16 | 'toast.hidden': false,
17 | 'toast.content': 'key 不能为空'
18 | })
19 | } else if (type === 'get' && key.length > 0) {
20 | this.setData({
21 | key: key,
22 | data: wx.getStorageSync(key),
23 | 'toast.hidden': false,
24 | 'toast.content': '读取数据成功'
25 | })
26 | } else if (type === 'set' && key.length > 0) {
27 | wx.setStorageSync(key, data)
28 | this.setData({
29 | key: key,
30 | data: data,
31 | 'toast.hidden': false,
32 | 'toast.content': '存储数据成功'
33 | })
34 | } else if (type === 'clear') {
35 | wx.clearStorageSync()
36 | this.setData({
37 | key: '',
38 | data: '',
39 | 'toast.hidden': false,
40 | 'toast.content': '清除数据成功'
41 | })
42 | }
43 | },
44 | toastChange: function () {
45 | this.setData({
46 | 'toast.hidden': true
47 | })
48 | }
49 | })
50 |
--------------------------------------------------------------------------------
/page/API/storage/storage.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "数据存储"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/storage/storage.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
22 |
23 |
24 |
25 | {{toast.content}}
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/page/API/storage/storage.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/API/storage/storage.wxss
--------------------------------------------------------------------------------
/page/API/upload-file/upload-file.js:
--------------------------------------------------------------------------------
1 | Page({})
2 |
--------------------------------------------------------------------------------
/page/API/upload-file/upload-file.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "上传文件"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/upload-file/upload-file.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | 搭建好自己的后台服务器后,可以将手机上的图片视频等资源上传到服务器上。
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/page/API/upload-file/upload-file.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/API/upload-file/upload-file.wxss
--------------------------------------------------------------------------------
/page/API/voice/voice.js:
--------------------------------------------------------------------------------
1 | var util = require('../../../util/util.js')
2 | var playTimeInterval,interval
3 |
4 | Page({
5 | data: {
6 | recording: false,
7 | playing: false,
8 | hasRecord: false,
9 | recordTime: 0,
10 | playTime: 0,
11 | formatedRecordTime: '00:00:00',
12 | formatedPlayTime: '00:00:00'
13 | },
14 | startRecord: function () {
15 | this.setData({ recording: true })
16 |
17 | var that = this
18 | interval = setInterval(function () {
19 | that.data.recordTime += 1
20 | that.setData({
21 | formatedRecordTime: util.formatTime(that.data.recordTime)
22 | })
23 | }, 1000)
24 | wx.startRecord({
25 | success: function (res) {
26 | that.setData({
27 | hasRecord: true,
28 | tempFilePath: res.tempFilePath,
29 | formatedPlayTime: util.formatTime(that.data.playTime)
30 | })
31 | },
32 | complete: function () {
33 | that.setData({ recording: false })
34 | clearInterval(interval)
35 | }
36 | })
37 | },
38 | stopRecord: function () {
39 | wx.stopRecord()
40 | this.setData({recording:false,recordTime:0,formatedRecordTime: '00:00:00'})
41 | clearInterval(interval)
42 | },
43 | playVoice: function () {
44 | var that = this
45 | playTimeInterval = setInterval(function () {
46 | that.data.playTime += 1
47 | that.setData({
48 | playing: true,
49 | formatedPlayTime: util.formatTime(that.data.playTime)
50 | })
51 | }, 1000)
52 | wx.playVoice({
53 | filePath: this.data.tempFilePath,
54 | success: function () {
55 | clearInterval(playTimeInterval)
56 | that.data.playTime = 0
57 | that.setData({
58 | playing: false,
59 | formatedPlayTime: util.formatTime(that.data.playTime)
60 | })
61 | }
62 | })
63 | },
64 | pauseVoice: function () {
65 | clearInterval(playTimeInterval)
66 | wx.pauseVoice()
67 | this.setData({
68 | playing: false
69 | })
70 | },
71 | stopVoice: function () {
72 | clearInterval(playTimeInterval)
73 | this.data.playTime = 0
74 | this.setData({
75 | playing: false,
76 | formatedPlayTime: util.formatTime(this.data.playTime)
77 | })
78 | wx.stopVoice()
79 | },
80 | clear: function () {
81 | this.data.recordTime = 0
82 | this.data.playTime = 0
83 | this.setData({
84 | hasRecord: false,
85 | tempFilePath: '',
86 | formatedRecordTime: util.formatTime(0)
87 | })
88 | },
89 | onUnload:function(){
90 | this.stopRecord()
91 | console.log("voice page has been unloaded!")
92 | }
93 | })
94 |
--------------------------------------------------------------------------------
/page/API/voice/voice.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "录音"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/voice/voice.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | {{formatedRecordTime}}
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | {{formatedRecordTime}}
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | {{formatedPlayTime}}
38 | {{formatedRecordTime}}
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | {{formatedPlayTime}}
54 | {{formatedRecordTime}}
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/page/API/voice/voice.wxss:
--------------------------------------------------------------------------------
1 | .page-body-wrapper {
2 | justify-content: space-between;
3 | flex-grow: 1;
4 | margin-bottom: 300rpx;
5 | }
6 | .page-body-time {
7 | display: flex;
8 | flex-direction: column;
9 | align-items: center;
10 | }
11 | .time-big {
12 | font-size: 60rpx;
13 | margin: 20rpx;
14 | }
15 | .time-small {
16 | font-size: 30rpx;
17 | }
18 |
19 | .page-body-buttons {
20 | display: flex;
21 | justify-content: space-around;
22 | }
23 | .page-body-button {
24 | width: 250rpx;
25 | text-align: center;
26 | }
27 | .button-stop-record {
28 | width: 110rpx;
29 | height: 110rpx;
30 | border: 20rpx solid #fff;
31 | background-color: #f55c23;
32 | border-radius: 130rpx;
33 | margin: 0 auto;
34 | }
35 |
--------------------------------------------------------------------------------
/page/API/web-socket/web-socket.js:
--------------------------------------------------------------------------------
1 | Page({})
2 |
--------------------------------------------------------------------------------
/page/API/web-socket/web-socket.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "Web Socket"
3 | }
4 |
--------------------------------------------------------------------------------
/page/API/web-socket/web-socket.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | 搭建好自己的后台服务器后,可以跟服务器建立持久连接,实现即时聊天等功能。
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/page/API/web-socket/web-socket.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/API/web-socket/web-socket.wxss
--------------------------------------------------------------------------------
/page/component/component-pages/wx-action-sheet/wx-action-sheet.js:
--------------------------------------------------------------------------------
1 | var items = ['item1', 'item2', 'item3', 'item4']
2 | var pageObject = {
3 | data: {
4 | actionSheetHidden: true,
5 | actionSheetItems: items
6 | },
7 | actionSheetTap: function(e) {
8 | this.setData({
9 | actionSheetHidden: !this.data.actionSheetHidden
10 | })
11 | },
12 | actionSheetChange: function(e) {
13 | this.setData({
14 | actionSheetHidden: !this.data.actionSheetHidden
15 | })
16 | }
17 | }
18 |
19 | for (var i = 0; i < items.length; ++i) {
20 | (function(itemName) {
21 | pageObject['bind' + itemName] = function(e) {
22 | console.log('click' + itemName, e)
23 | }
24 | })(items[i])
25 | }
26 |
27 | Page(pageObject)
28 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-action-sheet/wx-action-sheet.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | action-sheet
4 | action-sheet
5 |
6 |
7 |
8 |
9 |
10 |
11 | {{item}}
12 |
13 | 取消
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-action-sheet/wx-action-sheet.wxss:
--------------------------------------------------------------------------------
1 | /*
2 | .cancel {
3 | color: white;
4 | background: #303F9F;
5 | }
6 | .item {
7 | color: black;
8 | background: #C5CAE9;
9 | }*/
10 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-audio/wx-audio.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | audioAction: {
4 | method: 'pause'
5 | }
6 | },
7 | audioPlayed: function(e) {
8 | console.log('audio is played')
9 | }
10 | })
--------------------------------------------------------------------------------
/page/component/component-pages/wx-audio/wx-audio.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | audio
4 | 音频
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-button/wx-button.js:
--------------------------------------------------------------------------------
1 | var types = ['default', 'primary', 'warn']
2 | var pageObject = {
3 | data: {
4 | defaultSize: 'default',
5 | primarySize: 'default',
6 | warnSize: 'default',
7 | disabled: false,
8 | plain: false,
9 | loading: false
10 | },
11 | setDisabled: function(e) {
12 | this.setData({
13 | disabled: !this.data.disabled
14 | })
15 | },
16 | setPlain: function(e) {
17 | this.setData({
18 | plain: !this.data.plain
19 | })
20 | },
21 | setLoading: function(e) {
22 | this.setData({
23 | loading: !this.data.loading
24 | })
25 | }
26 | }
27 |
28 | for (var i = 0; i < types.length; ++i) {
29 | (function(type) {
30 | pageObject[type] = function(e) {
31 | var key = type + 'Size'
32 | var changedData = {}
33 | changedData[key] =
34 | this.data[key] === 'default' ? 'mini' : 'default'
35 | this.setData(changedData)
36 | }
37 | })(types[i])
38 | }
39 |
40 | Page(pageObject)
41 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-button/wx-button.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | button
4 | 按钮
5 |
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
18 |
19 |
20 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-button/wx-button.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/component/component-pages/wx-button/wx-button.wxss
--------------------------------------------------------------------------------
/page/component/component-pages/wx-checkbox/wx-checkbox.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | items: [
4 | {name: 'USA', value: '美国'},
5 | {name: 'CHN', value: '中国', checked: 'true'},
6 | {name: 'BRA', value: '巴西'},
7 | {name: 'JPN', value: '日本'},
8 | {name: 'ENG', value: '英国'},
9 | {name: 'FRA', value: '法国'},
10 | ]
11 | },
12 | checkboxChange: function(e) {
13 | console.log('checkbox发生change事件,携带value值为:', e.detail.value)
14 | }
15 | })
16 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-checkbox/wx-checkbox.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | checkbox
4 | 多选框
5 |
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-checkbox/wx-checkbox.wxss:
--------------------------------------------------------------------------------
1 | .checkbox{
2 | display: block;
3 | margin-bottom: 10px;
4 | }
--------------------------------------------------------------------------------
/page/component/component-pages/wx-form/wx-form.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | pickerHidden: true,
4 | chosen: ''
5 | },
6 | pickerConfirm: function(e) {
7 | this.setData({
8 | pickerHidden: true
9 | })
10 | this.setData({
11 | chosen: e.detail.value
12 | })
13 | },
14 | pickerCancel: function(e) {
15 | this.setData({
16 | pickerHidden: true
17 | })
18 | },
19 | pickerShow: function(e) {
20 | this.setData({
21 | pickerHidden: false
22 | })
23 | },
24 | formSubmit: function(e) {
25 | console.log('form发生了submit事件,携带数据为:', e.detail.value)
26 | },
27 | formReset: function(e) {
28 | console.log('form发生了reset事件,携带数据为:', e.detail.value)
29 | this.setData({
30 | chosen: ''
31 | })
32 | }
33 | })
34 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-form/wx-form.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | form
4 | 表单
5 |
6 |
39 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-form/wx-form.wxss:
--------------------------------------------------------------------------------
1 | wx-button {
2 | margin-top: 10px;
3 | margin-bottom: 10px;
4 | }
5 | wx-label {
6 | display: block;
7 | margin-top: 5px;
8 | }
9 | .picker-text {
10 | margin-left: 10px;
11 | position: relative;
12 | }
13 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-icon/wx-icon.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | iconSize: [20, 30, 40, 50, 60, 70],
4 | iconColor: [
5 | 'red', 'orange', 'yellow', 'green', 'rgb(0,255,255)', 'blue', 'purple'
6 | ],
7 | iconType: [
8 | 'success', 'info', 'warn', 'waiting', 'safe_success', 'safe_warn',
9 | 'success_circle', 'success_no_circle', 'waiting_circle', 'circle', 'download',
10 | 'info_circle', 'cancel', 'search', 'clear'
11 | ]
12 | }
13 | })
14 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-icon/wx-icon.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | icon
4 | icon图标
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-icon/wx-icon.wxss:
--------------------------------------------------------------------------------
1 | .group{
2 | flex-direction: row;
3 | align-items: center;
4 | }
--------------------------------------------------------------------------------
/page/component/component-pages/wx-image/wx-image.js:
--------------------------------------------------------------------------------
1 | Page({
2 | imageError: function(e) {
3 | console.log('image3发生error事件,携带值为', e.detail.errMsg)
4 | }
5 | })
--------------------------------------------------------------------------------
/page/component/component-pages/wx-image/wx-image.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | image
4 | 图片
5 |
6 |
7 |
8 | local image
9 |
10 |
11 |
12 |
13 |
14 | internet image
15 |
16 |
18 |
19 |
20 |
21 | error image
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-image/wx-image.wxss:
--------------------------------------------------------------------------------
1 | .section__ctn{
2 | text-align: center;
3 | }
--------------------------------------------------------------------------------
/page/component/component-pages/wx-input/wx-input.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data:{
3 | focus:false,
4 | inputValue:""
5 | },
6 | bindButtonTap:function(){
7 | this.setData({
8 | focus:true
9 | })
10 | },
11 | bindKeyInput:function(e){
12 | this.setData({
13 | inputValue:e.detail.value
14 | })
15 | },
16 | bindReplaceInput:function(e){
17 | var value = e.detail.value;
18 | var pos = e.detail.cursor;
19 | if(pos != -1){
20 | //光标在中间
21 | var left = e.detail.value.slice(0,pos);
22 | //计算光标的位置
23 | pos = left.replace(/11/g,'2').length;
24 | }
25 |
26 | //直接返回对象,可以对输入进行过滤处理,同时可以控制光标的位置
27 | return {
28 | value:value.replace(/11/g,'2'),
29 | cursor:pos
30 | }
31 |
32 | //或者直接返回字符串,光标在最后边
33 | //return value.replace(/11/g,'2'),
34 | },
35 | bindHideKeyboard:function(e){
36 | if(e.detail.value === "123"){
37 | //收起键盘
38 | wx.hideKeyboard();
39 | }
40 | }
41 | })
--------------------------------------------------------------------------------
/page/component/component-pages/wx-input/wx-input.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | input
4 | 输入框
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | 你输入的是:{{inputValue}}
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-input/wx-input.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/component/component-pages/wx-input/wx-input.wxss
--------------------------------------------------------------------------------
/page/component/component-pages/wx-label/wx-label.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | checkboxItems: [
4 | {name: 'USA', value: '美国'},
5 | {name: 'CHN', value: '中国', checked: 'true'},
6 | {name: 'BRA', value: '巴西'},
7 | {name: 'JPN', value: '日本', checked: 'true'},
8 | {name: 'ENG', value: '英国'},
9 | {name: 'FRA', value: '法国'},
10 | ],
11 | radioItems: [
12 | {name: 'USA', value: '美国'},
13 | {name: 'CHN', value: '中国', checked: 'true'},
14 | {name: 'BRA', value: '巴西'},
15 | {name: 'JPN', value: '日本'},
16 | {name: 'ENG', value: '英国'},
17 | {name: 'FRA', value: '法国'},
18 | ],
19 | hidden: false
20 | },
21 | checkboxChange: function(e) {
22 | var checked = e.detail.value
23 | var changed = {}
24 | for (var i = 0; i < this.data.checkboxItems.length; i ++) {
25 | if (checked.indexOf(this.data.checkboxItems[i].name) !== -1) {
26 | changed['checkboxItems['+i+'].checked'] = true
27 | } else {
28 | changed['checkboxItems['+i+'].checked'] = false
29 | }
30 | }
31 | this.setData(changed)
32 | },
33 | radioChange: function(e) {
34 | var checked = e.detail.value
35 | var changed = {}
36 | for (var i = 0; i < this.data.radioItems.length; i ++) {
37 | if (checked.indexOf(this.data.radioItems[i].name) !== -1) {
38 | changed['radioItems['+i+'].checked'] = true
39 | } else {
40 | changed['radioItems['+i+'].checked'] = false
41 | }
42 | }
43 | this.setData(changed)
44 | },
45 | tapEvent: function(e) {
46 | console.log('按钮被点击')
47 | }
48 | })
49 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-label/wx-label.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | label
4 | 标签
5 |
6 |
7 |
8 | 表单组件在label内
9 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 | label用for标识表单组件
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | 绑定button
32 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | label内有多个时选中第一个
42 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-label/wx-label.wxss:
--------------------------------------------------------------------------------
1 | .label-1, .label-2{
2 | margin-bottom: 15px;
3 | }
4 |
5 | .label-4_text{
6 | text-align: center;
7 | margin-top: 15px;
8 | }
--------------------------------------------------------------------------------
/page/component/component-pages/wx-mask/wx-mask.js:
--------------------------------------------------------------------------------
1 | var pageData = {}
2 | var maskNum = 4
3 | pageData.data = {}
4 | for(var i = 1; i <= maskNum; ++i) {
5 | pageData.data[`hidden${i}`] = true;
6 |
7 | (function(index) {
8 | pageData[`tap${index}`] = function(e) {
9 | var obj = {}
10 | obj[`hidden${index}`] = false
11 | this.setData(obj)
12 | }
13 | pageData[`mask${index}`] = function(e) {
14 | var obj = {}
15 | obj[`hidden${index}`] = true
16 | this.setData(obj)
17 | }
18 | })(i);
19 | }
20 | Page(pageData)
21 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-mask/wx-mask.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | mask
4 | 遮罩
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-modal/wx-modal.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | modalHidden: true,
4 | modalHidden2: true
5 | },
6 | modalTap: function(e) {
7 | this.setData({
8 | modalHidden: false
9 | })
10 | },
11 | modalChange: function(e) {
12 | this.setData({
13 | modalHidden: true
14 | })
15 | },
16 | modalTap2: function(e) {
17 | this.setData({
18 | modalHidden2: false
19 | })
20 | },
21 | modalChange2: function(e) {
22 | this.setData({
23 | modalHidden2: true
24 | })
25 | },
26 | })
27 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-modal/wx-modal.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | modal
4 | 模式对话框
5 |
6 |
7 |
8 | 这是对话框的内容。
9 |
10 |
11 |
12 | 没有标题没有取消的对话框
13 | 内容可以插入节点
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-navigator/navigate.js:
--------------------------------------------------------------------------------
1 | Page({
2 | onLoad: function(options) {
3 | console.log(options)
4 | this.setData({
5 | title: options.title
6 | })
7 | }
8 | })
9 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-navigator/navigate.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | {{title}}
4 | 这是新建的页面,点击左上角返回回到之前页面
5 |
6 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-navigator/redirect.js:
--------------------------------------------------------------------------------
1 | Page({
2 | onLoad: function(options) {
3 | console.log(options)
4 | this.setData({
5 | title: options.title
6 | })
7 | }
8 | })
9 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-navigator/redirect.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | {{title}}
4 | 这是当前页,点击左上角返回回到上级菜单
5 |
6 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-navigator/wx-navigator.js:
--------------------------------------------------------------------------------
1 | Page({})
--------------------------------------------------------------------------------
/page/component/component-pages/wx-navigator/wx-navigator.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | navigator
4 | 导航栏
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-navigator/wx-navigator.wxss:
--------------------------------------------------------------------------------
1 | .navigator-hover button{
2 | background-color:blue;
3 | }
4 | .other-navigator-hover button{
5 | background-color:red;
6 | }
--------------------------------------------------------------------------------
/page/component/component-pages/wx-picker/wx-picker.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | array:["中国","美国","巴西","日本"],
4 | index:0,
5 | date:"2016-09-01",
6 | time:"12:01"
7 | },
8 | bindPickerChange: function(e) {
9 | console.log('picker发送选择改变,携带值为', e.detail.value)
10 | this.setData({
11 | index: e.detail.value
12 | })
13 | },
14 | bindDateChange:function(e){
15 | this.setData({
16 | date:e.detail.value
17 | })
18 | },
19 | bindTimeChange:function(e){
20 | this.setData({
21 | time:e.detail.time
22 | })
23 | }
24 | })
--------------------------------------------------------------------------------
/page/component/component-pages/wx-picker/wx-picker.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | picker
4 | 选择器
5 |
6 |
7 |
8 | 地区选择器
9 |
10 |
11 | 当前选择:{{array[index]}}
12 |
13 |
14 |
15 |
16 | 时间选择器
17 |
18 |
19 | 当前选择: {{time}}
20 |
21 |
22 |
23 |
24 |
25 | 日期选择器
26 |
27 |
28 | 当前选择: {{date}}
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-picker/wx-picker.wxss:
--------------------------------------------------------------------------------
1 | .picker{
2 | padding: 13px;
3 | background-color: #FFFFFF;
4 | }
--------------------------------------------------------------------------------
/page/component/component-pages/wx-progress/wx-progress.js:
--------------------------------------------------------------------------------
1 | Page({})
2 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-progress/wx-progress.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | progress
4 | 进度条
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-progress/wx-progress.wxss:
--------------------------------------------------------------------------------
1 | progress{
2 | margin-bottom: 30px;
3 | }
--------------------------------------------------------------------------------
/page/component/component-pages/wx-radio/wx-radio.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | items: [
4 | {name: 'USA', value: '美国'},
5 | {name: 'CHN', value: '中国', checked: 'true'},
6 | {name: 'BRA', value: '巴西'},
7 | {name: 'JPN', value: '日本'},
8 | {name: 'ENG', value: '英国'},
9 | {name: 'FRA', value: '法国'},
10 | ]
11 | },
12 | radioChange: function(e) {
13 | console.log('radio发生change事件,携带value值为:', e.detail.value)
14 | }
15 | })
16 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-radio/wx-radio.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | radio
4 | 单选框
5 |
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-radio/wx-radio.wxss:
--------------------------------------------------------------------------------
1 | .radio {
2 | display: block;
3 | margin-bottom: 10px;
4 | }
--------------------------------------------------------------------------------
/page/component/component-pages/wx-scroll-view/wx-scroll-view.js:
--------------------------------------------------------------------------------
1 | var order = ['green', 'red', 'yellow', 'blue', 'green']
2 | Page({
3 | data: {
4 | toView: "green"
5 | },
6 | upper: function(e) {
7 | console.log(e)
8 | },
9 | lower: function(e) {
10 | console.log(e)
11 | },
12 | scroll: function(e) {
13 | console.log(e)
14 | },
15 | scrollToTop: function(e) {
16 | this.setData({
17 | scrollTop: 0
18 | })
19 | },
20 | tap: function(e) {
21 | for (var i = 0; i < order.length; ++i) {
22 | if (order[i] === this.data.toView) {
23 | this.setData({
24 | toView: order[i + 1],
25 | scrollTop: (i + 1) * 200
26 | })
27 | break
28 | }
29 | }
30 | },
31 | tapMove: function(e) {
32 | this.setData({
33 | scrollTop: this.data.scrollTop + 10
34 | })
35 | }
36 | })
37 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-scroll-view/wx-scroll-view.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | scroll-view
4 | 可滚动视图区域。
5 |
6 |
7 |
8 | vertical scroll
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | horizontal scroll
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-scroll-view/wx-scroll-view.wxss:
--------------------------------------------------------------------------------
1 | .scroll-view_H{
2 | white-space: nowrap;
3 | }
4 | .scroll-view-item{
5 | height: 200px;
6 | }
7 | .scroll-view-item_H{
8 | display: inline-block;
9 | width: 100%;
10 | height: 200px;
11 | }
--------------------------------------------------------------------------------
/page/component/component-pages/wx-slide-tab/wx-slide-tab.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | texts: [
4 | '这是第1个tab\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n嘻嘻,到底了',
5 | '这是第2个tab\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n嘻嘻,到底了',
6 | '这是第3个tab\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n嘻嘻,到底了'
7 | ]
8 | },
9 | tabchange: function(e){
10 | console.log('现在跳转到了第 ' + e.detail.current + ' 个tab')
11 | }
12 | })
13 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-slide-tab/wx-slide-tab.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | slide-tab
4 | slide-tab
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | {{item}}
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-slide-tab/wx-slide-tab.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/component/component-pages/wx-slide-tab/wx-slide-tab.wxss
--------------------------------------------------------------------------------
/page/component/component-pages/wx-slider/wx-slider.js:
--------------------------------------------------------------------------------
1 | var pageData = {}
2 | for(var i = 1; i < 5; ++i) {
3 | (function (index) {
4 | pageData[`slider${index}change`] = function(e) {
5 | console.log(`slider${index}发生change事件,携带值为`, e.detail.value)
6 | }
7 | })(i);
8 | }
9 | Page(pageData)
--------------------------------------------------------------------------------
/page/component/component-pages/wx-slider/wx-slider.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | slider
4 | 滑块
5 |
6 |
7 |
8 | 设置step
9 |
10 |
11 |
12 |
13 |
14 |
15 | 显示当前value
16 |
17 |
18 |
19 |
20 |
21 |
22 | 设置最小/最大值
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-swiper/wx-swiper.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data: {
3 | background: ['green', 'red', 'yellow'],
4 | indicatorDots: true,
5 | vertical: false,
6 | autoplay: false,
7 | interval: 3000,
8 | duration: 1000
9 | },
10 | changeIndicatorDots: function (e) {
11 | this.setData({
12 | indicatorDots: !this.data.indicatorDots
13 | })
14 | },
15 | changeVertical: function (e) {
16 | this.setData({
17 | vertical: !this.data.vertical
18 | })
19 | },
20 | changeAutoplay: function (e) {
21 | this.setData({
22 | autoplay: !this.data.autoplay
23 | })
24 | },
25 | intervalChange: function (e) {
26 | this.setData({
27 | interval: e.detail.value
28 | })
29 | },
30 | durationChange: function (e) {
31 | this.setData({
32 | duration: e.detail.value
33 | })
34 | }
35 | })
36 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-swiper/wx-swiper.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | swiper
4 | swiper
5 |
6 |
7 |
8 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | duration
24 |
25 | interval
26 |
27 |
28 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-swiper/wx-swiper.wxss:
--------------------------------------------------------------------------------
1 | .swiper-item{
2 | display: block;
3 | height: 150px;
4 | }
--------------------------------------------------------------------------------
/page/component/component-pages/wx-switch/wx-switch.js:
--------------------------------------------------------------------------------
1 | var pageData = {
2 | data: {
3 | switch1Checked: true,
4 | switch2Checked: false,
5 | switch1Style: '',
6 | switch2Style: 'text-decoration: line-through'
7 | }
8 | }
9 | for(var i = 1; i <= 2; ++i) {
10 | (function(index) {
11 | pageData[`switch${index}Change`] = function(e) {
12 | console.log(`switch${index}发生change事件,携带值为`, e.detail.value)
13 | var obj = {}
14 | obj[`switch${index}Checked`] = e.detail.value
15 | this.setData(obj)
16 | obj = {}
17 | obj[`switch${index}Style`] = e.detail.value ? '' : 'text-decoration: line-through'
18 | this.setData(obj)
19 | }
20 | })(i)
21 | }
22 | Page(pageData)
--------------------------------------------------------------------------------
/page/component/component-pages/wx-switch/wx-switch.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | switch
4 | 开关
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-text/wx-text.js:
--------------------------------------------------------------------------------
1 | var initData = 'this is first line\nthis is second line'
2 | Page({
3 | data: {
4 | text: initData
5 | },
6 | extraLine: [],
7 | add: function(e) {
8 | this.extraLine.push('other line')
9 | this.setData({
10 | text: initData + '\n' + this.extraLine.join('\n')
11 | })
12 | },
13 | remove: function(e) {
14 | if (this.extraLine.length > 0) {
15 | this.extraLine.pop()
16 | this.setData({
17 | text: initData + '\n' + this.extraLine.join('\n')
18 | })
19 | }
20 | }
21 | })
22 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-text/wx-text.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | text
4 | 文字标签
5 |
6 |
7 |
8 | {{text}}
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-toast/wx-toast.js:
--------------------------------------------------------------------------------
1 | var toastNum = 3
2 | var pageData = {}
3 | pageData.data = {}
4 | for(var i = 0; i <= toastNum; ++i) {
5 | pageData.data['toast'+i+'Hidden'] = true;
6 | (function (index) {
7 | pageData['toast'+index+'Change'] = function(e) {
8 | var obj = {}
9 | obj['toast'+index+'Hidden'] = true;
10 | this.setData(obj)
11 | }
12 | pageData['toast'+index+'Tap'] = function(e) {
13 | var obj = {}
14 | obj['toast'+index+'Hidden'] = false
15 | this.setData(obj)
16 | }
17 | })(i)
18 | }
19 | Page(pageData)
20 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-toast/wx-toast.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | toast
4 | toast提示
5 |
6 |
7 |
8 |
9 |
10 | 默认
11 |
12 |
13 |
14 |
15 |
16 | 设置icon
17 |
18 |
19 |
20 |
21 |
22 | 设置duration
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-video/wx-video.js:
--------------------------------------------------------------------------------
1 | Page({
2 | data:{
3 | src:""
4 | },
5 | bindButtonTap:function(){
6 | var that = this;
7 | wx.chooseVideo({
8 | sourceType:['album','camera'],
9 | maxDuration:60,
10 | camera:['front','back'],
11 | success:function(res){
12 | that.setData({
13 | src:res.tempFilePath
14 | })
15 | }
16 | })
17 | },
18 | videoErrorCallback: function (e) {
19 | console.log('视频错误信息:');
20 | console.log(e.detail.errMsg);
21 | }
22 | })
--------------------------------------------------------------------------------
/page/component/component-pages/wx-video/wx-video.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | video
4 | 视频
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-view/wx-view.js:
--------------------------------------------------------------------------------
1 | Page({})
2 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-view/wx-view.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | view
4 | 弹性框模型分为弹性容器以及弹性项目。当组件的display为flex或inline-flex时,该组件则为弹性容器,弹性容器的子组件为弹性项目。
5 |
6 |
7 |
8 | flex-direction: row
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | flex-direction: column
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | justify-content: flex-start
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | justify-content: flex-end
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | justify-content: center
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | justify-content: space-between
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | justify-content: space-around
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | align-items: flex-end
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | align-items: center
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/page/component/component-pages/wx-view/wx-view.wxss:
--------------------------------------------------------------------------------
1 | .flex-wrp{
2 | height: 100px;
3 | display:flex;
4 | background-color: #FFFFFF;
5 | }
6 | .flex-item{
7 | width: 100px;
8 | height: 100px;
9 | }
--------------------------------------------------------------------------------
/page/component/index.js:
--------------------------------------------------------------------------------
1 | var pageData = {},
2 | type = [
3 | 'view', 'content', 'form', 'interact', 'nav', 'media', 'map', 'canvas'
4 | ];
5 |
6 | pageData.widgetsToggle = function (e) {
7 | var id = e.currentTarget.id, data = {};
8 | for (var i = 0, len = type.length; i < len; ++i) {
9 | data[type[i] + 'Show'] = false;
10 | }
11 | data[id + 'Show'] = !this.data[id + 'Show'];
12 | this.setData(data);
13 | };
14 |
15 | Page(pageData);
--------------------------------------------------------------------------------
/page/component/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 小程序组件
4 | 这是展示小程序组件的DEMO。
5 |
6 |
7 |
8 |
9 |
10 |
11 | 内容分区
12 |
13 |
14 |
15 |
16 | view
17 |
18 |
19 |
20 |
21 | scroll-view
22 |
23 |
24 |
25 |
26 | swiper
27 |
28 |
29 |
30 |
31 |
32 |
33 | 内容
34 |
35 |
36 |
37 |
38 | text
39 |
40 |
41 |
42 |
43 | icon
44 |
45 |
46 |
47 |
48 | mask
49 |
50 |
51 |
52 |
53 | toast
54 |
55 |
56 |
57 |
58 | progress
59 |
60 |
61 |
62 |
63 |
64 |
65 | 表单组件
66 |
67 |
68 |
69 |
70 | button
71 |
72 |
73 |
74 |
75 | checkbox
76 |
77 |
78 |
79 |
80 | form
81 |
82 |
83 |
84 |
85 | input
86 |
87 |
88 |
89 |
90 | label
91 |
92 |
93 |
94 |
95 | picker
96 |
97 |
98 |
99 |
100 | radio
101 |
102 |
103 |
104 |
105 | slider
106 |
107 |
108 |
109 |
110 | switch
111 |
112 |
113 |
114 |
115 |
116 |
117 | 交互组件
118 |
119 |
120 |
121 |
122 | action-sheet
123 |
124 |
125 |
126 |
127 | modal
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 | 导航
136 |
137 |
138 |
139 |
140 | navigator
141 |
142 |
143 |
144 |
145 |
146 |
147 | 媒体
148 |
149 |
150 |
151 |
152 |
153 | image
154 |
155 |
156 |
157 |
158 | audio
159 |
160 |
161 |
162 |
163 | video
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
--------------------------------------------------------------------------------
/page/component/index.wxss:
--------------------------------------------------------------------------------
1 | .index{
2 | background-color: #FBF9FE;
3 | font-family: -apple-system-font,Helvetica Neue,Helvetica,sans-serif;
4 | flex: 1;
5 | min-height: 100%;
6 | font-size: 16px;
7 | }
8 | .head{
9 | padding: 40px;
10 | }
11 | .body{
12 | padding-left: 15px;
13 | padding-right: 15px;
14 | overflow: hidden;
15 | }
16 | .title{
17 | font-size: 30px;
18 | }
19 | .desc{
20 | margin-top: 5px;
21 | color: #888888;
22 | font-size: 14px;
23 | }
24 |
25 | .widgets__item{
26 | margin-top: 10px;
27 | margin-bottom: 10px;
28 | background-color: #FFFFFF;
29 | overflow: hidden;
30 | border-radius: 2px;
31 | cursor: pointer;
32 | }
33 | .widgets__info{
34 | display: flex;
35 | padding: 20px;
36 | align-items: center;
37 | flex-direction: row;
38 | }
39 | .widgets__info_show{
40 | opacity: .4;
41 | }
42 | .widgets__info-name{
43 | flex: 1;
44 | }
45 | .widgets__info-img{
46 | width: 30px;
47 | height: 30px;
48 | }
49 |
50 | .widgets__list{
51 | display: none;
52 | }
53 | .widgets__list_show{
54 | display: block;
55 | }
56 | /*
57 | .widgets__list{
58 | height: 0;
59 | overflow: hidden;
60 | }
61 | .widgets__list_show{
62 | height: auto;
63 | }
64 | .widgets__list-inner{
65 | opacity: 0;
66 | transform: translateY(-50%);
67 | transition: .3s;
68 | }
69 | .widgets__list-inner_show{
70 | opacity: 1;
71 | transform: translateY(0);
72 | }
73 | */
74 |
75 | .widget{
76 | position: relative;
77 | padding-top: 13px;
78 | padding-bottom: 13px;
79 | padding-left: 20px;
80 | padding-right: 20px;
81 | }
82 | .widget__arrow{
83 | position: absolute;
84 | top: 14px;
85 | right: 22px;
86 | width: 8px;
87 | height: 16px;
88 | }
89 | .widget__line{
90 | content: " ";
91 | position: absolute;
92 | left: 20px;
93 | bottom: 0;
94 | right: 20px;
95 | height: 1rpx;
96 | background-color: #DFDFDF;
97 | }
--------------------------------------------------------------------------------
/page/component/navigation-pages/controller/controller.js:
--------------------------------------------------------------------------------
1 | var components = [
2 | 'action-sheet', 'button', 'searchbar', 'modal', 'navigator', 'drawer'
3 | ]
4 | var pageData = {}
5 | for(var i = 0; i < components.length; ++i) {
6 | (function (index) {
7 | pageData[components[index]] = function(e) {
8 | var url = '../../component-pages/wx-' + components[index] + '/wx-' + components[index]
9 | wx.navigateTo({url: url})
10 | }
11 | })(i);
12 | }
13 | Page(pageData)
--------------------------------------------------------------------------------
/page/component/navigation-pages/controller/controller.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/page/component/navigation-pages/form/form.js:
--------------------------------------------------------------------------------
1 | var components = [
2 | 'checkbox', 'radio', 'form','selector', 'switch', 'slider', 'input', 'label', 'picker'
3 | ]
4 | var pageData = {}
5 | for(var i = 0; i < components.length; ++i) {
6 | (function (index) {
7 | pageData[components[index]] = function(e) {
8 | var url = '../../component-pages/wx-' + components[index] + '/wx-' + components[index]
9 | wx.navigateTo({url: url})
10 | }
11 | })(i);
12 | }
13 | Page(pageData)
--------------------------------------------------------------------------------
/page/component/navigation-pages/form/form.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/page/component/navigation-pages/media/media.js:
--------------------------------------------------------------------------------
1 | var components = [
2 | 'image', 'audio', 'video'
3 | ]
4 | var pageData = {}
5 | for(var i = 0; i < components.length; ++i) {
6 | (function (index) {
7 | pageData[components[index]] = function(e) {
8 | var url = '../../component-pages/wx-' + components[index] + '/wx-' + components[index]
9 | wx.navigateTo({url: url})
10 | }
11 | })(i)
12 | }
13 | Page(pageData)
--------------------------------------------------------------------------------
/page/component/navigation-pages/media/media.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/page/component/navigation-pages/view/view.js:
--------------------------------------------------------------------------------
1 | var components = [
2 | 'progress', 'toast', 'scroll-view', 'text', 'view', 'mask', 'icon', 'spinner', 'swiper', 'slide-tab'
3 | ]
4 | var pageData = {}
5 | for(var i = 0; i < components.length; ++i) {
6 | (function (index) {
7 | pageData[components[index]] = function(e) {
8 | var url = '../../component-pages/wx-' + components[index] + '/wx-' + components[index]
9 | wx.navigateTo({url: url})
10 | }
11 | })(i)
12 | }
13 | Page(pageData)
14 |
--------------------------------------------------------------------------------
/page/component/navigation-pages/view/view.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/page/component/resources/arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/component/resources/arrow.png
--------------------------------------------------------------------------------
/page/component/resources/kind/canvas.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/component/resources/kind/canvas.png
--------------------------------------------------------------------------------
/page/component/resources/kind/content.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/component/resources/kind/content.png
--------------------------------------------------------------------------------
/page/component/resources/kind/form.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/component/resources/kind/form.png
--------------------------------------------------------------------------------
/page/component/resources/kind/interact.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/component/resources/kind/interact.png
--------------------------------------------------------------------------------
/page/component/resources/kind/map.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/component/resources/kind/map.png
--------------------------------------------------------------------------------
/page/component/resources/kind/media.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/component/resources/kind/media.png
--------------------------------------------------------------------------------
/page/component/resources/kind/nav.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/component/resources/kind/nav.png
--------------------------------------------------------------------------------
/page/component/resources/kind/view.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/component/resources/kind/view.png
--------------------------------------------------------------------------------
/page/component/resources/pic.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwartz/wechat-app-demo/e23c943405fc10a3a76aec7eca3e2bf5f90810b7/page/component/resources/pic.jpg
--------------------------------------------------------------------------------
/util/util.js:
--------------------------------------------------------------------------------
1 | function formatTime(time) {
2 | if (typeof time !== 'number' || time < 0) {
3 | return time
4 | }
5 |
6 | var hour = parseInt(time / 3600)
7 | time = time % 3600
8 | var minute = parseInt(time / 60)
9 | time = time % 60
10 | // 这里秒钟也取整
11 | var second = parseInt(time)
12 |
13 | return ([hour, minute, second]).map(function (n) {
14 | n = n.toString()
15 | return n[1] ? n : '0' + n
16 | }).join(':')
17 | }
18 |
19 | module.exports = {
20 | formatTime: formatTime
21 | }
--------------------------------------------------------------------------------