├── QQZJ
├── .gitignore
├── pages
│ ├── msg
│ │ ├── msg.json
│ │ ├── msg.wxss
│ │ ├── msg.wxml
│ │ └── msg.js
│ ├── post
│ │ ├── post.json
│ │ ├── post.wxml
│ │ ├── post.wxss
│ │ └── post.js
│ ├── rank
│ │ ├── rank.json
│ │ ├── rank.wxml
│ │ ├── rank.wxss
│ │ └── rank.js
│ ├── index
│ │ ├── index.json
│ │ ├── index.wxml
│ │ ├── index.wxss
│ │ └── index.js
│ ├── login
│ │ ├── login.json
│ │ ├── login.wxml
│ │ ├── login.wxss
│ │ └── login.js
│ ├── user
│ │ ├── user.json
│ │ ├── posts
│ │ │ ├── posts.json
│ │ │ ├── posts.wxml
│ │ │ ├── posts.wxss
│ │ │ └── posts.js
│ │ ├── user.wxml
│ │ ├── user.wxss
│ │ └── user.js
│ └── profile
│ │ ├── profile.json
│ │ ├── mylike
│ │ ├── mylike.json
│ │ ├── mylike.wxml
│ │ ├── mylike.wxss
│ │ └── mylike.js
│ │ ├── mypost
│ │ ├── mypost.json
│ │ ├── mypost.wxml
│ │ ├── mypost.wxss
│ │ └── mypost.js
│ │ ├── post
│ │ ├── post.json
│ │ ├── post.wxml
│ │ ├── post.wxss
│ │ └── post.js
│ │ ├── profile.js
│ │ ├── profile.wxml
│ │ └── profile.wxss
├── icons
│ ├── add.png
│ ├── msg.png
│ ├── index.png
│ ├── like.png
│ ├── post.png
│ ├── rank.png
│ ├── myfavor.png
│ ├── mypost.png
│ ├── profile.png
│ ├── unlike.png
│ └── arrow-right.png
├── app.js
├── app.wxss
├── app.json
└── utils
│ ├── util.js
│ ├── funcs.js
│ └── untitled.js
├── README.md
├── FileStructure.md
└── Something-that-wxadoc-don't-tell-you.md
/QQZJ/.gitignore:
--------------------------------------------------------------------------------
1 | *swp
2 |
--------------------------------------------------------------------------------
/QQZJ/pages/msg/msg.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/QQZJ/pages/post/post.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/QQZJ/pages/rank/rank.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/QQZJ/pages/index/index.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/QQZJ/pages/login/login.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/QQZJ/pages/msg/msg.wxss:
--------------------------------------------------------------------------------
1 | /* pages/msg/msg.wxss */
--------------------------------------------------------------------------------
/QQZJ/pages/user/user.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "查看用户"
3 | }
--------------------------------------------------------------------------------
/QQZJ/pages/profile/profile.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "个人中心"
3 | }
--------------------------------------------------------------------------------
/QQZJ/pages/user/posts/posts.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "用户发布"
3 | }
--------------------------------------------------------------------------------
/QQZJ/icons/add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/actini/WeChatAPP/HEAD/QQZJ/icons/add.png
--------------------------------------------------------------------------------
/QQZJ/icons/msg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/actini/WeChatAPP/HEAD/QQZJ/icons/msg.png
--------------------------------------------------------------------------------
/QQZJ/pages/profile/mylike/mylike.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "我的收藏"
3 | }
--------------------------------------------------------------------------------
/QQZJ/pages/profile/mypost/mypost.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "我发布的"
3 | }
--------------------------------------------------------------------------------
/QQZJ/pages/profile/post/post.json:
--------------------------------------------------------------------------------
1 | {
2 |
3 | "navigationBarTitleText": "发布内容"
4 | }
--------------------------------------------------------------------------------
/QQZJ/icons/index.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/actini/WeChatAPP/HEAD/QQZJ/icons/index.png
--------------------------------------------------------------------------------
/QQZJ/icons/like.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/actini/WeChatAPP/HEAD/QQZJ/icons/like.png
--------------------------------------------------------------------------------
/QQZJ/icons/post.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/actini/WeChatAPP/HEAD/QQZJ/icons/post.png
--------------------------------------------------------------------------------
/QQZJ/icons/rank.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/actini/WeChatAPP/HEAD/QQZJ/icons/rank.png
--------------------------------------------------------------------------------
/QQZJ/pages/msg/msg.wxml:
--------------------------------------------------------------------------------
1 |
2 | pages/msg/msg.wxml
3 |
--------------------------------------------------------------------------------
/QQZJ/icons/myfavor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/actini/WeChatAPP/HEAD/QQZJ/icons/myfavor.png
--------------------------------------------------------------------------------
/QQZJ/icons/mypost.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/actini/WeChatAPP/HEAD/QQZJ/icons/mypost.png
--------------------------------------------------------------------------------
/QQZJ/icons/profile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/actini/WeChatAPP/HEAD/QQZJ/icons/profile.png
--------------------------------------------------------------------------------
/QQZJ/icons/unlike.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/actini/WeChatAPP/HEAD/QQZJ/icons/unlike.png
--------------------------------------------------------------------------------
/QQZJ/icons/arrow-right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/actini/WeChatAPP/HEAD/QQZJ/icons/arrow-right.png
--------------------------------------------------------------------------------
/QQZJ/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | onLaunch: function () {
4 | //调用API从本地缓存中获取数据
5 | },
6 | onShow: function () {
7 | let cache = wx.getStorageSync('userInfo')
8 | if(cache){
9 | this.globalData.userInfo = cache
10 | }
11 | },
12 | globalData:{
13 | userInfo:{id:null}
14 | }
15 | })
--------------------------------------------------------------------------------
/QQZJ/pages/msg/msg.js:
--------------------------------------------------------------------------------
1 | // pages/msg/msg.js
2 | Page({
3 | data:{},
4 | onLoad:function(options){
5 | // 页面初始化 options为页面跳转所带来的参数
6 | },
7 | onReady:function(){
8 | // 页面渲染完成
9 | },
10 | onShow:function(){
11 | // 页面显示
12 | },
13 | onHide:function(){
14 | // 页面隐藏
15 | },
16 | onUnload:function(){
17 | // 页面关闭
18 | }
19 | })
--------------------------------------------------------------------------------
/QQZJ/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | page{
3 | margin: 0rpx;
4 | padding: 0rpx;
5 | width: 100%;
6 | font-family: "微软雅黑";
7 | background: #efefef;
8 | font-size: 1rem;
9 | }
10 | .font-big {
11 | font-size: 1.25rem;
12 | }
13 | .font-mid {
14 | font-size: 1rem;
15 | }
16 | .font-small {
17 | font-size: 0.75rem;
18 | }
19 | .clear {
20 | clear: both;
21 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 说明
2 |
3 | ## 本文件包含以下内容:
4 |
5 | * 小程序源码
6 |
7 | > QQZJ
8 |
9 | * 小程序开发技巧总结
10 |
11 | > Something-that-wxadoc-don't-tell-you.md
12 |
13 | * 项目文件结构
14 |
15 | > FileStructure.md
16 |
17 | ## 使用说明:
18 |
19 | 1. 打开微信开发者工具 - 选择微信小程序
20 |
21 | 2. 创建项目 - 选择无 appid
22 |
23 | 3. 设置项目路径 - 确定
24 |
25 | 4. 点击左侧项目选项 - 勾选“开发环境不校验请求域名以及 TLS 版本”
26 |
27 | 5. DO WHAT YOU CAN AND YOU WANT
28 |
29 | ## TIPS
30 |
31 | * 本项目的服务器文件地址为 http://wx.romeo.wang
32 |
33 | * 服务器文件与一般 web 开发的文件相同,本项目服务器为 PHP 脚本文件
34 |
35 | * 如需要服务器文件(*.php)请[微博](http://weibo.com/zijian000)私信我并留下邮箱,或者发送邮件至 romeo0906@foxmail.com。
--------------------------------------------------------------------------------
/FileStructure.md:
--------------------------------------------------------------------------------
1 | ### QQZJ 小程序目录结构
2 |
3 | ```
4 | QQZJ // 项目根目录
5 |
6 | |—icons // 静态图标
7 |
8 | |—pages // 页面目录
9 |
10 | |—index // 主页
11 |
12 | |—login // 登录
13 |
14 | |—msg // 消息
15 |
16 | |—post // 帖子详情
17 |
18 | |—profile // 个人中心
19 |
20 | |—mylike // 我的收藏
21 |
22 | |—mypost // 我的发帖
23 |
24 | |—post // 发帖
25 |
26 | |—rank // 排行
27 |
28 | |—user // 用户信息
29 |
30 | |—posts // 用户帖子列表
31 |
32 | |—utils // 公共函数库
33 |
34 | |—funcs.js // 自定义函数文件
35 |
36 | |—untitled.js // 微信 API 封装文件
37 |
38 | |—util.js // 函数整合文件
39 |
40 | |—app.js // 项目逻辑文件
41 |
42 | |—app.json // 项目配置文件
43 |
44 | |—app.wxss // 项目样式文件
45 | ```
46 |
47 |
--------------------------------------------------------------------------------
/QQZJ/pages/login/login.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{msg}}
5 |
6 |
7 |
17 |
18 |
--------------------------------------------------------------------------------
/QQZJ/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | {{item.star}}
10 |
11 |
12 | {{item.ctime}}
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/QQZJ/pages/rank/rank.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | {{item.star}}
10 |
11 |
12 | {{item.ctime}}
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/QQZJ/pages/user/posts/posts.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | {{item.star}}
10 |
11 |
12 | {{item.ctime}}
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/QQZJ/pages/profile/mypost/mypost.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | {{item.star}}
10 |
11 |
12 | {{item.ctime}}
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/QQZJ/pages/profile/mylike/mylike.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | {{item.star}}
10 |
11 |
12 | {{item.nickname}}
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/QQZJ/pages/profile/post/post.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
21 |
22 |
--------------------------------------------------------------------------------
/QQZJ/pages/post/post.wxml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | 作者发布于 {{post.ctime}}
21 |
22 |
23 | {{post.outline}}
24 |
25 |
--------------------------------------------------------------------------------
/QQZJ/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /* pages/index/index.wxss */
2 | .container{
3 | width: 100%;
4 | }
5 | .section{
6 | width: 100%;
7 | }
8 | .post{
9 | width: 44%;
10 | height: 330rpx;
11 | float: left;
12 | margin-top: 30rpx;
13 | }
14 | .post-l{
15 | margin-left: 4%;
16 | margin-right: 2%;
17 | }
18 | .post-r{
19 | margin-left: 2%;
20 | margin-right: 4%;
21 | }
22 | .post image{
23 | width: 100%;
24 | height: 330rpx;
25 | display: block;
26 | }
27 | .info{
28 | width: 100%;
29 | height: 65rpx;
30 | background: rgba(50, 50, 50, 0.8);
31 | position: relative;
32 | top: -65rpx;
33 | }
34 | .like{
35 | height: 100%;
36 | width: 40%;
37 | float: left;
38 | line-height: 65rpx;
39 | color: #fff;
40 | }
41 | .like image{
42 | height: 50rpx;
43 | width: 50rpx;
44 | margin: 7.5rpx;
45 | display: block;
46 | float: left;
47 | }
48 | .ctime{
49 | height: 100%;
50 | width: 40%;
51 | float: right;
52 | line-height: 65rpx;
53 | text-align: right;
54 | padding-right: 10rpx;
55 | color: #fff;
56 | }
--------------------------------------------------------------------------------
/QQZJ/pages/rank/rank.wxss:
--------------------------------------------------------------------------------
1 | /* pages/rank/rank.wxss */
2 | .container{
3 | width: 100%;
4 | }
5 | .section{
6 | width: 100%;
7 | }
8 | .post{
9 | width: 44%;
10 | height: 330rpx;
11 | float: left;
12 | margin-top: 30rpx;
13 | }
14 | .post-l{
15 | margin-left: 4%;
16 | margin-right: 2%;
17 | }
18 | .post-r{
19 | margin-left: 2%;
20 | margin-right: 4%;
21 | }
22 | .post image{
23 | width: 100%;
24 | height: 330rpx;
25 | display: block;
26 | }
27 | .info{
28 | width: 100%;
29 | height: 65rpx;
30 | background: rgba(50, 50, 50, 0.8);
31 | position: relative;
32 | top: -65rpx;
33 | }
34 | .like{
35 | height: 100%;
36 | width: 40%;
37 | float: left;
38 | line-height: 65rpx;
39 | color: #fff;
40 | }
41 | .like image{
42 | height: 50rpx;
43 | width: 50rpx;
44 | margin: 7.5rpx;
45 | display: block;
46 | float: left;
47 | }
48 | .ctime{
49 | height: 100%;
50 | width: 40%;
51 | float: right;
52 | line-height: 65rpx;
53 | text-align: right;
54 | padding-right: 10rpx;
55 | color: #fff;
56 | }
--------------------------------------------------------------------------------
/QQZJ/pages/user/posts/posts.wxss:
--------------------------------------------------------------------------------
1 | /* pages/user/posts/posts.wxss */
2 | .container{
3 | width: 100%;
4 | }
5 | .section{
6 | width: 100%;
7 | }
8 | .post{
9 | width: 44%;
10 | height: 330rpx;
11 | float: left;
12 | margin-top: 30rpx;
13 | }
14 | .post-l{
15 | margin-left: 4%;
16 | margin-right: 2%;
17 | }
18 | .post-r{
19 | margin-left: 2%;
20 | margin-right: 4%;
21 | }
22 | .post image{
23 | width: 100%;
24 | height: 330rpx;
25 | display: block;
26 | }
27 | .info{
28 | width: 100%;
29 | height: 65rpx;
30 | background: rgba(50, 50, 50, 0.8);
31 | position: relative;
32 | top: -65rpx;
33 | }
34 | .like{
35 | height: 100%;
36 | width: 40%;
37 | float: left;
38 | line-height: 65rpx;
39 | color: #fff;
40 | }
41 | .like image{
42 | height: 50rpx;
43 | width: 50rpx;
44 | margin: 7.5rpx;
45 | display: block;
46 | float: left;
47 | }
48 | .ctime{
49 | height: 100%;
50 | width: 40%;
51 | float: right;
52 | line-height: 65rpx;
53 | text-align: right;
54 | padding-right: 10rpx;
55 | color: #fff;
56 | }
--------------------------------------------------------------------------------
/QQZJ/pages/login/login.wxss:
--------------------------------------------------------------------------------
1 | /* login.wxss */
2 | page{
3 | background: url('https://oj6nu6qqs.bkt.clouddn.com/bg1.jpg') no-repeat;
4 | background-size: 100% 100%;
5 | }
6 | .container {
7 | padding-top: 200rpx;
8 | }
9 | .msg{
10 | width: 90%;
11 | height: 80rpx;
12 | background: rgba(230, 230, 230, 0.5);
13 | margin: auto;
14 | border-radius: 20rpx;
15 | text-align: center;
16 | line-height: 80rpx;
17 | color: red;
18 | }
19 | .section{
20 | width: 90%;
21 | height: 50%;
22 | margin: auto;
23 | }
24 | .input-sect{
25 | width: 100%;
26 | }
27 | .placeholder{
28 | font-size: 1.2rem;
29 | color: #999;
30 | font-family: "微软雅黑";
31 | }
32 | input{
33 | border-radius: 10rpx;
34 | background: rgba(230, 230, 230, 0.5);
35 | margin: 30rpx auto;
36 | height: 100rpx;
37 | line-height: 100rpx;
38 | font-size: 1.35rem;
39 | font-family: "Times New Roman";
40 | padding-left: 10rpx;
41 | }
42 | .btn-sect{
43 | width: 80%;
44 | margin: auto;
45 | margin-top: 120rpx;
46 | }
47 | .btn-sect button{
48 | margin: 30rpx auto;
49 | }
--------------------------------------------------------------------------------
/QQZJ/pages/profile/mylike/mylike.wxss:
--------------------------------------------------------------------------------
1 | /* pages/profile/mylike/mylike.wxss */
2 | .container{
3 | width: 100%;
4 | }
5 | .section{
6 | width: 100%;
7 | }
8 | .post{
9 | width: 44%;
10 | height: 330rpx;
11 | float: left;
12 | margin-top: 30rpx;
13 | }
14 | .post-l{
15 | margin-left: 4%;
16 | margin-right: 2%;
17 | }
18 | .post-r{
19 | margin-left: 2%;
20 | margin-right: 4%;
21 | }
22 | .post image{
23 | width: 100%;
24 | height: 330rpx;
25 | display: block;
26 | }
27 | .info{
28 | width: 100%;
29 | height: 65rpx;
30 | background: rgba(50, 50, 50, 0.8);
31 | position: relative;
32 | top: -65rpx;
33 | }
34 | .like{
35 | height: 100%;
36 | width: 40%;
37 | float: left;
38 | line-height: 65rpx;
39 | color: #fff;
40 | }
41 | .like image{
42 | height: 50rpx;
43 | width: 50rpx;
44 | margin: 7.5rpx;
45 | display: block;
46 | float: left;
47 | }
48 | .ctime{
49 | height: 100%;
50 | width: 40%;
51 | float: right;
52 | line-height: 65rpx;
53 | text-align: right;
54 | padding-right: 10rpx;
55 | color: #fff;
56 | }
--------------------------------------------------------------------------------
/QQZJ/pages/profile/mypost/mypost.wxss:
--------------------------------------------------------------------------------
1 | /* pages/profile/mypost/mypost.wxss */
2 | .container{
3 | width: 100%;
4 | }
5 | .section{
6 | width: 100%;
7 | }
8 | .post{
9 | width: 44%;
10 | height: 330rpx;
11 | float: left;
12 | margin-top: 30rpx;
13 | }
14 | .post-l{
15 | margin-left: 4%;
16 | margin-right: 2%;
17 | }
18 | .post-r{
19 | margin-left: 2%;
20 | margin-right: 4%;
21 | }
22 | .post image{
23 | width: 100%;
24 | height: 330rpx;
25 | display: block;
26 | }
27 | .info{
28 | width: 100%;
29 | height: 65rpx;
30 | background: rgba(50, 50, 50, 0.8);
31 | position: relative;
32 | top: -65rpx;
33 | }
34 | .like{
35 | height: 100%;
36 | width: 40%;
37 | float: left;
38 | line-height: 65rpx;
39 | color: #fff;
40 | }
41 | .like image{
42 | height: 50rpx;
43 | width: 50rpx;
44 | margin: 7.5rpx;
45 | display: block;
46 | float: left;
47 | }
48 | .ctime{
49 | height: 100%;
50 | width: 40%;
51 | float: right;
52 | line-height: 65rpx;
53 | text-align: right;
54 | padding-right: 10rpx;
55 | color: #fff;
56 | }
--------------------------------------------------------------------------------
/QQZJ/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages":[
3 | "pages/index/index",
4 | "pages/profile/profile",
5 | "pages/profile/post/post",
6 | "pages/profile/mypost/mypost",
7 | "pages/profile/mylike/mylike",
8 | "pages/login/login",
9 | "pages/rank/rank",
10 | "pages/msg/msg",
11 | "pages/post/post",
12 | "pages/user/user",
13 | "pages/user/posts/posts"
14 | ],
15 | "window":{
16 | "backgroundTextStyle":"light",
17 | "navigationBarBackgroundColor": "#000",
18 | "navigationBarTitleText": "青青子衿",
19 | "navigationBarTextStyle":"white"
20 | },
21 | "tabBar": {
22 | "list": [{
23 | "pagePath": "pages/index/index",
24 | "text": "首页",
25 | "iconPath": "icons/index.png"
26 | }, {
27 | "pagePath": "pages/rank/rank",
28 | "text": "排行",
29 | "iconPath": "icons/rank.png"
30 | },{
31 | "pagePath": "pages/msg/msg",
32 | "text": "消息",
33 | "iconPath": "icons/msg.png"
34 | },{
35 | "pagePath": "pages/profile/profile",
36 | "text": "我的",
37 | "iconPath": "icons/profile.png"
38 | }],
39 | "backgroundColor": "black",
40 | "selectedColor": "white"
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/QQZJ/pages/user/user.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {{userInfo.nickname}}
6 |
7 | 发布 {{userInfo.pnum}} 个内容
8 | 收获 {{userInfo.stars}} 次收藏
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | {{item.star}}
18 |
19 |
20 | {{item.ctime}}
21 |
22 |
23 |
24 |
25 |
26 | 查看更多
--------------------------------------------------------------------------------
/QQZJ/pages/profile/post/post.wxss:
--------------------------------------------------------------------------------
1 | /* pages/profile/post/post.wxss */
2 | .container{
3 | width: 90%;
4 | margin: auto;
5 | }
6 | .img{
7 | width: 200rpx;
8 | height: 200rpx;
9 | background: #fff;
10 | margin: 30rpx 10rpx;
11 | border-radius: 10rpx;
12 | }
13 | .img-add{
14 | width: 200rpx;
15 | height: 200rpx;
16 | background: #fff;
17 | margin: 30rpx 10rpx;
18 | border-radius: 10rpx;
19 | opacity: 0.5;
20 | }
21 | .placeholder{
22 | font-size: 1.2rem;
23 | color: #999;
24 | font-family: "微软雅黑";
25 | }
26 | input{
27 | width: 100%;
28 | border-radius: 10rpx;
29 | background: rgba(255, 255, 255, 0.7);
30 | margin: 30rpx auto;
31 | height: 100rpx;
32 | line-height: 100rpx;
33 | font-size: 1.35rem;
34 | font-family: "微软雅黑";
35 | padding-left: 10rpx;
36 | }
37 | textarea{
38 | width: 100%;
39 | border-radius: 10rpx;
40 | background: rgba(255, 255, 255, 0.7);
41 | margin: 30rpx auto;
42 | line-height: 100rpx;
43 | font-size: 1.35rem;
44 | font-family: "微软雅黑";
45 | padding-left: 10rpx;
46 | }
47 | .btn-sect{
48 | display: flex;
49 | justify-content: space-between;
50 | }
51 | .btn-sect button{
52 | margin: 30rpx auto;
53 | width: 40%;
54 | }
--------------------------------------------------------------------------------
/QQZJ/pages/profile/profile.js:
--------------------------------------------------------------------------------
1 | // pages/profile/profile.js
2 | var util = require('../../utils/util.js')
3 | var app = getApp()
4 | Page({
5 | data:{
6 | userInfo: null
7 | },
8 | onShow:function(){
9 | // 页面显示
10 | this.setData({
11 | userInfo: app.globalData.userInfo
12 | })
13 | },
14 | navigate:function(e){
15 | //判断登陆状态:未登录用户以及微信用户无法跳转进入下级页面
16 | if(app.globalData.userInfo.id == null){
17 | wx.showModal({
18 | title: '提示',
19 | content: '您还未登录!',
20 | showCancel: false
21 | })
22 | }else if(app.globalData.userInfo.id == "weixin"){
23 | wx.showModal({
24 | title: '提示',
25 | content: '微信登陆用户没有权限!',
26 | showCancel: false
27 | })
28 | }else{
29 | wx.navigateTo({url: e.currentTarget.dataset.url})
30 | }
31 | },
32 | signin:function(){
33 | util.navigateTo({
34 | url: '/pages/login/login'
35 | })
36 | },
37 | signout:function(){
38 | let that = this
39 | wx.showModal({
40 | title: '提示',
41 | content: '确定要退出吗?',
42 | success: function(res) {
43 | if (res.confirm) {
44 | that.setData({
45 | userInfo: null
46 | })
47 | wx.clearStorageSync()
48 | app.globalData.userInfo = null
49 | }
50 | }
51 | })
52 | }
53 | })
--------------------------------------------------------------------------------
/QQZJ/pages/post/post.wxss:
--------------------------------------------------------------------------------
1 | /* pages/post/post.wxss */
2 | page{
3 | background: #fff;
4 | }
5 | .header{
6 | width: 100%;
7 | height: 150rpx;
8 | background: #fff;
9 | line-height: 150rpx;
10 | position: fixed;
11 | z-index: 10;
12 | border-bottom: 1rpx solid #efefef;
13 | }
14 | .avatar{
15 | float: left;
16 | width: 150rpx;
17 | height: 150rpx;
18 | }
19 | .avatar image{
20 | width: 70%;
21 | height: 70%;
22 | border-radius: 50%;
23 | display: block;
24 | margin: 15%;
25 | }
26 | .like{
27 | width: 150rpx;
28 | height: 150rpx;
29 | float: right;
30 | }
31 | .like image{
32 | width: 80%;
33 | height: 80%;
34 | margin: 10%;
35 | }
36 | .like .num{
37 | text-align: center;
38 | position: relative;
39 | z-index: 10;
40 | top: -213rpx;
41 | }
42 | .like-num{
43 | color: #fff;
44 | }
45 | .unlike-num{
46 | color: #000;
47 | }
48 | .container{
49 | width: 100%;
50 | margin-top: 150rpx;
51 | }
52 | .pic{
53 | width: 100%;
54 | height: 750rpx;
55 | margin: auto;
56 | margin-top: 20rpx;
57 | }
58 | .pic image{
59 | width: 100%;
60 | height: 100%;
61 | }
62 | .postTime{
63 | float: right;
64 | margin: 20rpx;
65 | }
66 | .outline{
67 | width: 90%;
68 | margin: 0rpx auto;
69 | line-height: 65rpx;
70 | background: #fff;
71 | text-indent: 2rem;
72 | }
--------------------------------------------------------------------------------
/QQZJ/pages/profile/profile.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 欢迎你
7 | {{userInfo.nickname}}
8 |
9 |
10 |
11 |
12 |
13 | 未登录
14 |
15 |
16 |
17 |
18 |
21 |
24 |
25 |
26 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/QQZJ/pages/index/index.js:
--------------------------------------------------------------------------------
1 | // pages/index/index.js
2 | const app = getApp()
3 | const util = require('../../utils/util.js')
4 | Page({
5 | data:{
6 | posts: null
7 | },
8 | onShow:function(){
9 | // 页面显示
10 | let that = this
11 | util.request({
12 | url: 'http://wx.romeo.wang/home/index/show',
13 | success: function(res){
14 | that.setData({
15 | posts: res.data
16 | })
17 | }
18 | })
19 | },
20 | showDetail:function(e){
21 | util.navigateTo({
22 | url:"/pages/post/post?id="+e.currentTarget.id
23 | })
24 | },
25 | like:function(e){
26 | let that = this
27 | let pid = e.currentTarget.id
28 | util.request({
29 | url: 'http://wx.romeo.wang/home/post/like',
30 | data: {"id": pid},
31 | success: function(res){
32 | // success
33 | if(res.data.err == 0){
34 | let posts = that.data.posts
35 | posts[pid].like = res.data.like
36 | posts[pid].star = res.data.star
37 | that.setData({
38 | posts: posts
39 | })
40 | wx.showToast({
41 | title: res.data.msg,
42 | icon: "success",
43 | mask: true,
44 | duration: 1000
45 | })
46 | }else{
47 | wx.showModal({
48 | title: "提示",
49 | content: res.data.msg,
50 | showCancel: false
51 | })
52 | }
53 | }
54 | })
55 | }
56 | })
--------------------------------------------------------------------------------
/QQZJ/pages/profile/profile.wxss:
--------------------------------------------------------------------------------
1 | /* pages/profile/profile.wxss */
2 | .profile{
3 | margin: 20rpx auto;
4 | margin-top: 0rpx;
5 | width: 100%;
6 | height: 400rpx;
7 | background: #fff;
8 | text-align: center;
9 | }
10 | .profile image{
11 | width: 200rpx;
12 | height: 200rpx;
13 | border-radius: 50%;
14 | margin: 15rpx;
15 | margin-top: 30rpx;
16 | }
17 | .profile text{
18 | display: block;
19 | margin: 15rpx auto;
20 | }
21 | .section{
22 | margin: 20rpx auto;
23 | width: 100%;
24 | }
25 | .section .menu{
26 | width: 100%;
27 | height: 100rpx;
28 | background: #fff;
29 | border-bottom: 1rpx solid #efefef;
30 | line-height: 100rpx;
31 | }
32 | .section .menu .icon{
33 | height: 60rpx;
34 | width: 60rpx;
35 | float: left;
36 | margin: 20rpx;
37 | }
38 | .arrow-right{
39 | background: url('/icons/arrow-right.png') no-repeat;
40 | background-size: 100% 100%;
41 | float: right;
42 | width: 60rpx;
43 | height: 60rpx;
44 | margin-right: 30rpx;
45 | margin-top: 20rpx;
46 | opacity: 0.5;
47 | }
48 | .menu .mypost{
49 | background: url("/icons/mypost.png") no-repeat;
50 | background-size: 100% 100%;
51 | }
52 | .menu .myfavor{
53 | background: url("/icons/myfavor.png") no-repeat;
54 | background-size: 100% 100%;
55 | }
56 | .menu .post{
57 | background: url("/icons/post.png") no-repeat;
58 | background-size: 100% 100%;
59 | }
60 | .btn{
61 | width: 80%;
62 | margin: 30rpx auto;
63 | }
--------------------------------------------------------------------------------
/QQZJ/pages/profile/mypost/mypost.js:
--------------------------------------------------------------------------------
1 | // pages/profile/mypost/mypost.js
2 | const util = require('../../../utils/util.js')
3 | const app = getApp()
4 | Page({
5 | data:{
6 | posts: null
7 | },
8 | onShow:function(){
9 | // 页面显示
10 | let that = this
11 | util.request({
12 | url: 'http://wx.romeo.wang/home/user/mypost?id='+app.globalData.userInfo.id,
13 | success: function(res){
14 | that.setData({
15 | posts: res.data
16 | })
17 | }
18 | })
19 | },
20 | showDetail:function(e){
21 | util.navigateTo({
22 | url:"/pages/post/post?id="+e.currentTarget.id
23 | })
24 | },
25 | like:function(e){
26 | let that = this
27 | let pid = e.currentTarget.id
28 | util.request({
29 | url: 'http://wx.romeo.wang/home/post/like',
30 | data: {"id": pid},
31 | success: function(res){
32 | // success
33 | if(res.data.err == 0){
34 | let posts = that.data.posts
35 | posts[pid].like = res.data.like
36 | posts[pid].star = res.data.star
37 | that.setData({
38 | posts: posts
39 | })
40 | wx.showToast({
41 | title: res.data.msg,
42 | icon: "success",
43 | mask: true,
44 | duration: 1000
45 | })
46 | }else{
47 | wx.showModal({
48 | title: "提示",
49 | content: res.data.msg,
50 | showCancel: false
51 | })
52 | }
53 | }
54 | })
55 | }
56 | })
--------------------------------------------------------------------------------
/QQZJ/pages/profile/mylike/mylike.js:
--------------------------------------------------------------------------------
1 | // pages/profile/mylike/mylike.js
2 | const app = getApp()
3 | const util = require('../../../utils/util.js')
4 | Page({
5 | data:{
6 | posts: null
7 | },
8 | onShow:function(){
9 | // 页面显示
10 | let that = this
11 | util.request({
12 | url: 'http://wx.romeo.wang/home/user/mylike',
13 | success: function(res){
14 | that.setData({
15 | posts: res.data
16 | })
17 | }
18 | })
19 | },
20 | showDetail:function(e){
21 | util.navigateTo({
22 | url:"/pages/post/post?id="+e.currentTarget.id
23 | })
24 | },
25 | unlike:function(e){
26 | let that = this
27 | let pid = e.currentTarget.id
28 | util.request({
29 | url: 'http://wx.romeo.wang/home/user/unlike',
30 | data: {"id": pid},
31 | success: function(res){
32 | // success
33 | if(res.data.err == 0){
34 | wx.showToast({
35 | title: res.data.msg,
36 | icon: "success",
37 | mask: true,
38 | duration: 1000
39 | })
40 | let posts = new Array();
41 | for(let i=0; i res.data.star){
47 | userInfo.stars = parseInt(userInfo.stars)-1
48 | }else{
49 | userInfo.stars = parseInt(userInfo.stars)+1
50 | }
51 | posts[pid].like = res.data.like
52 | posts[pid].star = res.data.star
53 | that.setData({
54 | posts: posts,
55 | userInfo: userInfo
56 | })
57 | wx.showToast({
58 | title: res.data.msg,
59 | icon: "success",
60 | mask: true,
61 | duration: 1000
62 | })
63 | }else{
64 | wx.showModal({
65 | title: "提示",
66 | content: res.data.msg,
67 | showCancel: false
68 | })
69 | }
70 | }
71 | })
72 | }
73 | })
--------------------------------------------------------------------------------
/QQZJ/pages/login/login.js:
--------------------------------------------------------------------------------
1 | //login.js
2 | const util = require('../../utils/util.js')
3 | const app = getApp()
4 | Page({
5 | data:{
6 | msg: null,
7 | code: null,
8 | wxlogin: null
9 | },
10 | onLoad:function(options){
11 | // 生命周期函数--监听页面加载
12 | let that = this
13 | // 微信用户登陆
14 | wx.login({
15 | success: function(res) {
16 | if (res.code) {
17 | that.setData({
18 | code: res.code
19 | })
20 | } else {
21 | that.setData({
22 | msg: '微信登陆调用失败!',
23 | wxlogin: true
24 | })
25 | }
26 | },
27 | fail: function(){
28 | that.setData({
29 | msg: "微信登陆调用失败!",
30 | wxlogin: true
31 | })
32 | }
33 | })
34 | },
35 | onReady:function(){
36 | // 生命周期函数--监听页面初次渲染完成
37 |
38 | },
39 | onShow:function(){
40 | // 生命周期函数--监听页面显示
41 |
42 | },
43 | onHide:function(){
44 | // 生命周期函数--监听页面隐藏
45 |
46 | },
47 | onUnload:function(){
48 | // 生命周期函数--监听页面卸载
49 |
50 | },
51 | onShareAppMessage: function() {
52 | // 用户点击右上角分享
53 | return {
54 | title: 'title', // 分享标题
55 | desc: 'desc', // 分享描述
56 | path: 'path' // 分享路径
57 | }
58 | },
59 | login: function(e){
60 | let that = this
61 | wx.request({
62 | url: 'http://wx.romeo.wang/home/login',
63 | data: e.detail.value,
64 | method: 'POST',
65 | header: {"content-type": "application/x-www-form-urlencoded"},
66 | success: function(res){
67 | // success
68 | if(res.data.err){
69 | that.setData({
70 | msg: res.data.msg
71 | })
72 | }else{
73 | wx.setStorageSync('userInfo', res.data.userInfo)
74 | app.globalData.userInfo = res.data.userInfo
75 | wx.navigateBack({ delta: 1 })
76 | }
77 | }
78 | })
79 | },
80 | wxlogin: function(){
81 | wx.getUserInfo({
82 | success: function(res){
83 | app.globalData.userInfo = {"nickname":res.userInfo.nickName, "avatar":res.userInfo.avatarUrl, "id":"weixin"}
84 | wx.setStorageSync('userInfo', app.globalData.userInfo)
85 | wx.navigateBack({ delta: 1 })
86 | }
87 | })
88 | }
89 | })
--------------------------------------------------------------------------------
/QQZJ/pages/profile/post/post.js:
--------------------------------------------------------------------------------
1 | // pages/profile/post/post.js
2 | var util = require('../../../utils/util.js')
3 | var app = getApp()
4 | Page({
5 | data:{
6 | imgs: null,
7 | title: null,
8 | outline: null
9 | },
10 | uploadImg:function(){
11 | //上传图片
12 | let that = this
13 | wx.chooseImage({
14 | count: 5,
15 | sizeType: ['original', 'compressed'],
16 | sourceType: ['album', 'camera'],
17 | success: function(res){
18 | // success
19 | that.setData({
20 | imgs: res.tempFilePaths
21 | })
22 | }
23 | })
24 | },
25 | submit:function(e){
26 | //判断图片是否上传
27 | if(this.data.imgs === null){
28 | wx.showModal({
29 | title: '提示',
30 | content: '至少添加一张图片!',
31 | showCancel: false
32 | })
33 | return;
34 | }
35 | //判断是否填写标题
36 | if(e.detail.value.title == ''){
37 | wx.showModal({
38 | title: '提示',
39 | content: '必须填写标题!',
40 | showCancel: false
41 | })
42 | return;
43 | }
44 | //判断是否填写内容
45 | if(e.detail.value.outline == ''){
46 | wx.showModal({
47 | title: '提示',
48 | content: '必须填写内容!',
49 | showCancel: false
50 | })
51 | return;
52 | }
53 | //准备参数:title、outline、id
54 | e.detail.value.uid = app.globalData.userInfo.id
55 | let that = this
56 | //发布文章标题及内容
57 | wx.request({
58 | url: 'http://wx.romeo.wang/home/post/save',
59 | data: e.detail.value,
60 | method: 'POST',
61 | header: {'content-type':'application/x-www-form-urlencoded'},
62 | success: function(res){
63 | //发布未成功,提示用户操作
64 | if(res.data.err != 0){
65 | wx.showModal({
66 | title: "提示",
67 | content: res.data.msg,
68 | confirmText: "重试",
69 | success: function(res){
70 | if(res.confirm){
71 | that.submit()
72 | }
73 | }
74 | })
75 | return
76 | }
77 | //发布成功发布成功,上传图片
78 | util.multiUpload({
79 | url: 'http://wx.romeo.wang/home/post/upload',
80 | files: that.data.imgs,
81 | name: 'imgs',
82 | formData: {pid: res.data.pid},
83 | success: function(){
84 | //图片上传成功成功,提示用户操作
85 | wx.showModal({
86 | title: "提示",
87 | content: "发布成功!",
88 | cancelText: "返回",
89 | confirmText: "继续发布",
90 | success: function(res){
91 | if(res.confirm){
92 | wx.redirectTo({url: '/pages/profile/post/post'})
93 | }else{
94 | wx.navigateBack({delta: 1,})
95 | }
96 | }
97 | })
98 | }
99 | })
100 | }
101 | })
102 | },
103 | reset:function() {
104 | let that = this
105 | wx.showModal({
106 | title: '提示',
107 | content: '确定要退出吗?',
108 | success: function(res) {
109 | if (res.confirm) {
110 | that.setData({
111 | imgs: [],
112 | title: null,
113 | outline: null
114 | })
115 | wx.navigateBack({delta: 1})
116 | }
117 | }
118 | })
119 | }
120 | })
--------------------------------------------------------------------------------
/QQZJ/utils/util.js:
--------------------------------------------------------------------------------
1 | //用于自定义函数
2 | var untitled = require('./untitled.js')
3 | var funcs = require('./funcs.js')
4 |
5 | module.exports = {
6 | //微信 API
7 | request: untitled.request,
8 | uploadFile: untitled.uploadFile,
9 | downloadFile: untitled.downloadFile,
10 | connectSocket: untitled.connectSocket,
11 | onSocketOpen: untitled.onSocketOpen,
12 | onSocketError: untitled.onSocketError,
13 | sendSocketMessage: untitled.sendSocketMessage,
14 | onSocketMessage: untitled.onSocketMessage,
15 | closeSocket: untitled.closeSocket,
16 | onSocketClose: untitled.onSocketClose,
17 | chooseImage: untitled.chooseImage,
18 | previewImage: untitled.previewImage,
19 | getImageInfo: untitled.getImageInfo,
20 | startRecord: untitled.startRecord,
21 | stopRecord: untitled.stopRecord,
22 | playVoice: untitled.playVoice,
23 | pauseVoice: untitled.pauseVoice,
24 | stopVoice: untitled.stopVoice,
25 | getBackgroundAudioPlayerState: untitled.getBackgroundAudioPlayerState,
26 | playBackgroundAudio: untitled.playBackgroundAudio,
27 | pauseBackgroundAudio: untitled.pauseBackgroundAudio,
28 | seekBackgroundAudio: untitled.seekBackgroundAudio,
29 | stopBackgroundAudio: untitled.stopBackgroundAudio,
30 | onBackgroundAudioPlay: untitled.onBackgroundAudioPlay,
31 | onBackgroundAudioPause: untitled.onBackgroundAudioPause,
32 | onBackgroundAudioStop: untitled.onBackgroundAudioStop,
33 | createAudioContext: untitled.createAudioContext,
34 | chooseVideo: untitled.chooseVideo,
35 | createVideoContext: untitled.createVideoContext,
36 | saveFile: untitled.saveFile,
37 | getSavedFileList: untitled.getSavedFileList,
38 | getSavedFileInfo: untitled.getSavedFileInfo,
39 | removeSavedFile: untitled.removeSavedFile,
40 | openDocument: untitled.openDocument,
41 | setStorage: untitled.setStorage,
42 | setStorageSync: untitled.setStorageSync,
43 | getStorage: untitled.getStorage,
44 | getStorageSync: untitled.getStorageSync,
45 | getStorageInfo: untitled.getStorageInfo,
46 | getStorageInfoSync: untitled.getStorageInfoSync,
47 | removeStorage: untitled.removeStorage,
48 | removeStorageSync: untitled.removeStorageSync,
49 | clearStorage: untitled.clearStorage,
50 | clearStorageSync: untitled.clearStorageSync,
51 | getLocation: untitled.getLocation,
52 | chooseLocation: untitled.chooseLocation,
53 | openLocation: untitled.openLocation,
54 | createMapContext: untitled.createMapContext,
55 | getSystemInfo: untitled.getSystemInfo,
56 | getStorageInfoSync: untitled.getStorageInfoSync,
57 | getNetworkType: untitled.getNetworkType,
58 | onAccelerometerChange: untitled.onAccelerometerChange,
59 | onCompassChange: untitled.onCompassChange,
60 | makePhoneCall: untitled.makePhoneCall,
61 | scanCode: untitled.scanCode,
62 | showToast: untitled.showToast,
63 | hideToast: untitled.hideToast,
64 | showModal: untitled.showModal,
65 | showActionSheet: untitled.showActionSheet,
66 | setNavigationBarTitle: untitled.setNavigationBarTitle,
67 | showNavigationBarLoading: untitled.showNavigationBarLoading,
68 | hideNavigationBarLoading: untitled.hideNavigationBarLoading,
69 | navigateTo: untitled.navigateTo,
70 | redirectTo: untitled.redirectTo,
71 | switchTab: untitled.switchTab,
72 | navigateBack: untitled.navigateBack,
73 | createAnimation: untitled.createAnimation,
74 | stopPullDownRefresh: untitled.stopPullDownRefresh,
75 | login: untitled.login,
76 | checkSession: untitled.checkSession,
77 | getUserInfo: untitled.getUserInfo,
78 | requestPayment: untitled.requestPayment,
79 | //自定义函数
80 | randomString: funcs.randomString,
81 | getDay: funcs.getDay,
82 | doHandleMonth: funcs.doHandleMonth,
83 | getCurTime: funcs.getCurTime,
84 | getCurDate: funcs.getCurDate,
85 | multiUpload: funcs.multiUpload
86 | }
--------------------------------------------------------------------------------
/QQZJ/utils/funcs.js:
--------------------------------------------------------------------------------
1 | // funs.js 自定义公共函数库文件
2 | /*
3 | * 生成随机字符串
4 | * @param int 随机字符串长度长度,默认值为 6
5 | * @return string 返回由大小写字母组成的随机字符串
6 | */
7 | function randomString(length=6){
8 | var str = ''
9 | for(var i=0; i 注:文件名无需添加扩展名
8 |
9 | 2. `app.josn` 中的 `pages` 数组中的第一个页面为小程序的启动页
10 |
11 | 3. 每个页面的 `js`、`json`、`wxml`、`wxss` 可与所在目录名不同,但必须具有相同的路径和文件名
12 |
13 | 4. 页面目录可以嵌套,按照页面目录在 `app.json` 中注册即可
14 |
15 | 5. 可通过直接赋值的方法修改 `app.js` 中的全局变量,但修改页面变量需要使用 `Page.prototype.setData()` 方法,且赋值数据不能超过 1024 kB
16 |
17 | 6. 在文件中引入模块时,`require` 使用相对路径引入(绝对路径会报错)
18 |
19 | 7. 如需引入多级文件,则使用如下方式:
20 | ```
21 | // func.js 文件中定义了两个函数 fun1 和 fun2
22 | fun1 = function(){
23 | // code
24 | }
25 |
26 | fun2 = function(){
27 | // code
28 | }
29 |
30 | module.export = {
31 | fun1: fun1,
32 | fun2: fun2
33 | }
34 |
35 | // util.js 中定义了函数 util 并需要导入 func.js 文件
36 | var funcs = require('func.js文件的相对路径')
37 |
38 | util = function(){
39 | // code
40 | }
41 |
42 | module.export = {
43 | fun1: funcs.fun1,
44 | fun2: funcs.fun2,
45 | util: util
46 | }
47 | ```
48 | 8. 小程序的 `wxss` 中使用 `@import` 导入文件时应使用相对路径
49 |
50 | 9. 小程序中 `wxss` 样式的优先级为 内联样式 > 外链样式 > 全局样式
51 |
52 | 10. 小程序的 `wxss` 样式文件中支持 CSS3 的大部分属性,但选择器支持有限,请戳[官方文档](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/view/wxss.html?t=20161222)
53 |
54 | ### 组件部分
55 |
56 | 1. `` 仅为包装元素,接受属性控制且**不能嵌套**不会被渲染
57 |
58 | 2. `` 组件内只能嵌套使用 `` 组件,其他不可用
59 |
60 | 3. 仅 `` 组件中的内容支持长按选中
61 |
62 | 4. `` 组件中的 `range` 数组下标必须连续且从 0 开始,否则会出现选项为 `null` 的情况
63 |
64 | 5. 组件名称均为小写,所有大写的组件名称都会在渲染时转换为小写
65 |
66 | 6. 任何自定义的组件 `<自定义名称>` 均会被当作 `` 组件来渲染,但需要注意**组件名称中不能出现数字**。(虽然可以自定义语义化组件,但是由于微信官方并未加以说明,所以不推荐使用)
67 |
68 | 7. 使用 `page` 标签选择器可以修改顶层节点的样式,相当于 HTML 中的 `` 元素
69 |
70 | ### API 部分
71 |
72 | 1. 程序中请求、上传、下载及 websocket 的请求地址必须为 https 地址,且在当前 APPID 的微信公众平台上注册合法域名
73 |
74 | 2. `wx.request()` 中发送 POST 请求时,需设置 `header` 如下:
75 | `{'content-type': 'application/x-www-form-urlencoded'}`
76 |
77 | 3. 某些情况下需要使用全局数据通常有两种方法:设置全局变量和写入缓存,区别在于全局变量的生存周期和小程序相同,而缓存则是永久储存的
78 |
79 | 4. `wx.login()` 只返回登陆 `code`,可向微信服务器发送此 `code` 获取用户的 `session_key` 和 `openid`,微信官方提供了登陆状态检验的接口和一套验证机制,请戳[官方文档](https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-login.html?t=20161222#wxloginobject)
80 |
81 | 5. 小程序的本地缓存不能超过 10M
82 |
83 | 6. 小程序的上传和下载中只能获取文件的 `key`,开发者在服务器端通过 `key` 获取文件二进制内容。
84 |
85 | 7. 小程序中的 wx.upload API 方法无法并行调用,多张上传时需在 success() 函数中递归调用 wx.upload 方法。
86 |
87 | ```
88 | function multiUpload(param, i=0){
89 |
90 | wx.hideToast()
91 |
92 | wx.showToast({
93 | title: "第"+(i+1)+"张图片上传中…",
94 | icon: "loading",
95 | duration: 10000,
96 | mask: true
97 | })
98 |
99 | wx.uploadFile({
100 | url: param.url,
101 | filePath: param.files[i],
102 | name: param.name,
103 | formData: param.formData,
104 | success: function(res){
105 | if(res.data.err){
106 | multiUpload(param, i)
107 | }else if(i < param.files.length-1){
108 | i++
109 | multiUpload(param, i)
110 | }else{
111 | wx.hideToast()
112 | if(param.success != undefined)
113 | param.success()
114 | return
115 | }
116 | },
117 | fail: function() {
118 | multiUpload(param, i)
119 | }
120 | })
121 | }
122 | ```
123 | > 详见[funcs.js](https://github.com/Romeo0906/WeChatAPP/blob/branch/QQZJ/utils/funcs.js)。
124 |
125 | ### 工具部分
126 |
127 | 1. 修改 `wxml` 和 `wxss` 文件将会刷新页面
128 |
129 | 2. 修改 `js` 和 `json` 文件将会重新编译小程序
130 |
131 | 3. 在 `app.json` 文件 `pages` 数组中添加目标页面,将会自动生成该页面目录和所需文件
132 |
133 | 4. 项目- 基础信息中设置勾选开发环境不校验请求安全域名以及 TLS 版本时,将可以使用 http 协议的请求地址,有助于本地调试
134 |
135 | 5. 可以在项目 - 配置信息中快捷查看当前 `appid` 配置的安全域名
136 |
137 | 6. 手机调试过程中可以点按右上角,选择 enable debug 打开手机调试模式
138 |
139 | 7. 项目 - 预览中可添加预览页面及参数信息,跳过繁琐的前戏直达你想要操作的位置
140 |
141 | 8. 快捷键
142 |
143 | 格式调整
144 | ```
145 | Ctrl+S:保存文件
146 |
147 | Ctrl+[, Ctrl+]:代码行缩进
148 |
149 | Ctrl+Shift+[, Ctrl+Shift+]:折叠打开代码块
150 |
151 | Ctrl+C Ctrl+V:复制粘贴,如果没有选中任何文字则复制粘贴一行
152 |
153 | Shift+Alt+F:代码格式化
154 |
155 | Alt+Up,Alt+Down:上下移动一行
156 |
157 | Shift+Alt+Up,Shift+Alt+Down:向上向下复制一行
158 |
159 | Ctrl+Shift+Enter:在当前行上方插入一行
160 |
161 | Ctrl+Shift+F:全局搜索
162 | ```
163 | 光标相关
164 | ```
165 | Ctrl+End:移动到文件结尾
166 |
167 | Ctrl+Home:移动到文件开头
168 |
169 | Ctrl+i:选中当前行
170 |
171 | Shift+End:选择从光标到行尾
172 |
173 | Shift+Home:选择从行首到光标处
174 |
175 | Ctrl+Shift+L:选中所有匹配
176 |
177 | Ctrl+D:选中匹配
178 |
179 | Ctrl+U:光标回退
180 | ```
181 | 界面相关
182 | ```
183 | Ctrl + \:隐藏侧边栏
184 |
185 | Ctrl + m: 打开或者隐藏模拟器
186 | ```
187 |
188 | ### 概念部分
189 |
190 | 1. 小程序基于包开发,开发和发布流程与 H5 应用是截然不同的
191 |
192 | 2. 小程序中 Web 开发的 session 管理部分由微信服务器实现
193 |
194 | 3. 小程序的域名仅用于通讯和验证,没有 Cookie 机制
195 |
196 | 更信息请戳腾讯云布道师、TEDxZhuhai策展人[贺嘉](https://www.zhihu.com/people/he-jia-43/answers)老师关于小程序的知乎回答:[怎么看待 2017 微信公开课上张小龙对微信小程序的发言?](https://www.zhihu.com/question/54129120/answer/138024934)、[微信小程序(应用号)价值是什么?](https://www.zhihu.com/question/50875544/answer/133070413)
--------------------------------------------------------------------------------
/QQZJ/utils/untitled.js:
--------------------------------------------------------------------------------
1 | //untitled.js 封装微信 API
2 | /**
3 | * 发送请求
4 | * @Author 王子建
5 | * @DateTime 2016-12-22T18:09:51+0800
6 | */
7 | function request(param){
8 | let app = getApp()
9 | if(param.data){
10 | param.data.uid = app.globalData.userInfo.id
11 | }else{
12 | param.data = {uid: app.globalData.userInfo.id}
13 | }
14 | wx.request({
15 | url: param.url,
16 | data: param.data,
17 | header: param.header,
18 | method: param.method,
19 | dataType: param.dataType,
20 | success: function(res){
21 | if(param.success != undefined)
22 | param.success(res)
23 | },
24 | fail: function(){
25 | wx.showModal({
26 | title: '系统消息',
27 | content: '请求失败,请重试!',
28 | showCancel: false,
29 | confirmText: '确定'
30 | })
31 | if(param.fail != undefined)
32 | param.fail()
33 | },
34 | complete: param.complete
35 | })
36 | }
37 |
38 | /**
39 | * 上传文件
40 | * @Author 王子建
41 | * @DateTime 2016-12-22T11:56:09+0800
42 | */
43 | function uploadFile(param){
44 | wx.uploadFile({
45 | url: param.url,
46 | filePath: param.filePath,
47 | name: param.name,
48 | header: param.header,
49 | formData: param.formData,
50 | success: function(res){
51 | // success
52 | if(param.success != undefined)
53 | param.success(res)
54 | },
55 | fail: function(){
56 | // fail
57 | wx.showModal({
58 | title: "系统提示",
59 | content: "上传失败!",
60 | showCancel: false
61 | })
62 | if(param.fail != undefined)
63 | param.fail()
64 | },
65 | complete: param.complete
66 | })
67 | }
68 |
69 | /**
70 | * 下载图片
71 | * @Author 王子建
72 | * @DateTime 2016-12-22T11:57:36+0800
73 | */
74 | function downloadFile(param){
75 | wx.downloadFile({
76 | url: param.url,
77 | header: param.header,
78 | success: function(res){
79 | // success
80 | if(param.success != undefined)
81 | param.success(res)
82 | },
83 | fail: function(){
84 | // fail
85 | wx.showModal({
86 | title: "系统提示",
87 | content: "下载失败!",
88 | showCancel: false
89 | })
90 | if(param.fail != undefined)
91 | param.fail()
92 | },
93 | complete: param.complete
94 | })
95 | }
96 |
97 | /**
98 | * 新建 websocket 连接
99 | * @Author 王子建
100 | * @DateTime 2016-12-22T11:58:31+0800
101 | */
102 | function connectSocket(param){
103 | wx.connectSocket({
104 | url: param.url,
105 | data: param.data,
106 | header: param.header,
107 | method: param.method,
108 | success: function(res){
109 | // success
110 | if(param.success != undefined)
111 | param.success(res)
112 | },
113 | fail: function(){
114 | // fail
115 | wx.showModal({
116 | title: "系统提示",
117 | content: "连接 webSocket 失败!",
118 | showCancel: false
119 | })
120 | if(param.fail != undefined)
121 | param.fail()
122 | },
123 | complete: param.complete
124 | })
125 | }
126 |
127 | /**
128 | * 监听 websocket 打开事件
129 | * @Author 王子建
130 | * @DateTime 2016-12-22T11:58:56+0800
131 | */
132 | function onSocketOpen(CALLBACK){
133 | wx.onSocketOpen(CALLBACK)
134 | }
135 |
136 | /**
137 | * 监听 websocket 错误事件
138 | * @Author 王子建
139 | * @DateTime 2016-12-22T11:58:56+0800
140 | */
141 | function onSocketError(CALLBACK){
142 | wx.onSocketError(CALLBACK)
143 | }
144 |
145 | /**
146 | * websocket 发送数据
147 | * @Author 王子建
148 | * @DateTime 2016-12-22T11:58:56+0800
149 | */
150 | function sendSocketMessage(param){
151 | wx.sendSocketMessage({
152 | data: param.data,
153 | success: function(res){
154 | // success
155 | if(param.success != undefined)
156 | param.success(res)
157 | },
158 | fail: function(){
159 | // fail
160 | wx.showModal({
161 | title: "系统提示",
162 | content: "发送消息失败!",
163 | showCancel: false
164 | })
165 | if(param.fail != undefined)
166 | param.fail()
167 | },
168 | complete: param.complete
169 | })
170 | }
171 |
172 | /**
173 | * 监听 websocket 接受消息事件
174 | * @Author 王子建
175 | * @DateTime 2016-12-22T11:58:56+0800
176 | */
177 | function onSocketMessage(CALLBACK){
178 | wx.onSocketMessage(CALLBACK)
179 | }
180 |
181 | /**
182 | * 关闭 websocket 连接
183 | * @Author 王子建
184 | * @DateTime 2016-12-22T11:58:56+0800
185 | */
186 | function closeSocket(){
187 | wx.closeSocket()
188 | }
189 |
190 | /**
191 | * 监听 websocket 关闭事件
192 | * @Author 王子建
193 | * @DateTime 2016-12-22T11:58:56+0800
194 | */
195 | function onSocketClose(CALLBACK){
196 | wx.onSocketClose(CALLBACK)
197 | }
198 |
199 | /**
200 | * 选择图片
201 | * @Author 王子建
202 | * @DateTime 2016-12-22T11:58:56+0800
203 | */
204 | function chooseImage(param){
205 | wx.chooseImage({
206 | count: param.count,
207 | sizeType: param.sizeType,
208 | sourceType: param.sourceType,
209 | success: function(res){
210 | // success
211 | if(param.success != undefined)
212 | param.success(res)
213 | },
214 | fail: function(){
215 | // fail
216 | wx.showModal({
217 | title: "系统提示",
218 | content: "操作失败!",
219 | showCancel: false
220 | })
221 | if(param.fail != undefined)
222 | param.fail()
223 | },
224 | complete: param.complete
225 | })
226 | }
227 |
228 | /**
229 | * 预览图片
230 | * @Author 王子建
231 | * @DateTime 2016-12-22T11:58:56+0800
232 | */
233 | function previewImage(param){
234 | wx.previewImage({
235 | current: param.current,
236 | urls: param.urls,
237 | success: function(res){
238 | // success
239 | if(param.success != undefined)
240 | param.success(res)
241 | },
242 | fail: function(){
243 | // fail
244 | wx.showModal({
245 | title: "系统提示",
246 | content: "预览失败!",
247 | showCancel: false
248 | })
249 | if(param.fail != undefined)
250 | param.fail()
251 | },
252 | complete: param.complete
253 | })
254 | }
255 |
256 | /**
257 | * 获取图片信息
258 | * @Author 王子建
259 | * @DateTime 2016-12-22T11:58:56+0800
260 | */
261 | function getImageInfo(param){
262 | wx.getImageInfo({
263 | src: param.src,
264 | success: function(res){
265 | // success
266 | if(param.success != undefined)
267 | param.success(res)
268 | },
269 | fail: function(){
270 | // fail
271 | wx.showModal({
272 | title: "系统提示",
273 | content: "获取图像信息失败!",
274 | showCancel: false
275 | })
276 | if(param.fail != undefined)
277 | param.fail()
278 | },
279 | complete: param.complete
280 | })
281 | }
282 |
283 | /**
284 | * 开始录音
285 | * @Author 王子建
286 | * @DateTime 2016-12-22T11:58:56+0800
287 | */
288 | function startRecord(param){
289 | wx.startRecord({
290 | success: function(res){
291 | // success
292 | if(param.success != undefined)
293 | param.success(res)
294 | },
295 | fail: function(){
296 | // fail
297 | wx.showModal({
298 | title: "系统提示",
299 | content: "录音失败!",
300 | showCancel: false
301 | })
302 | if(param.fail != undefined)
303 | param.fail()
304 | },
305 | complete: param.complete
306 | })
307 | }
308 |
309 | /**
310 | * 停止录音
311 | * @Author 王子建
312 | * @DateTime 2016-12-22T11:58:56+0800
313 | */
314 | function stopRecord(){
315 | wx.stopRecord()
316 | }
317 |
318 | /**
319 | * 播放语音
320 | * @Author 王子建
321 | * @DateTime 2016-12-22T11:58:56+0800
322 | */
323 | function playVoice(param){
324 | wx.playVoice({
325 | filePath: param.filePath,
326 | success: function(res){
327 | // success
328 | if(param.success != undefined)
329 | param.success(res)
330 | },
331 | fail: function(){
332 | // fail
333 | wx.showModal({
334 | title: "系统提示",
335 | content: "操作失败!",
336 | showCancel: false
337 | })
338 | if(param.fail != undefined)
339 | param.fail()
340 | },
341 | complete: param.complete
342 | })
343 | }
344 |
345 | /**
346 | * 暂停播放语音
347 | * @Author 王子建
348 | * @DateTime 2016-12-22T11:58:56+0800
349 | */
350 | function pauseVoice(){
351 | wx.pauseVoice()
352 | }
353 |
354 | /**
355 | * 停止播放语音
356 | * @Author 王子建
357 | * @DateTime 2016-12-22T12:11:23+0800
358 | */
359 | function stopVoice(){
360 | wx.stopVoice()
361 | }
362 |
363 | /**
364 | * 获取后台音乐播放状态
365 | * @Author 王子建
366 | * @DateTime 2016-12-22T11:58:56+0800
367 | */
368 | function getBackgroundAudioPlayerState(param){
369 | wx.getBackgroundAudioPlayerState({
370 | success: function(res){
371 | // success
372 | if(param.success != undefined)
373 | param.success(res)
374 | },
375 | fail: function(){
376 | // fail
377 | wx.showModal({
378 | title: "系统提示",
379 | content: "获取播放状态失败!",
380 | showCancel: false
381 | })
382 | if(param.fail != undefined)
383 | param.fail()
384 | },
385 | complete: param.complete
386 | })
387 | }
388 |
389 | /**
390 | * 后台播放音乐
391 | * @Author 王子建
392 | * @DateTime 2016-12-22T11:58:56+0800
393 | */
394 | function playBackgroundAudio(param){
395 | wx.playBackgroundAudio({
396 | dataUrl: param.dataUrl,
397 | title: param.title,
398 | coverImgUrl: param.coverImgUrl,
399 | success: function(res){
400 | // success
401 | if(param.success != undefined)
402 | param.success(res)
403 | },
404 | fail: function(){
405 | // fail
406 | wx.showModal({
407 | title: "系统提示",
408 | content: "播放失败!",
409 | showCancel: false
410 | })
411 | if(param.fail != undefined)
412 | param.fail()
413 | },
414 | complete: param.complete
415 | })
416 | }
417 |
418 | /**
419 | * 暂停播放音乐
420 | * @Author 王子建
421 | * @DateTime 2016-12-22T11:58:56+0800
422 | */
423 | function pauseBackgroundAudio(){
424 | wx.pauseBackgroundAudio()
425 | }
426 |
427 | /**
428 | * 控制音乐播放进度
429 | * @Author 王子建
430 | * @DateTime 2016-12-22T11:58:56+0800
431 | */
432 | function seekBackgroundAudio(param){
433 | wx.seekBackgroundAudio({
434 | position: param.position,
435 | success: function(res){
436 | // success
437 | if(param.success != undefined)
438 | param.success(res)
439 | },
440 | fail: function(){
441 | // fail
442 | wx.showModal({
443 | title: "系统提示",
444 | content: "操作失败!",
445 | showCancel: false
446 | })
447 | if(param.fail != undefined)
448 | param.fail()
449 | },
450 | complete: param.complete
451 | })
452 | }
453 |
454 | /**
455 | * 停止播放音乐
456 | * @Author 王子建
457 | * @DateTime 2016-12-22T11:58:56+0800
458 | */
459 | function stopBackgroundAudio(){
460 | wx.stopBackgroundAudio()
461 | }
462 |
463 | /**
464 | * 监听后台播放音乐事件
465 | * @Author 王子建
466 | * @DateTime 2016-12-22T11:58:56+0800
467 | */
468 | function onBackgroundAudioPlay(CALLBACK){
469 | wx.onBackgroundAudioPlay(CALLBACK)
470 | }
471 |
472 | /**
473 | * 监听后台音乐暂停事件
474 | * @Author 王子建
475 | * @DateTime 2016-12-22T11:58:56+0800
476 | */
477 | function onBackgroundAudioPause(CALLBACK){
478 | wx.onBackgroundAudioPause(CALLBACK)
479 | }
480 |
481 | /**
482 | * 监听音乐播放停止事件
483 | * @Author 王子建
484 | * @DateTime 2016-12-22T11:58:56+0800
485 | */
486 | function onBackgroundAudioStop(CALLBACK){
487 | wx.onBackgroundAudioStop(CALLBACK)
488 | }
489 |
490 | /**
491 | * 创建并返回一个 audioContext 对象
492 | * @Author 王子建
493 | * @DateTime 2016-12-22T11:58:56+0800
494 | */
495 | function createAudioContext(audioid){
496 | wx.createAudioContext(audioid)
497 | }
498 |
499 | /**
500 | * 选择视频
501 | * @Author 王子建
502 | * @DateTime 2016-12-23T17:35:41+0800
503 | */
504 | function chooseVideo(param){
505 | wx.chooseVideo({
506 | sourceType: param.sourceType,
507 | maxDuration: param.maxDuration,
508 | camera: param.camera,
509 | success: function(res){
510 | // success
511 | if(param.success != undefined)
512 | param.success(res)
513 | },
514 | fail: function(){
515 | // fail
516 | wx.showModal({
517 | title: "系统提示",
518 | content: "操作失败!",
519 | showCancel: false
520 | })
521 | if(param.fail != undefined)
522 | param.fail()
523 | },
524 | complete: param.complete
525 | })
526 | }
527 |
528 | /**
529 | * 创建并返回一个 videoContext 上下文
530 | * @Author 王子建
531 | * @DateTime 2016-12-22T11:58:56+0800
532 | */
533 | function createVideoContext(param){
534 | wx.createVideoContext()
535 | }
536 |
537 | /**
538 | * 保存文件到本地
539 | * @Author 王子建
540 | * @DateTime 2016-12-22T11:58:56+0800
541 | */
542 | function saveFile(param){
543 | wx.saveFile({
544 | tempFilePath: param.tempFilePath,
545 | success: function(res){
546 | // success
547 | if(param.success != undefined)
548 | param.success(res)
549 | },
550 | fail: function(){
551 | // fail
552 | wx.showModal({
553 | title: "系统提示",
554 | content: "保存失败!",
555 | showCancel: false
556 | })
557 | if(param.fail != undefined)
558 | param.fail()
559 | },
560 | complete: param.complete
561 | })
562 | }
563 |
564 | /**
565 | * 获取本地文件列表
566 | * @Author 王子建
567 | * @DateTime 2016-12-22T11:58:56+0800
568 | */
569 | function getSavedFileList(param){
570 | wx.getSavedFileList({
571 | success: function(res){
572 | // success
573 | if(param.success != undefined)
574 | param.success(res)
575 | },
576 | fail: function(){
577 | // fail
578 | wx.showModal({
579 | title: "系统提示",
580 | content: "获取文件列表失败!",
581 | showCancel: false
582 | })
583 | if(param.fail != undefined)
584 | param.fail()
585 | },
586 | complete: param.complete
587 | })
588 | }
589 |
590 | /**
591 | * 获取本地文件信息
592 | * @Author 王子建
593 | * @DateTime 2016-12-22T11:58:56+0800
594 | */
595 | function getSavedFileInfo(param){
596 | wx.getSavedFileInfo({
597 | filePath: param.filePath,
598 | success: function(res){
599 | // success
600 | if(param.success != undefined)
601 | param.success(res)
602 | },
603 | fail: function(){
604 | // fail
605 | wx.showModal({
606 | title: "系统提示",
607 | content: "获取文件信息失败!",
608 | showCancel: false
609 | })
610 | if(param.fail != undefined)
611 | param.fail()
612 | },
613 | complete: param.complete
614 | })
615 | }
616 |
617 | /**
618 | * 删除本地文件
619 | * @Author 王子建
620 | * @DateTime 2016-12-22T12:19:30+0800
621 | */
622 | function removeSavedFile(param){
623 | wx.removeSavedFile({
624 | filePath: param.filePath,
625 | success: function(res){
626 | // success
627 | if(param.success != undefined)
628 | param.success(res)
629 | },
630 | fail: function(){
631 | // fail
632 | wx.showModal({
633 | title: "系统提示",
634 | content: "删除文件失败!",
635 | showCancel: false
636 | })
637 | if(param.fail != undefined)
638 | param.fail()
639 | },
640 | complete: param.complete
641 | })
642 | }
643 |
644 | /**
645 | * 新页面打开文档
646 | * @Author 王子建
647 | * @DateTime 2016-12-23T18:44:01+0800
648 | */
649 | function openDocument(param){
650 | wx.openDocument({
651 | filePath: param.filePath,
652 | success: function(res){
653 | // success
654 | if(param.success != undefined)
655 | param.success(res)
656 | },
657 | fail: function(){
658 | // fail
659 | wx.showModal({
660 | title: "系统提示",
661 | content: "打开文档失败!",
662 | showCancel: false
663 | })
664 | if(param.fail != undefined)
665 | param.fail()
666 | },
667 | complete: param.complete
668 | })
669 | }
670 |
671 | /**
672 | * 异步设置本地缓存
673 | * @Author 王子建
674 | * @DateTime 2016-12-22T11:58:56+0800
675 | */
676 | function setStorage(param){
677 | wx.setStorage({
678 | key: param.key,
679 | data: param.data,
680 | success: function(res){
681 | // success
682 | if(param.success != undefined)
683 | param.success(res)
684 | },
685 | fail: function(){
686 | // fail
687 | wx.showModal({
688 | title: "系统提示",
689 | content: "设置缓存失败!",
690 | showCancel: false
691 | })
692 | if(param.fail != undefined)
693 | param.fail()
694 | },
695 | complete: param.complete
696 | })
697 | }
698 |
699 | /**
700 | * 同步设置本地缓存
701 | * @Author 王子建
702 | * @DateTime 2016-12-22T12:27:20+0800
703 | */
704 | function setStorageSync(key, data){
705 | wx.setStorageSync(key, data)
706 | }
707 |
708 | /**
709 | * 异步获取本地缓存
710 | * @Author 王子建
711 | * @DateTime 2016-12-22T11:58:56+0800
712 | */
713 | function getStorage(param){
714 | wx.getStorage({
715 | key: param.key,
716 | success: function(res){
717 | // success
718 | if(param.success != undefined)
719 | param.success(res)
720 | },
721 | fail: function(){
722 | // fail
723 | wx.showModal({
724 | title: "系统提示",
725 | content: "获取缓存失败!",
726 | showCancel: false
727 | })
728 | if(param.fail != undefined)
729 | param.fail()
730 | },
731 | complete: param.complete
732 | })
733 | }
734 |
735 | /**
736 | * 同步获取本地缓存
737 | * @Author 王子建
738 | * @DateTime 2016-12-22T11:58:56+0800
739 | */
740 | function getStorageSync(key){
741 | wx.getStorageSync(key)
742 | }
743 |
744 | /**
745 | * 异步获取当前缓存数据的信息
746 | * @Author 王子建
747 | * @DateTime 2016-12-22T11:58:56+0800
748 | */
749 | function getStorageInfo(param){
750 | wx.getStorageInfo({
751 | success: function(res){
752 | // success
753 | if(param.success != undefined)
754 | param.success(res)
755 | },
756 | fail: function(){
757 | // fail
758 | wx.showModal({
759 | title: "系统提示",
760 | content: "获取缓存信息失败!",
761 | showCancel: false
762 | })
763 | if(param.fail != undefined)
764 | param.fail()
765 | },
766 | complete: param.complete
767 | })
768 | }
769 |
770 | /**
771 | * 同步获取当前缓存的信息
772 | * @Author 王子建
773 | * @DateTime 2016-12-22T11:58:56+0800
774 | */
775 | function getStorageInfoSync(){
776 | wx.getStorageInfoSync()
777 | }
778 |
779 | /**
780 | * 异步移除指定缓存
781 | * @Author 王子建
782 | * @DateTime 2016-12-22T11:58:56+0800
783 | */
784 | function removeStorage(param){
785 | wx.removeStorage({
786 | key: param.key,
787 | success: function(res){
788 | // success
789 | if(param.success != undefined)
790 | param.success(res)
791 | },
792 | fail: function(){
793 | // fail
794 | wx.showModal({
795 | title: "系统提示",
796 | content: "删除缓存失败!",
797 | showCancel: false
798 | })
799 | if(param.fail != undefined)
800 | param.fail()
801 | },
802 | complete: param.complete
803 | })
804 | }
805 |
806 | /**
807 | * 同步获取当前缓存的信息
808 | * @Author 王子建
809 | * @DateTime 2016-12-22T11:58:56+0800
810 | */
811 | function removeStorageSync(key){
812 | wx.removeStorageSync(key)
813 | }
814 |
815 | /**
816 | * 异步清除所有缓存
817 | * @Author 王子建
818 | * @DateTime 2016-12-22T11:58:56+0800
819 | */
820 | function clearStorage(){
821 | wx.clearStorage()
822 | }
823 |
824 |
825 | /**
826 | * 同步清除所有缓存
827 | * @Author 王子建
828 | * @DateTime 2016-12-22T11:58:56+0800
829 | */
830 | function clearStorageSync(){
831 | wx.clearStorageSync()
832 | }
833 |
834 | /**
835 | * 获取当前地理位置
836 | * @Author 王子建
837 | * @DateTime 2016-12-22T11:58:56+0800
838 | */
839 | function getLocation(param){
840 | wx.getLocation({
841 | type: param.type,
842 | success: function(res){
843 | // success
844 | if(param.success != undefined)
845 | param.success(res)
846 | },
847 | fail: function(){
848 | // fail
849 | wx.showModal({
850 | title: "系统提示",
851 | content: "定位失败!",
852 | showCancel: false
853 | })
854 | if(param.fail != undefined)
855 | param.fail()
856 | },
857 | complete: param.complete
858 | })
859 | }
860 |
861 | /**
862 | * 标记位置
863 | * @Author 王子建
864 | * @DateTime 2016-12-22T11:58:56+0800
865 | */
866 | function chooseLocation(param){
867 | wx.chooseLocation({
868 | success: function(res){
869 | // success
870 | if(param.success != undefined)
871 | param.success(res)
872 | },
873 | cancel: function(){
874 | // cancel
875 | param.cancel()
876 | },
877 | fail: function(){
878 | // fail
879 | wx.showModal({
880 | title: "系统提示",
881 | content: "选择定位失败!",
882 | showCancel: false
883 | })
884 | if(param.fail != undefined)
885 | param.fail()
886 | },
887 | complete: param.complete
888 | })
889 | }
890 |
891 | /**
892 | * 打开位置
893 | * @Author 王子建
894 | * @DateTime 2016-12-22T11:58:56+0800
895 | */
896 | function openLocation(param){
897 | wx.openLocation({
898 | latitude: param.latitude,
899 | longitude: param.longitude,
900 | scale: param.scale,
901 | name: param.name,
902 | address: param.address,
903 | success: function(res){
904 | // success
905 | if(param.success != undefined)
906 | param.success(res)
907 | },
908 | fail: function(){
909 | // fail
910 | wx.showModal({
911 | title: "系统提示",
912 | content: "打开定位失败!",
913 | showCancel: false
914 | })
915 | if(param.fail != undefined)
916 | param.fail()
917 | },
918 | complete: param.complete
919 | })
920 | }
921 |
922 | /**
923 | * 创建并返回一个 map 上下文
924 | * @Author 王子建
925 | * @DateTime 2016-12-24T09:18:05+0800
926 | */
927 | function createMapContext(mapid){
928 | wx.createMapContext(mapid)
929 | }
930 |
931 | /**
932 | * 异步获取系统信息
933 | * @Author 王子建
934 | * @DateTime 2016-12-22T11:58:56+0800
935 | */
936 | function getSystemInfo(param){
937 | wx.getSystemInfo({
938 | success: function(res) {
939 | // success
940 | param.success(res)
941 | },
942 | fail: function(){
943 | // fail
944 | wx.showModal({
945 | title: "系统提示",
946 | content: "获取系统信息失败!",
947 | showCancel: false
948 | })
949 | if(param.fail != undefined)
950 | param.fail()
951 | },
952 | complete: param.complete
953 | })
954 | }
955 |
956 | /**
957 | * 同步获取系统信息
958 | * @Author 王子建
959 | * @DateTime 2016-12-24T09:23:20+0800
960 | */
961 | function getStorageInfoSync(){
962 | wx.getSystemInfoSync()
963 | }
964 |
965 | /**
966 | * 获取当前网络类型
967 | * @Author 王子建
968 | * @DateTime 2016-12-22T11:58:56+0800
969 | */
970 | function getNetworkType(param){
971 | wx.getNetworkType({
972 | success: function(res) {
973 | // success
974 | param.success()
975 | },
976 | fail: function(){
977 | // fail
978 | wx.showModal({
979 | title: "系统提示",
980 | content: "获取网络类型失败!",
981 | showCancel: false
982 | })
983 | if(param.fail != undefined)
984 | param.fail()
985 | },
986 | complete: param.complete
987 | })
988 | }
989 |
990 | /**
991 | * 监听重力感应数据
992 | * @Author 王子建
993 | * @DateTime 2016-12-22T11:58:56+0800
994 | */
995 | function onAccelerometerChange(CALLBACK){
996 | wx.onAccelerometerChange(CALLBACK)
997 | }
998 |
999 | /**
1000 | * 监听罗盘数据
1001 | * @Author 王子建
1002 | * @DateTime 2016-12-22T11:58:56+0800
1003 | */
1004 | function onCompassChange(CALLBACK){
1005 | wx.onCompassChange(CALLBACK)
1006 | }
1007 |
1008 | /**
1009 | * 拨打电话
1010 | * @Author 王子建
1011 | * @DateTime 2016-12-22T11:58:56+0800
1012 | */
1013 | function makePhoneCall(param){
1014 | wx.makePhoneCall({
1015 | phoneNumber: param.phoneNumber,
1016 | success: function() {
1017 | // success
1018 | param.success()
1019 | },
1020 | fail: function(){
1021 | // fail
1022 | wx.showModal({
1023 | title: "系统提示",
1024 | content: "拨号失败!",
1025 | showCancel: false
1026 | })
1027 | if(param.fail != undefined)
1028 | param.fail()
1029 | },
1030 | complete: param.complete
1031 | })
1032 | }
1033 |
1034 | /**
1035 | * 扫描二维码
1036 | * @Author 王子建
1037 | * @DateTime 2016-12-24T09:26:33+0800
1038 | */
1039 | function scanCode(param){
1040 | wx.scanCode({
1041 | success: function() {
1042 | // success
1043 | param.success()
1044 | },
1045 | fail: function(){
1046 | // fail
1047 | wx.showModal({
1048 | title: "系统提示",
1049 | content: "扫码失败!",
1050 | showCancel: false
1051 | })
1052 | if(param.fail != undefined)
1053 | param.fail()
1054 | },
1055 | complete: param.complete
1056 | })
1057 | }
1058 |
1059 | /**
1060 | * 提示框
1061 | * @Author 王子建
1062 | * @DateTime 2016-12-22T11:58:56+0800
1063 | */
1064 | function showToast(param){
1065 | wx.showToast({
1066 | title: param.title,
1067 | icon: param.icon,
1068 | duration: param.duration,
1069 | mask: param.duration,
1070 | success: function() {
1071 | // success
1072 | param.success()
1073 | },
1074 | fail: function(){
1075 | // fail
1076 | wx.showModal({
1077 | title: "系统提示",
1078 | content: "操作失败!",
1079 | showCancel: false
1080 | })
1081 | if(param.fail != undefined)
1082 | param.fail()
1083 | },
1084 | complete: param.complete
1085 | })
1086 | }
1087 |
1088 | /**
1089 | * 隐藏消息提示框
1090 | * @Author 王子建
1091 | * @DateTime 2016-12-24T09:52:55+0800
1092 | */
1093 | function hideToast(){
1094 | wx.hideToast()
1095 | }
1096 |
1097 | /**
1098 | * 弹确认框
1099 | * @Author 王子建
1100 | * @DateTime 2016-12-22T11:58:56+0800
1101 | */
1102 | function showModal(param){
1103 | wx.showModal({
1104 | title: param.title,
1105 | content: param.content,
1106 | showCancel: param.showCancel,
1107 | cancelText: param.cancelText,
1108 | cancelColor: param.cancelColor,
1109 | confirmText: param.confirmText,
1110 | confirmColor: param.confirmColor,
1111 | success: function(res) {
1112 | // success
1113 | param.success(res)
1114 | },
1115 | fail: function(){
1116 | // fail
1117 | wx.showModal({
1118 | title: "系统提示",
1119 | content: "操作失败!",
1120 | showCancel: false
1121 | })
1122 | if(param.fail != undefined)
1123 | param.fail()
1124 | },
1125 | complete: param.complete
1126 | })
1127 | }
1128 |
1129 | /**
1130 | * 显示操作菜单
1131 | * @Author 王子建
1132 | * @DateTime 2016-12-22T11:58:56+0800
1133 | */
1134 | function showActionSheet(param){
1135 | wx.showActionSheet({
1136 | itemList: param.itemList,
1137 | itemColor: param.itemColor,
1138 | success: function(res) {
1139 | // success
1140 | param.success(res)
1141 | },
1142 | fail: function(){
1143 | // fail
1144 | wx.showModal({
1145 | title: "系统提示",
1146 | content: "操作失败!",
1147 | showCancel: false
1148 | })
1149 | if(param.fail != undefined)
1150 | param.fail()
1151 | },
1152 | complete: param.complete
1153 | })
1154 | }
1155 |
1156 | /**
1157 | * 动态设置当前页面的标题
1158 | * @Author 王子建
1159 | * @DateTime 2016-12-22T11:58:56+0800
1160 | */
1161 | function setNavigationBarTitle(param){
1162 | wx.setNavigationBarTitle({
1163 | title: param.title,
1164 | success: function(res) {
1165 | // success
1166 | param.success(res)
1167 | },
1168 | fail: function(){
1169 | // fail
1170 | wx.showModal({
1171 | title: "系统提示",
1172 | content: "设置导航标题失败!",
1173 | showCancel: false
1174 | })
1175 | if(param.fail != undefined)
1176 | param.fail()
1177 | },
1178 | complete: param.complete
1179 | })
1180 | }
1181 |
1182 | /**
1183 | * 在当前页面显示导航条加载动画
1184 | * @Author 王子建
1185 | * @DateTime 2016-12-22T11:58:56+0800
1186 | */
1187 | function showNavigationBarLoading(){
1188 | wx.showNavigationBarLoading()
1189 | }
1190 |
1191 | /**
1192 | * 隐藏导航条加载动画
1193 | * @Author 王子建
1194 | * @DateTime 2016-12-22T11:58:56+0800
1195 | */
1196 | function hideNavigationBarLoading(){
1197 | wx.hideNavigationBarLoading()
1198 | }
1199 |
1200 | /**
1201 | * 页面跳转
1202 | * @Author 王子建
1203 | * @DateTime 2016-12-22T11:58:56+0800
1204 | */
1205 | function navigateTo(param){
1206 | wx.navigateTo({
1207 | url: param.url,
1208 | success: function(res){
1209 | // success
1210 | if(param.success != undefined)
1211 | param.success(res)
1212 | },
1213 | fail: function(){
1214 | // fail
1215 | wx.showModal({
1216 | title: "系统提示",
1217 | content: "页面跳转失败!",
1218 | showCancel: false
1219 | })
1220 | if(param.fail != undefined)
1221 | param.fail()
1222 | },
1223 | complete: param.complete
1224 | })
1225 | }
1226 |
1227 | /**
1228 | *
1229 | * @Author 王子建
1230 | * @DateTime 2016-12-22T11:58:56+0800
1231 | */
1232 | function redirectTo(param){
1233 | wx.redirectTo({
1234 | url: param.url,
1235 | success: function(res){
1236 | // success
1237 | if(param.success != undefined)
1238 | param.success(res)
1239 | },
1240 | fail: function(){
1241 | // fail
1242 | wx.showModal({
1243 | title: "系统提示",
1244 | content: "页面重定向失败!",
1245 | showCancel: false
1246 | })
1247 | if(param.fail != undefined)
1248 | param.fail()
1249 | },
1250 | complete: param.complete
1251 | })
1252 | }
1253 |
1254 | function switchTab(param){
1255 | wx.switchTab({
1256 | url: param.url,
1257 | success: function(res){
1258 | // success
1259 | if(param.success != undefined)
1260 | param.success(res)
1261 | },
1262 | fail: function(){
1263 | // fail
1264 | wx.showModal({
1265 | title: "系统提示",
1266 | content: "切换 tabBar 失败!",
1267 | showCancel: false
1268 | })
1269 | if(param.fail != undefined)
1270 | param.fail()
1271 | },
1272 | complete: param.complete
1273 | })
1274 | }
1275 |
1276 | /**
1277 | * 返回上一个页面
1278 | * @Author 王子建
1279 | * @DateTime 2016-12-22T11:58:56+0800
1280 | */
1281 | function navigateBack(param){
1282 | wx.navigateBack({
1283 | delta: param.delta,
1284 | success: function(res){
1285 | // success
1286 | if(param.success != undefined)
1287 | param.success(res)
1288 | },
1289 | fail: function(){
1290 | // fail
1291 | wx.showModal({
1292 | title: "系统提示",
1293 | content: "操作失败!",
1294 | showCancel: false
1295 | })
1296 | if(param.fail != undefined)
1297 | param.fail()
1298 | },
1299 | complete: param.complete
1300 | })
1301 | }
1302 |
1303 | /**
1304 | * 创建一个动画实例
1305 | * @Author 王子建
1306 | * @DateTime 2016-12-22T11:58:56+0800
1307 | */
1308 | function createAnimation(param){
1309 | wx.createAnimation({
1310 | duration: param.duration,
1311 | timingFunction: param.timingFunction,
1312 | delay: param.delay,
1313 | transformOrigin: param.transformOrigin,
1314 | })
1315 | }
1316 |
1317 | /**
1318 | * 停止当前页面下拉刷新
1319 | * @Author 王子建
1320 | * @DateTime 2016-12-22T18:05:32+0800
1321 | * @return {void}
1322 | */
1323 | function stopPullDownRefresh(){
1324 | wx.stopPullDownRefresh()
1325 | }
1326 |
1327 | /**
1328 | * 登陆
1329 | * @Author 王子建
1330 | * @DateTime 2016-12-22T11:58:56+0800
1331 | */
1332 | function login(param){
1333 | wx.login({
1334 | success: function(res){
1335 | // success
1336 | if(param.success != undefined)
1337 | param.success(res)
1338 | },
1339 | fail: function(){
1340 | // fail
1341 | wx.showModal({
1342 | title: "系统提示",
1343 | content: "操作失败!",
1344 | showCancel: false
1345 | })
1346 | if(param.fail != undefined)
1347 | param.fail()
1348 | },
1349 | complete: param.complete
1350 | })
1351 | }
1352 |
1353 | /**
1354 | * 检查用户登陆状态
1355 | * @Author 王子建
1356 | * @DateTime 2016-12-22T11:58:56+0800
1357 | */
1358 | function checkSession(param){
1359 | wx.checkSession({
1360 | success: function() {
1361 | //登陆状态未过期
1362 | param.success()
1363 | },
1364 | fail: function() {
1365 | //登陆状态过期
1366 | if(param.fail != undefined)
1367 | param.fail()
1368 | }
1369 | })
1370 | }
1371 |
1372 | /**
1373 | * 获取用户信息
1374 | * @Author 王子建
1375 | * @DateTime 2016-12-22T11:58:56+0800
1376 | */
1377 | function getUserInfo(param){
1378 | wx.getUserInfo({
1379 | success: function(res){
1380 | // success
1381 | if(param.success != undefined)
1382 | param.success(res)
1383 | },
1384 | fail: function(){
1385 | // fail
1386 | wx.showModal({
1387 | title: "系统提示",
1388 | content: "操作失败!",
1389 | showCancel: false
1390 | })
1391 | if(param.fail != undefined)
1392 | param.fail()
1393 | },
1394 | complete: param.complete
1395 | })
1396 | }
1397 |
1398 | /**
1399 | * 申请支付
1400 | * @Author 王子建
1401 | * @DateTime 2016-12-22T11:58:56+0800
1402 | */
1403 | function requestPayment(param){
1404 | wx.requestPayment({
1405 | timeStamp: param.timeStamp,
1406 | nonceStr: param.nonceStr,
1407 | package: param.package,
1408 | signType: param.signType,
1409 | paySign: param.paySign,
1410 | success: function(res){
1411 | // success
1412 | if(param.success != undefined)
1413 | param.success(res)
1414 | },
1415 | fail: function(){
1416 | // fail
1417 | wx.showModal({
1418 | title: "系统提示",
1419 | content: "操作失败!",
1420 | showCancel: false
1421 | })
1422 | if(param.fail != undefined)
1423 | param.fail()
1424 | },
1425 | complete: param.complete
1426 | })
1427 | }
1428 |
1429 | module.exports = {
1430 | request: request,
1431 | uploadFile: uploadFile,
1432 | downloadFile: downloadFile,
1433 | connectSocket: connectSocket,
1434 | onSocketOpen: onSocketOpen,
1435 | onSocketError: onSocketError,
1436 | sendSocketMessage: sendSocketMessage,
1437 | onSocketMessage: onSocketMessage,
1438 | closeSocket: closeSocket,
1439 | onSocketClose: onSocketClose,
1440 | chooseImage: chooseImage,
1441 | previewImage: previewImage,
1442 | getImageInfo: getImageInfo,
1443 | startRecord: startRecord,
1444 | stopRecord: stopRecord,
1445 | playVoice: playVoice,
1446 | pauseVoice: pauseVoice,
1447 | stopVoice: stopVoice,
1448 | getBackgroundAudioPlayerState: getBackgroundAudioPlayerState,
1449 | playBackgroundAudio: playBackgroundAudio,
1450 | pauseBackgroundAudio: pauseBackgroundAudio,
1451 | seekBackgroundAudio: seekBackgroundAudio,
1452 | stopBackgroundAudio: stopBackgroundAudio,
1453 | onBackgroundAudioPlay: onBackgroundAudioPlay,
1454 | onBackgroundAudioPause: onBackgroundAudioPause,
1455 | onBackgroundAudioStop: onBackgroundAudioStop,
1456 | createAudioContext: createAudioContext,
1457 | chooseVideo: chooseVideo,
1458 | createVideoContext: createVideoContext,
1459 | saveFile: saveFile,
1460 | getSavedFileList: getSavedFileList,
1461 | getSavedFileInfo: getSavedFileInfo,
1462 | removeSavedFile: removeSavedFile,
1463 | openDocument: openDocument,
1464 | setStorage: setStorage,
1465 | setStorageSync: setStorageSync,
1466 | getStorage: getStorage,
1467 | getStorageSync: getStorageSync,
1468 | getStorageInfo: getStorageInfo,
1469 | getStorageInfoSync: getStorageInfoSync,
1470 | removeStorage: removeStorage,
1471 | removeStorageSync: removeStorageSync,
1472 | clearStorage: clearStorage,
1473 | clearStorageSync: clearStorageSync,
1474 | getLocation: getLocation,
1475 | chooseLocation: chooseLocation,
1476 | openLocation: openLocation,
1477 | createMapContext: createMapContext,
1478 | getSystemInfo: getSystemInfo,
1479 | getStorageInfoSync: getStorageInfoSync,
1480 | getNetworkType: getNetworkType,
1481 | onAccelerometerChange: onAccelerometerChange,
1482 | onCompassChange: onCompassChange,
1483 | makePhoneCall: makePhoneCall,
1484 | scanCode: scanCode,
1485 | showToast: showToast,
1486 | hideToast: hideToast,
1487 | showModal: showModal,
1488 | showActionSheet: showActionSheet,
1489 | setNavigationBarTitle: setNavigationBarTitle,
1490 | showNavigationBarLoading: showNavigationBarLoading,
1491 | hideNavigationBarLoading: hideNavigationBarLoading,
1492 | navigateTo: navigateTo,
1493 | redirectTo: redirectTo,
1494 | switchTab: switchTab,
1495 | navigateBack: navigateBack,
1496 | createAnimation: createAnimation,
1497 | stopPullDownRefresh: stopPullDownRefresh,
1498 | login: login,
1499 | checkSession: checkSession,
1500 | getUserInfo: getUserInfo,
1501 | requestPayment: requestPayment,
1502 | }
--------------------------------------------------------------------------------