댓글과 대댓글 익명으로 저장장

This commit is contained in:
dyhj625 2025-02-25 10:04:41 +09:00
parent 84c43d5baf
commit 99d89008ed
3 changed files with 138 additions and 73 deletions

View File

@ -48,7 +48,7 @@
<PlusButton v-if="isPlusButton" @click="toggleComment" class="mt-6"/>
<BoardCommentArea v-if="isComment" @submitComment="submitComment"/>
<!-- 대댓글 -->
<ul v-if="comment.children && comment.children.length" class="list-unstyled">
<li
@ -56,12 +56,12 @@
:key="child.commentId"
class="mt-8 pt-6 ps-10 border-top"
>
<BoardComment
<BoardComment
:comment="child"
:unknown="unknown"
:isPlusButton="false"
:isPlusButton="false"
:isLike="true"
@submitComment="submitComment"
@submitComment="submitComment"
@updateReaction="handleUpdateReaction"
/>
</li>
@ -124,7 +124,8 @@ const toggleComment = () => {
//
const submitComment = (newComment) => {
emit('submitComment', { parentId: props.comment.commentId, ...newComment });
console.log(newComment)
emit('submitComment', { parentId: props.comment.commentId, ...newComment, LOCBRDTYP: newComment.LOCBRDTYP });
isComment.value = false;
};
@ -141,7 +142,7 @@ const handleUpdateReaction = (reactionData) => {
//
const logPasswordAndEmit = () => {
emit('submitPassword', props.comment, password.value);
password.value = "";
password.value = "";
};
watch(() => props.comment.isEditTextarea, (newVal) => {

View File

@ -23,7 +23,7 @@
<!-- 옵션 버튼 섹션 -->
<div class="d-flex justify-content-between flex-wrap mt-4">
<div class="d-flex flex-wrap align-items-center">
<!-- 익명 체크박스 (익명게시판일 경우에만)-->
<!-- 익명 체크박스 (익명게시판일 경우에만) -->
<div v-if="unknown" class="form-check form-check-inline mb-0 me-4">
<input
class="form-check-input"
@ -35,7 +35,7 @@
</div>
<!-- 비밀번호 입력 필드 (익명이 선택된 경우에만 표시) -->
<div v-if="isCheck" class="d-flex align-items-center flex-grow-1">
<div v-if="unknown && isCheck" class="d-flex align-items-center flex-grow-1">
<label class="form-label mb-0 me-3" for="basic-default-password">비밀번호</label>
<input
type="password"
@ -50,7 +50,6 @@
<!-- 답변 쓰기 버튼 -->
<div class="ms-auto mt-3 mt-md-0">
<button class="btn btn-primary" @click="handleCommentSubmit">
<!-- <i class="icon-base bx bx-check"></i> -->
확인
</button>
</div>
@ -60,7 +59,7 @@
</template>
<script setup>
import { ref, defineEmits, defineProps, computed, watch } from 'vue';
import { ref, defineEmits, defineProps } from 'vue';
const props = defineProps({
unknown: {
@ -79,23 +78,24 @@ const props = defineProps({
const comment = ref('');
const password = ref('');
const isCheck = ref(props.unknown);
const isCheck = ref(false);
const emit = defineEmits(['submitComment']);
watch(() => props.unknown, (newVal) => {
isCheck.value = newVal;
});
function handleCommentSubmit() {
if (props.unknown && isCheck.value && !password.value) {
alert('익명 댓글을 작성하려면 비밀번호를 입력해야 합니다.');
return;
}
const LOCBRDTYP = isCheck.value ? '300102' : null;
emit('submitComment', {
comment: comment.value,
password: isCheck.value ? password.value : '',
LOCBRDTYP, // '300102'
isCheck: isCheck.value
});
comment.value = '';
password.value = '';
isCheck.value = false; //
}
</script>

View File

@ -59,10 +59,10 @@
</ul> -->
</div>
</div>
<!-- HTML 콘텐츠 렌더링 -->
<div class="board-content text-body" style="line-height: 1.6;" v-html="$common.contentToHtml(boardContent)"></div>
<!-- 좋아요 버튼 -->
<div class="row justify-content-center my-10">
<BoardRecommendBtn
@ -78,11 +78,11 @@
</div>
<p>현재 로그인한 사용자 ID: {{ currentUserId }}</p>
<p>게시글 작성자: {{ authorId }}</p>
<p>isAuthor : {{ isAuthor }}</p>
<p>isAuthor : {{ isAuthor }}</p>
<!-- <p>use이미지:{{userStore.user.img}}</p> -->
<!-- <img :src="`http://localhost:10325/upload/img/profile/${userStore.user.profile}`" alt="Profile Image" class="w-px-40 h-auto rounded-circle"/> -->
<!-- 첨부파일 목록 -->
<!-- <ul v-if="attachments.length" class="attachments mt-4 list-unstyled">
<li v-for="(attachment, index) in attachments" :key="index" class="mb-2">
@ -209,13 +209,13 @@ const fetchBoardDetails = async () => {
// API
// const boardDetail = data.boardDetail || {};
profileName.value = data.author;
//
// profileName.value = '';
authorId.value = data.authorId; // id
boardTitle.value = data.title || '제목 없음';
boardContent.value = data.content || '';
@ -225,7 +225,7 @@ const fetchBoardDetails = async () => {
dislikes.value = data.dislikeCount || 0;
attachment.value = data.hasAttachment || null;
commentNum.value = data.commentCount || 0;
} catch (error) {
alert('게시물 데이터를 불러오는 중 오류가 발생했습니다.');
}
@ -293,7 +293,7 @@ const fetchComments = async (page = 1) => {
});
console.log(response.data.data)
const commentsList = response.data.data.list.map(comment => ({
commentId: comment.LOCCMTSEQ, // ID
boardId: comment.LOCBRDSEQ,
@ -366,26 +366,17 @@ const fetchComments = async (page = 1) => {
// const isSubmitting = ref(false);
//
const handleCommentSubmit = async ({ comment, password }) => {
console.log('댓글')
//
// if (!password) {
// passwordAlert.value = " .";
// return;
// }
// console.log(' ')
//
// if (isSubmitting.value) return;
// isSubmitting.value = true;
const handleCommentSubmit = async (data) => {
const { comment, password } = data;
const LOCBRDTYP = data.LOCBRDTYP || null; // undefined
try {
const response = await axios.post(`board/${currentBoardId.value}/comment`, {
LOCBRDSEQ: currentBoardId.value,
LOCCMTRPY: comment,
LOCCMTPWD: password,
LOCCMTPNT: 1
LOCCMTPNT: 1,
LOCBRDTYP //
});
if (response.status === 200) {
@ -399,48 +390,121 @@ const handleCommentSubmit = async ({ comment, password }) => {
}
};
// const handleCommentSubmit = async ({ comment, password, LOCBRDTYP }) => {
// console.log('')
// //
// // if (!password) {
// // passwordAlert.value = " .";
// // return;
// // }
// // console.log(' ')
// //
// // if (isSubmitting.value) return;
// // isSubmitting.value = true;
// try {
// // const response = await axios.post(`board/${currentBoardId.value}/comment`, {
// // LOCBRDSEQ: currentBoardId.value,
// // LOCCMTRPY: comment,
// // LOCCMTPWD: password,
// // LOCCMTPNT: 1
// // });
// if (response.status === 200) {
// console.log(' :', response.data.message);
// await fetchComments();
// } else {
// console.log(' :', response.data.message);
// }
// } catch (error) {
// console.log(' :', error);
// }
// };
// ( `BoardCommentList` )
const handleCommentReply = async (reply) => {
try {
// console.log(' :', {
// LOCBRDSEQ: currentBoardId.value,
// LOCCMTRPY: reply.comment,
// LOCCMTPWD: reply.password || null,
// LOCCMTPNT: reply.parentId
// });
// ( LOCBRDTYP 300102 )
const response = await axios.post(`board/${currentBoardId.value}/comment`, {
const requestBody = {
LOCBRDSEQ: currentBoardId.value,
LOCCMTRPY: reply.comment,
LOCCMTPWD: reply.password || null,
LOCCMTPNT: reply.parentId
});
//
// console.log(' :', {
// status: response.status,
// data: response.data,
// headers: response.headers
// });
LOCCMTPNT: reply.parentId,
LOCBRDTYP: reply.isCheck ? "300102" : null
};
console.log(requestBody)
const response = await axios.post(`board/${currentBoardId.value}/comment`, requestBody);
if (response.status === 200) {
if (response.data.code === 200) { //
console.log('대댓글 작성 성공:', response.data);
await fetchComments(); //
if (response.data.code === 200) {
console.log('✅ 대댓글 작성 성공:', response.data);
await fetchComments();
} else {
console.log('대댓글 작성 실패 - 서버 응답:', response.data);
console.log('대댓글 작성 실패 - 서버 응답:', response.data);
alert('대댓글 작성에 실패했습니다.');
}
}
} catch (error) {
console.error('대댓글 작성 중 오류 발생:', error);
console.error('🚨 대댓글 작성 중 오류 발생:', error);
if (error.response) {
console.error('서버 응답 에러:', error.response.data);
console.error('📌 서버 응답 에러:', error.response.data);
}
alert('대댓글 작성 중 오류가 발생했습니다.');
alert('대댓글 작성 중 오류가 발생했습니다.');
}
}
};
// const handleCommentReply = async (reply) => {
// try {
// // console.log(' :', {
// // LOCBRDSEQ: currentBoardId.value,
// // LOCCMTRPY: reply.comment,
// // LOCCMTPWD: reply.password || null,
// // LOCCMTPNT: reply.parentId
// // });
// // const response = await axios.post(`board/${currentBoardId.value}/comment`, {
// // LOCBRDSEQ: currentBoardId.value,
// // LOCCMTRPY: reply.comment,
// // LOCCMTPWD: reply.password || null,
// // LOCCMTPNT: reply.parentId
// // });
// const requestBody = {
// LOCBRDSEQ: currentBoardId.value,
// LOCCMTRPY: reply.comment,
// LOCCMTPWD: reply.password || null,
// LOCCMTPNT: reply.parentId,
// LOCBRDTYP
// };
// //
// // console.log(' :', {
// // status: response.status,
// // data: response.data,
// // headers: response.headers
// // });
// const response = await axios.post(`board/${currentBoardId.value}/comment`, requestBody);
// if (response.status === 200) {
// if (response.data.code === 200) { //
// console.log(' :', response.data);
// await fetchComments(); //
// } else {
// console.log(' - :', response.data);
// alert(' .');
// }
// }
// } catch (error) {
// console.error(' :', error);
// if (error.response) {
// console.error(' :', error.response.data);
// }
// alert(' .');
// }
// }
//
const editClick = (unknown) => {
@ -463,7 +527,7 @@ const deleteClick = (unknown) => {
//
const editComment = (comment) => {
const targetComment = comments.value.find(c => c.commentId === comment.commentId);
if (!targetComment) {
return;
}
@ -571,7 +635,7 @@ const submitPassword = async () => {
// ( )
const submitCommentPassword = async (comment, password) => {
if (!password) {
passwordCommentAlert.value = "비밀번호를 입력해주세요.";
return;
@ -586,12 +650,12 @@ const submitCommentPassword = async (comment, password) => {
if (response.data.code === 200 && response.data.data === true) {
passwordCommentAlert.value = "";
comment.isCommentPassword = false;
if (lastCommentClickedButton.value === "edit") {
comment.isEditTextarea = true;
passwordCommentAlert.value = "";
// handleSubmitEdit(comment, comment.content);
// handleSubmitEdit(comment, comment.content);
} else if (lastCommentClickedButton.value === "delete") {
passwordCommentAlert.value = "";
@ -644,7 +708,7 @@ const deleteReplyComment = async (comment) => {
if (response.data.code === 200) {
// console.log(" !");
await fetchComments();
await fetchComments();
} else {
// console.log(" :", response.data.message);
alert("댓글 삭제에 실패했습니다.");
@ -665,7 +729,7 @@ const handleSubmitEdit = async (comment, editedContent) => {
//
// comment.content = editedContent;
// comment.isEditTextarea = false;
// comment.isEditTextarea = false;
if (response.status === 200) {
//
await fetchComments();