diff --git a/app.js b/app.js index bb208d32dc95f7adb52dcd6e875eaeeb335bd3ec..382ba808fd4b12eeaa51796f3802910f7975d451 100644 --- a/app.js +++ b/app.js @@ -1,39 +1,39 @@ //app.js App({ - onLaunch: function () { - //调用API从本地缓存中获取数据 - var user_oauth = wx.getStorageSync('user-oauth') || {} - - //if (!user_oauth) { - wx.redirectTo({'url': '/pages/user/login'}); - //} - this.accessToken = user_oauth.access_token; - this.user = wx.getStorageSync('user') || {}; - }, - getUserInfo:function(cb){ - var that = this - if(this.globalData.userInfo){ - typeof cb == "function" && cb(this.globalData.userInfo) - }else{ - //调用登录接口 - /*wx.login({ - success: function () { - wx.getUserInfo({ - success: function (res) { - that.globalData.userInfo = res.userInfo - typeof cb == "function" && cb(that.globalData.userInfo) - } - }) + onLaunch: function () { + //调用API从本地缓存中获取数据 + var user_oauth = wx.getStorageSync('user-oauth') || {} + + //if (!user_oauth) { + wx.redirectTo({ 'url': '/pages/user/login' }); + //} + this.accessToken = user_oauth.access_token; + this.user = wx.getStorageSync('user') || {}; + }, + getUserInfo: function (cb) { + var that = this + if (this.globalData.userInfo) { + typeof cb == "function" && cb(this.globalData.userInfo) + } else { + //调用登录接口 + /*wx.login({ + success: function () { + wx.getUserInfo({ + success: function (res) { + that.globalData.userInfo = res.userInfo + typeof cb == "function" && cb(that.globalData.userInfo) + } + }) + } + })*/ } - })*/ - } - }, - cnbConfig: { - apiPrefix: "https://api.cnblogs.com/", - clientId: "5312b4d3-897a-4eac-9dfc-ebbc3d160bf5", - clientSecret: "NLukeDte09-2Eyf0anqlezNyVFM5RoCtJ1twwKMvQjW0tSVbisGv61tcnUgn1_hs2Y6kqO2CLax5e920", - publicKey: "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp0wHYbg/NOPO3nzMD3dndwS0MccuMeXCHgVlGOoYyFwLdS24Im2e7YyhB0wrUsyYf0/nhzCzBK8ZC9eCWqd0aHbdgOQT6CuFQBMjbyGYvlVYU2ZP7kG9Ft6YV6oc9ambuO7nPZh+bvXH0zDKfi02prknrScAKC0XhadTHT3Al0QIDAQAB" - }, - accessToken: '', - user: {} + }, + cnbConfig: { + apiPrefix: "https://api.cnblogs.com/", + clientId: "5312b4d3-897a-4eac-9dfc-ebbc3d160bf5", + clientSecret: "NLukeDte09-2Eyf0anqlezNyVFM5RoCtJ1twwKMvQjW0tSVbisGv61tcnUgn1_hs2Y6kqO2CLax5e920", + publicKey: "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp0wHYbg/NOPO3nzMD3dndwS0MccuMeXCHgVlGOoYyFwLdS24Im2e7YyhB0wrUsyYf0/nhzCzBK8ZC9eCWqd0aHbdgOQT6CuFQBMjbyGYvlVYU2ZP7kG9Ft6YV6oc9ambuO7nPZh+bvXH0zDKfi02prknrScAKC0XhadTHT3Al0QIDAQAB" + }, + accessToken: '', + user: {} }) \ No newline at end of file diff --git a/app.json b/app.json index e5e01b7ed9aa8889fcce2ea485630f936b2a9a69..01b66a6659e236a4d16c166296950bc08cd737f7 100644 --- a/app.json +++ b/app.json @@ -1,6 +1,6 @@ { "pages": [ - "pages/home/index", + "pages/index/index", "pages/question/index", "pages/user/login", "pages/user/index", @@ -17,7 +17,7 @@ }, "tabBar": { "list": [{ - "pagePath": "pages/home/index", + "pagePath": "pages/index/index", "text": "首页" }, { diff --git a/pages/blogpost/body.js b/pages/blogpost/body.js index f9eca8e1f7f6d88fc1bdc8471da81e4aae4d684a..020bae4101f8aa62b4c8fed6f0a95ff35acfe0d4 100644 --- a/pages/blogpost/body.js +++ b/pages/blogpost/body.js @@ -2,44 +2,83 @@ var WxParse = require('../../vendor/wxParse/wxParse.js') var app = getApp() Page({ - data:{ - article: "" - }, - onLoad:function(options){ - // 页面初始化 options为页面跳转所带来的参数 - var that = this; - wx.request({ - url: 'https://api.cnblogs.com/api/blogposts/'+ options.post_id +'/body', - method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT - header: { - "Content-Type":"application/x-www-form-urlencoded", - "Authorization":"Bearer " + app.globalData.access_token, - }, - success: function(res){ - that.setData({ - article: res.data + data: { + article: '', + comments: [], + pageIndex: 1, + pageSize: 10, + }, + onLoad: function (options) { + this.loadArticle(options); + }, + + loadArticle: function (options) { + // 页面初始化 options为页面跳转所带来的参数 + 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 + header: { + "Content-Type": "application/json; charset=utf-8", + "Authorization": "Bearer " + app.globalData.access_token, + }, + success: function (res) { + if (res) { + that.setData({ + article: res.data + }) + + WxParse.wxParse('article', 'html', that.data.article, that, 5); + } + + }, + fail: function () { + // fail + }, + complete: function () { + // complete + } }) - WxParse.wxParse('article', 'html', that.data.article, that, 5); - console.log(res.data); - }, - fail: function() { - // fail - }, - complete: function() { - // complete - } - }) - }, - onReady:function(){ - // 页面渲染完成 - }, - onShow:function(){ - // 页面显示 - }, - onHide:function(){ - // 页面隐藏 - }, - onUnload:function(){ - // 页面关闭 - } + }, + + loadComments: function (options) { + 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, + method: 'GET', + header: { + "Content-Type": "application/json; charset=utf-8", + "Authorization": "Bearer " + app.globalData.access_token, + }, + success: function (res) { + if (res) { + that.setData({ + comments: res.data + }) + + WxParse.wxParse('article', 'html', that.data.article, that, 5); + } + + }, + fail: function () { + // fail + }, + complete: function () { + // complete + } + }) + }, + onReady: function () { + // 页面渲染完成 + }, + onShow: function () { + // 页面显示 + }, + onHide: function () { + // 页面隐藏 + }, + onUnload: function () { + // 页面关闭 + } }) \ No newline at end of file diff --git a/pages/blogpost/body.wxml b/pages/blogpost/body.wxml index 7a81362fbe56bc641e1fd67f1e4f30ea686fbd0a..73f74b5e6758b01d9982c336fd9d156709f1fc62 100644 --- a/pages/blogpost/body.wxml +++ b/pages/blogpost/body.wxml @@ -1,3 +1,3 @@ -