Browse Source

feat: 完成评论框的回复与点赞

node 5 years ago
parent
commit
dcddb71818

+ 3
- 3
src/components/CommentBox/index.css View File

@@ -2,14 +2,14 @@
2 2
   color: #4a90e2;
3 3
   text-align: center;
4 4
   width: 100px;
5
-  background-color: #f8f8f8;
5
+  /* background-color: #f8f8f8; */
6 6
   cursor: pointer;
7
-  padding: 10px;
7
+  /* padding: 10px; */
8 8
   margin: 0 auto;
9 9
   transition: all 0.3s;
10 10
 }
11 11
 .comment-show-more:hover {
12
-  background-color: #f5f5f5;
12
+  /* background-color: #f5f5f5; */
13 13
   color: #1890ff;
14 14
 }
15 15
 .comment-more-box {

+ 23
- 44
src/components/CommentBox/index.js View File

@@ -1,7 +1,7 @@
1 1
 import React, { Component } from "react";
2 2
 import PropTypes from "prop-types";
3
-import { Icon } from "antd";
4
-import intl from "react-intl-universal";
3
+import { Icon, AutoComplete } from "antd";
4
+// import intl from "react-intl-universal";
5 5
 import Comment from "../../Comment";
6 6
 import ContentItem from "./../ContentItem";
7 7
 import ReplyItem from "./../ReplyItem";
@@ -12,14 +12,12 @@ class CommentBox extends Component {
12 12
     super(props);
13 13
     this.state = {
14 14
       showReply: true,
15
-      page: 1,
16
-      isShowOver3: false
15
+      page: 1
17 16
     };
18 17
 
19 18
     this.handleToggleReply = this.handleToggleReply.bind(this);
20 19
     this.handleGetMoreReply = this.handleGetMoreReply.bind(this);
21 20
     this.renderReplies = this.renderReplies.bind(this);
22
-    this.handleClickCollapse = this.handleClickCollapse.bind(this);
23 21
   }
24 22
 
25 23
   /**
@@ -29,14 +27,6 @@ class CommentBox extends Component {
29 27
     this.setState({ showReply: !this.state.showReply });
30 28
   }
31 29
 
32
-  /**
33
-   * 点击收起按钮的时候只展示最多三条留言
34
-   */
35
-  handleClickCollapse() {
36
-    this.setState({ isShowOver3: !this.state.isShowOver3 });
37
-    console.log("this.isMore", this.state.isShowOver3);
38
-  }
39
-
40 30
   /**
41 31
    * 获取更多评论
42 32
    * @param {string} commentId comment id
@@ -116,14 +106,9 @@ class CommentBox extends Component {
116 106
    * @param {boolean} isNoMoreReply 是否没有更多回复
117 107
    */
118 108
   renderReplies(replies, replyCount, isNoMoreReply) {
119
-    console.log("this.isMore3", this.state.isShowOver3);
120 109
     const { commentId } = this.props;
121 110
     const { showReply } = this.state;
122
-    console.log("replies", replies);
123
-    console.log("replyCount", replyCount);
124
-    console.log("isNoMoreReply", isNoMoreReply);
125 111
     if (showReply && replies && replies.length) {
126
-      console.log("showReply", showReply);
127 112
       const len = replies.length;
128 113
       return (
129 114
         <div
@@ -131,52 +116,46 @@ class CommentBox extends Component {
131 116
             marginLeft: 50,
132 117
             borderTop: "1px solid #e3e3e3",
133 118
             paddingTop: 15,
134
-            marginTop: -5
119
+            marginTop: 10,
120
+            overflow: "auto"
135 121
           }}
136 122
         >
137 123
           {replies.map((item, index) => {
138 124
             if (index === len - 1) {
139 125
               return [
140
-                <ReplyItem replyItem={item} key={item.id} />,
126
+                <ReplyItem
127
+                  replyItem={item}
128
+                  key={item.id}
129
+                  commentId={commentId}
130
+                  action="replyToReply"
131
+                />,
141 132
                 <div key="show_more_button">
142 133
                   {!isNoMoreReply && replyCount !== len && (
143 134
                     <span
144
-                      // className="comment-show-more"
135
+                      className="comment-show-more"
145 136
                       onClick={() => this.handleGetMoreReply(commentId)}
146 137
                     >
147 138
                       展开更多评论
148 139
                       <Icon type="down" />
149 140
                     </span>
150 141
                   )}
151
-                  {replyCount === len && (
152
-                    <span
153
-                      // className="comment-show-more"
154
-                      onClick={() => this.handleClickCollapse()}
155
-                    >
156
-                      收起
157
-                      <Icon type="up" />
158
-                    </span>
159
-                  )}
160
-
161
-                  {/* <a
142
+                  <a
162 143
                     style={{ float: "right" }}
163 144
                     onClick={this.handleToggleReply}
164 145
                   >
165
-                    <Icon type="up" /> {intl.get("reply.collapse")}
166
-                  </a> */}
146
+                    <Icon type="up" /> 收起
147
+                  </a>
167 148
                 </div>
168 149
               ];
169 150
             }
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;
151
+            return (
152
+              <ReplyItem
153
+                replyItem={item}
154
+                key={item.id}
155
+                commentId={commentId}
156
+                action="replyToReply"
157
+              />
158
+            );
180 159
           })}
181 160
         </div>
182 161
       );

+ 3
- 2
src/components/CommentList/index.js View File

@@ -1,6 +1,6 @@
1 1
 import React, { Component } from "react";
2 2
 import { Spin, Pagination } from "antd";
3
-import intl from "react-intl-universal";
3
+// import intl from "react-intl-universal";
4 4
 import Comment from "../../Comment";
5 5
 import CommentBox from "../CommentBox";
6 6
 import "./index.css";
@@ -44,7 +44,8 @@ class CommentList extends Component {
44 44
               onPageChange(page + 1);
45 45
             }}
46 46
           >
47
-            <span>{intl.get("comment.moreComment")}</span>
47
+            {/* <span>{intl.get("comment.moreComment")}</span> */}
48
+            <span>更多评论</span>
48 49
           </div>
49 50
         );
