From 1b7684c19a01211e55a4cb7a7f6b2d6bfb396772 Mon Sep 17 00:00:00 2001 From: ktb Date: Sat, 8 Apr 2017 18:00:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=86=E9=A1=B5,=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/status/detail.js | 130 +++++++++++++++++++++++++++++---------- pages/status/detail.wxml | 7 ++- pages/status/detail.wxss | 5 +- pages/status/index.js | 69 +++++++++++++++------ pages/status/index.wxml | 3 +- 5 files changed, 155 insertions(+), 59 deletions(-) diff --git a/pages/status/detail.js b/pages/status/detail.js index f57d923..e7d534f 100644 --- a/pages/status/detail.js +++ b/pages/status/detail.js @@ -3,43 +3,35 @@ var app = getApp() Page({ data:{ statuses:[], - comments:'' + comments:'', + pageIndex:1, + pageSize:10, + status_id:0, + user_id:app.user.SpaceUserId }, onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 + this.setData({ + status_id:options.status_id + }); var status_id = options.status_id; var that = this; //获取闪存信息 wx.request({ - url: 'http://api.cnblogs.com/api/statuses/' + status_id, - data: { - }, + url: 'http://api.cnblogs.com/api/statuses/' + status_id, + data: { + }, header: { "Content-Type":"application/x-www-form-urlencoded", - "Authorization":"Bearer " + app.globalData.access_token + "Authorization":"Bearer " + app.accessToken }, success: function(res) { that.setData({ statuses:res.data }) } - }), - //获取闪存评论 - wx.request({ - // url: 'http://api.cnblogs.com/api/statuses/'+ status_id +'/comments', - url: 'http://api.cnblogs.com/api/statuses/1093141/comments', - data: { - }, - header: { - "Content-Type":"application/x-www-form-urlencoded", - "Authorization":"Bearer " + app.globalData.access_token - }, - success: function(res2) { - that.setData({ - comments:res2.data - }) - } }) + this.loadStatusescomment(this, status_id, this.data.pageIndex, this.data.pageSize) }, onReady:function(){ // 页面渲染完成 @@ -52,33 +44,103 @@ Page({ }, onUnload:function(){ // 页面关闭 - }, - content: function(text) { - console.log(text.detail.value); - this.setData({ - content:text.detail.value - }) - }, - put:function(text){ - }, formSubmit: function(e) { var content = e.detail.value.content; + var status_id = e.detail.value.status_id; + var that = this; //发表闪存评论 wx.request({ - // url: 'http://api.cnblogs.com/api/statuses/'+ status_id +'/comments', - url: 'http://api.cnblogs.com/api/statuses/1093141/comments', + url: 'http://api.cnblogs.com/api/statuses/'+ status_id +'/comments', method: 'post', data: { - ReplyTo:1093141, + ReplyTo:status_id, Content:content }, header: { "Content-Type":"application/x-www-form-urlencoded", - "Authorization":"Bearer " + app.globalData.access_token + "Authorization":"Bearer " + app.accessToken + }, + success: function(res2) { + }, + complete: function () { + that.getStatus(that, status_id); + that.onPullDownRefresh(); + } + }) + }, + //下拉刷新 + onPullDownRefresh:function(){ + wx.showNavigationBarLoading(); + this.setData({ + pageIndex:1, + statuses:[] + }); + this.loadStatusescomment(this, this.data.status_id, this.data.pageIndex, this.data.pageSize) + }, + //上拉加载更多 + onReachBottom:function(){ + this.setData({ + pageIndex:this.data.pageIndex + 1 + }); + this.loadStatusescomment(this, this.data.status_id, this.data.pageIndex, this.data.pageSize) + }, + getStatus:function(that, status_id) { + wx.request({ + url: 'http://api.cnblogs.com/api/statuses/' + status_id, + data: { + }, + header: { + "Content-Type":"application/x-www-form-urlencoded", + "Authorization":"Bearer " + app.accessToken + }, + success: function(res) { + that.setData({ + statuses:res.data + }) + } + }) + }, + //获取闪存评论 + loadStatusescomment:function(that, status_id, pageIndex, pageSize) { + wx.request({ + url: 'http://api.cnblogs.com/api/statuses/'+ status_id +'/comments', + data: { + }, + header: { + "Content-Type":"application/x-www-form-urlencoded", + "Authorization":"Bearer " + app.accessToken }, success: function(res2) { + that.setData({ + comments:res2.data + }) + }, + complete: function () { + wx.hideNavigationBarLoading(); + wx.stopPullDownRefresh(); } }) }, + //删除评论 + deleteComment:function(event) { + var that = this; + wx.request({ + url: 'http://api.cnblogs.com/api/statuses/'+ event.target.dataset.status_id +'/comments/' + event.target.dataset.comment_id, + method: 'delete', + data: { + }, + header: { + "Content-Type":"application/x-www-form-urlencoded", + "Authorization":"Bearer " + app.accessToken + }, + success: function(res) { + + }, + complete: function () { + that.getStatus(that, event.target.dataset.status_id); + that.onPullDownRefresh(); + } + }) + } }) \ No newline at end of file diff --git a/pages/status/detail.wxml b/pages/status/detail.wxml index d238d54..3c1b757 100644 --- a/pages/status/detail.wxml +++ b/pages/status/detail.wxml @@ -33,7 +33,9 @@ {{item.DateAdded}} - 回应 + 删除 + + 回应 @@ -45,6 +47,7 @@ + @@ -53,7 +56,5 @@ - - \ No newline at end of file diff --git a/pages/status/detail.wxss b/pages/status/detail.wxss index 4781a2a..2692f40 100644 --- a/pages/status/detail.wxss +++ b/pages/status/detail.wxss @@ -10,7 +10,7 @@ .comments{ position:fixed; bottom:0px; - width:100% + width:100%; } .pdb60{ padding-bottom:62px; @@ -18,4 +18,7 @@ .wxgreen{ background-color:#1AAD19; color:white; +} +.hid{ + display:none; } \ No newline at end of file diff --git a/pages/status/index.js b/pages/status/index.js index f653e44..7ba94f5 100644 --- a/pages/status/index.js +++ b/pages/status/index.js @@ -3,6 +3,8 @@ var app = getApp() Page({ data:{ tabs: ["我的回应", "提到我的", "选项三"], + pageIndex:1, + pageSize:10, activeIndex: 0, sliderOffset: 0, sliderLeft: 0, @@ -10,27 +12,9 @@ Page({ ] }, - //获取token onLoad:function(options){ - var that = this; - //获取闪存信息 - wx.request({ - url: 'http://api.cnblogs.com/api/statuses/@all', - data: { - pageIndex:1, - pageSize:10, - tag:'is' - }, - header: { - "Content-Type":"application/x-www-form-urlencoded", - "Authorization":"Bearer " + app.globalData.access_token - }, - success: function(res3) { - that.setData({ - statuses_all:res3.data - }) - } - }) + this.loadStatuses(this, this.data.pageIndex, this.data.pageSize); + wx.stopPullDownRefresh(); }, tabClick: function (e) { this.setData({ @@ -49,5 +33,50 @@ Page({ }, onUnload:function(){ // 页面关闭 + }, + //下拉刷新 + onPullDownRefresh:function(){ + wx.showNavigationBarLoading(); + this.setData({ + pageIndex:1, + statuses_all:[] + }); + this.loadStatuses(this, this.data.pageIndex, this.data.pageSize) + }, + //上拉加载更多 + onReachBottom:function(){ + this.setData({ + pageIndex:this.data.pageIndex + 1 + }); + this.loadStatuses(this, this.data.pageIndex, this.data.pageSize) + }, + loadStatuses: function(that, pageIndex, pageSize){ + //获取闪存信息 + wx.request({ + url: 'http://api.cnblogs.com/api/statuses/@all', + data: { + pageIndex:pageIndex, + pageSize:pageSize, + tag:'is' + }, + header: { + "Content-Type":"application/x-www-form-urlencoded", + "Authorization":"Bearer " + app.accessToken + }, + success: function(res) { + console.log(res); + var list = that.data.statuses_all; + for (var i = 0; i < res.data.length; i++) { + list.push(res.data[i]); + } + that.setData({ + statuses_all: list + }); + }, + complete: function () { + wx.hideNavigationBarLoading(); + wx.stopPullDownRefresh(); + } + }) } }) \ No newline at end of file diff --git a/pages/status/index.wxml b/pages/status/index.wxml index b9f3ee0..41b8eb8 100644 --- a/pages/status/index.wxml +++ b/pages/status/index.wxml @@ -31,7 +31,7 @@ 文字来源 {{item.DateAdded}} - 回应 + {{item.CommentCount}}回应 @@ -40,6 +40,7 @@ + -- Gitee From 62c23848312f87d4f7fba8b0a8e491b04f153c4a Mon Sep 17 00:00:00 2001 From: ktb Date: Sat, 8 Apr 2017 18:06:15 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=86=E9=A1=B5,=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/status/detail.js | 2 +- pages/status/detail.wxml | 4 ++-- pages/status/detail.wxss | 1 + pages/status/index.js | 2 +- pages/status/index.wxml | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pages/status/detail.js b/pages/status/detail.js index e7d534f..49a53eb 100644 --- a/pages/status/detail.js +++ b/pages/status/detail.js @@ -12,7 +12,7 @@ Page({ onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 this.setData({ - status_id:options.status_id + status_id:options.status_id, }); var status_id = options.status_id; var that = this; diff --git a/pages/status/detail.wxml b/pages/status/detail.wxml index 3c1b757..8b24c1c 100644 --- a/pages/status/detail.wxml +++ b/pages/status/detail.wxml @@ -33,9 +33,9 @@ {{item.DateAdded}} - 删除 + 删除 - 回应 + 回应 diff --git a/pages/status/detail.wxss b/pages/status/detail.wxss index 2692f40..2ae51a0 100644 --- a/pages/status/detail.wxss +++ b/pages/status/detail.wxss @@ -21,4 +21,5 @@ } .hid{ display:none; + } \ No newline at end of file diff --git a/pages/status/index.js b/pages/status/index.js index 7ba94f5..05d1f3e 100644 --- a/pages/status/index.js +++ b/pages/status/index.js @@ -39,7 +39,7 @@ Page({ wx.showNavigationBarLoading(); this.setData({ pageIndex:1, - statuses_all:[] + statuses_all:[], }); this.loadStatuses(this, this.data.pageIndex, this.data.pageSize) }, diff --git a/pages/status/index.wxml b/pages/status/index.wxml index 41b8eb8..6764991 100644 --- a/pages/status/index.wxml +++ b/pages/status/index.wxml @@ -31,7 +31,7 @@ 文字来源 {{item.DateAdded}} - {{item.CommentCount}}回应 + {{item.CommentCount}} 回应 -- Gitee