Skip to content

Commit db6cd88

Browse files
author
chunwei
committed
almost done
1 parent 6a4d17a commit db6cd88

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed

.idea/encodings.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/comment/Comment.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ var CommentHeader = React.createClass({
1313
var avatar=this.props.author.avatar||defaultAvatar;
1414
let tag=(this.props.showTag&&this.props.tag)?(<span className="tag">#{this.props.tag}</span>):null;
1515
return (
16+
<div>
17+
{tag}
1618
<div className="commentHeader">
1719
<div className="commentAuthor">
1820
<span className="avatar"><img src={avatar}/></span>
19-
<span className="author">{this.props.author.name||"游客"} {tag}</span>
21+
<span className="author">{this.props.author.name||"游客"}</span>
2022
</div>
2123
<LikeButton liked={this.props.liked} count={this.props.likedCount} commentid={this.props.id}/>
2224
</div>
25+
</div>
2326
);
2427
}
2528
});

src/components/comment/CommentBox.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ var CommentBox = React.createClass({
2121
success: function (res) {
2222
if(res&&res.Status=="Success") {
2323
var comments=res.Result;
24-
if(!comments||comments.length==0){
24+
/*if(!comments||comments.length==0){
2525
comments=[];
2626
var first=RSVP.createComment();
2727
first.author.name='景区';
2828
first.text='欢迎留下您的足迹!';
2929
comments.push(first);
30-
}
30+
}*/
3131
this.setState({data: comments,hasmore:res.Result.length>=RSVP.config.pagesize});
3232
}
3333
}.bind(this),
@@ -46,8 +46,8 @@ var CommentBox = React.createClass({
4646
data:{params:JSON.stringify(params)},
4747
success: function (res) {
4848
if(res&&res.Status=="Success") {
49-
//var newData=this.state.data.concat(res.Result);//正序,最后位置插入
50-
var newData=res.Result.concat(this.state.data);//逆序,最前位置插入
49+
var newData=this.state.data.concat(res.Result);//正序,最后位置插入
50+
//var newData=res.Result.concat(this.state.data);//逆序,最前位置插入
5151
this.setState({data: newData,hasmore:res.Result.length>=RSVP.config.pagesize});
5252
RSVP.config.page=params.page;
5353
}
@@ -63,8 +63,8 @@ var CommentBox = React.createClass({
6363
if(pId&&pId!=0){
6464
var parentComment=RSVP.getCommentById(comments,pId);
6565
comment.parentId =parentComment.id;
66-
var ppid=parentComment.parentId;
67-
comment.syncId=(ppid&&ppid!=0&&ppid!="0")?ppid:parentComment.id;
66+
var psid=parentComment.syncId;
67+
comment.syncId=(psid&&psid!=0&&psid!="0")?psid:parentComment.id;
6868
comment.toOpenid=parentComment.author.openid;
6969
comment.toAppid=parentComment.author.appid;
7070
comment.toWho=parentComment.author.name;
@@ -100,7 +100,7 @@ var CommentBox = React.createClass({
100100
//var newComments = comments.concat([comment]);
101101
this.setState({data: comments});
102102

103-
console.log("insert to local comments Success");
103+
//console.log("insert to local comments Success");
104104
$.ajax({
105105
url: this.props.inserturl,
106106
dataType: 'json',
@@ -109,9 +109,9 @@ var CommentBox = React.createClass({
109109
success: function (res) {//console.log("insert Success");
110110
if(res&&res.Status=="Success") {//console.log("res&&res.Status==Success");
111111
//this.setState({data: data});
112-
var comment=res.Result[0];console.log(res);//console.log(comment);
113-
if (comment && res.tempid) {console.log("comment && res.tempid");
114-
var old = RSVP.getCommentById(comments, res.tempid);console.log('old=');//console.log(old);console.log('==old end');
112+
var comment=res.Result[0];//console.log(res);//console.log(comment);
113+
if (comment && res.tempid) {//console.log("comment && res.tempid");
114+
var old = RSVP.getCommentById(comments, res.tempid);//console.log('old=');//console.log(old);console.log('==old end');
115115
old.id = comment.id;
116116
old.author = comment.author;
117117
old.text=comment.text;
@@ -161,13 +161,15 @@ var CommentBox = React.createClass({
161161
child.props.onCommentSubmit=this.handleCommentSubmit;
162162
child.props.getCommentById=this.getCommentById;
163163
},this);
164+
var welcome=this.state.data.length==0?<span>欢迎留下您的足迹!</span>:null;
164165
var loadMoreBtn=this.state.hasmore?<div className="LoadMoreBtn" onClick={this.loadMore}>加载更多</div>:null;
165166
return (
166167
<div className="commentBox">
167168
<div className="BoxHeader">
168169
<b>驴友评论</b><Link to='/post' className="writeComment">写评论<i className="icon-writeComment"></i></Link>
169170
</div>
170171
<CommentList data={this.state.data} sortBy="oldest" showTag={RSVP.config.showCommentTag}/>
172+
{welcome}
171173
{loadMoreBtn}
172174
<CommentBar/>
173175
{/*

src/components/comment/comment.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ button, html input[type="button"], input[type="reset"], input[type="submit"] {
5050
width: 100%;
5151
border-radius: 20%;
5252
}
53-
.commentHeader .tag {
53+
.comment .tag {
5454
font-size: 0.8em;
55-
margin-left:10px;
55+
margin-left:0px;
5656
color: #1448aa;
5757
}
5858

src/components/utils/common.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ RSVP.urlp=function(key, qstring){
3535

3636
RSVP.createComment=function(){
3737
var uuid=this.config.uuid;
38-
if(uuid.indexOf('_Add'))uuid=uuid.substr(0,uuid.indexOf('_Add'));
38+
if(uuid.indexOf('_All')>-1)uuid=uuid.substr(0,uuid.indexOf('_All'));
3939
return {
4040
id:"__"+this.uuid(10),
41-
uuid:this.config.uuid,
42-
targetId:this.config.uuid,
41+
uuid:uuid,
42+
targetId:uuid,
4343
tag:this.config.tag,
4444
author:{id:this.config.openid, appid:this.config.appid,name:"我"},
4545
time:new Date().getTime()

src/pages/index/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ var App = React.createClass({
2323
});
2424

2525
/*reply/:id/:towho/:towhoname*/
26+
var onEnter=function(){
27+
console.log("onEnter");
28+
};
29+
var onLeave=function(){
30+
console.log("onLeave");
31+
};
2632
React.render((
2733
<Router>
2834
<Route path="/" component={App}>
29-
<Route path="post" component={CommentForm}/>
30-
<Route path="reply/:id" component={CommentForm}/>
35+
<Route path="post" component={CommentForm} onEnter={onEnter} onLeave={onLeave}/>
36+
<Route path="reply/:id" component={CommentForm} onEnter={onEnter} onLeave={onLeave}/>
3137
</Route>
3238
</Router>
3339
), document.getElementById("comments")

0 commit comments

Comments
 (0)