|
|
@@ -4,6 +4,7 @@ import { Icon } from "antd";
|
|
4
|
4
|
import intl from "react-intl-universal";
|
|
5
|
5
|
import Comment from "../../Comment";
|
|
6
|
6
|
import ContentItem from "./../ContentItem";
|
|
|
7
|
+import ReplyItem from "./../ReplyItem";
|
|
7
|
8
|
import "./index.css";
|
|
8
|
9
|
|
|
9
|
10
|
class CommentBox extends Component {
|
|
|
@@ -11,12 +12,14 @@ class CommentBox extends Component {
|
|
11
|
12
|
super(props);
|
|
12
|
13
|
this.state = {
|
|
13
|
14
|
showReply: true,
|
|
14
|
|
- page: 1
|
|
|
15
|
+ page: 1,
|
|
|
16
|
+ isShowOver3: false
|
|
15
|
17
|
};
|
|
16
|
18
|
|
|
17
|
19
|
this.handleToggleReply = this.handleToggleReply.bind(this);
|
|
18
|
20
|
this.handleGetMoreReply = this.handleGetMoreReply.bind(this);
|
|
19
|
21
|
this.renderReplies = this.renderReplies.bind(this);
|
|
|
22
|
+ this.handleClickCollapse = this.handleClickCollapse.bind(this);
|
|
20
|
23
|
}
|
|
21
|
24
|
|
|
22
|
25
|
/**
|
|
|
@@ -26,6 +29,14 @@ class CommentBox extends Component {
|
|
26
|
29
|
this.setState({ showReply: !this.state.showReply });
|
|
27
|
30
|
}
|
|
28
|
31
|
|
|
|
32
|
+ /**
|
|
|
33
|
+ * 点击收起按钮的时候只展示最多三条留言
|
|
|
34
|
+ */
|
|
|
35
|
+ handleClickCollapse() {
|
|
|
36
|
+ this.setState({ isShowOver3: !this.state.isShowOver3 });
|
|
|
37
|
+ console.log("this.isMore", this.state.isShowOver3);
|
|
|
38
|
+ }
|
|
|
39
|
+
|
|
29
|
40
|
/**
|
|
30
|
41
|
* 获取更多评论
|
|
31
|
42
|
* @param {string} commentId comment id
|
|
|
@@ -43,56 +54,133 @@ class CommentBox extends Component {
|
|
43
|
54
|
* @param {number} replies 回复的数量
|
|
44
|
55
|
* @param {boolean} isNoMoreReply 是否没有更多回复
|
|
45
|
56
|
*/
|
|
|
57
|
+ // renderReplies(replies, replyCount, isNoMoreReply) {
|
|
|
58
|
+ // console.log('replies', replies);
|
|
|
59
|
+ // console.log('replyCount', replyCount);
|
|
|
60
|
+ // console.log('isNoMoreReply', isNoMoreReply);
|
|
|
61
|
+ // const { commentId } = this.props;
|
|
|
62
|
+ // const { showReply } = this.state;
|
|
|
63
|
+ // if (showReply && replies && replies.length) {
|
|
|
64
|
+ // const len = replies.length;
|
|
|
65
|
+ // return (
|
|
|
66
|
+ // <div style={{ marginLeft: 50 }}>
|
|
|
67
|
+ // {replies.map((item, index) => {
|
|
|
68
|
+ // if (index === len - 1) {
|
|
|
69
|
+ // return [
|
|
|
70
|
+ // <ContentItem
|
|
|
71
|
+ // commentId={commentId}
|
|
|
72
|
+ // replyId={item.id}
|
|
|
73
|
+ // key={item.id}
|
|
|
74
|
+ // content={item}
|
|
|
75
|
+ // action="replyToReply" // 回复的回复
|
|
|
76
|
+ // />,
|
|
|
77
|
+ // <div className="comment-more-box" key="show_more_button">
|
|
|
78
|
+ // {!isNoMoreReply && replyCount !== len && (
|
|
|
79
|
+ // <span
|
|
|
80
|
+ // className="comment-show-more"
|
|
|
81
|
+ // onClick={() => this.handleGetMoreReply(commentId)}
|
|
|
82
|
+ // >
|
|
|
83
|
+ // {intl.get("reply.moreReply")}
|
|
|
84
|
+ // </span>
|
|
|
85
|
+ // )}
|
|
|
86
|
+
|
|
|
87
|
+ // <a
|
|
|
88
|
+ // style={{ float: "right" }}
|
|
|
89
|
+ // onClick={this.handleToggleReply}
|
|
|
90
|
+ // >
|
|
|
91
|
+ // <Icon type="up" /> {intl.get("reply.collapse")}
|
|
|
92
|
+ // </a>
|
|
|
93
|
+ // </div>
|
|
|
94
|
+ // ];
|
|
|
95
|
+ // }
|
|
|
96
|
+ // return (
|
|
|
97
|
+ // <ContentItem
|
|
|
98
|
+ // commentId={commentId}
|
|
|
99
|
+ // replyId={item.id}
|
|
|
100
|
+ // key={item.id}
|
|
|
101
|
+ // content={item}
|
|
|
102
|
+ // action="replyToReply" // 评论的回复
|
|
|
103
|
+ // />
|
|
|
104
|
+ // );
|
|
|
105
|
+ // })}
|
|
|
106
|
+ // </div>
|
|
|
107
|
+ // );
|
|
|
108
|
+ // }
|
|
|
109
|
+ // return null;
|
|
|
110
|
+ // }
|
|
|
111
|
+
|
|
|
112
|
+ /**
|
|
|
113
|
+ * 渲染回复 DOM
|
|
|
114
|
+ * @param {array} replies 回复列表
|
|
|
115
|
+ * @param {number} replyCount 回复的数量
|
|
|
116
|
+ * @param {boolean} isNoMoreReply 是否没有更多回复
|
|
|
117
|
+ */
|
|
46
|
118
|
renderReplies(replies, replyCount, isNoMoreReply) {
|
|
|
119
|
+ console.log("this.isMore3", this.state.isShowOver3);
|
|
47
|
120
|
const { commentId } = this.props;
|
|
48
|
121
|
const { showReply } = this.state;
|
|
|
122
|
+ console.log("replies", replies);
|
|
|
123
|
+ console.log("replyCount", replyCount);
|
|
|
124
|
+ console.log("isNoMoreReply", isNoMoreReply);
|
|
49
|
125
|
if (showReply && replies && replies.length) {
|
|
|
126
|
+ console.log("showReply", showReply);
|
|
50
|
127
|
const len = replies.length;
|
|
51
|
128
|
return (
|
|
52
|
|
- <div style={{ marginLeft: 50 }}>
|
|
|
129
|
+ <div
|
|
|
130
|
+ style={{
|
|
|
131
|
+ marginLeft: 50,
|
|
|
132
|
+ borderTop: "1px solid #e3e3e3",
|
|
|
133
|
+ paddingTop: 15,
|
|
|
134
|
+ marginTop: -5
|
|
|
135
|
+ }}
|
|
|
136
|
+ >
|
|
53
|
137
|
{replies.map((item, index) => {
|
|
54
|
138
|
if (index === len - 1) {
|
|
55
|
139
|
return [
|
|
56
|
|
- <ContentItem
|
|
57
|
|
- commentId={commentId}
|
|
58
|
|
- replyId={item.id}
|
|
59
|
|
- key={item.id}
|
|
60
|
|
- content={item}
|
|
61
|
|
- action="replyToReply" // 回复的回复
|
|
62
|
|
- />,
|
|
63
|
|
- <div className="comment-more-box" key="show_more_button">
|
|
|
140
|
+ <ReplyItem replyItem={item} key={item.id} />,
|
|
|
141
|
+ <div key="show_more_button">
|
|
64
|
142
|
{!isNoMoreReply && replyCount !== len && (
|
|
65
|
143
|
<span
|
|
66
|
|
- className="comment-show-more"
|
|
|
144
|
+ // className="comment-show-more"
|
|
67
|
145
|
onClick={() => this.handleGetMoreReply(commentId)}
|
|
68
|
146
|
>
|
|
69
|
|
- {intl.get("reply.moreReply")}
|
|
|
147
|
+ 展开更多评论
|
|
|
148
|
+ <Icon type="down" />
|
|
|
149
|
+ </span>
|
|
|
150
|
+ )}
|
|
|
151
|
+ {replyCount === len && (
|
|
|
152
|
+ <span
|
|
|
153
|
+ // className="comment-show-more"
|
|
|
154
|
+ onClick={() => this.handleClickCollapse()}
|
|
|
155
|
+ >
|
|
|
156
|
+ 收起
|
|
|
157
|
+ <Icon type="up" />
|
|
70
|
158
|
</span>
|
|
71
|
159
|
)}
|
|
72
|
160
|
|
|
73
|
|
- <a
|
|
|
161
|
+ {/* <a
|
|
74
|
162
|
style={{ float: "right" }}
|
|
75
|
163
|
onClick={this.handleToggleReply}
|
|
76
|
164
|
>
|
|
77
|
165
|
<Icon type="up" /> {intl.get("reply.collapse")}
|
|
78
|
|
- </a>
|
|
|
166
|
+ </a> */}
|
|
79
|
167
|
</div>
|
|
80
|
168
|
];
|
|
81
|
169
|
}
|
|
82
|
|
- return (
|
|
83
|
|
- <ContentItem
|
|
84
|
|
- commentId={commentId}
|
|
85
|
|
- replyId={item.id}
|
|
86
|
|
- key={item.id}
|
|
87
|
|
- content={item}
|
|
88
|
|
- action="replyToReply" // 评论的回复
|
|
89
|
|
- />
|
|
90
|
|
- );
|
|
|
170
|
+ if (this.state.isShowOver3) {
|
|
|
171
|
+ console.log("11111");
|
|
|
172
|
+ return <ReplyItem replyItem={item} key={item.id} />;
|
|
|
173
|
+ }
|
|
|
174
|
+ if (!this.state.isShowOver3 && index < 3) {
|
|
|
175
|
+ console.log("222222");
|
|
|
176
|
+ return <ReplyItem replyItem={item} key={item.id} />;
|
|
|
177
|
+ }
|
|
|
178
|
+ console.log("3333");
|
|
|
179
|
+ return null;
|
|
91
|
180
|
})}
|
|
92
|
181
|
</div>
|
|
93
|
182
|
);
|
|
94
|
183
|
}
|
|
95
|
|
- return null;
|
|
96
|
184
|
}
|
|
97
|
185
|
|
|
98
|
186
|
render() {
|