From fac2c50d17084bf45769d68f6098bd5b3983496a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com>
Date: Fri, 27 Mar 2020 15:32:13 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/modules/courses/boards/TopicDetail.js | 141 +++--
.../courses/common/comments/CommonReply.js | 595 +++++++++---------
.../tasks/GraduationTaskssettingReply.js | 55 +-
.../graduation/topics/GraduateTopicReply.js | 544 ++++++++--------
4 files changed, 673 insertions(+), 662 deletions(-)
diff --git a/public/react/src/modules/courses/boards/TopicDetail.js b/public/react/src/modules/courses/boards/TopicDetail.js
index d42b68c17..05d446209 100644
--- a/public/react/src/modules/courses/boards/TopicDetail.js
+++ b/public/react/src/modules/courses/boards/TopicDetail.js
@@ -65,7 +65,7 @@ class TopicDetail extends Component {
const topicId = this.props.match.params.topicId
const bid = this.props.match.params.boardId
-
+
const memoUrl = `/messages/${topicId}.json`;
this.setState({
memoLoading: true
@@ -73,7 +73,7 @@ class TopicDetail extends Component {
axios.get(memoUrl,{
})
.then((response) => {
-
+
if (response.data.status === -1) {
setTimeout(() => {
this.props.showNotification('帖子不存在!')
@@ -81,7 +81,7 @@ class TopicDetail extends Component {
// this.props.toListPage(response.data.data.course_id, bid)
return;
} else {
-
+
this.setState({
memo: Object.assign({}, {
...response.data.data,
@@ -93,7 +93,7 @@ class TopicDetail extends Component {
// const { memo_replies, memo } = response.data;
// let hasMoreComments = false;
- // if (memo_replies && memo_replies.length === 10 && memo.total_replies_count > 10) {
+ // if (memo_replies && memo_replies.length === 10 && memo.total_replies_count > 10) {
// // 遍历一遍,计算下是否还有评论未加载
// let totalCount = 10;
// memo_replies.forEach(item=>{
@@ -123,14 +123,14 @@ class TopicDetail extends Component {
})
this.fetchReplies()
-
- $('body>#root').on('onMemoDelete', (event) => {
+
+ $('body>#root').on('onMemoDelete', (event) => {
// const val = $('body>#root').data('onMemoDelete')
const val = window.onMemoDelete ;
this.onMemoDelete( JSON.parse(decodeURIComponent(val)) )
})
-
+
}
onPaginationChange = (pageCount) => {
@@ -157,7 +157,7 @@ class TopicDetail extends Component {
this.props.showNotification('删除成功');
const props = Object.assign({}, this.props, {})
this.props.toListPage( Object.assign({}, this.props.match.params, {'coursesId': this.state.memo.course_id} ) )
-
+
} else if (status === -1) {
this.props.showNotification('帖子已被删除');
this.props.history.push(`/forums`)
@@ -168,11 +168,11 @@ class TopicDetail extends Component {
}
componentDidUpdate(prevProps, prevState, snapshot) {
- // if (this.state.memo && this.state.memo.content
+ // if (this.state.memo && this.state.memo.content
// && (!prevProps.memo || prevProps.memo.content != this.state.memo.content) ) {
if (this.state.memo && this.state.memo.content && prevState.memoLoading === true && this.state.memoLoading === false) {
// md渲染content,等xhr执行完(即memoLoading变化),memo.content更新后初始化md
-
+
setTimeout(()=>{
// var shixunDescr = window.editormd.markdownToHTML("memo_content_editorMd", {
// htmlDecode: "style,script,iframe", // you can filter tags decode
@@ -183,7 +183,7 @@ class TopicDetail extends Component {
// });
}, 200)
}
-
+
}
clickPraise(){
@@ -192,7 +192,7 @@ class TopicDetail extends Component {
const url = memo.user_praise ? '/praise_tread/unlike.json' : `/praise_tread/like.json`;
const _method = memo.user_praise ? axios.delete : axios.post
let _data = {
- object_id: memo.id,
+ object_id: memo.id,
object_type: 'message', //Discuss
}
if (memo.user_praise) {
@@ -204,10 +204,10 @@ class TopicDetail extends Component {
..._data
},
{
-
+
}
).then((response) => {
-
+
const newMemo = Object.assign({}, this.state.memo)
newMemo.praises_count = newMemo.user_praise ? newMemo.praises_count - 1 : newMemo.praises_count + 1
newMemo.total_praises_count = newMemo.user_praise ? newMemo.total_praises_count - 1 : newMemo.total_praises_count + 1
@@ -248,10 +248,10 @@ class TopicDetail extends Component {
className="mr12 color9B9B overflowHidden1" length="58" style={{maxWidth: '480px'}}>
{fileName}
-
+
{item.filesize}
-
+
)
})
@@ -268,7 +268,7 @@ class TopicDetail extends Component {
permission: true, //
children: children,
child_message_count: reply.total_count,
- hidden: reply.is_hidden,
+ hidden: reply.is_hidden,
id: reply.id,
image_url: reply.author.image_url,
reward: null, //
@@ -289,7 +289,7 @@ class TopicDetail extends Component {
})
.then((response) => {
const { replies, liked, total_replies_count, total_count } = response.data.data
-
+
const memo = Object.assign({}, this.state.memo)
memo.user_praise = liked
memo.total_replies_count = total_replies_count;
@@ -322,15 +322,15 @@ class TopicDetail extends Component {
return;
}
const url = `/messages/${id}/reply.json`;
-
+
const { comments } = this.state;
const user = this._getUser();
/*
移除末尾的空行
.replace(/(\n
\n\t
\n<\/p>)*$/g,'');
-
+
*/
-
+
commentContent = handleContentBeforeCreateSecondLevelComment(commentContent)
if (!commentContent) {
this.props.showNotification('不能为空')
@@ -340,16 +340,18 @@ class TopicDetail extends Component {
content: commentContent
},
{
- }
+ }
).then((response) => {
- if (response.data.data.id) {
+ if (response.data.data.id) {
let newId = response.data.data.id;
- const commentIndex = this._findById(id, comments);
+ let mycontent = response.data.data.content;
+
+ const commentIndex = this._findById(id, comments);
const parentComment = comments[commentIndex]
this.setState({
// runTesting: false,
- comments: addSecondLevelComment(comments, parentComment, commentIndex, newId, commentContent, user, editor)
+ comments: addSecondLevelComment(comments, parentComment, commentIndex, newId, mycontent, user, editor)
}, ()=>{
// keditor代码美化
editor.html && window.prettyPrint()
@@ -361,7 +363,7 @@ class TopicDetail extends Component {
memo: newMemo2
})
}
-
+
}).catch((error) => {
console.log(error)
})
@@ -369,14 +371,14 @@ class TopicDetail extends Component {
// 公共接口 --- 删除回复
deleteComment = (parrentComment, childCommentId) => {
handleDeleteComment(this, parrentComment, childCommentId, 'message')
-
+
}
// 公共接口 --- 回复点赞
commentPraise = (discussId) => {
handleCommentPraise(this, discussId, 'message', (old_user_praise) => {
const newMemo2 = Object.assign({}, this.state.memo);
- newMemo2.total_praises_count = old_user_praise
+ newMemo2.total_praises_count = old_user_praise
? newMemo2.total_praises_count - 1 : newMemo2.total_praises_count + 1;
this.setState({
memo: newMemo2
@@ -390,7 +392,7 @@ class TopicDetail extends Component {
createNewComment = (commentContent, id, editor) => {
let content = handleContentBeforeCreateNew(commentContent);
const { memo } = this.props;
-
+
const url = `/messages/${id}/reply.json`;
// const url = `/api/v1/memos/${memo.id}/reply`;
@@ -399,7 +401,7 @@ class TopicDetail extends Component {
content: content
},
{
- }
+ }
).then((response) => {
if (response.data.status === -1) {
console.error('服务端异常')
@@ -407,18 +409,19 @@ class TopicDetail extends Component {
}
// this.props.showNotification('帖子发表成功')
- if (response.data) {
+ if (response.data) {
const _id = response.data.data.id;
+ let mycontent=response.data.data.content;
// ke
editor.html && editor.html('');
editor.afterBlur && editor.afterBlur()
// md
editor.setValue && editor.setValue('')
-
-
+
+
const user = this._getUser();
this.setState({
- comments: addNewComment(comments, _id, content, user, this.props.isSuperAdmin(), this)
+ comments: addNewComment(comments, _id, mycontent, user, this.props.isSuperAdmin(), this)
})
const newMemo2 = Object.assign({}, this.state.memo);
newMemo2.total_replies_count = newMemo2.total_replies_count + 1;
@@ -427,8 +430,8 @@ class TopicDetail extends Component {
})
this.refs.editor.showEditor();
this.refs.editor.close();
-
-
+
+
}
}).catch((error) => {
console.log(error)
@@ -444,7 +447,7 @@ class TopicDetail extends Component {
})
.then((response) => {
const { replies, liked, total_replies_count } = response.data.data
-
+
// const memo = Object.assign({}, this.state.memo)
// memo.total_replies_count = total_replies_count;
this.setState({
@@ -460,19 +463,19 @@ class TopicDetail extends Component {
// 置顶
setTop(memo) {
// const params = {
- // sticky: memo.sticky ? 0 : 1,
+ // sticky: memo.sticky ? 0 : 1,
// }
- // if (this.state.p_s_order) {
+ // if (this.state.p_s_order) {
// params.order = this.state.p_s_order;
// }
- // if (this.state.p_forum_id) {
+ // if (this.state.p_forum_id) {
// params.forum_id = this.state.p_forum_id;
// }
// let paramsUrl = urlStringify(params)
const set_top_or_down_Url = `/messages/${memo.id}/sticky_top.json`;
// 获取memo list
axios.put(set_top_or_down_Url, {
-
+
})
.then((response) => {
const status = response.data.status
@@ -487,7 +490,7 @@ class TopicDetail extends Component {
console.log(error)
})
}
-
+
setRewardDialogVisible = (visible) => {
this.setState({
goldRewardDialogOpen: visible
@@ -512,7 +515,7 @@ class TopicDetail extends Component {
}
}
-
+
render() {
const { match, history } = this.props
const { recommend_shixun, current_user,author_info } = this.props;
@@ -567,7 +570,7 @@ class TopicDetail extends Component {
{memo.subject}
- { !!memo.sticky &&
置顶}
{ !!memo.reward &&
@@ -578,9 +581,9 @@ class TopicDetail extends Component {
}
-
+
-
+
@@ -625,7 +628,7 @@ class TopicDetail extends Component {
{memo.visits || '1'}
- { !!memo.total_replies_count &&
+ { !!memo.total_replies_count &&
@@ -633,8 +636,8 @@ class TopicDetail extends Component {
}
- {!!memo.total_praises_count &&
-
+ {!!memo.total_praises_count &&
+
{ memo.total_praises_count }
@@ -654,12 +657,12 @@ class TopicDetail extends Component {
-
+
{/*
*/}
- {memo.is_md == true ?
-
- :
+ {memo.is_md == true ?
+
+ :
}
@@ -674,17 +677,17 @@ class TopicDetail extends Component {
- { memo.attachments && !!memo.attachments.length &&
+ { memo.attachments && !!memo.attachments.length &&
{this.renderAttachment()}
}
-
- {!isCourseEnd &&
}
- {/* onClick={ this.createNewComment }
+ {/* onClick={ this.createNewComment }
enableReplyTo={true}
*/}
-
-
- {/* { true ? :
+
+
+ {/* { true ? :
} */}
-
-
+
+
- { total_count > REPLY_PAGE_COUNT &&
+ { total_count > REPLY_PAGE_COUNT &&
}
{!isCourseEnd && 写评论
}
-
-
+
+
diff --git a/public/react/src/modules/courses/common/comments/CommonReply.js b/public/react/src/modules/courses/common/comments/CommonReply.js
index 8b7817e85..7884eb890 100644
--- a/public/react/src/modules/courses/common/comments/CommonReply.js
+++ b/public/react/src/modules/courses/common/comments/CommonReply.js
@@ -1,296 +1,299 @@
-import React,{ Component } from "react";
-import { Pagination } from "antd";
-
-import update from 'immutability-helper'
-import axios from 'axios'
-import MemoDetailMDEditor from '../../../forums/MemoDetailMDEditor'
-
-import '../../../forums/Post.css'
-import '../../../forums/RightSection.css'
-import {ImageLayerOfCommentHOC} from '../../../page/layers/ImageLayerOfCommentHOC'
-
-import Comments from '../../../comment/Comments'
-// import './GraduateTopicReply.css'
-import '../../common/courseMessage.css'
-import { generateComments, generateChildComments, _findById, handleContentBeforeCreateNew, addNewComment
- , addSecondLevelComment, NEED_TO_WRITE_CONTENT, handleContentBeforeCreateSecondLevelComment
- , handleDeleteComment, handleCommentPraise, handleHiddenComment } from '../../common/CommentsHelper'
-const REPLY_PAGE_COUNT = 10
-const $ = window.$;
-
-/*
- 相比较GraduateTopicReply 改动的地方
- 列表接口名 /graduation_tasks/${graduation_topic_id}/show_comment.json?parent_id=${parent.id}&limit=500
- 回复类型名 jour_type: this.props.jour_type,
-*/
-class CommonReply extends Component{
- constructor(props){
- super(props);
- this.state={
- pageCount: 1
- }
- }
-
- componentDidMount(){
- this.fetchReplies()
-
-
- }
- _getUser() {
- const { current_user } = this.props;
- current_user.user_url = `/users/${current_user.login}`;
- return current_user;
- }
- _findById = _findById
- createNewComment = (commentContent, id, editor) => {
- const graduation_topic_id = this.props.memo.id
-
- let content = handleContentBeforeCreateNew(commentContent);
- const { memo } = this.props;
- const url = `/users/reply_message.json`;
-
- let { comments } = this.state;
- axios.post(url, {
- journals_for_message: {
- jour_type: this.props.jour_type,
- jour_id: graduation_topic_id,
- notes: content,
- // m_parent_id
- reply_id: memo.user_id || this.state.homework_user_id
- }
- }
- ).then((response) => {
- if (response.data.status === -1) {
- console.error('服务端异常')
- return;
- }
- // this.props.showNotification('帖子发表成功')
-
- if (response.data && response.data.id) {
- const _id = response.data.id;
- // md
- editor.setValue && editor.setValue('')
- this.refs.editor.close && this.refs.editor.close()
-
- const user = this._getUser();
- const isSuperAdmin = this.props.isSuperAdmin()
-
- this.setState({
- comments: addNewComment(this.state.comments, _id, content, user, isSuperAdmin, this),
- total_count: this.state.total_count + 1
- })
- this.refs.editor.showEditor();
-
- }
- }).catch((error) => {
- console.log(error)
- })
- }
- replyComment = (commentContent, id, editor) => {
- const { showNotification } = this.props;
- // if (!commentContent || commentContent.length === 0) {
- // showNotification(NEED_TO_WRITE_CONTENT)
- // return;
- // }
-
- if (this.props.memo.id === id ) { // 回复帖子
- this.createNewComment(commentContent, id, editor);
- return;
- }
- const url = `/users/reply_message.json`;
-
- const { comments } = this.state;
- const user = this._getUser();
- const graduation_topic_id = this.props.memo.id
- const commentIndex = this._findById(id, comments);
- let comment = comments[commentIndex];
-
- commentContent = handleContentBeforeCreateSecondLevelComment(commentContent)
- axios.post(url, {
- journals_for_message: {
- // 'GraduationTask'
- jour_type: this.props.jour_type,
- jour_id: graduation_topic_id,
- notes: commentContent,
- m_parent_id: id,
- reply_id: comment.user_id
- }
- },
- {
- }
- ).then((response) => {
- if (response.data.id) {
- let newId = response.data.id;
-
- const newMemo2 = Object.assign({}, this.props.memo);
- newMemo2.total_count = newMemo2.total_count + 1;
-
- this.setState({
- comments: addSecondLevelComment(comments, comment, commentIndex, newId, commentContent, user, editor),
- memo: newMemo2,
- total_count: this.state.total_count + 1
-
- })
- }
-
- }).catch((error) => {
- console.log(error)
- })
- }
-
- loadMoreChildComments = (parent) => {
- const graduation_topic_id = this.props.memo.id
- const course_id = this.props.course_id
- const url = `/${this.props.apiRouteName}/${graduation_topic_id}/show_comment.json?parent_id=${parent.id}&limit=500`
- axios.get(url,{
- })
- .then((response) => {
- const { comments } = response.data
-
-
- // const memo = Object.assign({}, this.state.memo)
- // memo.sum_replies_count = sum_replies_count;
- this.setState({
- // memo,
- comments: generateChildComments(comments, this.state.comments, parent, this.transformReply)
- })
- }).catch((error) => {
- console.log(error)
- })
- }
-
- onPaginationChange = (pageCount) => {
- this.setState({ pageCount }, () => {
- this.fetchReplies()
- })
- }
-
- fetchReplies = () => {
- const graduation_topic_id = this.props.memo.id
- const course_id = this.props.course_id
- const url = `/${this.props.apiRouteName}/${graduation_topic_id}/show_comment.json?page=${this.state.pageCount}`
- // page limit parent_id
- axios.get(url,{
- })
- .then((response) => {
- const { comments, messages_count, homework_user_id, parent_messages_count } = response.data
-
- this.setState({
- comments: generateComments(comments, this.transformReply),
- // : this.state.comments.concat(comments),
- total_count: parent_messages_count,
- homework_user_id
- })
- }).catch((error) => {
- console.log(error)
- })
- }
-
- transformReply = (reply, children = []) => {
- const isAdmin = this.props.isAdmin()
- const isSuperAdmin = this.props.isSuperAdmin()
- return {
- admin: isAdmin, //
- isSuperAdmin: isSuperAdmin,
- permission: true, //
- children: children,
- hidden: reply.hidden,
- id: reply.id,
- image_url: reply.author.image_url,
- reward: null, //
- time: reply.time, // moment(reply.created_on).fromNow(),
- user_id: reply.author.id,
- user_login: reply.author.login,
- user_praise: reply.user_praise,
- username: reply.author.name,
- content: reply.content,
- praise_count: reply.praise_count,
- child_message_count: reply.child_message_count
- }
- }
-
- // 公共接口 --- 删除回复
- deleteComment = (parrentComment, childCommentId) => {
- handleDeleteComment(this, parrentComment, childCommentId, 'journals_for_message')
- }
- // 公共接口 --- 回复点赞
- commentPraise = (discussId) => {
- handleCommentPraise(this, discussId, 'journals_for_message')
- }
- // 公共接口 --- 隐藏回复
- hiddenComment = (item, childCommentId) => {
- handleHiddenComment(this, item, childCommentId, 'journals_for_message')
- }
-
- showCommentInput = () => {
- this.refs.editor.showEditor();
- }
- initReply = (parent) => {
- if (!parent.isAllChildrenLoaded) {
- this.loadMoreChildComments(parent)
- }
- }
-
- render(){
- let { total_count, comments, pageCount } = this.state
- const { current_user, memo } = this.props
-
- return(
-
-
-
- {/* bor-bottom-greyE */}
-
-
- 全部回复
- {total_count}
-
-
-
-
-
- {/* { true ? :
-
} */}
-
-
- { total_count > REPLY_PAGE_COUNT &&
-
}
-
- )
- }
-}
-export default ImageLayerOfCommentHOC() (CommonReply);
\ No newline at end of file
+import React,{ Component } from "react";
+import { Pagination } from "antd";
+
+import update from 'immutability-helper'
+import axios from 'axios'
+import MemoDetailMDEditor from '../../../forums/MemoDetailMDEditor'
+
+import '../../../forums/Post.css'
+import '../../../forums/RightSection.css'
+import {ImageLayerOfCommentHOC} from '../../../page/layers/ImageLayerOfCommentHOC'
+
+import Comments from '../../../comment/Comments'
+// import './GraduateTopicReply.css'
+import '../../common/courseMessage.css'
+import { generateComments, generateChildComments, _findById, handleContentBeforeCreateNew, addNewComment
+ , addSecondLevelComment, NEED_TO_WRITE_CONTENT, handleContentBeforeCreateSecondLevelComment
+ , handleDeleteComment, handleCommentPraise, handleHiddenComment } from '../../common/CommentsHelper'
+const REPLY_PAGE_COUNT = 10
+const $ = window.$;
+
+/*
+ 相比较GraduateTopicReply 改动的地方
+ 列表接口名 /graduation_tasks/${graduation_topic_id}/show_comment.json?parent_id=${parent.id}&limit=500
+ 回复类型名 jour_type: this.props.jour_type,
+*/
+class CommonReply extends Component{
+ constructor(props){
+ super(props);
+ this.state={
+ pageCount: 1
+ }
+ }
+
+ componentDidMount(){
+ this.fetchReplies()
+
+
+ }
+ _getUser() {
+ const { current_user } = this.props;
+ current_user.user_url = `/users/${current_user.login}`;
+ return current_user;
+ }
+ _findById = _findById
+ createNewComment = (commentContent, id, editor) => {
+ const graduation_topic_id = this.props.memo.id
+
+ let content = handleContentBeforeCreateNew(commentContent);
+ const { memo } = this.props;
+ const url = `/users/reply_message.json`;
+
+ let { comments } = this.state;
+ axios.post(url, {
+ journals_for_message: {
+ jour_type: this.props.jour_type,
+ jour_id: graduation_topic_id,
+ notes: content,
+ // m_parent_id
+ reply_id: memo.user_id || this.state.homework_user_id
+ }
+ }
+ ).then((response) => {
+ if (response.data.status === -1) {
+ console.error('服务端异常')
+ return;
+ }
+ // this.props.showNotification('帖子发表成功')
+
+ if (response.data && response.data.id) {
+ const _id = response.data.id;
+ let mycontent= response.data.content;
+
+ // md
+ editor.setValue && editor.setValue('')
+ this.refs.editor.close && this.refs.editor.close()
+
+ const user = this._getUser();
+ const isSuperAdmin = this.props.isSuperAdmin()
+
+ this.setState({
+ comments: addNewComment(this.state.comments, _id, mycontent, user, isSuperAdmin, this),
+ total_count: this.state.total_count + 1
+ })
+ this.refs.editor.showEditor();
+
+ }
+ }).catch((error) => {
+ console.log(error)
+ })
+ }
+ replyComment = (commentContent, id, editor) => {
+ const { showNotification } = this.props;
+ // if (!commentContent || commentContent.length === 0) {
+ // showNotification(NEED_TO_WRITE_CONTENT)
+ // return;
+ // }
+
+ if (this.props.memo.id === id ) { // 回复帖子
+ this.createNewComment(commentContent, id, editor);
+ return;
+ }
+ const url = `/users/reply_message.json`;
+
+ const { comments } = this.state;
+ const user = this._getUser();
+ const graduation_topic_id = this.props.memo.id
+ const commentIndex = this._findById(id, comments);
+ let comment = comments[commentIndex];
+
+ commentContent = handleContentBeforeCreateSecondLevelComment(commentContent)
+ axios.post(url, {
+ journals_for_message: {
+ // 'GraduationTask'
+ jour_type: this.props.jour_type,
+ jour_id: graduation_topic_id,
+ notes: commentContent,
+ m_parent_id: id,
+ reply_id: comment.user_id
+ }
+ },
+ {
+ }
+ ).then((response) => {
+ if (response.data.id) {
+ let newId = response.data.id;
+ let mycontent= response.data.content;
+
+ const newMemo2 = Object.assign({}, this.props.memo);
+ newMemo2.total_count = newMemo2.total_count + 1;
+
+ this.setState({
+ comments: addSecondLevelComment(comments, comment, commentIndex, newId, mycontent, user, editor),
+ memo: newMemo2,
+ total_count: this.state.total_count + 1
+
+ })
+ }
+
+ }).catch((error) => {
+ console.log(error)
+ })
+ }
+
+ loadMoreChildComments = (parent) => {
+ const graduation_topic_id = this.props.memo.id
+ const course_id = this.props.course_id
+ const url = `/${this.props.apiRouteName}/${graduation_topic_id}/show_comment.json?parent_id=${parent.id}&limit=500`
+ axios.get(url,{
+ })
+ .then((response) => {
+ const { comments } = response.data
+
+
+ // const memo = Object.assign({}, this.state.memo)
+ // memo.sum_replies_count = sum_replies_count;
+ this.setState({
+ // memo,
+ comments: generateChildComments(comments, this.state.comments, parent, this.transformReply)
+ })
+ }).catch((error) => {
+ console.log(error)
+ })
+ }
+
+ onPaginationChange = (pageCount) => {
+ this.setState({ pageCount }, () => {
+ this.fetchReplies()
+ })
+ }
+
+ fetchReplies = () => {
+ const graduation_topic_id = this.props.memo.id
+ const course_id = this.props.course_id
+ const url = `/${this.props.apiRouteName}/${graduation_topic_id}/show_comment.json?page=${this.state.pageCount}`
+ // page limit parent_id
+ axios.get(url,{
+ })
+ .then((response) => {
+ const { comments, messages_count, homework_user_id, parent_messages_count } = response.data
+
+ this.setState({
+ comments: generateComments(comments, this.transformReply),
+ // : this.state.comments.concat(comments),
+ total_count: parent_messages_count,
+ homework_user_id
+ })
+ }).catch((error) => {
+ console.log(error)
+ })
+ }
+
+ transformReply = (reply, children = []) => {
+ const isAdmin = this.props.isAdmin()
+ const isSuperAdmin = this.props.isSuperAdmin()
+ return {
+ admin: isAdmin, //
+ isSuperAdmin: isSuperAdmin,
+ permission: true, //
+ children: children,
+ hidden: reply.hidden,
+ id: reply.id,
+ image_url: reply.author.image_url,
+ reward: null, //
+ time: reply.time, // moment(reply.created_on).fromNow(),
+ user_id: reply.author.id,
+ user_login: reply.author.login,
+ user_praise: reply.user_praise,
+ username: reply.author.name,
+ content: reply.content,
+ praise_count: reply.praise_count,
+ child_message_count: reply.child_message_count
+ }
+ }
+
+ // 公共接口 --- 删除回复
+ deleteComment = (parrentComment, childCommentId) => {
+ handleDeleteComment(this, parrentComment, childCommentId, 'journals_for_message')
+ }
+ // 公共接口 --- 回复点赞
+ commentPraise = (discussId) => {
+ handleCommentPraise(this, discussId, 'journals_for_message')
+ }
+ // 公共接口 --- 隐藏回复
+ hiddenComment = (item, childCommentId) => {
+ handleHiddenComment(this, item, childCommentId, 'journals_for_message')
+ }
+
+ showCommentInput = () => {
+ this.refs.editor.showEditor();
+ }
+ initReply = (parent) => {
+ if (!parent.isAllChildrenLoaded) {
+ this.loadMoreChildComments(parent)
+ }
+ }
+
+ render(){
+ let { total_count, comments, pageCount } = this.state
+ const { current_user, memo } = this.props
+
+ return(
+
+
+
+ {/* bor-bottom-greyE */}
+
+
+ 全部回复
+ {total_count}
+
+
+
+
+
+ {/* { true ? :
+
} */}
+
+
+ { total_count > REPLY_PAGE_COUNT &&
+
}
+
+ )
+ }
+}
+export default ImageLayerOfCommentHOC() (CommonReply);
diff --git a/public/react/src/modules/courses/graduation/tasks/GraduationTaskssettingReply.js b/public/react/src/modules/courses/graduation/tasks/GraduationTaskssettingReply.js
index 4281d0ec6..186004062 100644
--- a/public/react/src/modules/courses/graduation/tasks/GraduationTaskssettingReply.js
+++ b/public/react/src/modules/courses/graduation/tasks/GraduationTaskssettingReply.js
@@ -18,7 +18,7 @@ import { generateComments, generateChildComments, _findById, handleContentBefore
const REPLY_PAGE_COUNT = 10
const $ = window.$;
-/*
+/*
相比较GraduateTopicReply 改动的地方
列表接口名 /graduation_tasks/${graduation_topic_id}/show_comment.json?parent_id=${parent.id}&limit=500
回复类型名 jour_type: 'GraduationTask',
@@ -34,7 +34,7 @@ class GraduationTaskssettingReply extends Component{
componentDidMount(){
this.fetchReplies()
-
+
}
_getUser() {
const { current_user } = this.props;
@@ -58,7 +58,7 @@ class GraduationTaskssettingReply extends Component{
// m_parent_id
reply_id: memo.user_id
}
- }
+ }
).then((response) => {
if (response.data.status === -1) {
console.error('服务端异常')
@@ -66,18 +66,20 @@ class GraduationTaskssettingReply extends Component{
}
// this.props.showNotification('帖子发表成功')
- if (response.data && response.data.id) {
+ if (response.data && response.data.id) {
const _id = response.data.id;
- // md
+ let mycontent= response.data.content;
+
+ // md
editor.setValue && editor.setValue('')
-
+
const user = this._getUser();
this.setState({
- comments: addNewComment(this.state.comments, _id, content, user, this.props.isSuperAdmin(), this),
+ comments: addNewComment(this.state.comments, _id, mycontent, user, this.props.isSuperAdmin(), this),
total_count: this.state.total_count + 1
})
this.refs.editor.showEditor();
-
+
}
}).catch((error) => {
console.log(error)
@@ -95,13 +97,13 @@ class GraduationTaskssettingReply extends Component{
return;
}
const url = `/users/reply_message.json`;
-
+
const { comments } = this.state;
const user = this._getUser();
const graduation_topic_id = this.props.memo.id
const commentIndex = this._findById(id, comments);
let comment = comments[commentIndex];
-
+
commentContent = handleContentBeforeCreateSecondLevelComment(commentContent)
axios.post(url, {
journals_for_message: {
@@ -113,13 +115,14 @@ class GraduationTaskssettingReply extends Component{
}
},
{
- }
+ }
).then((response) => {
- if (response.data.id) {
+ if (response.data.id) {
let newId = response.data.id;
+ let mycontent= response.data.content;
this.setState({
- comments: addSecondLevelComment(comments, comment, commentIndex, newId, commentContent, user, editor)
+ comments: addSecondLevelComment(comments, comment, commentIndex, newId, mycontent, user, editor)
})
const newMemo2 = Object.assign({}, this.props.memo);
@@ -128,7 +131,7 @@ class GraduationTaskssettingReply extends Component{
memo: newMemo2
})
}
-
+
}).catch((error) => {
console.log(error)
})
@@ -142,7 +145,7 @@ class GraduationTaskssettingReply extends Component{
})
.then((response) => {
const { comments } = response.data
-
+
// const memo = Object.assign({}, this.state.memo)
// memo.sum_replies_count = sum_replies_count;
@@ -160,7 +163,7 @@ class GraduationTaskssettingReply extends Component{
this.fetchReplies()
})
}
-
+
fetchReplies = () => {
const graduation_topic_id = this.props.memo.id
const course_id = this.props.course_id
@@ -170,7 +173,7 @@ class GraduationTaskssettingReply extends Component{
})
.then((response) => {
const { comments, messages_count } = response.data
-
+
this.setState({
comments: generateComments(comments, this.transformReply),
// : this.state.comments.concat(comments),
@@ -180,7 +183,7 @@ class GraduationTaskssettingReply extends Component{
console.log(error)
})
}
-
+
transformReply = (reply, children = []) => {
const isAdmin = this.props.isAdmin()
const isSuperAdmin = this.props.isSuperAdmin()
@@ -189,7 +192,7 @@ class GraduationTaskssettingReply extends Component{
isSuperAdmin: isSuperAdmin,
permission: true, //
children: children,
- hidden: reply.hidden,
+ hidden: reply.hidden,
id: reply.id,
image_url: reply.author.image_url,
reward: null, //
@@ -251,7 +254,7 @@ class GraduationTaskssettingReply extends Component{
commentPraise={this.commentPraise}
rewardCode={this.rewardCode}
hiddenComment={this.hiddenComment}
-
+
usingAntdModal={true}
isChildCommentPagination={true}
loadMoreChildComments={this.loadMoreChildComments}
@@ -259,15 +262,15 @@ class GraduationTaskssettingReply extends Component{
showRewardButton={false}
onlySuperAdminCouldHide={true}
>
-
-
- {/* { true ? :
+
+
+ {/* { true ? :
} */}
-
- { total_count > REPLY_PAGE_COUNT &&
+
+ { total_count > REPLY_PAGE_COUNT &&
写评论
@@ -276,4 +279,4 @@ class GraduationTaskssettingReply extends Component{
)
}
}
-export default ImageLayerOfCommentHOC() (GraduationTaskssettingReply);
\ No newline at end of file
+export default ImageLayerOfCommentHOC() (GraduationTaskssettingReply);
diff --git a/public/react/src/modules/courses/graduation/topics/GraduateTopicReply.js b/public/react/src/modules/courses/graduation/topics/GraduateTopicReply.js
index 4e318a0c1..49f0171df 100644
--- a/public/react/src/modules/courses/graduation/topics/GraduateTopicReply.js
+++ b/public/react/src/modules/courses/graduation/topics/GraduateTopicReply.js
@@ -1,271 +1,273 @@
-import React,{ Component } from "react";
-import { Pagination } from "antd";
-
-import update from 'immutability-helper'
-import axios from 'axios'
-import MemoDetailMDEditor from '../../../forums/MemoDetailMDEditor'
-
-import '../../../forums/Post.css'
-import '../../../forums/RightSection.css'
-import {ImageLayerOfCommentHOC} from '../../../page/layers/ImageLayerOfCommentHOC'
-
-import Comments from '../../../comment/Comments'
-import './GraduateTopicReply.css'
-import '../../common/courseMessage.css'
-import { generateComments, generateChildComments, _findById, handleContentBeforeCreateNew, addNewComment
- , addSecondLevelComment, NEED_TO_WRITE_CONTENT, handleContentBeforeCreateSecondLevelComment
- , handleDeleteComment, handleCommentPraise, handleHiddenComment } from '../../common/CommentsHelper'
-const REPLY_PAGE_COUNT = 10
-const $ = window.$;
-class GraduateTopicReply extends Component{
- constructor(props){
- super(props);
- this.state={
- pageCount: 1
- }
- }
-
- componentDidMount(){
- this.fetchReplies()
-
-
- }
- _getUser() {
- const { current_user } = this.props;
- current_user.user_url = `/users/${current_user.login}`;
- return current_user;
- }
- _findById = _findById
- createNewComment = (commentContent, id, editor) => {
- const graduation_topic_id = this.props.memo.id
-
- let content = handleContentBeforeCreateNew(commentContent);
- const { memo } = this.props;
- const url = `/users/reply_message.json`;
-
- let { comments } = this.state;
- axios.post(url, {
- journals_for_message: {
- jour_type: 'GraduationTopic',
- jour_id: graduation_topic_id,
- notes: content,
- // m_parent_id
- reply_id: memo.user_id
- }
- }
- ).then((response) => {
- if (response.data.status === -1) {
- console.error('服务端异常')
- return;
- }
- // this.props.showNotification('帖子发表成功')
-
- if (response.data && response.data.id) {
- const _id = response.data.id;
- // md
- editor.setValue && editor.setValue('')
-
- const user = this._getUser();
- this.setState({
- comments: addNewComment(this.state.comments, _id, content, user, this.props.isSuperAdmin(), this),
- total_count: this.state.total_count + 1
- })
- this.refs.editor.showEditor();
-
- }
- }).catch((error) => {
- console.log(error)
- })
- }
- replyComment = (commentContent, id, editor) => {
- const { showNotification } = this.props;
- // if (!commentContent || commentContent.length === 0) {
- // showNotification(NEED_TO_WRITE_CONTENT)
- // return;
- // }
-
- if (this.props.memo.id === id ) { // 回复帖子
- this.createNewComment(commentContent, id, editor);
- return;
- }
- const url = `/users/reply_message.json`;
-
- const { comments } = this.state;
- const user = this._getUser();
- const graduation_topic_id = this.props.memo.id
- const commentIndex = this._findById(id, comments);
- let comment = comments[commentIndex];
-
- commentContent = handleContentBeforeCreateSecondLevelComment(commentContent)
- axios.post(url, {
- journals_for_message: {
- jour_type: 'GraduationTopic',
- jour_id: graduation_topic_id,
- notes: commentContent,
- m_parent_id: id,
- reply_id: comment.user_id
- }
- },
- {
- }
- ).then((response) => {
- if (response.data.id) {
- let newId = response.data.id;
-
- this.setState({
- comments: addSecondLevelComment(comments, comment, commentIndex, newId, commentContent, user, editor)
- })
-
- const newMemo2 = Object.assign({}, this.props.memo);
- newMemo2.total_count = newMemo2.total_count + 1;
- this.setState({
- memo: newMemo2
- })
- }
-
- }).catch((error) => {
- console.log(error)
- })
- }
-
- loadMoreChildComments = (parent) => {
- const graduation_topic_id = this.props.memo.id
- const course_id = this.props.course_id
- const url = `/courses/${course_id}/graduation_topics/${graduation_topic_id}/show_comment.json?parent_id=${parent.id}&limit=500`
- axios.get(url,{
- })
- .then((response) => {
- const { comments } = response.data
-
-
- // const memo = Object.assign({}, this.state.memo)
- // memo.sum_replies_count = sum_replies_count;
- this.setState({
- // memo,
- comments: generateChildComments(comments, this.state.comments, parent, this.transformReply)
- })
- }).catch((error) => {
- console.log(error)
- })
- }
-
- onPaginationChange = (pageCount) => {
- this.setState({ pageCount }, () => {
- this.fetchReplies()
- })
- }
-
- fetchReplies = () => {
- const graduation_topic_id = this.props.memo.id
- const course_id = this.props.course_id
- const url = `/courses/${course_id}/graduation_topics/${graduation_topic_id}/show_comment.json?page=${this.state.pageCount}`
- // page limit parent_id
- axios.get(url,{
- })
- .then((response) => {
- const { comments, messages_count } = response.data
-
- this.setState({
- comments: generateComments(comments, this.transformReply),
- // : this.state.comments.concat(comments),
- total_count: messages_count
- })
- }).catch((error) => {
- console.log(error)
- })
- }
-
- transformReply = (reply, children = []) => {
- const isAdmin = this.props.isAdmin()
- const isSuperAdmin = this.props.isSuperAdmin()
- return {
- isSuperAdmin: isSuperAdmin,
- admin: isAdmin, //
- permission: true, //
- children: children,
- child_message_count: reply.child_message_count,
- hidden: reply.hidden,
- id: reply.id,
- image_url: reply.author.image_url,
- reward: null, //
- time: reply.time, // moment(reply.created_on).fromNow(),
- user_id: reply.author.id,
- user_login: reply.author.login,
- user_praise: reply.user_praise,
- username: reply.author.name,
- content: reply.content,
- praise_count: reply.praise_count
- }
- }
-
- // 公共接口 --- 删除回复
- deleteComment = (parrentComment, childCommentId) => {
- handleDeleteComment(this, parrentComment, childCommentId, 'journals_for_message')
- }
- // 公共接口 --- 回复点赞
- commentPraise = (discussId) => {
- handleCommentPraise(this, discussId, 'journals_for_message')
- }
- // 公共接口 --- 隐藏回复
- hiddenComment = (item, childCommentId) => {
- handleHiddenComment(this, item, childCommentId, 'journals_for_message')
- }
-
- showCommentInput = () => {
- this.refs.editor.showEditor();
- }
- initReply = (parent) => {
- if (!parent.isAllChildrenLoaded) {
- this.loadMoreChildComments(parent)
- }
- }
-
- render(){
- let { total_count, comments, pageCount } = this.state
- const { current_user, memo } = this.props
-
- return(
-
-
-
-
-
- 全部回复
- {total_count}
-
-
-
-
-
- {/* { true ? :
-
} */}
-
-
- { total_count > REPLY_PAGE_COUNT &&
- }
-
- )
- }
-}
-export default ImageLayerOfCommentHOC() (GraduateTopicReply);
\ No newline at end of file
+import React,{ Component } from "react";
+import { Pagination } from "antd";
+
+import update from 'immutability-helper'
+import axios from 'axios'
+import MemoDetailMDEditor from '../../../forums/MemoDetailMDEditor'
+
+import '../../../forums/Post.css'
+import '../../../forums/RightSection.css'
+import {ImageLayerOfCommentHOC} from '../../../page/layers/ImageLayerOfCommentHOC'
+
+import Comments from '../../../comment/Comments'
+import './GraduateTopicReply.css'
+import '../../common/courseMessage.css'
+import { generateComments, generateChildComments, _findById, handleContentBeforeCreateNew, addNewComment
+ , addSecondLevelComment, NEED_TO_WRITE_CONTENT, handleContentBeforeCreateSecondLevelComment
+ , handleDeleteComment, handleCommentPraise, handleHiddenComment } from '../../common/CommentsHelper'
+const REPLY_PAGE_COUNT = 10
+const $ = window.$;
+class GraduateTopicReply extends Component{
+ constructor(props){
+ super(props);
+ this.state={
+ pageCount: 1
+ }
+ }
+
+ componentDidMount(){
+ this.fetchReplies()
+
+
+ }
+ _getUser() {
+ const { current_user } = this.props;
+ current_user.user_url = `/users/${current_user.login}`;
+ return current_user;
+ }
+ _findById = _findById
+ createNewComment = (commentContent, id, editor) => {
+ const graduation_topic_id = this.props.memo.id
+
+ let content = handleContentBeforeCreateNew(commentContent);
+ const { memo } = this.props;
+ const url = `/users/reply_message.json`;
+
+ let { comments } = this.state;
+ axios.post(url, {
+ journals_for_message: {
+ jour_type: 'GraduationTopic',
+ jour_id: graduation_topic_id,
+ notes: content,
+ // m_parent_id
+ reply_id: memo.user_id
+ }
+ }
+ ).then((response) => {
+ if (response.data.status === -1) {
+ console.error('服务端异常')
+ return;
+ }
+ // this.props.showNotification('帖子发表成功')
+
+ if (response.data && response.data.id) {
+ const _id = response.data.id;
+ let mycontent= response.data.content;
+ // md
+ editor.setValue && editor.setValue('')
+
+ const user = this._getUser();
+ this.setState({
+ comments: addNewComment(this.state.comments, _id, mycontent, user, this.props.isSuperAdmin(), this),
+ total_count: this.state.total_count + 1
+ })
+ this.refs.editor.showEditor();
+
+ }
+ }).catch((error) => {
+ console.log(error)
+ })
+ }
+ replyComment = (commentContent, id, editor) => {
+ const { showNotification } = this.props;
+ // if (!commentContent || commentContent.length === 0) {
+ // showNotification(NEED_TO_WRITE_CONTENT)
+ // return;
+ // }
+
+ if (this.props.memo.id === id ) { // 回复帖子
+ this.createNewComment(commentContent, id, editor);
+ return;
+ }
+ const url = `/users/reply_message.json`;
+
+ const { comments } = this.state;
+ const user = this._getUser();
+ const graduation_topic_id = this.props.memo.id
+ const commentIndex = this._findById(id, comments);
+ let comment = comments[commentIndex];
+
+ commentContent = handleContentBeforeCreateSecondLevelComment(commentContent)
+ axios.post(url, {
+ journals_for_message: {
+ jour_type: 'GraduationTopic',
+ jour_id: graduation_topic_id,
+ notes: commentContent,
+ m_parent_id: id,
+ reply_id: comment.user_id
+ }
+ },
+ {
+ }
+ ).then((response) => {
+ if (response.data.id) {
+ let newId = response.data.id;
+ let mycontent= response.data.content;
+
+ this.setState({
+ comments: addSecondLevelComment(comments, comment, commentIndex, newId, mycontent, user, editor)
+ })
+
+ const newMemo2 = Object.assign({}, this.props.memo);
+ newMemo2.total_count = newMemo2.total_count + 1;
+ this.setState({
+ memo: newMemo2
+ })
+ }
+
+ }).catch((error) => {
+ console.log(error)
+ })
+ }
+
+ loadMoreChildComments = (parent) => {
+ const graduation_topic_id = this.props.memo.id
+ const course_id = this.props.course_id
+ const url = `/courses/${course_id}/graduation_topics/${graduation_topic_id}/show_comment.json?parent_id=${parent.id}&limit=500`
+ axios.get(url,{
+ })
+ .then((response) => {
+ const { comments } = response.data
+
+
+ // const memo = Object.assign({}, this.state.memo)
+ // memo.sum_replies_count = sum_replies_count;
+ this.setState({
+ // memo,
+ comments: generateChildComments(comments, this.state.comments, parent, this.transformReply)
+ })
+ }).catch((error) => {
+ console.log(error)
+ })
+ }
+
+ onPaginationChange = (pageCount) => {
+ this.setState({ pageCount }, () => {
+ this.fetchReplies()
+ })
+ }
+
+ fetchReplies = () => {
+ const graduation_topic_id = this.props.memo.id
+ const course_id = this.props.course_id
+ const url = `/courses/${course_id}/graduation_topics/${graduation_topic_id}/show_comment.json?page=${this.state.pageCount}`
+ // page limit parent_id
+ axios.get(url,{
+ })
+ .then((response) => {
+ const { comments, messages_count } = response.data
+
+ this.setState({
+ comments: generateComments(comments, this.transformReply),
+ // : this.state.comments.concat(comments),
+ total_count: messages_count
+ })
+ }).catch((error) => {
+ console.log(error)
+ })
+ }
+
+ transformReply = (reply, children = []) => {
+ const isAdmin = this.props.isAdmin()
+ const isSuperAdmin = this.props.isSuperAdmin()
+ return {
+ isSuperAdmin: isSuperAdmin,
+ admin: isAdmin, //
+ permission: true, //
+ children: children,
+ child_message_count: reply.child_message_count,
+ hidden: reply.hidden,
+ id: reply.id,
+ image_url: reply.author.image_url,
+ reward: null, //
+ time: reply.time, // moment(reply.created_on).fromNow(),
+ user_id: reply.author.id,
+ user_login: reply.author.login,
+ user_praise: reply.user_praise,
+ username: reply.author.name,
+ content: reply.content,
+ praise_count: reply.praise_count
+ }
+ }
+
+ // 公共接口 --- 删除回复
+ deleteComment = (parrentComment, childCommentId) => {
+ handleDeleteComment(this, parrentComment, childCommentId, 'journals_for_message')
+ }
+ // 公共接口 --- 回复点赞
+ commentPraise = (discussId) => {
+ handleCommentPraise(this, discussId, 'journals_for_message')
+ }
+ // 公共接口 --- 隐藏回复
+ hiddenComment = (item, childCommentId) => {
+ handleHiddenComment(this, item, childCommentId, 'journals_for_message')
+ }
+
+ showCommentInput = () => {
+ this.refs.editor.showEditor();
+ }
+ initReply = (parent) => {
+ if (!parent.isAllChildrenLoaded) {
+ this.loadMoreChildComments(parent)
+ }
+ }
+
+ render(){
+ let { total_count, comments, pageCount } = this.state
+ const { current_user, memo } = this.props
+
+ return(
+
+
+
+
+
+ 全部回复
+ {total_count}
+
+
+
+
+
+ {/* { true ? :
+
} */}
+
+
+ { total_count > REPLY_PAGE_COUNT &&
+ }
+
+ )
+ }
+}
+export default ImageLayerOfCommentHOC() (GraduateTopicReply);