├── pages
├── index
│ ├── index.json
│ ├── index.wxml
│ ├── index.wxss
│ └── index.js
├── map
│ ├── index.json
│ ├── index.wxml
│ ├── index.wxss
│ └── index.js
├── video
│ ├── index.json
│ ├── index.wxss
│ ├── index.wxml
│ └── index.js
├── invitation
│ ├── index.json
│ ├── index.wxml
│ ├── index.js
│ └── index.wxss
└── chat
│ ├── index.json
│ ├── index.wxml
│ ├── index.wxss
│ └── index.js
├── WxComment
├── libs
│ ├── leancloud
│ │ └── .gitignore
│ └── scripts
│ │ └── common.js
├── component
│ └── WxComment
│ │ ├── WxComment.json
│ │ ├── images
│ │ ├── views.png
│ │ ├── zan.png
│ │ ├── coffee.png
│ │ ├── comment.png
│ │ └── zan_self.png
│ │ ├── WxComment.wxss
│ │ ├── WxComment.wxml
│ │ └── WxComment.js
└── README.md
├── .DS_Store
├── images
├── 1.png
├── 2.png
├── 3.png
├── 4.png
├── 5.png
├── he.jpg
├── t1.png
├── we.png
├── nav.png
├── she.jpg
├── lovemail.gif
├── music_icon.png
├── music_play.png
├── map_bottom_new.png
└── save_the_date_pu.gif
├── README.md
├── .idea
├── misc.xml
├── vcs.xml
├── modules.xml
├── OnceLove-master.iml
└── workspace.xml
├── app.wxss
├── utils
└── util.js
├── project.config.json
├── app.js
├── components
└── item
│ ├── item-template.wxml
│ └── item-template.wxss
└── app.json
/pages/index/index.json:
--------------------------------------------------------------------------------
1 | {
2 |
3 | }
--------------------------------------------------------------------------------
/WxComment/libs/leancloud/.gitignore:
--------------------------------------------------------------------------------
1 | rest_api_leancloud.js
2 |
--------------------------------------------------------------------------------
/pages/map/index.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "地图"
3 | }
--------------------------------------------------------------------------------
/WxComment/component/WxComment/WxComment.json:
--------------------------------------------------------------------------------
1 | {
2 | "component": true
3 | }
--------------------------------------------------------------------------------
/pages/video/index.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "爱情轨迹"
3 |
4 | }
--------------------------------------------------------------------------------
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/.DS_Store
--------------------------------------------------------------------------------
/images/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/1.png
--------------------------------------------------------------------------------
/images/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/2.png
--------------------------------------------------------------------------------
/images/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/3.png
--------------------------------------------------------------------------------
/images/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/4.png
--------------------------------------------------------------------------------
/images/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/5.png
--------------------------------------------------------------------------------
/images/he.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/he.jpg
--------------------------------------------------------------------------------
/images/t1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/t1.png
--------------------------------------------------------------------------------
/images/we.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/we.png
--------------------------------------------------------------------------------
/images/nav.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/nav.png
--------------------------------------------------------------------------------
/images/she.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/she.jpg
--------------------------------------------------------------------------------
/pages/invitation/index.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "请柬"
3 |
4 |
5 | }
6 |
7 |
--------------------------------------------------------------------------------
/images/lovemail.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/lovemail.gif
--------------------------------------------------------------------------------
/images/music_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/music_icon.png
--------------------------------------------------------------------------------
/images/music_play.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/music_play.png
--------------------------------------------------------------------------------
/images/map_bottom_new.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/map_bottom_new.png
--------------------------------------------------------------------------------
/images/save_the_date_pu.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/images/save_the_date_pu.gif
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | ## 婚礼请柬小程序
3 | 基于微信小程序做的一个婚礼请柬
4 |
5 | ## 有哪些功能?
6 |
7 | * 相册展示
8 | * 邀请函展示
9 | * 地图导航
10 | * 好友祝福
11 | * 留言评论
12 |
13 |
--------------------------------------------------------------------------------
/WxComment/component/WxComment/images/views.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/WxComment/component/WxComment/images/views.png
--------------------------------------------------------------------------------
/WxComment/component/WxComment/images/zan.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/WxComment/component/WxComment/images/zan.png
--------------------------------------------------------------------------------
/WxComment/component/WxComment/images/coffee.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/WxComment/component/WxComment/images/coffee.png
--------------------------------------------------------------------------------
/WxComment/component/WxComment/images/comment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/WxComment/component/WxComment/images/comment.png
--------------------------------------------------------------------------------
/WxComment/component/WxComment/images/zan_self.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lovehanyang/wedding_invitation/HEAD/WxComment/component/WxComment/images/zan_self.png
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/pages/chat/index.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "留言评论",
3 | "enablePullDownRefresh": true,
4 | "usingComponents": {
5 | "WxComment": "/WxComment/component/WxComment/WxComment"
6 | }
7 | }
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/pages/chat/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | .container {
3 | font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
4 | display: flex;
5 | flex-direction: column;
6 | justify-content: space-between;
7 | box-sizing: border-box;
8 | }
9 |
10 | page {
11 | background-color: #fff;
12 | }
13 | .fl {
14 | float: left;
15 | }
16 | .fr {
17 | float: right;
18 | }
--------------------------------------------------------------------------------
/.idea/OnceLove-master.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/utils/util.js:
--------------------------------------------------------------------------------
1 | const formatTime = date => {
2 | const year = date.getFullYear()
3 | const month = date.getMonth() + 1
4 | const day = date.getDate()
5 | const hour = date.getHours()
6 | const minute = date.getMinutes()
7 | const second = date.getSeconds()
8 |
9 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
10 | }
11 |
12 | const formatNumber = n => {
13 | n = n.toString()
14 | return n[1] ? n : '0' + n
15 | }
16 |
17 | module.exports = {
18 | formatTime: formatTime
19 | }
20 |
--------------------------------------------------------------------------------
/pages/video/index.wxss:
--------------------------------------------------------------------------------
1 | .movie-list {
2 | box-shadow: 0 8rpx 17rpx 0 rgba(7, 17, 27, 0.1);
3 | margin: 0 25rpx;
4 | overflow: hidden;
5 | border-radius: 10rpx;
6 | margin-bottom: 30rpx;
7 | background: #fff;
8 | }
9 |
10 | .video-des {
11 | padding: 10px;
12 | }
13 |
14 | .myVideo {
15 |
16 | width: 100%;
17 | }
18 |
19 | .video_title {
20 | display: block;
21 | font-size: 15px;
22 | overflow: hidden;
23 | white-space: nowrap;
24 | color: #333;
25 | text-overflow: ellipsis;
26 | }
27 |
28 | .video_time {
29 | font-size: 13px;
30 | color: #979797;
31 | }
32 |
--------------------------------------------------------------------------------
/pages/invitation/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | 呼叫新郎
12 |
13 |
14 |
15 |
16 |
17 | 呼叫新娘
18 |
19 |
20 |
--------------------------------------------------------------------------------
/pages/video/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | {{item.title}}
11 | {{item.desc}}
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/project.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "项目配置文件。",
3 | "setting": {
4 | "urlCheck": true,
5 | "es6": true,
6 | "postcss": true,
7 | "minified": true,
8 | "newFeature": true
9 | },
10 | "compileType": "miniprogram",
11 | "libVersion": "2.2.0",
12 | "appid": "wx81047ceffce4e095",
13 | "projectname": "%E9%9F%A9%E6%B4%8B%E4%B8%A8%E9%98%9A%E6%97%AD%E5%A9%9A%E7%A4%BC%E8%AF%B7%E6%9F%AC",
14 | "condition": {
15 | "search": {
16 | "current": -1,
17 | "list": []
18 | },
19 | "conversation": {
20 | "current": -1,
21 | "list": []
22 | },
23 | "miniprogram": {
24 | "current": -1,
25 | "list": []
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | // app.js
2 | App({
3 | onLaunch: function () {
4 | var that = this;
5 | if (this.globalData.userInfo) {
6 | typeof cb == "function" && cb(this.globalData.userInfo)
7 | } else {
8 | //调用登录接口
9 | wx.login({
10 | success: function () {
11 | wx.getUserInfo({
12 | success: function (res) {
13 | //console.info(res);
14 | that.globalData.userInfo = res.userInfo;
15 | typeof cb == "function" && cb(that.globalData.userInfo)
16 | }
17 | })
18 | }
19 | });
20 | }
21 | },
22 | globalData: {
23 | userInfo: null,
24 | appid:'wx81047ceffce4e095',
25 | }
26 | });
27 |
28 |
--------------------------------------------------------------------------------
/components/item/item-template.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | {{item.title}}
11 | {{item.create_time}}
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/pages/map/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | 呼叫新郎
17 |
18 |
19 |
20 |
21 |
22 | 呼叫新娘
23 |
24 |
25 | MADE WITH ❤ BY 韩洋 & 阚旭
26 | ©2018.10.3
27 |
28 |
29 |
--------------------------------------------------------------------------------
/components/item/item-template.wxss:
--------------------------------------------------------------------------------
1 | /* 视频 */
2 |
3 | .movie-list {
4 | box-shadow: 0 8rpx 16rpx 0 rgba(7, 17, 27, 0.1);
5 | margin: 0 20rpx;
6 | overflow: hidden;
7 | border-radius: 8rpx;
8 | margin-bottom: 30rpx;
9 | background: #fff;
10 | }
11 |
12 | .movie-list .wrap-img {
13 | height: 420rpx;
14 | background-color: #ccc;
15 | background-repeat: no-repeat;
16 | background-position: center;
17 | background-size: cover;
18 | display: flex;
19 | flex-direction: column;
20 | justify-content: center;
21 | align-items: center;
22 | }
23 |
24 | .movie-list .wrap-img .btn {
25 | width: 90rpx;
26 | height: 90rpx;
27 | background-image: url(http://i.gtimg.cn/qqlive/images/20150911/i1441959133_1.jpg);
28 | background-size: 90rpx;
29 | }
30 |
31 | .movie-list .video-des {
32 | padding: 10px;
33 | }
34 |
35 | .movie-list .video_title {
36 | display: block;
37 | font-size: 15px;
38 | overflow: hidden;
39 | white-space: nowrap;
40 | color: #333;
41 | text-overflow: ellipsis;
42 | }
43 |
44 | .movie-list .video-des .time {
45 | font-size: 13px;
46 | color: #979797;
47 | }
48 |
--------------------------------------------------------------------------------
/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /**index.wxss**/
2 |
3 |
4 | .swiper {
5 | width: 750rpx;
6 | height: 100vh;
7 | }
8 | .swiper swiper{
9 | width: 750rpx;
10 | height: 100vh;
11 | }
12 | .swiper swiper-item{
13 | width: 750rpx;
14 | height: 100vh;
15 | }
16 | .swiper image{
17 | width: 750rpx;
18 | height: 100vh;
19 | }
20 |
21 | .background_music{
22 | position: fixed;
23 | top: 20rpx;
24 | right: 10rpx;
25 | z-index: 10001;
26 | width: 100rpx;
27 | }
28 | .musicImg{
29 | width: 80rpx;
30 | height: 80rpx;
31 | }
32 | .music_icon{
33 | animation:musicRotate 3s linear infinite;
34 | }
35 | .music_play{
36 | width:28rpx;
37 | height: 80rpx;
38 | margin-left:-5px;
39 | transform-origin: top;
40 | -webkit-transform:rotate(20deg)
41 | }
42 | .playImg{
43 | animation:musicStop 1s linear forwards ;
44 | }
45 | .pauseImg{
46 | animation:musicStart 1s linear forwards ;
47 | }
48 | @-webkit-keyframes musicRotate{
49 | from{-webkit-transform:rotate(0deg);}
50 | to{-webkit-transform:rotate(360deg);}
51 | }
52 | @-webkit-keyframes musicStop{
53 | from{-webkit-transform:rotate(20deg);}
54 | to{-webkit-transform:rotate(0deg);}
55 | }
56 | @-webkit-keyframes musicStart{
57 | from{-webkit-transform:rotate(0deg);}
58 | to{-webkit-transform:rotate(20deg);}
59 | }
60 | .music_stop{width:4em;display:none;}
--------------------------------------------------------------------------------
/pages/map/index.wxss:
--------------------------------------------------------------------------------
1 | /* pages/bless/index.wxss */
2 |
3 | .container {
4 | min-height: 100vh;
5 | background: url('http://oq8pu5sju.bkt.clouddn.com/bg2.jpg') no-repeat center;
6 | background-size: cover;
7 | }
8 |
9 | .t1 {
10 | width: 626rpx;
11 | height: 180rpx;
12 | margin: 0 auto;
13 | display: block;
14 | }
15 |
16 | /* pages/map/index.wxss */
17 |
18 | #map {
19 | width: 694rpx;
20 | height: 694rpx;
21 | margin: 0 auto;
22 | margin-bottom: 30rpx;
23 | margin-top: 20rpx;
24 | border: 3rpx solid rgba(0, 0, 0, .3)
25 | }
26 |
27 | .bottomImg {
28 | width: 100%;
29 | min-height: 0;
30 | position: fixed;
31 | bottom: 0;
32 | }
33 |
34 |
35 | .tel {
36 | width: 500rpx;
37 | margin: 0 auto;
38 | min-height: 0;
39 | overflow: hidden;
40 | text-align: center;
41 | font-size: 24rpx;
42 | color: #684c4b;
43 | line-height: 50rpx;
44 | z-index: 99999;
45 | padding-bottom: 50rpx;
46 | }
47 |
48 | .tel_he {
49 | width: 200rpx;
50 | float: left;
51 | }
52 |
53 | .tel_she {
54 | width: 200rpx;
55 | float: right;
56 | }
57 |
58 | .call {
59 | width: 80rpx;
60 | height: 80rpx;
61 | display: block;
62 | margin: 0 auto;
63 | }
64 |
65 | .call image {
66 | width: 80rpx;
67 | height: 80rpx;
68 | margin-bottom: 10rpx;
69 | }
70 |
71 | .copyright {
72 | text-align: center;
73 | font-size: 20rpx;
74 | line-height: 25rpx;
75 | padding-bottom: 20rpx;
76 | color: #684c4b;
77 | }
--------------------------------------------------------------------------------
/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages": [
3 | "pages/invitation/index",
4 | "pages/index/index",
5 | "pages/video/index",
6 | "pages/map/index",
7 | "pages/chat/index"
8 | ],
9 | "window": {
10 | "backgroundTextStyle": "light",
11 | "navigationBarBackgroundColor": "#fff",
12 | "navigationBarTitleText": "韩洋❤阚旭 Married",
13 | "navigationBarTextStyle": "black",
14 | "enablePullDownRefresh": false
15 | },
16 | "tabBar": {
17 | "color": "#ccc",
18 | "selectedColor": "#ff4c91",
19 | "borderStyle": "white",
20 | "backgroundColor": "#ffffff",
21 | "list": [
22 | {
23 | "pagePath": "pages/invitation/index",
24 | "iconPath": "images/2.png",
25 | "selectedIconPath": "images/2.png",
26 | "text": "邀请函"
27 | },
28 | {
29 | "pagePath": "pages/index/index",
30 | "iconPath": "images/1.png",
31 | "selectedIconPath": "images/1.png",
32 | "text": "婚纱照"
33 | },
34 | {
35 | "pagePath": "pages/video/index",
36 | "iconPath": "images/3.png",
37 | "selectedIconPath": "images/3.png",
38 | "text": "爱的记录"
39 | },
40 | {
41 | "pagePath": "pages/map/index",
42 | "iconPath": "images/4.png",
43 | "selectedIconPath": "images/4.png",
44 | "text": "地图"
45 | },
46 | {
47 | "pagePath": "pages/chat/index",
48 | "iconPath": "images/5.png",
49 | "selectedIconPath": "images/5.png",
50 | "text": "留言评论"
51 | }
52 | ]
53 | }
54 | }
--------------------------------------------------------------------------------
/pages/chat/index.wxss:
--------------------------------------------------------------------------------
1 | /* pages/chat/index.wxss */
2 |
3 | page {
4 | background-color: #fde7e3;
5 | padding-bottom: 150rpx;
6 | }
7 |
8 | .chat_list {
9 | width: 630rpx;
10 | margin: 0 auto;
11 | margin-top: 30rpx;
12 | padding: 30rpx;
13 | min-height: 0;
14 | overflow: hidden;
15 | background-color: rgba(255, 255, 255, 0.9);
16 | border-radius: 5px;
17 | box-shadow: 0 0 20px rgba(190, 77, 43, 0.2);
18 | }
19 |
20 | .chat_face {
21 | width: 100rpx;
22 | height: 100rpx;
23 | float: left;
24 | margin-right: 30rpx;
25 | margin-top: 30rpx;
26 | }
27 |
28 | .chat_face image {
29 | width: 100rpx;
30 | height: 100rpx;
31 | border-radius: 50%;
32 | }
33 |
34 | .chat_words {
35 | width: 500rpx;
36 | float: left;
37 | font-size: 30rpx;
38 | line-height: 50rpx;
39 | color: #999;
40 | }
41 |
42 | .chat_meta {
43 | width: 100%;
44 | min-height: 0;
45 | overflow: hidden;
46 | margin-bottom: 10rpx;
47 | }
48 |
49 | .chat_user {
50 | display: inline-block;
51 | font-size: 30rpx;
52 | font-weight: 600;
53 | color: #666;
54 | float: left;
55 | }
56 |
57 | .chat_date {
58 | display: inline-block;
59 | font-size: 24rpx;
60 | color: #ccc;
61 | float: right;
62 | }
63 |
64 | .send_msg {
65 | width: 700rpx;
66 | padding: 25rpx;
67 | background-color: #fff;
68 | min-height: 0;
69 | position: fixed;
70 | bottom: 0;
71 | left: 0;
72 | border-top: 1px solid #f1f1f1;
73 | border-bottom: 1px solid #f1f1f1;
74 | }
75 |
76 | .send_ipt {
77 | width: 500rpx;
78 | padding: 10rpx;
79 | font-size: 30rpx;
80 | height: 60rpx;
81 | line-height: 60rpx;
82 | float: left;
83 | background-color: #f5f5f5;
84 | border-radius: 5px;
85 | }
86 |
87 | .send_btn {
88 | width: 150rpx;
89 | height: 80rpx;
90 | font-size: 36rpx;
91 | line-height: 80rpx;
92 | float: right;
93 | }
94 |
95 |
--------------------------------------------------------------------------------
/pages/invitation/index.js:
--------------------------------------------------------------------------------
1 | // pages/invitation/index.js
2 | const app = getApp()
3 | var server = app.globalData.server;
4 | var appid = app.globalData.appid;
5 | var touchDot = 0;//触摸时的原点
6 | var time = 0;// 时间记录,用于滑动时且时间小于1s则执行左右滑动
7 | var interval = "";// 记录/清理时间记录
8 | Page({
9 |
10 | /**
11 | * 页面的初始数据
12 | */
13 | data: {
14 | userInfo: {},
15 | },
16 |
17 | /**
18 | * 生命周期函数--监听页面加载
19 | */
20 | onLoad: function (options) {
21 | var that = this
22 |
23 | wx.getUserInfo({
24 | success: function (res) {
25 | that.setData({
26 | userInfo: res.userInfo
27 | })
28 | }
29 | })
30 | },
31 |
32 | /**
33 | * 生命周期函数--监听页面初次渲染完成
34 | */
35 | onReady: function () {
36 |
37 | },
38 |
39 | /**
40 | * 生命周期函数--监听页面显示
41 | */
42 | onShow: function () {
43 |
44 | },
45 |
46 | /**
47 | * 生命周期函数--监听页面隐藏
48 | */
49 | onHide: function () {
50 |
51 | },
52 |
53 | /**
54 | * 生命周期函数--监听页面卸载
55 | */
56 | onUnload: function () {
57 |
58 | },
59 |
60 | /**
61 | * 页面相关事件处理函数--监听用户下拉动作
62 | */
63 | onPullDownRefresh: function () {
64 |
65 | },
66 |
67 | /**
68 | * 页面上拉触底事件的处理函数
69 | */
70 | onReachBottom: function () {
71 |
72 | },
73 |
74 | /**
75 | * 用户点击右上角分享
76 | */
77 | onShareAppMessage: function () {
78 | var that = this;
79 | //console.log(that.data);
80 | return {
81 | title: that.data.mainInfo.share,
82 | imageUrl: that.data.mainInfo.thumb,
83 | path: 'pages/index/index',
84 | success: function (res) {
85 | wx.showToast({
86 | title: '分享成功',
87 | })
88 | },
89 | fail: function (res) {
90 | // 转发失败
91 | wx.showToast({
92 | title: '分享取消',
93 | })
94 | }
95 | }
96 | },
97 | callhe: function (event) {
98 | wx.makePhoneCall({
99 | phoneNumber: '18612643487'
100 | })
101 | },
102 | callshe: function (event) {
103 | wx.makePhoneCall({
104 | phoneNumber: '15041170858'
105 | })
106 | }
107 | })
--------------------------------------------------------------------------------
/WxComment/libs/scripts/common.js:
--------------------------------------------------------------------------------
1 | const timeAgoWithTimeStr = (dateString) => {
2 | // ios: 2018/06/02 11:11:11
3 | // android: 2018-06-02 11:11:11 & 2018/06/02 11:11:11
4 | var date_time_arr = dateString.split(' ');
5 | var ios_date_arr = date_time_arr[0].split('-');
6 | var ios_date_str = ios_date_arr[0] + '/' + ios_date_arr[1] + '/' + ios_date_arr[2];
7 | var ios_datetime_str = ios_date_str + ' ' + date_time_arr[1];
8 |
9 | var newDateString = dateString;
10 | newDateString = ios_datetime_str;
11 |
12 | var date = new Date(newDateString)
13 |
14 | try {
15 | var oldTime = date.getTime();
16 | var currTime = new Date().getTime();
17 | var diffValue = currTime - oldTime;
18 |
19 | var days = Math.floor(diffValue / (24 * 3600 * 1000));
20 |
21 | if (days === 0) {
22 | //计算相差小时数
23 | var leave1 = diffValue % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
24 | var hours = Math.floor(leave1 / (3600 * 1000));
25 | if (hours === 0) {
26 | //计算相差分钟数
27 | var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
28 | var minutes = Math.floor(leave2 / (60 * 1000));
29 | if (minutes === 0) {
30 | //计算相差秒数
31 | var leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数
32 | var seconds = Math.round(leave3 / 1000);
33 | return seconds + ' 秒前';
34 | }
35 | return minutes + ' 分钟前';
36 | }
37 | return hours + ' 小时前';
38 | }
39 | if (days < 0) return '刚刚';
40 |
41 | if (days < 3) {
42 | return days + ' 天前';
43 | } else {
44 | return dateString
45 | }
46 | } catch (error) {
47 | console.log(error)
48 | }
49 | }
50 |
51 | function getTime() {
52 | //获取当前时间戳
53 | var timestamp = Date.parse(new Date());
54 | var n = timestamp;
55 | var date = new Date(n);
56 | //年
57 | var Y = date.getFullYear();
58 | //月
59 | var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
60 | //日
61 | var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
62 | //时
63 | var h = date.getHours();
64 | //分
65 | var m = date.getMinutes();
66 | //秒
67 | var s = date.getSeconds();
68 | return Y + '-' + M + '-' + D + ' ' + h + ":" + m + ":" + s;
69 | }
70 |
71 | module.exports = {
72 | timeAgoWithTimeStr: timeAgoWithTimeStr,
73 | getTime: getTime
74 | }
--------------------------------------------------------------------------------
/pages/invitation/index.wxss:
--------------------------------------------------------------------------------
1 | /* pages/invitation/index.wxss */
2 |
3 | .container {
4 | background: url('http://pcgm4rcvg.bkt.clouddn.com/new_invite_page.jpg') no-repeat center;
5 | background-size: cover;
6 | width: 750rpx;
7 | height: 100vh;
8 | }
9 |
10 | .date {
11 | text-align: center;
12 | font-size: 30rpx;
13 | line-height: 50rpx;
14 | margin-top: 20rpx;
15 | }
16 |
17 | .name {
18 | width: 400rpx;
19 | margin: 0 auto;
20 | min-height: 0;
21 | overflow: hidden;
22 | margin-top: 20rpx;
23 | }
24 |
25 | .savethedate {
26 | width: 200rpx;
27 | height: 200rpx;
28 | margin: 0 auto;
29 | margin-top: 20rpx;
30 | margin-bottom: 20rpx;
31 | }
32 |
33 | .savethedate image {
34 | width: 200rpx;
35 | height: 200rpx;
36 | }
37 |
38 | .diamond {
39 | width: 400rpx;
40 | height: 59rpx;
41 | margin: 0 auto;
42 | margin-top: 20rpx;
43 | margin-bottom: 20rpx;
44 | }
45 |
46 | .diamond image {
47 | width: 400rpx;
48 | height: 59rpx;
49 | }
50 |
51 | .address {
52 | text-align: center;
53 | padding: 20rpx;
54 | font-size: 34rpx;
55 | line-height: 40rpx;
56 | }
57 |
58 | .s_icon {
59 | width: 60rpx;
60 | height: 60rpx;
61 | margin: 0 auto;
62 | margin-top: 30rpx;
63 | }
64 |
65 | .s_icon image {
66 | width: 60rpx;
67 | height: 60rpx;
68 | }
69 |
70 | .words {
71 | width: 400rpx;
72 | height: 96rpx;
73 | margin: 0 auto;
74 | margin-top: 20rpx;
75 | margin-bottom: 20rpx;
76 | }
77 |
78 | .words image {
79 | width: 400rpx;
80 | height: 96rpx;
81 | }
82 |
83 | .tel {
84 | position: fixed;
85 | bottom: 0;
86 | width: 750rpx;
87 | margin: 0 auto;
88 | min-height: 0;
89 | overflow: hidden;
90 | text-align: center;
91 | font-size: 20rpx;
92 | line-height: 50rpx;
93 | margin-top: 20rpx;
94 | margin-bottom: 40rpx;
95 | }
96 |
97 | /* display: flex;
98 | flex-flow: row;
99 | justify-content: center; */
100 |
101 | .tel_he {
102 | width: 250rpx;
103 | float: left;
104 | }
105 |
106 | .tel_she {
107 | width: 250rpx;
108 | float: right;
109 | }
110 |
111 | .call {
112 | width: 80rpx;
113 | height: 80rpx;
114 | display: block;
115 | margin: 0 auto;
116 | }
117 |
118 | .call image {
119 | width: 80rpx;
120 | height: 80rpx;
121 | margin-bottom: 10rpx;
122 | }
123 |
--------------------------------------------------------------------------------
/pages/map/index.js:
--------------------------------------------------------------------------------
1 | // pages/bless/index.js
2 |
3 | const app = getApp()
4 | var server = app.globalData.server;
5 | var appid = app.globalData.appid;
6 | Page({
7 |
8 | /**
9 | * 页面的初始数据
10 | */
11 | data: {
12 | userInfo: {},
13 | },
14 |
15 | markertap(e) {
16 |
17 | var lng = "114.842384"
18 | var lat = "38.023914"
19 | console.log(lat)
20 | wx.openLocation({
21 | latitude: parseFloat(lat),
22 | longitude: parseFloat(lng),
23 | scale: 18,
24 | name: "渔人码头宴会厅",
25 | address: "河北省 石家庄市 藁城区 "
26 | })
27 | },
28 |
29 | /**
30 | * 生命周期函数--监听页面加载
31 | */
32 | onLoad: function(options) {
33 | var that = this
34 |
35 | wx.getUserInfo({
36 | success: function(res) {
37 | that.setData({
38 | userInfo: res.userInfo
39 | })
40 | }
41 | })
42 |
43 | //地图信息
44 | var lng = "114.842384"
45 | var lat = "38.023914"
46 |
47 | // var lng = res.data.mainInfo.lng
48 | // var lat = res.data.mainInfo.lat
49 | that.setData({
50 | lng: lng, // 全局属性,用来取定位坐标
51 | lat: lat,
52 | markers: [{
53 | iconPath: "/images/nav.png",
54 | id: 0,
55 | latitude: lat, // 页面初始化 options为页面跳转所带来的参数
56 | longitude: lng,
57 | width: 50,
58 | height: 50
59 | }],
60 | });
61 | },
62 |
63 | /**
64 | * 生命周期函数--监听页面初次渲染完成
65 | */
66 | onReady: function() {
67 |
68 | },
69 |
70 | /**
71 | * 生命周期函数--监听页面显示
72 | */
73 | onShow: function() {
74 |
75 | },
76 |
77 | /**
78 | * 生命周期函数--监听页面隐藏
79 | */
80 | onHide: function() {
81 |
82 | },
83 |
84 | /**
85 | * 生命周期函数--监听页面卸载
86 | */
87 | onUnload: function() {
88 |
89 | },
90 |
91 | /**
92 | * 页面相关事件处理函数--监听用户下拉动作
93 | */
94 | onPullDownRefresh: function() {
95 |
96 |
97 | },
98 | /**
99 | * 页面上拉触底事件的处理函数
100 | */
101 | onReachBottom: function() {
102 |
103 | },
104 |
105 | /**
106 | * 用户点击右上角分享
107 | */
108 | onShareAppMessage: function() {
109 | var that = this;
110 | //console.log(that.data);
111 | return {
112 | title: that.data.mainInfo.share,
113 | imageUrl: that.data.mainInfo.thumb,
114 | path: 'pages/index/index',
115 | success: function(res) {
116 | wx.showToast({
117 | title: '分享成功',
118 | })
119 | },
120 | fail: function(res) {
121 | // 转发失败
122 | wx.showToast({
123 | title: '分享取消',
124 | })
125 | }
126 | }
127 | },
128 | })
--------------------------------------------------------------------------------
/WxComment/README.md:
--------------------------------------------------------------------------------
1 | # WxComment
2 |
3 | `WxComment`[https://github.com/yicm/WxComment](https://github.com/yicm/WxComment)是一个微信小程序的评论插件,结合BaaS提供商[LeanCloud](https://leancloud.cn/),无需其他另外的个人或者云服务器,就可以免费使用。解决了需要个人去注册域名、备案、购买云服务器的繁杂问题。
4 |
5 |
6 | # 特色
7 |
8 | - 独立插件,独立放入小程序项目即可使用
9 | - 友好的UI界面和交互界面
10 | - 与微信用户信息绑定,显示微信用户头像和昵称
11 | - 支持插件内容修改,包括按钮文字,评论提示,评论字数最低限制等属性
12 | - 支持长按删除评论操作
13 | - 支持评论点赞功能
14 | - 支持评论回复功能,即子评论
15 | - 子评论支持点赞功能
16 | - 支持emoji表情显示😉
17 | - 支持文章阅读量统计功能
18 | - 支持light/dark两种样式设置
19 | - 支持点击头像关注用户功能
20 | - 对发布高质量文章的用户关注(见微信小程序`小白AI`)
21 | - 关注后,可通过在WxComment组件外对用户详细资料查看等操作(见微信小程序`小白AI`)
22 | - 支持评论消息订阅功能
23 | - 评论指定文章或页面后,会自动订阅该文章或页面的评论,当有新的评论则可以实现消息更新,提示已有新的评论。
24 | - 支持配置Admin用户删除其他用户的评论
25 |
26 |
27 | # 屏幕截图
28 |
29 | 下图为`WxComment`嵌入式到具体博客中显示的效果。
30 |
31 | 
32 |
33 | # 快速入手
34 |
35 | 1. 注册LeanCloud账号,并创建过LeanCloud应用;
36 |
37 | 2. 登陆LeanCloud账号,打开链接[https://leancloud.cn/docs/weapp-domains.html](https://leancloud.cn/docs/weapp-domains.html),将显示域名配置到你的微信小程序服务器配置中;
38 |
39 | 3. 设置小程序的 AppID 与 AppSecret
40 | 3.1 登录 微信公众平台,在`设置` > `开发设置` 中获得 AppID 与 AppSecret
41 | 3.2 前往 LeanCloud `控制台` > `组件` > `社交`,保存「微信小程序」的 AppID 与 AppSecret
42 |
43 | 4. 克隆项目WxComment并将其放入小程序根目录
44 |
45 | ```
46 | $ git clone https://github.com/yicm/WxComment.git
47 | ```
48 |
49 | 5. 将LeanCloud自己的AppID和AppKey复制到WxComment.js对应位置;
50 |
51 | ```
52 | AV.init({
53 | appId: 'your leancloud appid',
54 | appKey: 'your leancloud appkey',
55 | });
56 | ```
57 |
58 | 6. 在小程序其他wxml文件中引入WxComment组件
59 |
60 | test.wxml
61 |
62 | ```
63 |
66 | ```
67 |
68 | test.json
69 |
70 | ```
71 | "usingComponents": {
72 | "WxComment": "/component/WxComment/WxComment"
73 | }
74 | ```
75 |
76 | 7. 配置Admin删除其他用户评论
77 |
78 | - 登陆LeanCloud,进入应用->`存储`->`数据`->`创建Class`->创建`Admin` Class:
79 |
80 | 
81 |
82 |
83 | WxComment组件属性说明:
84 |
85 | ```bash
86 | tipOne: 颜色显示tip区域文字内容
87 | tipTwo: 无颜色显示tip区域文字内容
88 | submitBtnText:提交按钮文字内容,默认为“回复”
89 | textMaxLength: 评论最大文字长度限制,默认300
90 | articleID:文章或页面与WxComment绑定的唯一ID
91 | articleTitle: 文章或页面标题,默认值为空
92 | articleURL: 文章或页面的访问链接,默认值为空
93 | contentLen:评论内容至少为多长限制,默认为1
94 | theme: 评论组件样式,支持light/dark两种样式,默认值为light
95 | ```
96 |
97 | # Demo
98 |
99 | 小程序`小白AI`博客引用WxComment组件示例,评论消息订阅可见`我的`->`消息`:
100 |
101 | 
102 |
103 | # TODO
104 |
105 | - 支持查看用户详细信息以及优化关注功能
106 | - 支持设置用户资料
107 | - 支持匿名群聊和私聊
108 | - 支持评论附加图片
109 | - ...
110 |
111 | # License
112 |
113 | [MIT](https://opensource.org/licenses/MIT)
114 |
115 |
--------------------------------------------------------------------------------
/pages/chat/index.js:
--------------------------------------------------------------------------------
1 | // pages/chat/index.js
2 | const app = getApp()
3 | var appid = app.globalData.appid;
4 |
5 | Page({
6 |
7 | /**
8 | * 页面的初始数据
9 | */
10 | data: {
11 | userInfo: {},
12 | inputValue:'',
13 | article_id:'1'
14 | },
15 |
16 | /**
17 | * 生命周期函数--监听页面加载
18 | */
19 | onLoad: function (options) {
20 | var that = this
21 |
22 | wx.getUserInfo({
23 | success: function (res) {
24 | that.setData({
25 | userInfo: res.userInfo
26 | })
27 | }
28 | })
29 | },
30 |
31 | /**
32 | * 生命周期函数--监听页面初次渲染完成
33 | */
34 | onReady: function () {
35 |
36 | },
37 |
38 | /**
39 | * 生命周期函数--监听页面显示
40 | */
41 | onShow: function () {
42 |
43 | },
44 |
45 | /**
46 | * 生命周期函数--监听页面隐藏
47 | */
48 | onHide: function () {
49 |
50 | },
51 |
52 | /**
53 | * 生命周期函数--监听页面卸载
54 | */
55 | onUnload: function () {
56 |
57 | },
58 |
59 | /**
60 | * 页面相关事件处理函数--监听用户下拉动作
61 | */
62 | onPullDownRefresh: function () {
63 |
64 | },
65 |
66 | /**
67 | * 页面上拉触底事件的处理函数
68 | */
69 | onReachBottom: function () {
70 |
71 | },
72 |
73 | /**
74 | * 用户点击右上角分享
75 | */
76 | onShareAppMessage: function () {
77 | var that = this;
78 | //console.log(that.data);
79 | return {
80 | title: that.data.mainInfo.share,
81 | imageUrl: that.data.mainInfo.thumb,
82 | path: 'pages/index/index',
83 | success: function (res) {
84 | wx.showToast({
85 | title: '分享成功',
86 | })
87 | },
88 | fail: function (res) {
89 | // 转发失败
90 | wx.showToast({
91 | title: '分享取消',
92 | })
93 | }
94 | }
95 | },
96 | bindKeyInput: function(e) {
97 | this.setData({
98 | inputValue: e.detail.value
99 | })
100 | },
101 | foo:function(){
102 | var that = this;
103 | if(that.data.inputValue){
104 | //留言内容不是空值
105 |
106 | var userInfo = that.data.userInfo;
107 | var name = userInfo.nickName;
108 | var face = userInfo.avatarUrl;
109 | var words = that.data.inputValue;
110 | wx.request({
111 | url: "",
112 | data: { 'c': 'send', 'appid': appid, 'nickname': name, 'face': face , 'words': words },
113 | header: {},
114 | method: "GET",
115 | dataType: "json",
116 | success: res => {
117 | // console.log(res.data);
118 | if (res.data.success) {
119 | that.setData({
120 | chatList: res.data.chatList,
121 | chatNum: res.data.chatNum
122 | });
123 | wx.showModal({
124 | title: '提示',
125 | content: res.data.msg,
126 | showCancel: false
127 | })
128 | } else {
129 | wx.showModal({
130 | title: '提示',
131 | content: res.data.msg,
132 | showCancel: false
133 | })
134 | }
135 | }
136 | })
137 | }
138 | that.setData({
139 | inputValue:''//将data的inputValue清空
140 | });
141 | return;
142 | }
143 | })
--------------------------------------------------------------------------------
/pages/video/index.js:
--------------------------------------------------------------------------------
1 | // pages/map/index.js
2 | const app = getApp()
3 | var server = app.globalData.server;
4 | var appid = app.globalData.appid;
5 |
6 | const AV = require("../../WxComment/libs/leancloud/av-weapp-min.js");
7 | var Common = require('../../WxComment/libs/scripts/common.js');
8 | // LeanCloud 应用的 ID 和 Key
9 | // AV.init({
10 | // appId: 'Q7y6ChsRaO66w6DLJ7XR0IF9-gzGzoHsz',
11 | // appKey: 'tO9g5jhd0ETAx2vrRtR1NLp5',
12 | // });
13 |
14 | Page({
15 |
16 | /**
17 | * 页面的初始数据
18 | */
19 | data: {
20 | userInfo: {},
21 |
22 | movieList:
23 |
24 | [{
25 | img: "http://pcgm4rcvg.bkt.clouddn.com/marry/video1532782634171.mp4?vframe/jpg/offset/7/rotate/auto",
26 | desc: "缘分来得早或者迟,没有关系,遇见你,就是我最好的时光",
27 | time: 1532519734589,
28 | title: "海边",
29 | vid: "e0354z3cqjp",
30 | src: "http://pcgm4rcvg.bkt.clouddn.com/marry/video1532782634171.mp4"
31 | },
32 | {
33 | img: "http://pcgm4rcvg.bkt.clouddn.com/marry/video1532871405425.mp4?vframe/jpg/offset/3/rotate/auto",
34 | desc: "阳光与你同在,就是我想要的未来",
35 | time: 1532519734589,
36 | title: "绿地",
37 | vid: "e0354z3cqjp",
38 | src: "http://pcgm4rcvg.bkt.clouddn.com/marry/video1532871405425.mp4"
39 | },
40 | {
41 | img: "http://pcgm4rcvg.bkt.clouddn.com/marry/video1532963841560.mp4?vframe/jpg/offset/1/rotate/auto",
42 | desc: "大步大步地跑向你,像海洋歌颂旭日一样,歌颂我爱的你~",
43 | time: 1532519734589,
44 | title: "喷泉",
45 | vid: "e0354z3cqjp",
46 | src: "http://pcgm4rcvg.bkt.clouddn.com/marry/video1532963841560.mp4"
47 | }
48 | ]
49 | },
50 |
51 | /**
52 | * 生命周期函数--监听页面加载
53 | */
54 | onLoad: function(options) {
55 | var that = this
56 |
57 | wx.getUserInfo({
58 | success: function(res) {
59 | that.setData({
60 | userInfo: res.userInfo
61 | })
62 | }
63 | })
64 |
65 | var query = new AV.Query('VideoList');
66 | query.include('src');
67 | console.log('韩洋1');
68 | query.find().then(function(videoList) {
69 | // 将返回结果返回到 data 数据中,以在 wxml 渲染
70 |
71 |
72 | console.log('韩洋4:' + videoList.length);
73 |
74 | for (var i = 0, len = videoList.length; i < len; i++) {
75 |
76 | var str = JSON.stringify(videoList[i]);
77 | var obj = JSON.parse(str);
78 | that.data.movieList.unshift(obj);
79 | console.log('韩洋9' + obj.name);//遍历输出
80 | }
81 |
82 | that.setData({
83 | movieList: that.data.movieList
84 | })
85 |
86 | }, function(err) {
87 | console.log(err);
88 | });
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 | },
105 |
106 | /**
107 | * 生命周期函数--监听页面初次渲染完成
108 | */
109 | onReady: function() {
110 |
111 | },
112 |
113 | /**
114 | * 生命周期函数--监听页面显示
115 | */
116 | onShow: function() {
117 |
118 | },
119 |
120 | /**
121 | * 生命周期函数--监听页面隐藏
122 | */
123 | onHide: function() {
124 |
125 | },
126 |
127 | /**
128 | * 生命周期函数--监听页面卸载
129 | */
130 | onUnload: function() {
131 |
132 | },
133 |
134 | /**
135 | * 页面相关事件处理函数--监听用户下拉动作
136 | */
137 | onPullDownRefresh: function() {
138 |
139 | },
140 |
141 | /**
142 | * 页面上拉触底事件的处理函数
143 | */
144 | onReachBottom: function() {
145 |
146 | },
147 |
148 | /**
149 | * 用户点击右上角分享
150 | */
151 | onShareAppMessage: function() {
152 | var that = this;
153 | //console.log(that.data);
154 | return {
155 | title: that.data.mainInfo.share,
156 | imageUrl: that.data.mainInfo.thumb,
157 | path: 'pages/index/index',
158 | success: function(res) {
159 | wx.showToast({
160 | title: '分享成功',
161 | })
162 | },
163 | fail: function(res) {
164 | // 转发失败
165 | wx.showToast({
166 | title: '分享取消',
167 | })
168 | }
169 | }
170 | }
171 | })
--------------------------------------------------------------------------------
/pages/index/index.js:
--------------------------------------------------------------------------------
1 | //index.js
2 | //获取应用实例
3 | const app = getApp()
4 | var appid = app.globalData.appid;
5 | const AV = require("../../WxComment/libs/leancloud/av-weapp-min.js");
6 | var Common = require('../../WxComment/libs/scripts/common.js');
7 | // LeanCloud 应用的 ID 和 Key
8 | // AV.init({
9 | // appId: 'Q7y6ChsRaO66w6DLJ7XR0IF9-gzGzoHsz',
10 | // appKey: 'tO9g5jhd0ETAx2vrRtR1NLp5',
11 | // });
12 |
13 |
14 | Page({
15 | data: {
16 | userInfo: {},
17 | music_url: 'http://pcgm4rcvg.bkt.clouddn.com/bgmusic_yudao.mp3',
18 | isPlayingMusic: true,
19 | title: '我们结婚啦',
20 | coverImgUrl: 'http://pcgm4rcvg.bkt.clouddn.com/marry/img/music_cover.jpg',
21 |
22 |
23 | testimgUrls: [
24 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img16.jpg',
25 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img2.jpg',
26 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img3.jpg',
27 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img4.jpg',
28 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img5.jpg',
29 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img6.jpg',
30 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img17.jpg',
31 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img8.jpg',
32 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img9.jpg',
33 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img10.jpg',
34 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img11.jpg',
35 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img12.jpg',
36 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img13.jpg',
37 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img14.jpg',
38 | 'http://pcgm4rcvg.bkt.clouddn.com/marry/img15.jpg',
39 |
40 | ],
41 |
42 |
43 | },
44 |
45 | onLoad: function() {
46 | var that = this
47 |
48 | wx.getUserInfo({
49 | success: function(res) {
50 | that.setData({
51 | userInfo: res.userInfo
52 | })
53 | }
54 | })
55 |
56 | var query = new AV.Query('ImageList');
57 | query.include('src');
58 | query.find().then(function(imageList) {
59 | // 将返回结果返回到 data 数据中,以在 wxml 渲染
60 |
61 |
62 | console.log('韩洋4:' + imageList.length);
63 |
64 | for (var i = 0, len = imageList.length; i < len; i++) {
65 |
66 | var str = JSON.stringify(imageList[i]);
67 | var obj = JSON.parse(str);
68 | that.data.testimgUrls.unshift(obj.src);
69 | console.log('韩洋9' + obj.src); //遍历输出
70 | }
71 |
72 | that.setData({
73 | testimgUrls: that.data.testimgUrls
74 | })
75 |
76 | }, function(err) {
77 | console.log(err);
78 | });
79 |
80 |
81 |
82 | /**
83 | * 不支持aac格式
84 | */
85 | const backgroundAudioManager = wx.getBackgroundAudioManager()
86 | player()
87 |
88 | function player() {
89 | backgroundAudioManager.title = that.data.title,
90 | backgroundAudioManager.src = that.data.music_url
91 | backgroundAudioManager.coverImgUrl = that.data.coverImgUrl
92 | backgroundAudioManager.play();
93 |
94 | backgroundAudioManager.onEnded(() => {
95 | player()
96 | })
97 | }
98 |
99 | // wx.playBackgroundAudio({
100 | // dataUrl: this.data.music_url,
101 | // title: this.data.title,
102 | // coverImgUrl: this.data.coverImgUrl
103 | // })
104 |
105 |
106 |
107 | },
108 | onReady: function() {
109 | // 页面渲染完成
110 | },
111 | onShow: function() {
112 | // 页面显示
113 | },
114 | onHide: function() {
115 | // 页面隐藏
116 | },
117 | onUnload: function() {
118 | // 页面关闭
119 | },
120 | onShareAppMessage: function(res) {
121 | var that = this;
122 | //console.log(that.data);
123 | return {
124 | title: that.data.mainInfo.share,
125 | imageUrl: that.data.mainInfo.thumb,
126 | path: 'pages/index/index',
127 | success: function(res) {
128 | wx.showToast({
129 | title: '分享成功',
130 | })
131 | },
132 | fail: function(res) {
133 | // 转发失败
134 | wx.showToast({
135 | title: '分享取消',
136 | })
137 | }
138 | }
139 | },
140 | play: function(event) {
141 | if (this.data.isPlayingMusic) {
142 | wx.pauseBackgroundAudio();
143 | this.setData({
144 | isPlayingMusic: false
145 | })
146 | } else {
147 | wx.playBackgroundAudio({
148 | dataUrl: this.data.music_url,
149 | title: this.data.title,
150 | coverImgUrl: this.data.coverImgUrl
151 | })
152 | this.setData({
153 | isPlayingMusic: true
154 | })
155 | }
156 | },
157 | })
--------------------------------------------------------------------------------
/WxComment/component/WxComment/WxComment.wxss:
--------------------------------------------------------------------------------
1 | image, video {
2 | width: 100%;
3 | margin: 0 auto auto auto;
4 | }
5 |
6 | image {
7 | height: auto;
8 | }
9 |
10 | .theme_dark {
11 | background-color: black;
12 | color: white;
13 | }
14 |
15 | .title_box {
16 | display: flex;
17 | height: 70rpx;
18 | justify-content: center;
19 | margin-top: 20rpx;
20 | }
21 |
22 | .comment_list_box {
23 | display: flex;
24 | justify-content: center;
25 | }
26 |
27 | .comment_list {
28 | display: flex;
29 | width: 630rpx;
30 | margin: 0 auto;
31 | margin-top: 30rpx;
32 | padding: 30rpx;
33 | min-height: 0;
34 | background-color: rgba(255, 255, 255, 0.9);
35 | border-radius: 5px;
36 | box-shadow: 0 0 20px rgba(190, 77, 43, 0.2);
37 | }
38 |
39 | .comment_avatar {
40 | width: 90rpx;
41 | height: 90rpx;
42 | }
43 |
44 | .comment_avatar image {
45 | width: 90rpx;
46 | height: 90rpx;
47 | border-radius: 50%;
48 | }
49 |
50 | .avatar_button {
51 | background: none;
52 | border: none;
53 | padding: 1rpx 20rpx 1rpx 1rpx;
54 | margin: 1rpx 5rpx 0rpx 5rpx;
55 | }
56 |
57 | .avatar_button::after {
58 | border: none;
59 | outline: none;
60 |
61 | }
62 |
63 | .comment_total_box {
64 | width: 610rpx;
65 | display: flex;
66 | flex-direction: column;
67 | }
68 |
69 | .comment_content_box {
70 | display: flex;
71 | flex-direction: row;
72 | width: 100%;
73 | margin-bottom: 17rpx;
74 | }
75 |
76 | .comment_meta {
77 | display: flex;
78 | flex-direction: row;
79 | flex-wrap: wrap;
80 | justify-content: flex-start;
81 | width: 100%;
82 | margin-bottom: 8rpx;
83 | }
84 |
85 | .comment_nickname {
86 | display: flex;
87 | width: 100%;
88 | margin-right: 20rpx;
89 | margin-left: 20rpx;
90 | font-size: 26rpx;
91 | font-weight: 600;
92 | color: #3f9f94;
93 | }
94 |
95 | .comment_content {
96 | word-break:break-all;
97 | font-size: 32rpx;
98 | margin-left: 25rpx;
99 | width: 100%;
100 | color: #6f6f6f;
101 | }
102 |
103 | .commnet_date {
104 | margin-left: 10rpx;
105 | font-size: 24rpx;
106 | color: #8e8e8e;
107 | }
108 |
109 | .comment_zan {
110 | margin-left: 20rpx;
111 | display: flex;
112 | flex-direction: row;
113 |
114 | }
115 |
116 | .comment_zan image {
117 | width: 30rpx;
118 | height: 30rpx;
119 | }
120 |
121 | .comment_zan_num {
122 | color: #425888;
123 | font-size: 24rpx;
124 | height: 30rpx;
125 |
126 | }
127 |
128 | .no_comment {
129 | color: #dadada;
130 | }
131 |
132 | .title_display {
133 | width: 720rpx;
134 | display: flex;
135 | margin-left: 40rpx;
136 | flex-direction: row;
137 | padding-bottom: 2rpx;
138 | /*border-bottom: 1px solid #f1f1f1;*/
139 | }
140 |
141 | .views_box {
142 | display: flex;
143 | height: 30rpx;
144 | justify-content: center;
145 | margin-top: 25rpx;
146 | margin-bottom: 10rpx;
147 | }
148 |
149 | .views_title_display {
150 | display: flex;
151 | flex-direction: row;
152 | width: 720rpx;
153 | padding-bottom: 2rpx;
154 | }
155 |
156 | .views_image {
157 | }
158 |
159 | .views_image image {
160 | width: 35rpx;
161 | height: 35rpx;
162 | }
163 |
164 | .views_text {
165 | width: 200rpx;
166 | height: 35rpx;
167 | color: #bfbfbf;
168 | font-size: 22rpx;
169 | line-height: 35rpx;
170 | margin-left: 10rpx;
171 | }
172 |
173 | .seg_line_box {
174 | display: flex;
175 | height: 5rpx;
176 | justify-content: center;
177 | margin-top: 5rpx;
178 | }
179 |
180 | .seg_line_left {
181 | width: 325rpx;
182 | border-bottom: 1rpx solid #e1e1e1;
183 | }
184 |
185 | .seg_line_dot {
186 | width: 50rpx;
187 | border-bottom: 5rpx dotted #dbdbdb;
188 | margin-left: 10rpx;
189 | margin-right: 10rpx;
190 | }
191 |
192 | .seg_line_right {
193 | width: 325rpx;
194 | border-bottom: 1rpx solid #e1e1e1;
195 | }
196 |
197 | .title_img image {
198 | width: 60rpx;
199 | height: 60rpx;
200 | }
201 |
202 | .title_text {
203 | display: flex;
204 | color: #3f9f94;
205 | font-size: 38rpx;
206 | line-height: 60rpx;
207 | margin-left: 10rpx;
208 | }
209 |
210 | .comment_submit_tip {
211 | width: 550rpx;
212 | font-size: 22rpx;
213 | height: 72rpx;
214 | line-height: 100rpx;
215 | margin: 2rpx auto 2rpx auto;
216 | }
217 |
218 | .markdown_tip {
219 | color: #ee9a49;
220 | }
221 |
222 | .sub_comment_list_box {
223 | margin-left: 70rpx;
224 | display: flex;
225 | flex-direction: column;
226 |
227 | }
228 |
229 | .sub_comment_display_box {
230 | display: flex;
231 | flex-direction: row;
232 | }
233 |
234 | .sub_comment_box {
235 | display: flex;
236 | flex-direction: column;
237 | width: 510rpx;
238 | }
239 |
240 | .hide {
241 | position: fixed;
242 | display: none;
243 | }
244 |
245 | .show {
246 | display: block;
247 | }
248 |
249 | .comment_submit_display {
250 | width: 150rpx;
251 | height: 80rpx;
252 | font-size: 36rpx;
253 | line-height: 80rpx;
254 | float: right;
255 | }
256 |
257 | .comment_display {
258 | display: flex;
259 | align-items: Center;
260 | justify-content: space-between;
261 | width: 700rpx;
262 | padding: 25rpx;
263 | background-color: #fff;
264 | min-height: 0;
265 | position: fixed;
266 | bottom: 0;
267 | left: 0;
268 | border-top: 1px solid #f1f1f1;
269 | border-bottom: 1px solid #f1f1f1;
270 | }
271 |
272 | .comment_textarea {
273 | width: 500rpx;
274 | padding: 10rpx;
275 | font-size: 30rpx;
276 | height: 65rpx;
277 | line-height: 1;
278 | float: left;
279 | background-color: #f5f5f5;
280 | border-radius: 5px;
281 | }
282 |
283 | .commit_submit_btn {
284 | width: 150rpx;
285 | height: 80rpx;
286 | font-size: 36rpx;
287 | line-height: 80rpx;
288 | float: right;
289 | }
290 |
291 | .befirst {
292 | width: 600rpx;
293 | height: 450rpx;
294 | margin: 0 auto;
295 | min-height: 0;
296 | overflow: hidden;
297 | margin-top: 200rpx;
298 | }
299 |
300 | .befirst image {
301 | width: 600rpx;
302 | height: 450rpx;
303 | }
304 |
--------------------------------------------------------------------------------
/WxComment/component/WxComment/WxComment.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | 阅读量:{{article_views}}
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | 评论列表
29 |
30 | ,共{{comment_num}}条评论
31 |
32 |
33 |
34 |
35 |
36 |
37 |
153 |
154 |
155 |
165 |
166 |
167 |
191 |
192 |
193 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
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 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 | markertap
139 |
140 |
141 |
142 |
143 |
144 |
145 |
160 |
161 |
162 |
163 |
164 | true
165 | DEFINITION_ORDER
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 | project
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 | project
379 |
380 |
381 | true
382 |
383 |
384 |
385 | DIRECTORY
386 |
387 | false
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 | 1532426681119
398 |
399 |
400 | 1532426681119
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 |
598 |
599 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
620 |
621 |
622 |
623 |
624 |
625 |
626 |
627 |
628 |
629 |
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 |
651 |
652 |
653 |
654 |
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
672 |
673 |
674 |
675 |
676 |
677 |
678 |
679 |
680 |
681 |
682 |
683 |
684 |
685 |
686 |
687 |
688 |
689 |
690 |
691 |
692 |
693 |
694 |
695 |
696 |
697 |
698 |
699 |
700 |
701 |
702 |
703 |
704 |
705 |
706 |
707 |
708 |
709 |
710 |
711 |
712 |
713 |
714 |
715 |
716 |
717 |
718 |
719 |
720 |
721 |
722 |
723 |
724 |
725 |
726 |
727 |
728 |
729 |
730 |
731 |
732 |
733 |
734 |
735 |
736 |
737 |
738 |
739 |
740 |
741 |
742 |
743 |
744 |
745 |
746 |
747 |
748 |
749 |
750 |
751 |
752 |
753 |
754 |
755 |
756 |
757 |
758 |
759 |
760 |
761 |
762 |
763 |
764 |
765 |
766 |
767 |
768 |
769 |
770 |
771 |
772 |
773 |
774 |
775 |
776 |
777 |
778 |
779 |
780 |
781 |
782 |
783 |
784 |
785 |
786 |
787 |
788 |
789 |
790 |
791 |
792 |
793 |
794 |
795 |
796 |
797 |
--------------------------------------------------------------------------------
/WxComment/component/WxComment/WxComment.js:
--------------------------------------------------------------------------------
1 | /*
2 | * author: yicm1102@gmail.com
3 | * github: https://github.com/yicm/WxComment
4 | * github_page: https://yicm.github.io
5 | */
6 | const AV = require('../../libs/leancloud/av-weapp-min.js');
7 | var Common = require('../../libs/scripts/common.js');
8 | // LeanCloud 应用的 ID 和 Key
9 | AV.init({
10 | appId: 'Q7y6ChsRaO66w6DLJ7XR0IF9-gzGzoHsz',
11 | appKey: 'tO9g5jhd0ETAx2vrRtR1NLp5',
12 | });
13 |
14 | Component({
15 | properties: {
16 | tipOne: {
17 | type: String,
18 | value: 'Markdown'
19 | },
20 | tipTwo: {
21 | type: String,
22 | value: 'will be supported, Powered by yicm.'
23 | },
24 | submitBtnText: {
25 | type: String,
26 | value: '回复'
27 | },
28 | textMaxLength: {
29 | type: Number,
30 | value: 300
31 | },
32 | articleTitle: {
33 | type: String,
34 | value: ''
35 | },
36 | articleURL: {
37 | type: String,
38 | value: ''
39 | },
40 | theme: {
41 | type: String,
42 | value: 'light' // light & dark
43 | },
44 | articleID: {
45 | type: String,
46 | value: '',
47 | observer: function (newVal, oldVal) {
48 | console.log(this.data.articleID);
49 | var that = this;
50 | // 定义内部Promise相关函数
51 | function promiseGetSubComment(index, p_id) {
52 | return new Promise(function (resolve, reject) {
53 | var sub_query = new AV.Query('WxSubComment');
54 | sub_query.ascending('createdAt');
55 | sub_query.include('targetUser');
56 | sub_query.include('targetZan');
57 | sub_query.equalTo('p_id', p_id)
58 | sub_query.find().then(function (sub_comments) {
59 | resolve([index, p_id, sub_comments]);
60 | })
61 | });
62 | }
63 |
64 | wx.showLoading({
65 | title: '加载中',
66 | })
67 | setTimeout(function () {
68 | wx.hideLoading()
69 | }, 3000)
70 | // 文章阅读量和文章点赞统计和显示
71 | var count_query = new AV.Query('Count');
72 | count_query.equalTo('article_id', that.data.articleID);
73 | count_query.find().then(function (results) {
74 | // 阅读量统计对象一文章对应一对象
75 | if (results.length == 1) {
76 | var count_todo = AV.Object.createWithoutData('Count', results[0].id);
77 | count_todo.save().then(function (count_todo) {
78 | count_todo.increment('views', 1);
79 | count_todo.fetchWhenSave(true);
80 | return count_todo.save();
81 | }).then(function (count_todo) {
82 | // show
83 | //console.log(count_todo);
84 | //console.log(count_todo.attributes.views);
85 | that.setData({
86 | article_views: count_todo.attributes.views
87 | });
88 | }, function (error) {
89 | // 异常处理
90 | console.log(error);
91 | });
92 | }
93 | else if (results.length == 0) {
94 | // 初始化文章统计对象
95 | var ArticleCount = AV.Object.extend('Count');
96 | var articlecount = new ArticleCount();
97 | articlecount.set('article_id', that.data.articleID);
98 | articlecount.set('views', 1);
99 | articlecount.set('zan', 0);
100 | articlecount.save();
101 | // show
102 | that.setData({
103 | article_views: 1
104 | });
105 | // 初始化文章评论计数
106 | var ArticleCommentCount = AV.Object.extend('WxCommentCount');
107 | var articlecommentcount = new ArticleCommentCount();
108 | articlecommentcount.set('article_id', that.data.articleID);
109 | articlecommentcount.set('article_title', that.data.articleTitle);
110 | articlecommentcount.set('article_url', that.data.articleURL);
111 | articlecommentcount.set('count', 0);
112 | articlecommentcount.save();
113 | }
114 | else {
115 | console.log(that.data.articleID);
116 | console.log("文章ID有重复,请检查!");
117 | }
118 | }, function (error) {
119 | console.log(error.message);
120 | console.log(error.code);
121 | // https://leancloud.cn/docs/error_code.html#hash1444
122 | // 第一次创建Count Class
123 | if (error.code == 101) {
124 | var ArticleCount = AV.Object.extend('Count');
125 | var articlecount = new ArticleCount();
126 | articlecount.set('article_id', that.data.articleID);
127 | articlecount.set('views', 1);
128 | articlecount.set('zan', 0);
129 | articlecount.save();
130 | // show
131 | that.setData({
132 | article_views: 1
133 | });
134 | }
135 | });
136 |
137 | // 完成阅读量统计查询,Then...
138 | // 加载评论列表和评论点赞信息
139 | AV.User.loginWithWeapp().then(user => {
140 | that.data.leancloud_user_id = user.id;
141 | that.data.login_user_info = user.toJSON();
142 |
143 | var query = new AV.Query('WxComment');
144 | query.equalTo('article_id', that.data.articleID);
145 | // descending:降序/ascending:升序
146 | query.ascending('createdAt');
147 | // 同时查询包含对象Pointer的详细信息
148 | query.include('targetUser');
149 | query.include('targetZan');
150 | query.include('subCommentList');
151 | query.find().then(function (results) {
152 | //console.log(results);
153 | that.data.all_comment_num = results.length;
154 | // 处理初次加载的评论
155 | var promiseFuncArr = [];
156 | for (var i = 0; i < results.length; i++) {
157 | var item = {};
158 | item['p_index'] = i;
159 | item['p_id'] = results[i].id;
160 | item['id'] = results[i].id;
161 | item['userId'] = results[i].attributes.targetUser.id;
162 | item['zanId'] = results[i].attributes.targetZan.id;
163 | // 赞list
164 | var zanUserList = results[i].attributes.targetZan.attributes.userList;
165 | item['zanCurrent'] = false;
166 | for (var j = 0; j < zanUserList.length; j++) {
167 | if (zanUserList[j] == that.data.leancloud_user_id) {
168 | item['zanCurrent'] = true;
169 | break;
170 | } else {
171 | item['zanCurrent'] = false;
172 | }
173 | }
174 |
175 | item['zanNum'] = results[i].attributes.targetZan.attributes.zan;
176 | item['articleID'] = results[i].attributes.article_id;
177 | item['nickName'] = results[i].attributes.targetUser.attributes.nickName;
178 | if (item['nickName'].length > that.data.comment_nickname_len) {
179 | item['showNickName'] = item['nickName'].substr(0, that.data.comment_nickname_len) + "...";
180 | }
181 | else {
182 | item['showNickName'] = item['nickName'];
183 | }
184 | item['pre_' + item['id']] = item['nickName'];
185 | item['avatarUrl'] = results[i].attributes.targetUser.attributes.avatarUrl;
186 | item['content'] = results[i].attributes.content;
187 | item['time'] = Common.timeAgoWithTimeStr(results[i].attributes.time);
188 | item['at'] = results[i].attributes.at;
189 |
190 | item['subCommentList'] = [];
191 | if (results[i].attributes.subCommentList.length > 0) {
192 | that.data.all_comment_num = that.data.all_comment_num + results[i].attributes.subCommentList.length;
193 | that.data.leancloud_comment_data.push(item);
194 | promiseFuncArr.push(promiseGetSubComment(i, results[i].id));
195 | } else {
196 | that.data.leancloud_comment_data.push(item);
197 | }
198 | } // end for results
199 |
200 | var p = Promise.resolve();
201 | for (var x = 0; x <= promiseFuncArr.length; x++) {
202 | (function (x) {
203 | p = p.then(function (data) {
204 | // 第一次data为空promise,undefined
205 | // 开始处理子评论
206 | if (x > 0) {
207 | var p_index = data[0];
208 | var p_id = data[1];
209 | var sub_comments = data[2];
210 | for (var k = 0; k < sub_comments.length; k++) {
211 | var sub_item = {}
212 | sub_item['p_index'] = p_index;
213 | sub_item['p_id'] = p_id;
214 | sub_item['id'] = sub_comments[k].id;
215 | sub_item['userId'] = sub_comments[k].attributes.targetUser.id;
216 | sub_item['zanId'] = sub_comments[k].attributes.targetZan.id;
217 | // 子评论赞list
218 | var subzanUserList = sub_comments[k].attributes.targetZan.attributes.userList;
219 | sub_item['zanCurrent'] = false;
220 | for (var m = 0; m < subzanUserList.length; m++) {
221 | if (subzanUserList[m] == that.data.leancloud_user_id) {
222 | sub_item['zanCurrent'] = true;
223 | break;
224 | } else {
225 | sub_item['zanCurrent'] = false;
226 | }
227 | }
228 | sub_item['zanNum'] = sub_comments[k].attributes.targetZan.attributes.zan;
229 | sub_item['articleID'] = sub_comments[k].attributes.article_id;
230 | sub_item['nickName'] = sub_comments[k].attributes.targetUser.attributes.nickName;
231 | if (sub_item['nickName'].length > that.data.subcomment_nickname_len) {
232 | sub_item['showNickName'] = sub_item['nickName'].substr(0, that.data.subcomment_nickname_len) + "...";
233 | }
234 | else {
235 | sub_item['showNickName'] = sub_item['nickName'];
236 | }
237 | sub_item['pre_' + sub_item['id']] = sub_item['nickName'];
238 | sub_item['avatarUrl'] = sub_comments[k].attributes.targetUser.attributes.avatarUrl;
239 | sub_item['content'] = sub_comments[k].attributes.content;
240 | sub_item['time'] = Common.timeAgoWithTimeStr(sub_comments[k].attributes.time);
241 | sub_item['at'] = sub_comments[k].attributes.at;
242 | that.data.leancloud_comment_data[p_index].subCommentList.push(sub_item)
243 | } // end for subcoments
244 | } // end if
245 | if (x == promiseFuncArr.length) {
246 | //console.log('finished')
247 | console.log(that.data.all_comment_num);
248 | // 显示所有评论
249 | that.setData({
250 | leancloud_comment_data: that.data.leancloud_comment_data,
251 | comment_num: that.data.leancloud_comment_data.length
252 | });
253 | that._isAdmin();
254 | return null;
255 | }
256 | // 当x为length时,return promiseFuncArr[x]()后,循环退出,
257 | // 没有then方法获取promiseFuncArr[x]()的回调
258 | // 因此多循环一次
259 | return promiseFuncArr[x];
260 | });
261 | })(x)
262 | }
263 |
264 | wx.hideLoading();
265 | }).catch(console.error);
266 | }, function (error) {
267 | wx.showToast({
268 | title: '评论加载失败!',
269 | icon: 'none',
270 | duration: 2000
271 | })
272 | });
273 | }
274 | },
275 | contentLen: {
276 | // 评论内容至少为多长限制
277 | type: Number,
278 | value: 1
279 | }
280 | },
281 | data: {
282 | textarea_focus: false,
283 | is_sub_comment: false,
284 | sub_comment_p_comment_id: '',
285 | sub_comment_p_index: -1,
286 | article_id: "",
287 | comment_count_id: "",
288 | comment_data: "",
289 | comment_num: 0,
290 | all_comment_num: 0,
291 | show_aur_button: false,
292 | user_info: [],
293 | leancloud_user_id: '',
294 | login_user_info: [],
295 | leancloud_comment_data: [],
296 | leancloud_comment_zan_data: [],
297 | article_views: 0,
298 | is_admin: false,
299 | comment_nickname_len: 12,
300 | subcomment_nickname_len: 10
301 | },
302 | methods: {
303 | // 事件响应函数
304 | bindFormSubmit: function (e) {
305 | var that = this;
306 | // 判断内容是否满足要求
307 | //console.log(that.data.contentLen);
308 | if (e.detail.value.comment_text.length <= that.data.contentLen) {
309 | wx.showToast({
310 | title: '评论内容长度不够!',
311 | icon: 'none',
312 | duration: 2000
313 | })
314 | return;
315 | }
316 |
317 | //console.log(that.data.articleID);
318 | that.data.article_id = that.data.articleID;
319 | that.data.comment_data = e.detail.value.comment_text;
320 |
321 | // 双重判断是否是子评论
322 | if (that.data.is_sub_comment) {
323 | // 再通过文本内容是否含有@字符判断
324 | if (that.data.comment_data.charAt(0) == '@') {
325 | // Done
326 | }
327 | else {
328 | that.data.is_sub_comment = false
329 | }
330 | }
331 |
332 | // 获取用户信息
333 | wx.getSetting({
334 | success(res) {
335 | if (!res.authSetting['scope.userInfo']) {
336 | console.log("没有授权获取用户信息");
337 | wx.showToast({
338 | title: '没有授权获取用户信息',
339 | icon: 'none',
340 | duration: 2000
341 | })
342 | that.setData({
343 | show_aur_button: true
344 | });
345 | } else {
346 | console.log("已经授权获取用户信息,开始获取信息");
347 | that.setData({
348 | comment_textarea_value: ''
349 | })
350 |
351 | wx.getUserInfo({
352 | success: function (res) {
353 | that.setData({
354 | user_info: res.userInfo
355 | });
356 | // LeanCloud 用户一键登录
357 | AV.User.loginWithWeapp().then(user => {
358 | //console.log('user...');
359 | //console.log(user);
360 | that.data.login_user_info = user.toJSON();
361 | //console.log(that.data.login_user_info);
362 | // 更新LeanCloud用户信息
363 | that._updateUserInfoInLeanCloud();
364 | // 写入评论
365 | // 写入并更新显示评论
366 | if (that.data.is_sub_comment) {
367 | // 子评论
368 | that._writeSubCommentInLeanCloud();
369 | that.data.is_sub_comment = false;
370 | }
371 | else {
372 | that._writeCommentInLeanCloud();
373 | }
374 | }).catch(console.error);
375 | }
376 | })
377 | }
378 | }, fail: function () {
379 | console.log("获取用户的当前设置失败");
380 | }
381 | })
382 |
383 | },
384 | commentTextTap: function (e) {
385 | //console.log('commentTextTap')
386 | // 子评论
387 | var that = this;
388 | var parent_comment_id = e.currentTarget.dataset.p_comment_id;
389 | var user_id = e.currentTarget.dataset.user_id;
390 | var comment_id = e.currentTarget.dataset.comment_id;
391 | var nickname = e.currentTarget.dataset.nickname;
392 | var p_index = e.currentTarget.dataset.p_index;
393 |
394 | //console.log(p_index)
395 | //console.log(parent_comment_id)
396 |
397 | that.setData({
398 | comment_textarea_value: '@' + nickname + ' ',
399 | textarea_focus: true,
400 | })
401 |
402 | that.data.is_sub_comment = true;
403 | that.data.sub_comment_p_comment_id = parent_comment_id;
404 | that.data.sub_comment_p_index = p_index;
405 | // 使页面滚动到底部
406 | wx.pageScrollTo({
407 | scrollTop: 10000
408 | })
409 | },
410 | _isAdmin: function() {
411 | var that = this;
412 | const user = AV.User.current();
413 |
414 | var query = new AV.Query('Admin');
415 | query.equalTo('adminId', user.id);
416 | query.find().then(function (results) {
417 | if(results.length >= 1) {
418 | that.data.is_admin = true;
419 | wx.showToast({
420 | title: '欢迎Admin!',
421 | icon: 'success',
422 | duration: 1000
423 | })
424 | }
425 | }, function(error) {
426 | console.log(error)
427 | // 101: 查询的 Class 不存在
428 | if (error.code == 101) {
429 | wx.showToast({
430 | title: 'Admin Class不存在,请手动添加',
431 | icon: 'none',
432 | duration: 2000
433 | })
434 | }
435 | })
436 | },
437 | _writeCommentSubscribeInLeanCloud: function() {
438 | var that = this;
439 | // 评论订阅
440 | const user = AV.User.current();
441 | // 先判断评论订阅Class里面是否已有当前用户ID
442 | var query = new AV.Query('WxCommentSubscribe');
443 | query.equalTo('user_id', user.id);
444 | query.find().then(function (results) {
445 | //console.log(results);
446 | if(results.length == 1) {
447 | var op_str = "update WxCommentSubscribe set comment_count_array=op('AddUnique', {'objects':[pointer('WxCommentCount','" + that.data.comment_count_id + "')]}) where objectId='" + results[0].id + "'";
448 | AV.Query.doCloudQuery(op_str).then(function (data) {
449 | console.log('更新评论订阅成功');
450 | }, function (error) {
451 | // 异常处理
452 | console.error(error);
453 | });
454 | }
455 | else if(results.length > 1){
456 | console.log('WxCommentSubscribe ID重复')
457 | }
458 | else{
459 | console.log('评论订阅还未有该用户')
460 | console.log(results.length)
461 | var ArticleCommentSubscribe = AV.Object.extend('WxCommentSubscribe');
462 | var articlecommentsubscribe = new ArticleCommentSubscribe();
463 | // writeCommentCountInLeanCloud必须先执行
464 | var comment_count_obj = AV.Object.createWithoutData('WxCommentCount', that.data.comment_count_id);
465 | articlecommentsubscribe.addUnique('comment_count_array', [comment_count_obj]);
466 | articlecommentsubscribe.set('user_id', user.id);
467 | articlecommentsubscribe.save();
468 | }
469 | }, function (error) {
470 | console.log(error);
471 | console.log(error.code)
472 | // 101: 查询的 Class 不存在
473 | if(error.code == 101) {
474 | console.log(that.data.comment_count_id);
475 | var ArticleCommentSubscribe = AV.Object.extend('WxCommentSubscribe');
476 | var articlecommentsubscribe = new ArticleCommentSubscribe();
477 | // writeCommentCountInLeanCloud必须先执行
478 | var comment_count_obj = AV.Object.createWithoutData('WxCommentCount', that.data.comment_count_id);
479 | articlecommentsubscribe.addUnique('comment_count_array', [comment_count_obj]);
480 | articlecommentsubscribe.set('user_id', user.id);
481 | articlecommentsubscribe.save();
482 | }
483 | });
484 | },
485 | _writeCommentCountInLeanCloud: function() {
486 | // 更新评论计数
487 | var that = this;
488 | //console.log('开始更新评论计数');
489 | var commentcount_query = new AV.Query('WxCommentCount');
490 | commentcount_query.equalTo('article_id', that.data.articleID);
491 | commentcount_query.find().then(function (results) {
492 | //console.log(results.length)
493 | if (results.length == 1) {
494 | var todo = AV.Object.createWithoutData('WxCommentCount', results[0].id);
495 | todo.set('count', that.data.all_comment_num);
496 | todo.set('article_url', that.data.articleURL)
497 | todo.save().then(function(todo){
498 | that.data.comment_count_id = todo.id;
499 | // 更新用户评论订阅,count增加和减少都触发订阅
500 | that._writeCommentSubscribeInLeanCloud();
501 | })
502 | }
503 | else if (results.length > 1) {
504 | console.log("WxCommentCount有重复ID");
505 | }
506 | else {
507 | console.log("还未创建WxCommentCount对象");
508 | // TODO
509 | // BUG: 会出现discovery_discovery_xxxid
510 | // 初始化文章评论计数
511 | var ArticleCommentCount = AV.Object.extend('WxCommentCount');
512 | var articlecommentcount = new ArticleCommentCount();
513 | articlecommentcount.set('article_id', that.data.articleID);
514 | articlecommentcount.set('article_title', that.data.articleTitle);
515 | articlecommentcount.set('article_url', that.data.articleURL);
516 | articlecommentcount.set('count', 0);
517 | articlecommentcount.save();
518 | }
519 | }, function (error) {
520 | console.log(error)
521 | });
522 | },
523 | commentLongTap: function (e) {
524 | var that = this;
525 | wx.showModal({
526 | title: '提示',
527 | content: '确定删除该评论吗?',
528 | success: function (res) {
529 | if (res.confirm) {
530 | //console.log('用户点击确定')
531 | // 长按删除评论
532 | AV.User.loginWithWeapp().then(user => {
533 | if (user.id == e.currentTarget.dataset.user_id || that.data.is_admin) {
534 | // 如果该评论下有子评论
535 | // 1.可以删除父评论和所有子评论?2.还是只能所以子评论删除完毕后才可以删除?
536 | // Done 1
537 | var p_index = e.currentTarget.dataset.p_index;
538 | if (that.data.leancloud_comment_data[p_index].subCommentList.length > 0) {
539 | // 父评论下有子评论
540 | wx.showModal({
541 | title: '提示',
542 | content: '父评论下有子评论,无法删除!',
543 | showCancel: false,
544 | success: function (res) {
545 | if (res.confirm) {
546 | console.log('用户点击确定')
547 | // nothing to do
548 | } else if (res.cancel) {
549 | console.log('用户点击取消')
550 | }
551 | }
552 | })
553 | return;
554 | }
555 |
556 | //console.log('当前登陆用户与待删除评论用户id相同');
557 | var todo = new AV.Object.createWithoutData('WxComment', e.currentTarget.dataset.comment_id);
558 | todo.destroy().then(function (success) {
559 | // 删除成功
560 | // 删除评论对应的点赞对象
561 | //console.log(e.currentTarget.dataset.zan_id)
562 | var zantodo = new AV.Object.createWithoutData('Zan', e.currentTarget.dataset.zan_id);
563 | zantodo.destroy().then(function (success) {
564 | // 删除评论对应赞成功
565 | wx.showToast({
566 | title: '删除评论成功!',
567 | icon: 'success',
568 | duration: 2000
569 | })
570 | // 同步本地显示
571 | var index;
572 | //console.log(that.data.leancloud_comment_data.length);
573 | for (var i = 0; i < that.data.leancloud_comment_data.length; i++) {
574 | if ((that.data.leancloud_comment_data[i].id).indexOf(e.currentTarget.dataset.comment_id) > -1) {
575 | index = i;
576 | that.data.leancloud_comment_data.splice(index, 1);
577 | break;
578 | }
579 | }
580 | // 更新p_id for all comments
581 | for (var i = 0; i < that.data.leancloud_comment_data.length; i++) {
582 | // update
583 | if (i >= index) {
584 | that.data.leancloud_comment_data[i].p_index = that.data.leancloud_comment_data[i].p_index - 1;
585 | for (var j = 0; j < that.data.leancloud_comment_data[i].subCommentList.length; j++) {
586 | that.data.leancloud_comment_data[i].subCommentList[j].p_index = that.data.leancloud_comment_data[i].subCommentList[j].p_index - 1;
587 | }
588 | }
589 | }
590 |
591 | that.setData({
592 | leancloud_comment_data: that.data.leancloud_comment_data,
593 | comment_num: that.data.leancloud_comment_data.length
594 | })
595 | // 更新评论计数
596 | that.data.all_comment_num = that.data.all_comment_num - 1;
597 | that._writeCommentCountInLeanCloud();
598 | }), function (error) {
599 | // 删除评论对应赞失败
600 | wx.showToast({
601 | title: '删除评论赞失败!',
602 | icon: 'none',
603 | duration: 2000
604 | })
605 | }
606 | }, function (error) {
607 | // 删除失败
608 | wx.showToast({
609 | title: '删除评论失败!',
610 | icon: 'none',
611 | duration: 2000
612 | })
613 | });
614 | }
615 | else {
616 | wx.showToast({
617 | title: '无权删除其他用户评论!',
618 | icon: 'none',
619 | duration: 2000
620 | })
621 | }
622 | }).catch(console.error);
623 | } else if (res.cancel) {
624 | //console.log('用户点击取消')
625 | }
626 | }
627 | })
628 | },
629 | subCommentLongTap: function (e) {
630 | var that = this;
631 | wx.showModal({
632 | title: '提示',
633 | content: '确定删除该评论吗?',
634 | success: function (res) {
635 | if (res.confirm) {
636 | //console.log('用户点击确定')
637 | // 长按删除评论
638 | AV.User.loginWithWeapp().then(user => {
639 | if (user.id == e.currentTarget.dataset.user_id || that.data.is_admin) {
640 | //console.log('当前登陆用户与待删除评论用户id相同');
641 | var todo = new AV.Object.createWithoutData('WxSubComment', e.currentTarget.dataset.comment_id);
642 | todo.destroy().then(function (success) {
643 | // 删除成功
644 | // 删除评论对应的点赞对象
645 | //console.log(e.currentTarget.dataset.zan_id)
646 | var zantodo = new AV.Object.createWithoutData('SubZan', e.currentTarget.dataset.zan_id);
647 | zantodo.destroy().then(function (success) {
648 | // 删除评论对应赞成功
649 | // 删除父评论WxComment中subCommentList信息
650 | var op_str = "update WxComment set subCommentList=op('Remove', {'objects':[pointer('WxSubComment','" + e.currentTarget.dataset.comment_id + "')]}) where objectId='" + e.currentTarget.dataset.p_comment_id + "'";
651 | AV.Query.doCloudQuery(op_str).then(function (data) {
652 | // 同步本地显示
653 | var index;
654 | //console.log(that.data.leancloud_comment_data.length);
655 | for (var i = 0; i < that.data.leancloud_comment_data[e.currentTarget.dataset.p_index].subCommentList.length; i++) {
656 | if ((that.data.leancloud_comment_data[e.currentTarget.dataset.p_index].subCommentList[i].id).indexOf(e.currentTarget.dataset.comment_id) > -1) {
657 | index = i;
658 | that.data.leancloud_comment_data[e.currentTarget.dataset.p_index].subCommentList.splice(index, 1);
659 | break;
660 | }
661 | }
662 | that.setData({
663 | leancloud_comment_data: that.data.leancloud_comment_data
664 | })
665 | // 更新评论计数
666 | that.data.all_comment_num = that.data.all_comment_num - 1;
667 | that._writeCommentCountInLeanCloud();
668 |
669 | wx.showToast({
670 | title: '删除子评论成功!',
671 | icon: 'success',
672 | duration: 2000
673 | })
674 | }, function (error) {
675 | // 异常处理
676 | console.error(error);
677 | });
678 |
679 | }), function (error) {
680 | // 删除评论对应赞失败
681 | wx.showToast({
682 | title: '删除评论赞失败!',
683 | icon: 'none',
684 | duration: 2000
685 | })
686 | }
687 | }, function (error) {
688 | // 删除失败
689 | wx.showToast({
690 | title: '删除评论失败!',
691 | icon: 'none',
692 | duration: 2000
693 | })
694 | });
695 | }
696 | else {
697 | wx.showToast({
698 | title: '无权删除其他用户评论!',
699 | icon: 'none',
700 | duration: 2000
701 | })
702 | }
703 | }).catch(console.error);
704 | } else if (res.cancel) {
705 | //console.log('用户点击取消')
706 | }
707 | }
708 | })
709 | },
710 | _updateZanShow: function (mode, comment_id, is_sub_comment, p_index) {
711 | var that = this;
712 |
713 | if (is_sub_comment == "true") {
714 | for (var i = 0; i < that.data.leancloud_comment_data[p_index].subCommentList.length; i++) {
715 | if (that.data.leancloud_comment_data[p_index].subCommentList[i].id == comment_id) {
716 | if (mode == 'cancel') {
717 | that.data.leancloud_comment_data[p_index].subCommentList[i].zanNum = that.data.leancloud_comment_data[p_index].subCommentList[i].zanNum - 1;
718 | that.data.leancloud_comment_data[p_index].subCommentList[i].zanCurrent = false;
719 | }
720 | else if (mode == 'submit') {
721 | that.data.leancloud_comment_data[p_index].subCommentList[i].zanNum = that.data.leancloud_comment_data[p_index].subCommentList[i].zanNum + 1;
722 | that.data.leancloud_comment_data[p_index].subCommentList[i].zanCurrent = true;
723 | }
724 |
725 | break;
726 | }
727 | }
728 | }
729 | else {
730 | if (mode == 'cancel') {
731 | that.data.leancloud_comment_data[p_index].zanNum = that.data.leancloud_comment_data[p_index].zanNum - 1;
732 | that.data.leancloud_comment_data[p_index].zanCurrent = false;
733 | }
734 | else if (mode == 'submit') {
735 | that.data.leancloud_comment_data[p_index].zanNum = that.data.leancloud_comment_data[p_index].zanNum + 1;
736 | that.data.leancloud_comment_data[p_index].zanCurrent = true;
737 | }
738 | }
739 | that.setData({
740 | leancloud_comment_data: that.data.leancloud_comment_data
741 | })
742 | },
743 | _writeZanInLeanCloud: function (user_id, comment_id, zan_id, class_name, is_sub_comment, p_index) {
744 | var that = this;
745 | // 查询当前用户是否已点赞
746 | var query = new AV.Query(class_name);
747 | var search = [that.data.leancloud_user_id];
748 | query.equalTo('commentObjId', comment_id);
749 | query.containsAll('userList', search);
750 | query.find().then(function (results) {
751 | //console.log(results);
752 | if (results.length == 1) {
753 | // 当前用户已给该评论点赞,取消赞
754 | var op_str = "update " + class_name + " set zan=op('Decrement', {'amount': 1}),userList=op('Remove', {'objects':[\"" + that.data.leancloud_user_id + "\"]}) where objectId='" + zan_id + "'";
755 | AV.Query.doCloudQuery(op_str).then(function (data) {
756 | // data 中的 results 是本次查询返回的结果,AV.Object 实例列表
757 | // 更新显示, -1
758 | //console.log('update zan cancel');
759 | that._updateZanShow('cancel', comment_id, is_sub_comment, p_index);
760 | }, function (error) {
761 | // 异常处理
762 | console.error(error);
763 | });
764 | }
765 | else {
766 | // 当前用户还未给该评论点赞
767 | var op_str = "update " + class_name + " set zan=op('Increment', {'amount': 1}),userList=op('AddUnique', {'objects':[\"" + that.data.leancloud_user_id + "\"]}) where objectId='" + zan_id + "'";
768 | AV.Query.doCloudQuery(op_str).then(function (data) {
769 | // data 中的 results 是本次查询返回的结果,AV.Object 实例列表
770 | // 更新显示
771 | //console.log('update zan submit');
772 | that._updateZanShow('submit', comment_id, is_sub_comment, p_index);
773 | }, function (error) {
774 | // 异常处理
775 | console.error(error);
776 | });
777 | }
778 | }).catch(console.error);
779 | },
780 | zanCommentClick: function (e) {
781 | var that = this;
782 | // user_id为评论发布者的用户id,非当前用户id
783 | var user_id = e.currentTarget.dataset.user_id;
784 | var comment_id = e.currentTarget.dataset.comment_id;
785 | var zan_id = e.currentTarget.dataset.zan_id;
786 | var p_index = e.currentTarget.dataset.p_index;
787 |
788 | var class_name = "Zan";
789 | if (e.currentTarget.dataset.is_sub_comment == "true") {
790 | class_name = "SubZan";
791 | }
792 |
793 | that._writeZanInLeanCloud(user_id, comment_id, zan_id, class_name, e.currentTarget.dataset.is_sub_comment, p_index);
794 | },
795 | onGetUserInfo: function (e) {
796 | var that = this;
797 | if (e.detail.userInfo) {
798 | //console.log(e.detail.userInfo);
799 | wx.showToast({
800 | title: '授权成功!',
801 | icon: 'success',
802 | duration: 2000
803 | })
804 | that.setData({
805 | user_info: e.detail.userInfo,
806 | show_aur_button: false
807 | });
808 | // LeanCloud 一键登录
809 | AV.User.loginWithWeapp().then(user => {
810 | that.data.login_user_info = user.toJSON();
811 | // 更新LeanCloud用户信息
812 | that._updateUserInfoInLeanCloud();
813 | }).catch(console.error);
814 | }
815 | },
816 | avatarClicked: function (e) {
817 | //console.log(e.currentTarget.dataset.user_id);
818 | var that = this;
819 | if (e.detail.userInfo) {
820 | //console.log(e.detail.userInfo);
821 | // 查阅是否已经关注该用户
822 | var query = AV.User.current().followeeQuery();
823 | //query.include('followee');
824 | var targetFollower = AV.Object.createWithoutData('_Followee', e.currentTarget.dataset.user_id);
825 | query.equalTo('followee', targetFollower);
826 | query.find().then(function (followees) {
827 | // 关注的用户列表 followees
828 | //console.log(followees);
829 | if (followees.length == 1) {
830 | // 已经关注了该用户,是否取关
831 | wx.showModal({
832 | title: '提示',
833 | content: '已关注,是否取消关注该用户?',
834 | success: function (res) {
835 | if (res.confirm) {
836 | AV.User.current().unfollow(e.currentTarget.dataset.user_id).then(function () {
837 | // 取消关注成功
838 | wx.showToast({
839 | title: '取消关注成功!',
840 | icon: 'success',
841 | duration: 2000
842 | });
843 | return;
844 | }, function (err) {
845 | // 取消关注失败
846 | console.log(err);
847 | return;
848 | });
849 | }
850 | else if (res.cancel) {
851 | // nothing to do
852 | return;
853 | }
854 | }
855 | });
856 | } else {
857 | // 处理关注
858 | wx.showModal({
859 | title: '提示',
860 | content: '关注该用户?',
861 | success: function (res) {
862 | if (res.confirm) {
863 | AV.User.current().follow(e.currentTarget.dataset.user_id).then(function () {
864 | // 关注成功
865 | // https://leancloud.cn/docs/status_system.html#hash918332471
866 | // TODO: 取消关注
867 | wx.showToast({
868 | title: '关注成功!',
869 | icon: 'success',
870 | duration: 2000
871 | })
872 | }, function (err) {
873 | // 关注失败
874 | //console.log(err.message);
875 | //console.log(err.code);
876 | wx.showToast({
877 | title: err.message,
878 | icon: 'none',
879 | duration: 4000
880 | })
881 | });
882 | } else if (res.cancel) {
883 | //console.log('用户点击取消')
884 | }
885 | }
886 | })
887 | }
888 | }, function (err) {
889 | // 查询失败
890 | console.log('查询失败');
891 | console.log(err);
892 | });
893 | }
894 | },
895 | _updateUserInfoInLeanCloud: function () {
896 | // 获得当前登录用户
897 | const user = AV.User.current();
898 | // 调用小程序 API,得到用户信息
899 | wx.getUserInfo({
900 | success: ({ userInfo }) => {
901 | // 更新当前用户的信息
902 | user.set(userInfo).save().then(user => {
903 | // 成功,此时可在控制台中看到更新后的用户信息
904 | this.data.login_user_info = user.toJSON();
905 | }).catch(console.error);
906 | },
907 | fail: function () {
908 | console.log("获取用户信息失败");
909 | }
910 | });
911 | },
912 | _writeSubCommentInLeanCloud: function () {
913 | var that = this;
914 | // new WxSubComment
915 | var WxSubComment = AV.Object.extend('WxSubComment');
916 | var wxsubcomment = new WxSubComment();
917 |
918 | var current_time = Common.getTime();
919 | const user = AV.User.current();
920 | //console.log(that.data.login_user_info);
921 | wxsubcomment.set('p_id', that.data.sub_comment_p_comment_id)
922 | wxsubcomment.set('username', that.data.login_user_info.username);
923 | wxsubcomment.set('article_id', that.data.article_id);
924 | wxsubcomment.set('article_title', that.data.articleTitle);
925 | // article_url暂未用到
926 | wxsubcomment.set('article_url', that.data.articleURL);
927 | wxsubcomment.set('content', that.data.comment_data);
928 | wxsubcomment.set('time', current_time);
929 | wxsubcomment.set('at', '');
930 | var targetUser = AV.Object.createWithoutData('_User', user.id);
931 | wxsubcomment.set('targetUser', targetUser);
932 |
933 | wxsubcomment.save().then(function (wxsubcomment) {
934 | // new Zan
935 | var Zan = AV.Object.extend('SubZan');
936 | var zan = new Zan();
937 | zan.set('zan', 0);
938 | zan.set('commentObjId', wxsubcomment.id);
939 | zan.set('userList', []);
940 | zan.save().then(function (zan) {
941 | var targetZan = AV.Object.createWithoutData('SubZan', zan.id);
942 | wxsubcomment.set('targetZan', targetZan);
943 | wxsubcomment.save().then(function (wxsubcomment) {
944 | console.log('子评论和赞处理完毕')
945 | // 子评论和赞处理完毕
946 | // 将子评论加入到父评论索引数组中
947 | // WxComment添加子评论objectId
948 | var op_str = "update WxComment set subCommentList=op('AddUnique', {'objects':[pointer('WxSubComment','" + wxsubcomment.id + "')]}) where objectId='" + that.data.sub_comment_p_comment_id + "'";
949 | AV.Query.doCloudQuery(op_str).then(function (data) {
950 | console.log('子评论和赞及父评论处理完毕')
951 | // data 中的 results 是本次查询返回的结果,AV.Object 实例列表
952 | // 同步更新子评论和相关初赞显示
953 | // nickName/city/country/gender/province
954 | //console.log(that.data.sub_comment_p_index)
955 | var current_comment = {};
956 | current_comment['p_index'] = that.data.sub_comment_p_index;
957 | current_comment['p_id'] = that.data.sub_comment_p_comment_id;
958 | current_comment['id'] = wxsubcomment.id;
959 | current_comment['userId'] = user.id;
960 | current_comment['articleID'] = that.data.articleID;
961 | current_comment['nickName'] = that.data.login_user_info.nickName;
962 | if (current_comment['nickName'].length > that.data.subcomment_nickname_len) {
963 | current_comment['showNickName'] = current_comment['nickName'].substr(0, that.data.subcomment_nickname_len) + "...";
964 | }
965 | else {
966 | current_comment['showNickName'] = current_comment['nickName'];
967 | }
968 | current_comment['pre_' + current_comment['id']] = current_comment['nickName'];
969 | current_comment['avatarUrl'] = that.data.login_user_info.avatarUrl;
970 | current_comment['time'] = Common.timeAgoWithTimeStr(current_time);
971 | current_comment['content'] = that.data.comment_data;
972 | current_comment['at'] = '';
973 | current_comment['zanNum'] = 0;
974 | current_comment['zanId'] = zan.id;
975 | //console.log(that.data.leancloud_comment_data[that.data.sub_comment_p_index]['subCommentList'])
976 | that.data.leancloud_comment_data[that.data.sub_comment_p_index].subCommentList.push(current_comment);
977 | // 子评论不增加commnet_num
978 | that.setData({
979 | leancloud_comment_data: that.data.leancloud_comment_data,
980 | comment_data: '',
981 | comment_textarea_value: ''
982 | });
983 |
984 | that.data.all_comment_num = that.data.all_comment_num + 1;
985 | // 更新评论计数
986 | that._writeCommentCountInLeanCloud();
987 | console.log("评论和赞显示处理完毕");
988 | }, function (error) {
989 | // 异常处理
990 | console.error(error);
991 | });
992 | }), function (error) {
993 | console.log('子评论初始化赞失败!')
994 | console.log(error)
995 | }
996 | }), function (error) {
997 | // 异常处理
998 | console.log('赞初始化失败!')
999 | console.log(error)
1000 | }
1001 | }, function (error) {
1002 | // 异常处理
1003 | console.log('子评论初始化失败')
1004 | console.log(error)
1005 | });
1006 | },
1007 | // 自定义方法
1008 | _writeCommentInLeanCloud: function () {
1009 | var that = this;
1010 | // new WxComment
1011 | var WxComment = AV.Object.extend('WxComment');
1012 | var wxcomment = new WxComment();
1013 |
1014 | var current_time = Common.getTime();
1015 | const user = AV.User.current();
1016 | //console.log(that.data.login_user_info);
1017 | wxcomment.set('username', that.data.login_user_info.username);
1018 | wxcomment.set('article_id', that.data.article_id);
1019 | wxcomment.set('article_title', that.data.articleTitle);
1020 | // article_url暂未用到
1021 | wxcomment.set('article_url', that.data.articleURL);
1022 | wxcomment.set('content', that.data.comment_data);
1023 | wxcomment.set('time', current_time);
1024 | wxcomment.set('at', '');
1025 | wxcomment.set('subCommentList', []);
1026 | var targetUser = AV.Object.createWithoutData('_User', user.id);
1027 | wxcomment.set('targetUser', targetUser);
1028 |
1029 | wxcomment.save().then(function (wxcomment) {
1030 | // new Zan
1031 | var Zan = AV.Object.extend('Zan');
1032 | var zan = new Zan();
1033 | zan.set('zan', 0);
1034 | zan.set('commentObjId', wxcomment.id);
1035 | zan.set('userList', []);
1036 | zan.save().then(function (zan) {
1037 | var targetZan = AV.Object.createWithoutData('Zan', zan.id);
1038 | wxcomment.set('targetZan', targetZan);
1039 | wxcomment.save().then(function (wxcomment) {
1040 | // 评论和赞处理完毕
1041 | // do something...
1042 | // 同步更新评论显示
1043 | // nickName/city/country/gender/province
1044 | var current_comment = {};
1045 | current_comment['p_index'] = that.data.leancloud_comment_data.length;
1046 | current_comment['p_id'] = wxcomment.id;
1047 | current_comment['id'] = wxcomment.id;
1048 | current_comment['userId'] = user.id;
1049 | current_comment['articleID'] = that.data.articleID;
1050 | current_comment['nickName'] = that.data.login_user_info.nickName;
1051 | if (current_comment['nickName'].length > that.data.comment_nickname_len) {
1052 | current_comment['showNickName'] = current_comment['nickName'].substr(0, that.data.comment_nickname_len) + "...";
1053 | }
1054 | else {
1055 | current_comment['showNickName'] = current_comment['nickName'];
1056 | }
1057 | current_comment['pre_' + current_comment['id']] = current_comment['nickName'];
1058 | current_comment['avatarUrl'] = that.data.login_user_info.avatarUrl;
1059 | current_comment['time'] = Common.timeAgoWithTimeStr(current_time);
1060 | current_comment['content'] = that.data.comment_data;
1061 | current_comment['at'] = '';
1062 | current_comment['zanNum'] = 0;
1063 | current_comment['zanId'] = zan.id;
1064 | current_comment['subCommentList'] = [];
1065 | that.data.leancloud_comment_data.push(current_comment);
1066 | that.setData({
1067 | leancloud_comment_data: that.data.leancloud_comment_data,
1068 | comment_num: that.data.comment_num + 1,
1069 | comment_data: '',
1070 | comment_textarea_value: ''
1071 | });
1072 | // 更新评论计数
1073 | that.data.all_comment_num = that.data.all_comment_num + 1;
1074 | that._writeCommentCountInLeanCloud();
1075 | console.log("评论和赞处理完毕");
1076 | }), function (error) {
1077 | wx.showToast({
1078 | title: '评论处理失败!',
1079 | icon: 'none',
1080 | duration: 2000
1081 | })
1082 | }
1083 | }), function (error) {
1084 | // 异常处理
1085 | wx.showToast({
1086 | title: '赞初始化失败!',
1087 | icon: 'none',
1088 | duration: 2000
1089 | })
1090 | }
1091 |
1092 | // 成功保存之后,执行其他逻辑.
1093 | wx.showToast({
1094 | title: '评论成功!',
1095 | icon: 'success',
1096 | duration: 2000
1097 | });
1098 | }, function (error) {
1099 | // 异常处理
1100 | wx.showToast({
1101 | title: '评论失败!',
1102 | icon: 'none',
1103 | duration: 2000
1104 | })
1105 | });
1106 | }
1107 | },
1108 | _getCommentsInLeanCloud: function () {
1109 | var query = new AV.Query('WxComment');
1110 | query.equalTo('article_id', this.data.articleID);
1111 | query.find().then(function (results) {
1112 | // 如果这样写,第二个条件将覆盖第一个条件,查询只会返回 priority = 1 的结果
1113 | //console.log(results);
1114 | }, function (error) {
1115 | wx.showToast({
1116 | title: '评论加载失败!',
1117 | icon: 'none',
1118 | duration: 2000
1119 | })
1120 | });
1121 | },
1122 | _articleIDChange: function (newVal, oldVal) {
1123 | // [BUG] observer无法进入自定义函数
1124 | console.log('observer...');
1125 | //newVal == this.data.articleID
1126 | // 加载LeanCloud对应articleID评论
1127 | //console.log(this.data.articleID);
1128 | this._getCommentsInLeanCloud();
1129 | },
1130 | created: function () {
1131 | //console.log('create...');
1132 | },
1133 | ready: function () {
1134 | //console.log('ready...');
1135 | }
1136 | })
1137 |
--------------------------------------------------------------------------------