From aa45af40564e822392e158525f8f6da36a19521f Mon Sep 17 00:00:00 2001 From: ktb Date: Sun, 23 Apr 2017 18:52:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E5=88=AB=E4=BA=BA=E7=9A=84?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E4=BB=A5=E5=8F=8A=E8=8E=B7=E5=8F=96=E5=90=84?= =?UTF-8?q?=E4=B8=AA=E7=B1=BB=E5=9E=8B=E9=97=AA=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/status/detail.js | 19 +++++- pages/status/detail.wxml | 12 ++-- pages/status/index.js | 143 +++++++++++++++++++++++++++++++++++---- pages/status/index.wxml | 83 ++++++++++++++++++++++- 4 files changed, 231 insertions(+), 26 deletions(-) diff --git a/pages/status/detail.js b/pages/status/detail.js index 49a53eb..e2edcaf 100644 --- a/pages/status/detail.js +++ b/pages/status/detail.js @@ -7,7 +7,9 @@ Page({ pageIndex:1, pageSize:10, status_id:0, - user_id:app.user.SpaceUserId + user_id:app.user.SpaceUserId, + comment_id:'', + comment_text:'' }, onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 @@ -48,6 +50,7 @@ Page({ formSubmit: function(e) { var content = e.detail.value.content; var status_id = e.detail.value.status_id; + var comment_id = e.detail.value.comment_id; var that = this; //发表闪存评论 wx.request({ @@ -55,6 +58,7 @@ Page({ method: 'post', data: { ReplyTo:status_id, + ParentCommentId:comment_id, Content:content }, header: { @@ -66,6 +70,9 @@ Page({ complete: function () { that.getStatus(that, status_id); that.onPullDownRefresh(); + that.setData({ + comment_text:'' + }) } }) }, @@ -142,5 +149,15 @@ Page({ that.onPullDownRefresh(); } }) + }, + //回复别人评论 + replyComment:function(event) { + var comment_id = event.currentTarget.dataset.comment_id; + var comment_user_name = event.currentTarget.dataset.comment_user_name; + + this.setData({ + comment_id:comment_id, + comment_text:"@" + comment_user_name +":" + }); } }) \ No newline at end of file diff --git a/pages/status/detail.wxml b/pages/status/detail.wxml index 8b24c1c..ae0e756 100644 --- a/pages/status/detail.wxml +++ b/pages/status/detail.wxml @@ -13,9 +13,7 @@ 文字来源 {{statuses.DateAdded}} - - 回应 - + @@ -34,8 +32,7 @@ {{item.DateAdded}} 删除 - - 回应 + 回应 @@ -47,8 +44,9 @@ - - + + + diff --git a/pages/status/index.js b/pages/status/index.js index 05d1f3e..2526066 100644 --- a/pages/status/index.js +++ b/pages/status/index.js @@ -2,25 +2,34 @@ var app = getApp() Page({ data:{ - tabs: ["我的回应", "提到我的", "选项三"], + tabs: ["全部", "我的", "回复我", "我回应"], pageIndex:1, pageSize:10, activeIndex: 0, sliderOffset: 0, sliderLeft: 0, - statuses_all:[ - - ] + all_statuses:[], + my_statuses:[], + comment_statuses:[], + my_comment_statuses:[] }, onLoad:function(options){ - this.loadStatuses(this, this.data.pageIndex, this.data.pageSize); + // this.loadStatuses(this, this.data.pageIndex, this.data.pageSize); + this.getStatusByType(this.data.activeIndex, this, 1, this.data.pageSize); wx.stopPullDownRefresh(); }, tabClick: function (e) { + var activeIndex = e.currentTarget.id; this.setData({ sliderOffset: e.currentTarget.offsetLeft, - activeIndex: e.currentTarget.id + activeIndex: activeIndex, + pageIndex: 1, + all_statuses:[], + my_statuses:[], + comment_statuses:[], + my_comment_statuses:[] }); + this.getStatusByType(activeIndex, this, 1, this.data.pageSize); }, onReady:function(){ // 页面渲染完成 @@ -39,19 +48,40 @@ Page({ wx.showNavigationBarLoading(); this.setData({ pageIndex:1, - statuses_all:[], + all_statuses:[], + my_statuses:[], + comment_statuses:[], + my_comment_statuses:[] }); - this.loadStatuses(this, this.data.pageIndex, this.data.pageSize) + // this.getStatuses(this, this.data.pageIndex, this.data.pageSize) + this.getStatusByType(this.data.activeIndex, 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) + // this.getAllStatuses(this, this.data.pageIndex, this.data.pageSize) + this.getStatusByType(this.data.activeIndex, this, this.data.pageIndex, this.data.pageSize); }, - loadStatuses: function(that, pageIndex, pageSize){ - //获取闪存信息 + getStatusByType:function(activeIndex, that, pageIndex, pageSize) { + switch (parseInt(activeIndex)) { + case 0: + this.getAllStatuses(that, pageIndex, pageSize); + break; + case 1: + this.getMyStatuses(that, pageIndex, pageSize); + break; + case 2: + this.getReplyMyStatuses(that, pageIndex, pageSize); + break; + case 3: + this.getIReplyStatuses(that, pageIndex, pageSize); + break; + } + }, + getAllStatuses: function(that, pageIndex, pageSize){ + //获取全部闪存列表 wx.request({ url: 'http://api.cnblogs.com/api/statuses/@all', data: { @@ -64,13 +94,40 @@ Page({ "Authorization":"Bearer " + app.accessToken }, success: function(res) { - console.log(res); - var list = that.data.statuses_all; + var list = that.data.all_statuses; + for (var i = 0; i < res.data.length; i++) { + list.push(res.data[i]); + } + that.setData({ + all_statuses: list + }); + }, + complete: function () { + wx.hideNavigationBarLoading(); + wx.stopPullDownRefresh(); + } + }) + }, + getMyStatuses: function(that, pageIndex, pageSize){ + //获取我的闪存列表 + wx.request({ + url: 'http://api.cnblogs.com/api/statuses/@my', + data: { + pageIndex:pageIndex, + pageSize:pageSize, + tag:'is' + }, + header: { + "Content-Type":"application/x-www-form-urlencoded", + "Authorization":"Bearer " + app.accessToken + }, + success: function(res) { + var list = that.data.my_statuses; for (var i = 0; i < res.data.length; i++) { list.push(res.data[i]); } that.setData({ - statuses_all: list + my_statuses: list }); }, complete: function () { @@ -78,5 +135,61 @@ Page({ wx.stopPullDownRefresh(); } }) - } + }, + getReplyMyStatuses: function(that, pageIndex, pageSize){ + //获取回复我的闪存列表 + wx.request({ + url: 'http://api.cnblogs.com/api/statuses/@comment', + data: { + pageIndex:pageIndex, + pageSize:pageSize, + tag:'is' + }, + header: { + "Content-Type":"application/x-www-form-urlencoded", + "Authorization":"Bearer " + app.accessToken + }, + success: function(res) { + var list = that.data.comment_statuses; + for (var i = 0; i < res.data.length; i++) { + list.push(res.data[i]); + } + that.setData({ + comment_statuses: list + }); + }, + complete: function () { + wx.hideNavigationBarLoading(); + wx.stopPullDownRefresh(); + } + }) + }, + getMyReplyStatuses: function(that, pageIndex, pageSize){ + //获取我回复的闪存列表 + wx.request({ + url: 'http://api.cnblogs.com/api/statuses/@mycomment', + data: { + pageIndex:pageIndex, + pageSize:pageSize, + tag:'is' + }, + header: { + "Content-Type":"application/x-www-form-urlencoded", + "Authorization":"Bearer " + app.accessToken + }, + success: function(res) { + var list = that.data.my_comment_statuses; + for (var i = 0; i < res.data.length; i++) { + list.push(res.data[i]); + } + that.setData({ + my_comment_statuses: 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 6764991..e085550 100644 --- a/pages/status/index.wxml +++ b/pages/status/index.wxml @@ -16,10 +16,11 @@ + -- Gitee