feat: 添加修改评论功能
This commit is contained in:
@@ -45,7 +45,7 @@ export function createComment(data: CommentApi.Comment) {
|
|||||||
|
|
||||||
/** 修改评论 */
|
/** 修改评论 */
|
||||||
export function updateComment(data: CommentApi.Comment) {
|
export function updateComment(data: CommentApi.Comment) {
|
||||||
return requestClient.post('/license/comment/update', data);
|
return requestClient.put('/license/comment/update', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除客户 */
|
/** 删除客户 */
|
||||||
|
|||||||
@@ -7,5 +7,8 @@
|
|||||||
"delete": "Delete",
|
"delete": "Delete",
|
||||||
"comment": "Comment",
|
"comment": "Comment",
|
||||||
"deleteCommentTitle": "Are you sure you want to delete this comment?",
|
"deleteCommentTitle": "Are you sure you want to delete this comment?",
|
||||||
"sortByTime": "Sort by Time"
|
"sortByTime": "Sort by Time",
|
||||||
|
"edit": "Edit",
|
||||||
|
"editComment": "Edit Comment",
|
||||||
|
"cancelEdit": "Cancel Edit"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,8 @@
|
|||||||
"delete": "删除",
|
"delete": "删除",
|
||||||
"comment": "评论",
|
"comment": "评论",
|
||||||
"deleteCommentTitle": "确定删除该条评论吗?",
|
"deleteCommentTitle": "确定删除该条评论吗?",
|
||||||
"sortByTime": "按时间排序"
|
"sortByTime": "按时间排序",
|
||||||
|
"edit": "修改",
|
||||||
|
"editComment": "修改评论",
|
||||||
|
"cancelEdit": "取消修改"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,16 +39,30 @@ const emit = defineEmits(['getCommentByProjectId']);
|
|||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
|
||||||
const isShowReply = ref<boolean>();
|
const isShowReply = ref<boolean>();
|
||||||
|
const isShowEdit = ref<boolean>();
|
||||||
const parentId = ref<number>();
|
const parentId = ref<number>();
|
||||||
|
const commentType = ref<number>();
|
||||||
const reply = (id: number) => {
|
const reply = (id: number) => {
|
||||||
isShowReply.value = !isShowReply.value;
|
isShowReply.value = !isShowReply.value;
|
||||||
parentId.value = id;
|
parentId.value = id;
|
||||||
|
isShowEdit.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const edit = (id: number) => {
|
||||||
|
isShowEdit.value = !isShowEdit.value;
|
||||||
|
parentId.value = id;
|
||||||
|
commentType.value = 1;
|
||||||
|
isShowReply.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const showReply = (flag: boolean) => {
|
const showReply = (flag: boolean) => {
|
||||||
isShowReply.value = flag;
|
isShowReply.value = flag;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const showEdit = (flag: boolean) => {
|
||||||
|
isShowEdit.value = flag;
|
||||||
|
};
|
||||||
|
|
||||||
const onDelete = async (id: number) => {
|
const onDelete = async (id: number) => {
|
||||||
try {
|
try {
|
||||||
await deleteComment(id);
|
await deleteComment(id);
|
||||||
@@ -112,6 +126,27 @@ const formatContent = computed(() => {
|
|||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</template>
|
</template>
|
||||||
</span>
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="userStore.userInfo?.id === data.userId"
|
||||||
|
key="comment-basic-edit-to"
|
||||||
|
>
|
||||||
|
<template v-if="!isShowEdit">
|
||||||
|
<a-tooltip :title="$t('comment.edit')">
|
||||||
|
<span
|
||||||
|
class="icon-[clarity--edit-line] size-3.5"
|
||||||
|
@click="edit(data.id)"
|
||||||
|
></span>
|
||||||
|
</a-tooltip>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<a-tooltip :title="$t('comment.cancelEdit')">
|
||||||
|
<span
|
||||||
|
class="icon-[clarity--edit-solid] size-3.5"
|
||||||
|
@click="edit(data.id)"
|
||||||
|
></span>
|
||||||
|
</a-tooltip>
|
||||||
|
</template>
|
||||||
|
</span>
|
||||||
<span
|
<span
|
||||||
v-if="userStore.userInfo?.id === data.userId"
|
v-if="userStore.userInfo?.id === data.userId"
|
||||||
key="comment-basic-delete"
|
key="comment-basic-delete"
|
||||||
@@ -129,12 +164,21 @@ const formatContent = computed(() => {
|
|||||||
<div v-show="isShowReply">
|
<div v-show="isShowReply">
|
||||||
<CreateComment
|
<CreateComment
|
||||||
:project-id="projectId"
|
:project-id="projectId"
|
||||||
:comments="comments"
|
|
||||||
:parent-id="parentId"
|
:parent-id="parentId"
|
||||||
@show-reply="showReply"
|
@show-reply="showReply"
|
||||||
@get-comment-by-project-id="emit('getCommentByProjectId', projectId)"
|
@get-comment-by-project-id="emit('getCommentByProjectId', projectId)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="isShowEdit">
|
||||||
|
<CreateComment
|
||||||
|
:project-id="projectId"
|
||||||
|
:comment-content="data?.content || ''"
|
||||||
|
:parent-id="parentId"
|
||||||
|
:comment-type="commentType"
|
||||||
|
@show-reply="showEdit"
|
||||||
|
@get-comment-by-project-id="emit('getCommentByProjectId', projectId)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<template v-if="(data?.depth ?? 0) < 2">
|
<template v-if="(data?.depth ?? 0) < 2">
|
||||||
<child-comment
|
<child-comment
|
||||||
v-for="(item, index) of data.children"
|
v-for="(item, index) of data.children"
|
||||||
@@ -148,3 +192,8 @@ const formatContent = computed(() => {
|
|||||||
</template>
|
</template>
|
||||||
</a-comment>
|
</a-comment>
|
||||||
</template>
|
</template>
|
||||||
|
<style>
|
||||||
|
:where(.css-dev-only-do-not-override-14589v).ant-comment .ant-comment-actions {
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -5,20 +5,21 @@ import { ref } from 'vue';
|
|||||||
|
|
||||||
import { message } from 'ant-design-vue';
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
import { createComment } from '#/api/license/comment';
|
import { createComment, updateComment } from '#/api/license/comment';
|
||||||
import { Tinymce as RichTextarea } from '#/components/tinymce';
|
import { Tinymce as RichTextarea } from '#/components/tinymce';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
comments?: CommentApi.Comment[];
|
commentContent?: string;
|
||||||
|
commentType?: number;
|
||||||
parentId?: number;
|
parentId?: number;
|
||||||
projectId?: number;
|
projectId?: number;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits(['getCommentByProjectId', 'showReply']);
|
const emit = defineEmits(['getCommentByProjectId', 'showReply', 'showEdit']);
|
||||||
|
|
||||||
const submitting = ref<boolean>(false);
|
const submitting = ref<boolean>(false);
|
||||||
const value = ref<string>('');
|
const value = ref<string>(props.commentContent || '');
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
if (!value.value) {
|
if (!value.value) {
|
||||||
@@ -27,15 +28,17 @@ const handleSubmit = async () => {
|
|||||||
|
|
||||||
// 提交表单
|
// 提交表单
|
||||||
const data = {
|
const data = {
|
||||||
parentId: props.parentId,
|
id: props.commentType === 1 ? props.parentId : undefined,
|
||||||
|
parentId: props.commentType === 1 ? undefined : props.parentId,
|
||||||
projectId: props.projectId,
|
projectId: props.projectId,
|
||||||
content: value.value,
|
content: value.value,
|
||||||
} as CommentApi.Comment;
|
} as CommentApi.Comment;
|
||||||
try {
|
try {
|
||||||
submitting.value = true;
|
submitting.value = true;
|
||||||
await createComment(data);
|
await (props.commentType === 1 ? updateComment(data) : createComment(data));
|
||||||
submitting.value = false;
|
submitting.value = false;
|
||||||
emit('showReply', false);
|
emit('showReply', false);
|
||||||
|
emit('showEdit', false);
|
||||||
message.success($t('ui.actionMessage.operationSuccess'));
|
message.success($t('ui.actionMessage.operationSuccess'));
|
||||||
emit('getCommentByProjectId', props.projectId);
|
emit('getCommentByProjectId', props.projectId);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -57,7 +60,9 @@ const handleSubmit = async () => {
|
|||||||
{{
|
{{
|
||||||
(props.parentId ?? 0) === 0
|
(props.parentId ?? 0) === 0
|
||||||
? $t('comment.postComment')
|
? $t('comment.postComment')
|
||||||
: $t('comment.replyComment')
|
: props.commentType === 1
|
||||||
|
? $t('comment.editComment')
|
||||||
|
: $t('comment.replyComment')
|
||||||
}}
|
}}
|
||||||
</a-button>
|
</a-button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ function getCommentCount(comments?: CommentApi.Comment[]) {
|
|||||||
:comments="comments"
|
:comments="comments"
|
||||||
@get-comment-by-project-id="emit('getCommentByProjectId', projectId)"
|
@get-comment-by-project-id="emit('getCommentByProjectId', projectId)"
|
||||||
/>
|
/>
|
||||||
|
<a-divider style="margin-bottom: 0" />
|
||||||
<a-comment>
|
<a-comment>
|
||||||
<template #avatar>
|
<template #avatar>
|
||||||
<a-avatar
|
<a-avatar
|
||||||
|
|||||||
Reference in New Issue
Block a user