diff --git a/app.wxss b/app.wxss
index b5823b8ca1b4b4a3c42587f39c181933e29dba10..1396a36a9d830b39c69094f129e6cc971b81a450 100644
--- a/app.wxss
+++ b/app.wxss
@@ -1,5 +1,5 @@
@import "style/weui.wxss";
-
+@import "vendor/wxParse/wxParse.wxss";
page{
background-color: #F8F8F8;
font-size: 16px;
diff --git a/pages/blogpost/body.js b/pages/blogpost/body.js
index 09d68adfc9bcc827965694d269a2381277b15828..7aa04fa47e127032d5dd475abaf88c306569b93f 100644
--- a/pages/blogpost/body.js
+++ b/pages/blogpost/body.js
@@ -58,7 +58,6 @@ Page({
"Authorization": "Bearer " + getApp().accessToken
},
success: function (res) {
-
if (res) {
that.setData({
comments: res.data
@@ -80,7 +79,7 @@ Page({
url: 'https://api.cnblogs.com/api/blogs/' + this.data.blogApp + '/posts/' + this.data.postId + '/comments',
method: 'POST',
data: {
- "content": this.data.commentInput
+ "": this.data.commentInput
},
header: {
"Content-Type": "application/x-www-form-urlencoded",
diff --git a/pages/index/index.js b/pages/index/index.js
index 55e2196a37959ed88e1524eb18fe71b30cb39b54..0b4df317c7d5a3b0e0f6c2aa8d6aedad34e22ea1 100644
--- a/pages/index/index.js
+++ b/pages/index/index.js
@@ -125,6 +125,10 @@ Page({
* @param int postType 加载博文类型
*/
loadMoreBlogPosts: function (that, pageIndex, postType) {
+ wx.showLoading({
+ title: '加载中',
+ })
+
wx.request({
url: 'https://api.cnblogs.com/api/blogposts/@' + postType + '?pageIndex=' + pageIndex + '&pageSize=' + pageSize,
method: 'GET',
@@ -133,28 +137,30 @@ Page({
"Authorization": "Bearer " + getApp().accessToken
},
success: function (res) {
- pageIndex++;
- if (postType === 'sitehome') {
- that.setData({
- blog_articles: that.data.blog_articles.concat(res.data),
- siteHomeIndex: pageIndex
- });
+ if (res.data.length > 0) {
+ pageIndex++;
+ if (postType === 'sitehome') {
+ that.setData({
+ blog_articles: that.data.blog_articles.concat(res.data),
+ siteHomeIndex: pageIndex
+ });
- } else if (postType === 'picked') {
- that.setData({
- blog_pickeds: that.data.blog_pickeds.concat(res.data),
- pickedIndex: pageIndex
- });
+ } else if (postType === 'picked') {
+ that.setData({
+ blog_pickeds: that.data.blog_pickeds.concat(res.data),
+ pickedIndex: pageIndex
+ });
+ }
}
},
fail: function () {
// fail
},
complete: function () {
- console.log('-------完成后---------');
wx.hideNavigationBarLoading();
wx.stopPullDownRefresh();
+ wx.hideLoading();
}
});
},
@@ -166,6 +172,10 @@ Page({
* @param int newsType 加载新闻类型
*/
loadMoreNews: function (that, pageIndex, newsType) {
+ wx.showLoading({
+ title: '加载中',
+ })
+
var url = '';
if (newsType === 'recommended' || newsType === 'hot-week') {
url = 'https://api.cnblogs.com/api/newsitems/@' + newsType + '?pageIndex=' + pageIndex + '&pageSize=' + pageSize;
@@ -181,31 +191,33 @@ Page({
"Authorization": "Bearer " + getApp().accessToken
},
success: function (res) {
- pageIndex++;
- if (newsType === 'recommended') {
- that.setData({
- news_recommendeds: that.data.news_recommendeds.concat(res.data),
- recommendedIndex: pageIndex
- });
- } else if (newsType === 'hot') {
- that.setData({
- news_hots: that.data.news_hots.concat(res.data),
- hotIndex: pageIndex
- });
- } else if (newsType === 'hot-week') {
- that.setData({
- news_hots_week: that.data.news_hots_week.concat(res.data),
- hotWeekIndex: pageIndex
- });
+ if (res.data.length > 0) {
+ pageIndex++;
+ if (newsType === 'recommended') {
+ that.setData({
+ news_recommendeds: that.data.news_recommendeds.concat(res.data),
+ recommendedIndex: pageIndex
+ });
+ } else if (newsType === 'hot') {
+ that.setData({
+ news_hots: that.data.news_hots.concat(res.data),
+ hotIndex: pageIndex
+ });
+ } else if (newsType === 'hot-week') {
+ that.setData({
+ news_hots_week: that.data.news_hots_week.concat(res.data),
+ hotWeekIndex: pageIndex
+ });
+ }
}
},
fail: function () {
// fail
},
complete: function () {
- console.log('-------完成后---------');
wx.hideNavigationBarLoading();
wx.stopPullDownRefresh();
+ wx.hideLoading();
}
});
},
diff --git a/pages/news/index.js b/pages/news/index.js
index e89c9ea6d34b3673bae056675362fbc943cb6e61..f1d631e4e9eb013e8a61bcb088178e47cd0de76c 100644
--- a/pages/news/index.js
+++ b/pages/news/index.js
@@ -8,12 +8,28 @@ Page({
newsId: 0,
blogApp: '',
commentInput: '',
+ commentid: 0,
pageIndex: 1,
pageSize: 10,
+ user: [],
+ addStatus: true,
},
onLoad: function (options) {
- this.loadNews(options);
- this.loadComments(options);
+ wx.showLoading({
+ title: '加载中',
+ })
+
+ var that = this
+ that.setData({
+ user: getApp().user
+ })
+
+ that.loadNews(options);
+ },
+
+ onReachBottom: function () {
+ //上拉加载分页评论数据
+ this.loadComments(this.data.pageIndex);
},
loadNews: function (options) {
@@ -27,16 +43,20 @@ Page({
"Authorization": "Bearer " + getApp().accessToken
},
success: function (res) {
- if (res) {
+ if (res.data !== '') {
that.setData({
news: res.data,
newsId: options.newsId,
-// blogApp: options.blogApp
+ blogApp: options.blogApp
})
- WxParse.wxParse('news', 'html', that.data.news, that, 5);
+ WxParse.wxParse('news', 'html', that.data.news, that)
+
+ //加载评论
+ that.loadComments(that.data.pageIndex);
}
+
},
fail: function () {
// fail
@@ -47,21 +67,26 @@ Page({
})
},
- loadComments: function (options) {
- var that = this;
+ loadComments: function (pageIndex) {
+ wx.showLoading({
+ title: '加载中',
+ })
+
+ var that = this
wx.request({
- url: 'https://api.cnblogs.com/api/news/' + options.newsId +
- '/comments?pageIndex=' + this.data.pageIndex + '&pageSize=' + this.data.pageSize,
+ url: 'https://api.cnblogs.com/api/news/' + that.data.newsId +
+ '/comments?pageIndex=' + pageIndex + '&pageSize=' + that.data.pageSize,
method: 'GET',
header: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": "Bearer " + getApp().accessToken
},
success: function (res) {
-
- if (res) {
+ if (res.data.length > 0) {
+ pageIndex++
that.setData({
- comments: res.data
+ comments: that.data.comments.concat(res.data),
+ pageIndex: pageIndex
})
}
},
@@ -69,30 +94,100 @@ Page({
// fail
},
complete: function () {
- // complete
+ wx.hideLoading()
}
})
},
- addComment: function (options) {
- console.log(options);
+ //发布评论
+ addComment: function () {
wx.request({
- url: 'https://api.cnblogs.com/api/blogs/' + this.data.blogApp + '/posts/' + this.data.postId + '/comments',
+ url: 'https://api.cnblogs.com/api/news/' + this.data.newsId + '/comments',
method: 'POST',
data: {
+ "ParentId": 1,
"content": this.data.commentInput
},
header: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization': 'Bearer ' + getApp().accessToken,
},
+ success: function (res) {
+ if (res.statusCode === 201) {
+ wx.showToast({title: "添加评论成功"})
+ } else if (res.statusCode === 500) {
+ wx.showToast({title: res.data.Message})
+ }
+ }
+
+ });
+ },
+
+ //修改评论
+ editComment: function () {
+ var that = this
+ wx.request({
+ url: 'https://api.cnblogs.com/api/newscomments/' + that.data.commentid,
+ method: 'PATCH',
+ data: {
+ "": this.data.commentInput
+ },
+ header: {
+ "Content-Type": "application/x-www-form-urlencoded",
+ 'Authorization': 'Bearer ' + getApp().accessToken,
+ },
success: function (res) {
console.log(res)
+ if (res.statusCode === 200) {
+ wx.showToast({title: "修改评论成功"})
+ that.setData({
+ commentInput: event.target.dataset.content,
+ addStatus: true
+ })
+ }
}
+ });
+ },
+ //删除评论
+ deleteComment: function (event) {
+ var that = this
+ var commentId = event.target.dataset.commentid;
+ var commentsIndex = event.target.dataset.index;
+ wx.request({
+ url: 'https://api.cnblogs.com/api/newscomments/' + commentId,
+ method: 'DELETE',
+ header: {
+ "Content-Type": "application/x-www-form-urlencoded",
+ 'Authorization': 'Bearer ' + getApp().accessToken,
+ },
+ success: function (res) {
+ if (res.statusCode === 200) {
+ wx.showToast({title: "删除成功"})
+ } else if (res.statusCode === 500) {
+ wx.showToast({title: res.data.ExceptionMessage})
+ }
+ }
});
},
- listenCommontInput: function (event) {
+
+ editCommentStatus: function (event) {
+ this.setData({
+ commentid: event.target.dataset.commentid,
+ commentInput: event.target.dataset.content,
+ addStatus: false
+ })
+ },
+
+ cancelComment: function () {
+ this.setData({
+ commentid: 0,
+ commentInput: '',
+ addStatus: true
+ })
+ },
+
+ listenCommentInput: function (event) {
this.data.commentInput = event.detail.value;
},
onReady: function () {
diff --git a/pages/news/index.wxml b/pages/news/index.wxml
index 21a8b8f3d68365599057621ab0cf570f76524d16..5cc1eb82ee5a0efef788d78f58effe96e1fd0f1a 100644
--- a/pages/news/index.wxml
+++ b/pages/news/index.wxml
@@ -3,18 +3,24 @@
热门评论
-
+
-
+
- {{commont.Author}}|
-
+ {{index + 1}}楼
+
+
+
+
+
+
+
- {{commont.Body}}
+ {{comment.CommentContent}}
@@ -24,10 +30,12 @@
-
+
0/200
-
+
+
+
\ No newline at end of file
diff --git a/pages/news/index.wxss b/pages/news/index.wxss
index 4be533ac7f9493c474bfafacbb35fe71924893b0..63d3428c6f47f2e236e45eb02e2f0e59ef311089 100644
--- a/pages/news/index.wxss
+++ b/pages/news/index.wxss
@@ -1 +1,8 @@
-/* pages/news/index.wxss */
\ No newline at end of file
+/* pages/news/index.wxss */
+
+.view_hide{
+ display: none !important;
+}
+.view_show{
+ display: inline-block !important;
+}
\ No newline at end of file
diff --git a/pages/user/login.js b/pages/user/login.js
index 1b01c8ffab69d2d81b0a0b9ea2a99b59c0bace5a..34e65ca2d56bc8d9f21159454a3fe5bbcd70bd73 100644
--- a/pages/user/login.js
+++ b/pages/user/login.js
@@ -62,7 +62,7 @@ Page({
wx.setStorageSync('user', res.data);
getApp().user = res.data
- wx.switchTab({url: "/pages/home/index"});
+ wx.switchTab({url: "/pages/index/index"});
},
fail: function(e) {