From cd569750941df3d18a9a3493d15540a1f61226cd Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Tue, 24 Dec 2019 17:28:50 +0800 Subject: [PATCH] add comment --- public/react/src/AppConfig.js | 2 +- .../common/components/comment/CommentForm.js | 50 +++-- .../common/components/comment/CommentIcon.js | 12 +- .../common/components/comment/CommentItem.js | 188 +++++++++++------- .../common/components/comment/CommentList.js | 33 ++- .../src/common/components/comment/index.js | 32 ++- .../src/common/components/comment/index.scss | 69 ++++++- .../src/common/components/comment/util.js | 78 ++++++++ .../src/common/quillForEditor/ImageBlot.js | 8 +- .../developer/components/textNumber/index.js | 29 ++- .../modules/developer/newOrEditTask/index.js | 2 +- .../developer/newOrEditTask/leftpane/index.js | 1 - .../studentStudy/leftpane/comment/index.js | 103 +++++++++- .../developer/studentStudy/leftpane/index.js | 78 ++++++-- .../studentStudy/leftpane/index.scss | 24 ++- public/react/src/redux/actions/actionTypes.js | 8 + public/react/src/redux/actions/comment.js | 114 +++++++++++ public/react/src/redux/actions/index.js | 18 +- public/react/src/redux/actions/ojForUser.js | 4 +- public/react/src/redux/actions/ojForm.js | 78 +++++--- .../src/redux/reducers/commentReducer.js | 42 ++++ public/react/src/redux/reducers/index.js | 4 +- .../src/redux/reducers/ojForUserReducer.js | 26 ++- .../react/src/redux/reducers/ojFormReducer.js | 14 +- public/react/src/services/commentService.js | 45 +++++ 25 files changed, 877 insertions(+), 185 deletions(-) create mode 100644 public/react/src/common/components/comment/util.js create mode 100644 public/react/src/redux/actions/comment.js create mode 100644 public/react/src/redux/reducers/commentReducer.js create mode 100644 public/react/src/services/commentService.js diff --git a/public/react/src/AppConfig.js b/public/react/src/AppConfig.js index acd18e6c3..158011ea5 100644 --- a/public/react/src/AppConfig.js +++ b/public/react/src/AppConfig.js @@ -52,7 +52,7 @@ export function initAxiosInterceptors(props) { //proxy="http://47.96.87.25:48080" proxy="https://pre-newweb.educoder.net" proxy="https://test-newweb.educoder.net" - proxy="https://test-jupyterweb.educoder.net" + // proxy="https://test-jupyterweb.educoder.net" //proxy="http://192.168.2.63:3001" // 在这里使用requestMap控制,避免用户通过双击等操作发出重复的请求; diff --git a/public/react/src/common/components/comment/CommentForm.js b/public/react/src/common/components/comment/CommentForm.js index 73e36cff9..7683e2dea 100644 --- a/public/react/src/common/components/comment/CommentForm.js +++ b/public/react/src/common/components/comment/CommentForm.js @@ -3,22 +3,24 @@ * @Author: tangjiang * @Github: * @Date: 2019-12-17 17:32:55 - * @LastEditors: tangjiang - * @LastEditTime: 2019-12-18 17:51:44 + * @LastEditors : tangjiang + * @LastEditTime : 2019-12-24 17:27:41 */ +import './index.scss'; import React, { useState } from 'react'; import { Form, Button, Input } from 'antd'; import QuillForEditor from '../../quillForEditor'; -import { QuillDeltaToHtmlConverter } from 'quill-delta-to-html' +// import { QuillDeltaToHtmlConverter } from 'quill-delta-to-html' +import {formatDelta} from './util'; const FormItem = Form.Item; function CommentForm (props) { const { - commentCtxChagne, onCancel, onSubmit, - form + form, + type } = props; const { getFieldDecorator } = form; @@ -34,22 +36,25 @@ function CommentForm (props) { // const { form: { getFieldDecorator } } = props; const [showQuill, setShowQuill] = useState(false); // 点击输入框 - const handleInputClick = () => { + const handleInputClick = (type) => { setShowQuill(true); } // 取消 const handleCancle = () => { setShowQuill(false); - onCancel && onCancel(); + setCtx(''); + props.form.resetFields(); + onCancel && onCancel(); } // 编辑器内容变化时 const handleContentChange = (content) => { + console.log('编辑器内容', content); setCtx(content); try { - const _html = new QuillDeltaToHtmlConverter(content.ops, {}).convert(); + // const _html = new QuillDeltaToHtmlConverter(content.ops, {}).convert(); // props.form.setFieldsValue({'comment': _html.replace(/<\/?[^>]*>/g, '')}); - props.form.setFieldsValue({'comment': _html}); + props.form.setFieldsValue({'comment': content}); } catch (error) { console.log(error); } @@ -63,13 +68,25 @@ function CommentForm (props) { const content = ctx; props.form.setFieldsValue({'comment': ''}); setCtx(''); - console.log(content); - onSubmit && onSubmit(content); + const _html = formatDelta(content.ops); + onSubmit && onSubmit(_html); } }); } + + const handleShowImage = (url) => { + alert(url); + } + + // const _clazz = type === 'bottom' ? 'comment_form_bottom_area' : 'comment_form_area'; + let _clazz; + if (type === 'bottom') { + _clazz = showQuill ? 'comment_form_bottom_area active' : 'comment_form_bottom_area'; + } else { + _clazz = 'comment_form_area'; + } return ( -
+ { getFieldDecorator('comment', { @@ -78,13 +95,13 @@ function CommentForm (props) { ], })( handleInputClick(type)} placeholder="说点儿什么~" + className={showQuill ? '' : 'show_input'} style={{ height: showQuill ? '0px' : '40px', overflow: showQuill ? 'hidden' : 'auto', opacity: showQuill ? 0 : 1, - transition: 'all .3s' }} /> ) @@ -98,14 +115,15 @@ function CommentForm (props) { overflow: showQuill ? 'none' : 'hidden', transition: 'all 0.3s' }} - style={{ height: '150px', overflowY: 'auto' }} + style={{ height: '150px' }} placeholder="说点儿什么~" options={options} value={ctx} + showUploadImage={handleShowImage} onContentChange={handleContentChange} /> - + diff --git a/public/react/src/common/components/comment/CommentIcon.js b/public/react/src/common/components/comment/CommentIcon.js index 5440e2579..ff3b109e1 100644 --- a/public/react/src/common/components/comment/CommentIcon.js +++ b/public/react/src/common/components/comment/CommentIcon.js @@ -3,16 +3,19 @@ * @Author: tangjiang * @Github: * @Date: 2019-12-18 10:49:46 - * @LastEditors: tangjiang - * @LastEditTime: 2019-12-18 11:39:23 + * @LastEditors : tangjiang + * @LastEditTime : 2019-12-24 17:05:14 */ import './index.scss'; import React from 'react'; import { Icon } from 'antd'; +// import MyIcon from '../MyIcon'; function CommentIcon ({ type, // 图标类型 count, // 评论数 iconClick, + iconColor, + theme, ...props }) { @@ -21,10 +24,11 @@ function CommentIcon ({ iconClick && iconClick(); } + const _className = [undefined, null, ''].includes(count) ? 'comment_count_none' : 'comment_count'; return ( - - { count } + + { count } ) } diff --git a/public/react/src/common/components/comment/CommentItem.js b/public/react/src/common/components/comment/CommentItem.js index 19da645f5..28341a47c 100644 --- a/public/react/src/common/components/comment/CommentItem.js +++ b/public/react/src/common/components/comment/CommentItem.js @@ -3,104 +3,133 @@ * @Author: tangjiang * @Github: * @Date: 2019-12-17 17:35:17 - * @LastEditors: tangjiang - * @LastEditTime: 2019-12-19 18:02:28 + * @LastEditors : tangjiang + * @LastEditTime : 2019-12-24 17:11:59 */ import './index.scss'; import React, { useState } from 'react'; import CommentIcon from './CommentIcon'; import { getImageUrl, CNotificationHOC } from 'educoder' import { Icon } from 'antd'; -import moment from 'moment'; -// import QuillForEditor from '../../quillForEditor'; import CommentForm from './CommentForm'; -// import {ModalConfirm} from '../ModalConfirm'; function CommentItem ({ options, - confirm + confirm, + comment, + submitDeleteComment, + submitChildComment, + likeComment, + showOrHideComment }) { // 显示评论输入框 const [showQuill, setShowQuill] = useState(false); // 加载更多评论内容 - const [showMore, setShowMore] = useState(false); + // const [showMore, setShowMore] = useState(false); + // 显示子列数 + const [showItemCount, setShowItemCount] = useState(1); // 箭头方向 const [arrow, setArrow] = useState(false); - // 删除评论 - const deleteComment = () => { - console.log('删除评论...'); + + const { + author = {}, // 作者 + id, // 评论id + content, // 回复内容 + time, // 回复时间 + hidden, // 是否隐藏 + // hack_id, // OJ的ID + praise_count, // 点赞数 + user_praise, // 当前用户是否点赞 + can_delete, + children = [] // 子回复 + } = comment; + + // 删除评论 type: parent | child, id + const deleteComment = (id) => { confirm({ title: '提示', - content: (

