Pārlūkot izejas kodu

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

node 5 gadus atpakaļ
vecāks
revīzija
dcddb71818

+ 3
- 3
src/components/CommentBox/index.css Parādīt failu

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

+ 23
- 44
src/components/CommentBox/index.js Parādīt failu

1
 import React, { Component } from "react";
1
 import React, { Component } from "react";
2
 import PropTypes from "prop-types";
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
 import Comment from "../../Comment";
5
 import Comment from "../../Comment";
6
 import ContentItem from "./../ContentItem";
6
 import ContentItem from "./../ContentItem";
7
 import ReplyItem from "./../ReplyItem";
7
 import ReplyItem from "./../ReplyItem";
12
     super(props);
12
     super(props);
13
     this.state = {
13
     this.state = {
14
       showReply: true,
14
       showReply: true,
15
-      page: 1,
16
-      isShowOver3: false
15
+      page: 1
17
     };
16
     };
18
 
17
 
19
     this.handleToggleReply = this.handleToggleReply.bind(this);
18
     this.handleToggleReply = this.handleToggleReply.bind(this);
20
     this.handleGetMoreReply = this.handleGetMoreReply.bind(this);
19
     this.handleGetMoreReply = this.handleGetMoreReply.bind(this);
21
     this.renderReplies = this.renderReplies.bind(this);
20
     this.renderReplies = this.renderReplies.bind(this);
22
-    this.handleClickCollapse = this.handleClickCollapse.bind(this);
23
   }
21
   }
24
 
22
 
25
   /**
23
   /**
29
     this.setState({ showReply: !this.state.showReply });
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
    * @param {string} commentId comment id
32
    * @param {string} commentId comment id
116
    * @param {boolean} isNoMoreReply 是否没有更多回复
106
    * @param {boolean} isNoMoreReply 是否没有更多回复
117
    */
107
    */
118
   renderReplies(replies, replyCount, isNoMoreReply) {
108
   renderReplies(replies, replyCount, isNoMoreReply) {
119
-    console.log("this.isMore3", this.state.isShowOver3);
120
     const { commentId } = this.props;
109
     const { commentId } = this.props;
121
     const { showReply } = this.state;
110
     const { showReply } = this.state;
122
-    console.log("replies", replies);
123
-    console.log("replyCount", replyCount);
124
-    console.log("isNoMoreReply", isNoMoreReply);
125
     if (showReply && replies && replies.length) {
111
     if (showReply && replies && replies.length) {
126
-      console.log("showReply", showReply);
127
       const len = replies.length;
112
       const len = replies.length;
128
       return (
113
       return (
129
         <div
114
         <div
131
             marginLeft: 50,
116
             marginLeft: 50,
132
             borderTop: "1px solid #e3e3e3",
117
             borderTop: "1px solid #e3e3e3",
133
             paddingTop: 15,
118
             paddingTop: 15,
134
-            marginTop: -5
119
+            marginTop: 10,
120
+            overflow: "auto"
135
           }}
121
           }}
136
         >
122
         >
137
           {replies.map((item, index) => {
123
           {replies.map((item, index) => {
138
             if (index === len - 1) {
124
             if (index === len - 1) {
139
               return [
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
                 <div key="show_more_button">
132
                 <div key="show_more_button">
142
                   {!isNoMoreReply && replyCount !== len && (
133
                   {!isNoMoreReply && replyCount !== len && (
143
                     <span
134
                     <span
144
-                      // className="comment-show-more"
135
+                      className="comment-show-more"
145
                       onClick={() => this.handleGetMoreReply(commentId)}
136
                       onClick={() => this.handleGetMoreReply(commentId)}
146
                     >
137
                     >
147
                       展开更多评论
138
                       展开更多评论
148
                       <Icon type="down" />
139
                       <Icon type="down" />
149
                     </span>
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
                     style={{ float: "right" }}
143
                     style={{ float: "right" }}
163
                     onClick={this.handleToggleReply}
144
                     onClick={this.handleToggleReply}
164
                   >
145
                   >
165
-                    <Icon type="up" /> {intl.get("reply.collapse")}
166
-                  </a> */}
146
+                    <Icon type="up" /> 收起
147
+                  </a>
167
                 </div>
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
         </div>
160
         </div>
182
       );
161
       );

+ 3
- 2
src/components/CommentList/index.js Parādīt failu

1
 import React, { Component } from "react";
1
 import React, { Component } from "react";
2
 import { Spin, Pagination } from "antd";
2
 import { Spin, Pagination } from "antd";
3
-import intl from "react-intl-universal";
3
+// import intl from "react-intl-universal";
4
 import Comment from "../../Comment";
4
 import Comment from "../../Comment";
5
 import CommentBox from "../CommentBox";
5
 import CommentBox from "../CommentBox";
6
 import "./index.css";
6
 import "./index.css";
44
               onPageChange(page + 1);
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
           </div>
49
           </div>
49
         );
50
         );
50
       } else {
51
       } else {

+ 2
- 1
src/components/ContentItem/index.css Parādīt failu

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

+ 10
- 9
src/components/ContentItem/index.js Parādīt failu

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

+ 3
- 1
src/components/Editor/index.js Parādīt failu

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

+ 9
- 7
src/components/ReplyItem/index.js Parādīt failu

19
   }
19
   }
20
 
20
 
21
   render() {
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
     const { showInput } = this.state;
26
     const { showInput } = this.state;
25
 
27
 
36
             <Icon
38
             <Icon
37
               type="heart"
39
               type="heart"
38
               onClick={() => {
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
               className={
48
               className={
47
                 replyItem.favored
49
                 replyItem.favored