50 51
       } else {

+ 2
- 1
src/components/ContentItem/index.css View File

@@ -20,10 +20,11 @@
20 20
 .comment-item-content {
21 21
   margin: 10px 0 20px 0;
22 22
   word-break: break-all;
23
+  margin-bottom: 10px;
23 24
 }
24 25
 
25 26
 .comment-item-bottom {
26
-  margin: 20px auto;
27
+  margin: 0px auto;
27 28
 }
28 29
 
29 30
 .comment-item-bottom-left {

+ 10
- 9
src/components/ContentItem/index.js View File

@@ -5,7 +5,7 @@ import dayjs from "dayjs";
5 5
 import "dayjs/locale/zh-cn";
6 6
 // import 'dayjs/locale/es';
7 7
 import relativeTime from "dayjs/plugin/relativeTime";
8
-import intl from "react-intl-universal";
8
+// import intl from "react-intl-universal";
9 9
 import Comment from "../../Comment";
10 10
 import CommentInput from "../CommentInput";
11 11
 import avatar from "../../avatar";
@@ -17,9 +17,9 @@ import ImagePreviewer from "../ImagePreviewer/ImagePreviewer";
17 17
 dayjs.locale("zh-cn");
18 18
 dayjs.extend(relativeTime);
19 19
 
20
-const LOCALES = {
21
-  "zh-CN": "zh-cn"
22
-};
20
+// const LOCALES = {
21
+//   "zh-CN": "zh-cn"
22
+// };
23 23
 
24 24
 class CommentItem extends Component {
25 25
   constructor(props) {
@@ -84,7 +84,7 @@ class CommentItem extends Component {
84 84
       app
85 85
     } = this.props;
86 86
 
87
-    const { locale } = this.props.app;
87
+    // const { locale } = this.props.app;
88 88
     const { showInput } = this.state;
89 89
 
90 90
     let newContent = content.content;
@@ -123,7 +123,8 @@ class CommentItem extends Component {
123 123
               {content.user_name || "暂无昵称"}
124 124
             </a> */}
125 125
             <strong style={{ color: "#75ACFF" }}>
126
-              {content.user_name || intl.get("comment.tourist")}
126
+              {/* {content.user_name || intl.get("comment.tourist")} */}
127
+              {content.user_name || "游客"}
127 128
             </strong>
128 129
             {/* <span style={{ marginLeft: 10 }}>
129 130
               <Tooltip
@@ -170,7 +171,7 @@ class CommentItem extends Component {
170 171
             {dayjs(content.created * 1000).format("MM-DD HH:mm:ss")}
171 172
           </div>
172 173
         </div>
173
-        <div>
174
+        <div style={{ overflow: "auto" }}>
174 175
           <div
175 176
             className="comment-item-content"
176 177
             dangerouslySetInnerHTML={{
@@ -227,7 +228,7 @@ class CommentItem extends Component {
227 228
               <div className="clearfix" />
228 229
             </div>
229 230
           )}
230
-          {/* <div className="comment-item-bottom">
231
+          <div className="comment-item-bottom">
231 232
             {content.reply_count ? (
232 233
               <div>
233 234
                 <a className="comment-item-bottom-left" onClick={onShowReply}>
@@ -236,7 +237,7 @@ class CommentItem extends Component {
236 237
                 </a>
237 238
               </div>
238 239
             ) : null}
239
-          </div> */}
240
+          </div>
240 241
           {/* <div className="comment-item-bottom">
241 242
             {content.reply_count ? (
242 243
               <div>

+ 3
- 1
src/components/Editor/index.js View File

@@ -171,7 +171,7 @@ class Editor extends React.Component {
171 171
       // placeholder,
172 172
       rows,
173 173
       showEmoji,
174
-      showUpload,
174
+      // showUpload,
175 175
       closeUploadWhenBlur,
176 176
       maxUpload,
177 177
       // btnSubmitText,
@@ -183,6 +183,8 @@ class Editor extends React.Component {
183 183
       maxLength,
184 184
       autoFocus
185 185
     } = this.props;
186
+
187
+    const showUpload = false;
186 188
     let placeholder = this.props.placeholder || "快发表评论吧!";
187 189
     let btnSubmitText = this.props.placeholder || "发表评论";
188 190
     const handleSubmit = this.handleSubmit;

+ 9
- 7
src/components/ReplyItem/index.js View File

@@ -19,7 +19,9 @@ class ReplyItem extends Component {
19 19
   }
20 20
 
21 21
   render() {
22
-    const { commentId, replyItem, replyId, action, app } = this.props;
22
+    const { commentId, replyItem, action, app } = this.props;
23
+    const replyId = replyItem.id;
24
+    // console.log('replyId', replyId);
23 25
 
24 26
     const { showInput } = this.state;
25 27
 
@@ -36,12 +38,12 @@ class ReplyItem extends Component {
36 38
             <Icon
37 39
               type="heart"
38 40
               onClick={() => {
39
-                if (replyId) {
40
-                  // 如果有 replyId,则说明是评论的回复
41
-                  app.sReplyFavor(replyItem.id, commentId, replyItem.favored);
42
-                  return;
43
-                }
44
-                app.sCommentFavor(replyItem.id, replyItem.favored);
41
+                // if (replyId) {
42
+                // 如果有 replyId,则说明是评论的回复
43
+                app.sReplyFavor(replyItem.id, commentId, replyItem.favored);
44
+                // return;
45
+                // }
46
+                // app.sCommentFavor(replyItem.id, replyItem.favored);
45 47
               }}
46 48
               className={
47 49
                 replyItem.favored