确定要删除该条回复吗?

), + content: ('确定要删除该条回复吗?'), onOk () { - console.log('点击了删除'); + console.log('点击了删除', id); + submitDeleteComment && submitDeleteComment(id); } }); - // ModalConfirm('提示', (

确定要删除该条回复吗?

), () => { - // console.log('点击了删除'); - // }); } // 评论头像 - const commentAvatar = (url) => ( - + const commentAvatar = (author) => ( + ); // 评论信息 - const commentInfo = () => ( -

- 用户名 - {moment(new Date(), 'YYYYMMDD HHmmss').fromNow()} - -

- ); + const commentInfo = (id, author, time, can_delete) => { + const _classNames = can_delete ? 'item-close' : 'item-close hide'; + return ( +
+ {author.name || ''} + {time || ''} + + deleteComment(id)}/> + +
+ ); + }; // 评论内容 const commentCtx = (ctx) => ( -

- 这是评论内容这是评论内容这是评论内容这是评论内容这是评论内容这是评论内容这是评论内容这是评论内容这是评论内容这是评论内容 -

+

); // 加载更多 - const handleOnLoadMore = () => { - if (!arrow) { - // 展开所有 - } else { - // 收起 - } + const handleOnLoadMore = (len) => { + setShowItemCount(!arrow ? len : 1); setArrow(!arrow); }; // 评论追加内容 - const commentAppend = () => { + const commentAppend = (children = []) => { + + const len = children.length; + const _moreClass = len > 1 ? 'comment_item_loadmore show' : 'comment_item_loadmore' + const lastTxt = len - showItemCount; + const renderChild = (children) => { + return children.map((child, i) => { + const { + id, // 评论id + author = {}, + time, + content, + can_delete + } = child; + const showOrHide = i < showItemCount ? 'comment_item_show' : 'comment_item_hide'; + return ( +
  • +
    + {commentAvatar(author)} +
    + {commentInfo(id, author, time, can_delete)} + {commentCtx(content)} +
    +
    +
  • + ); + }) + } + const _clazz = len > 0 ? 'comment_item_append_list active' : 'comment_item_append_list'; return ( -