diff --git a/pages/blogpost/body.js b/pages/blogpost/body.js index 020bae4101f8aa62b4c8fed6f0a95ff35acfe0d4..09d68adfc9bcc827965694d269a2381277b15828 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 73f74b5e6758b01d9982c336fd9d156709f1fc62..b2ef185f1f65fb1db10aad0aff3f9a9c66c8b6b5 100644 --- a/pages/blogpost/body.wxml +++ b/pages/blogpost/body.wxml @@ -1,3 +1,34 @@ + -