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 @@
-
\ No newline at end of file
+
diff --git a/pages/home/index.js b/pages/home/index.js
deleted file mode 100644
index 8ab4cfe1ae72eeec0f52f1e7883d4915d060341a..0000000000000000000000000000000000000000
--- a/pages/home/index.js
+++ /dev/null
@@ -1,63 +0,0 @@
-//index.js
-//获取应用实例
-var app = getApp()
-Page({
- data: {
- tabs: ["博文", "精华区", "推荐新闻", "热门新闻", "本周新闻"],
- activeIndex: 0,
- sliderOffset: 0,
- sliderLeft: 0,
-
- //首页博文列表
- blog_articles: [],
- //精华区博文列表
- blog_pickeds: [],
- //推荐新闻
- news_recommendeds: [],
- //热门新闻
- news_hots: [],
- //本周新闻
- news_hots_week: []
- },
- onLoad: function () {
- var that = this;
-
- //首页博文列表
- wx.request({
- url: 'https://api.cnblogs.com/api/blogposts/@sitehome?pageIndex=1&pageSize=10',
- 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({
- blog_articles: res.data
- })
- },
- fail: function() {
- // fail
- },
- complete: function() {
- // complete
- }
- })
-
- },
-
- onPullDownRefresh: function() {
- console.log('下拉')
- console.log(this.data.activeIndex);
- },
-
- onReachBottom: function() {
- console.log('刷新')
- },
- //tabs
- tabClick: function (e) {
- this.setData({
- sliderOffset: e.currentTarget.offsetLeft,
- activeIndex: e.currentTarget.id
- });
- }
-})
diff --git a/pages/index/index.js b/pages/index/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..69b254d292c97243fa2749702a0b4f6cd9e580cf
--- /dev/null
+++ b/pages/index/index.js
@@ -0,0 +1,197 @@
+//index.js
+var pageSize = 10;
+var postType = 'sitehome';
+var newsType = 'recommended';
+
+//获取应用实例
+var app = getApp()
+Page({
+ data: {
+ tabs: ["博文", "精华区", "推荐新闻", "热门新闻", "本周新闻"],
+ activeIndex: 0,
+ sliderOffset: 0,
+ sliderLeft: 0,
+
+ siteHomeIndex: 1,
+ pickedIndex: 1,
+ recommendedIndex: 1,
+ hotIndex: 1,
+ hotWeekIndex: 1,
+
+ //首页博文列表
+ blog_articles: [],
+ //精华区博文列表
+ blog_pickeds: [],
+ //推荐新闻
+ news_recommendeds: [],
+ //热门新闻
+ news_hots: [],
+ //本周热门新闻
+ news_hots_week: []
+ },
+ onLoad: function () {
+ //默认加载首页文章列表
+ this.loadMoreBlogPosts(this, this.data.siteHomeIndex, postType);
+ },
+
+ onPullDownRefresh: function () {
+ console.log('--------下拉刷新-------')
+ wx.showNavigationBarLoading()
+ this.changeTab(this.data.activeIndex, 'pull');
+ },
+
+ onReachBottom: function () {
+ console.log('--------上拉刷新-------')
+ this.changeTab(this.data.activeIndex, 'reach');
+ },
+
+ //tabs
+ tabClick: function (e) {
+ this.setData({
+ sliderOffset: e.currentTarget.offsetLeft,
+ activeIndex: e.currentTarget.id
+ });
+
+ this.changeTab(this.data.activeIndex);
+ },
+
+ //切换tab 加载相应tab绑定的类别数据
+ changeTab: function (tabIndex, action) {
+ switch (parseInt(tabIndex)) {
+ case 0:
+ if (action === 'pull') {
+ this.setData({
+ siteHomeIndex: 1,
+ });
+ }
+ postType = 'sitehome'; //首页博文列表
+ this.loadMoreBlogPosts(this, this.data.siteHomeIndex, postType);
+ break;
+ case 1:
+ if (action === 'pull') {
+ this.setData({
+ pickedIndex: 1,
+ });
+ }
+ postType = 'picked'; //精华区博文列表
+ this.loadMoreBlogPosts(this, this.data.pickedIndex, postType);
+ break;
+ case 2:
+ if (action === 'pull') {
+ this.setData({
+ recommendedIndex: 1,
+ });
+ }
+ newsType = 'recommended';//推荐新闻
+ this.loadMoreNews(this, this.data.recommendedIndex, newsType);
+ break;
+ case 3:
+ if (action === 'pull') {
+ this.setData({
+ hotIndex: 1,
+ });
+ }
+ newsType = 'hot';//热门新闻
+ this.loadMoreNews(this, this.data.hotIndex, newsType);
+ break;
+ case 4:
+ if (action === 'pull') {
+ this.setData({
+ hotWeekIndex: 1,
+ });
+ }
+ newsType = 'hot-week';//本周热门新闻
+ this.loadMoreNews(this, this.data.hotWeekIndex, newsType);
+ break;
+ default:
+ console.log(this.data.siteHomeIndex, 'siteHomeIndex');
+ console.log(this.data.pickedIndex, 'pickedIndex');
+ console.log(this.data.recommendedIndex, 'recommendedIndex');
+ console.log(this.data.hotIndex, 'hotIndex');
+ console.log(this.data.hotWeekIndex, 'hotWeekIndex');
+ break;
+ }
+ },
+
+ //加载博文列表
+ 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,
+ },
+ success: function (res) {
+ pageIndex++;
+ if (postType === 'sitehome') {
+ that.setData({
+ blog_articles: res.data,
+ siteHomeIndex: pageIndex
+ });
+
+ } else if (postType === 'picked') {
+ that.setData({
+ blog_pickeds: res.data,
+ pickedIndex: pageIndex
+ });
+
+ }
+ },
+ fail: function () {
+ // fail
+ },
+ complete: function () {
+ console.log('-------完成后---------');
+ wx.hideNavigationBarLoading();
+ wx.stopPullDownRefresh();
+ }
+ });
+ },
+
+ //加载新闻列表
+ loadMoreNews: function (that, pageIndex, newsType) {
+ var url = '';
+ if (newsType === 'recommended' || newsType === 'hot-week') {
+ url = 'https://api.cnblogs.com/api/newsitems/@' + newsType + '?pageIndex=' + pageIndex + '&pageSize=' + pageSize;
+ } else {
+ url = 'https://api.cnblogs.com/api/newsitems/@' + newsType + '?startDate=2017-03-24&endDate=2017-03-25&pageIndex=' + pageIndex + '&pageSize=' + pageSize;
+ }
+
+ wx.request({
+ url: url,
+ method: 'GET',
+ header: {
+ "Content-Type": "application/json; charset=utf-8",
+ "Authorization": "Bearer " + app.globalData.access_token,
+ },
+ success: function (res) {
+ pageIndex++;
+ if (newsType === 'recommended') {
+ that.setData({
+ news_recommendeds: res.data,
+ recommendedIndex: pageIndex
+ });
+ } else if (newsType === 'hot') {
+ that.setData({
+ news_hots: res.data,
+ hotIndex: pageIndex
+ });
+ } else if (newsType === 'hot-week') {
+ that.setData({
+ news_hots_week: res.data,
+ hotWeekIndex: pageIndex
+ });
+ }
+ },
+ fail: function () {
+ // fail
+ },
+ complete: function () {
+ console.log('-------完成后---------');
+ wx.hideNavigationBarLoading();
+ wx.stopPullDownRefresh();
+ }
+ });
+ },
+})
diff --git a/pages/home/index.json b/pages/index/index.json
similarity index 100%
rename from pages/home/index.json
rename to pages/index/index.json
diff --git a/pages/home/index.wxml b/pages/index/index.wxml
similarity index 97%
rename from pages/home/index.wxml
rename to pages/index/index.wxml
index e457079123edbe8bd73a4fa7d286dfab33d6aaad..e0613b43a8c33d95d43481cf60993ab5d911480d 100644
--- a/pages/home/index.wxml
+++ b/pages/index/index.wxml
@@ -19,7 +19,7 @@
-
+
diff --git a/pages/home/index.wxss b/pages/index/index.wxss
similarity index 100%
rename from pages/home/index.wxss
rename to pages/index/index.wxss