From e2556ea59816035bde4122a8c871cc20f044fee9 Mon Sep 17 00:00:00 2001 From: ddl Date: Sat, 8 Apr 2017 14:27:46 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8D=9A=E6=96=87?= =?UTF-8?q?=E6=97=A0=E9=99=90=E4=B8=8B=E6=8B=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.js | 35 +++++++++++++++++++++++++---------- utils/util.js | 2 +- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index 69b254d..55e2196 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -41,7 +41,7 @@ Page({ }, onReachBottom: function () { - console.log('--------上拉刷新-------') + console.log('--------上拉加载-------') this.changeTab(this.data.activeIndex, 'reach'); }, @@ -62,6 +62,7 @@ Page({ if (action === 'pull') { this.setData({ siteHomeIndex: 1, + blog_articles: [] }); } postType = 'sitehome'; //首页博文列表 @@ -71,6 +72,7 @@ Page({ if (action === 'pull') { this.setData({ pickedIndex: 1, + blog_pickeds: [] }); } postType = 'picked'; //精华区博文列表 @@ -80,6 +82,7 @@ Page({ if (action === 'pull') { this.setData({ recommendedIndex: 1, + news_recommendeds: [] }); } newsType = 'recommended';//推荐新闻 @@ -89,6 +92,7 @@ Page({ if (action === 'pull') { this.setData({ hotIndex: 1, + news_hots: [] }); } newsType = 'hot';//热门新闻 @@ -98,6 +102,7 @@ Page({ if (action === 'pull') { this.setData({ hotWeekIndex: 1, + news_hots_week: [] }); } newsType = 'hot-week';//本周热门新闻 @@ -113,26 +118,31 @@ Page({ } }, - //加载博文列表 + /** + * 加载博文列表 + * @param object that 当前调用对象 + * @param int pageIndex + * @param int postType 加载博文类型 + */ loadMoreBlogPosts: function (that, pageIndex, postType) { wx.request({ url: 'https://api.cnblogs.com/api/blogposts/@' + postType + '?pageIndex=' + pageIndex + '&pageSize=' + pageSize, method: 'GET', header: { "Content-Type": "application/json; charset=utf-8", - "Authorization": "Bearer " + app.globalData.access_token, + "Authorization": "Bearer " + getApp().accessToken }, success: function (res) { pageIndex++; if (postType === 'sitehome') { that.setData({ - blog_articles: res.data, + blog_articles: that.data.blog_articles.concat(res.data), siteHomeIndex: pageIndex }); } else if (postType === 'picked') { that.setData({ - blog_pickeds: res.data, + blog_pickeds: that.data.blog_pickeds.concat(res.data), pickedIndex: pageIndex }); @@ -149,7 +159,12 @@ Page({ }); }, - //加载新闻列表 + /** + * 加载新闻列表 + * @param object that 当前调用对象 + * @param int pageIndex 当前第几页 + * @param int newsType 加载新闻类型 + */ loadMoreNews: function (that, pageIndex, newsType) { var url = ''; if (newsType === 'recommended' || newsType === 'hot-week') { @@ -163,23 +178,23 @@ Page({ method: 'GET', header: { "Content-Type": "application/json; charset=utf-8", - "Authorization": "Bearer " + app.globalData.access_token, + "Authorization": "Bearer " + getApp().accessToken }, success: function (res) { pageIndex++; if (newsType === 'recommended') { that.setData({ - news_recommendeds: res.data, + news_recommendeds: that.data.news_recommendeds.concat(res.data), recommendedIndex: pageIndex }); } else if (newsType === 'hot') { that.setData({ - news_hots: res.data, + news_hots: that.data.news_hots.concat(res.data), hotIndex: pageIndex }); } else if (newsType === 'hot-week') { that.setData({ - news_hots_week: res.data, + news_hots_week: that.data.news_hots_week.concat(res.data), hotWeekIndex: pageIndex }); } diff --git a/utils/util.js b/utils/util.js index 6581a59..d88310b 100644 --- a/utils/util.js +++ b/utils/util.js @@ -26,5 +26,5 @@ function json2Form(json) { module.exports = { json2Form: json2Form, - formatTime: formatTime + formatTime: formatTime, } -- Gitee From edf8435bee400eb581ec6f7359abe6db32aa63ba Mon Sep 17 00:00:00 2001 From: ddl Date: Sat, 8 Apr 2017 17:52:25 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=96=87=E7=AB=A0=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=EF=BC=8C=E5=8E=BB=E9=99=A4wxparse=20console?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/blogpost/body.js | 44 +++++++++++++++++++++++++++++-------- pages/blogpost/body.wxml | 33 +++++++++++++++++++++++++++- pages/index/index.wxml | 2 +- vendor/wxParse/html2json.js | 4 ++-- vendor/wxParse/wxParse.js | 10 ++++----- 5 files changed, 75 insertions(+), 18 deletions(-) diff --git a/pages/blogpost/body.js b/pages/blogpost/body.js index 020bae4..09d68ad 100644 --- a/pages/blogpost/body.js +++ b/pages/blogpost/body.js @@ -1,15 +1,19 @@ // pages/blogpost/body.js var WxParse = require('../../vendor/wxParse/wxParse.js') -var app = getApp() + Page({ data: { article: '', comments: [], + postId: 0, + blogApp: '', + commentInput: '', pageIndex: 1, pageSize: 10, }, onLoad: function (options) { this.loadArticle(options); + this.loadComments(options); }, loadArticle: function (options) { @@ -17,15 +21,17 @@ Page({ var that = this; wx.request({ url: 'https://api.cnblogs.com/api/blogposts/' + options.postId + '/body', - method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT + method: 'GET', header: { "Content-Type": "application/json; charset=utf-8", - "Authorization": "Bearer " + app.globalData.access_token, + "Authorization": "Bearer " + getApp().accessToken }, success: function (res) { if (res) { that.setData({ - article: res.data + article: res.data, + postId: options.postId, + blogApp: options.blogApp }) WxParse.wxParse('article', 'html', that.data.article, that, 5); @@ -45,21 +51,19 @@ Page({ var that = this; wx.request({ url: 'https://api.cnblogs.com/api/blogs/' + options.blogApp + '/posts/' + - options.postId + '/comments?pageIndex=' + this.data.pageSize + '&pageSize=' + this.data.pageSize, + options.postId + '/comments?pageIndex=' + this.data.pageIndex + '&pageSize=' + this.data.pageSize, method: 'GET', header: { "Content-Type": "application/json; charset=utf-8", - "Authorization": "Bearer " + app.globalData.access_token, + "Authorization": "Bearer " + getApp().accessToken }, success: function (res) { + if (res) { that.setData({ comments: res.data }) - - WxParse.wxParse('article', 'html', that.data.article, that, 5); } - }, fail: function () { // fail @@ -69,6 +73,28 @@ Page({ } }) }, + + addComment: function (options) { + console.log(options); + wx.request({ + url: 'https://api.cnblogs.com/api/blogs/' + this.data.blogApp + '/posts/' + this.data.postId + '/comments', + method: 'POST', + data: { + "content": this.data.commentInput + }, + header: { + "Content-Type": "application/x-www-form-urlencoded", + 'Authorization': 'Bearer ' + getApp().accessToken, + }, + success: function (res) { + console.log(res) + } + + }); + }, + listenCommontInput: function (event) { + this.data.commentInput = event.detail.value; + }, onReady: function () { // 页面渲染完成 }, diff --git a/pages/blogpost/body.wxml b/pages/blogpost/body.wxml index 73f74b5..b2ef185 100644 --- a/pages/blogpost/body.wxml +++ b/pages/blogpost/body.wxml @@ -1,3 +1,34 @@ + -