보드 원복복

This commit is contained in:
dyhj625 2025-02-25 16:27:22 +09:00
parent 37c335fc12
commit bd91e0a72d
3 changed files with 86 additions and 42 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<div> <div>
<BoardProfile <BoardProfile
:unknown="unknown" :unknown="comment.author === '익명'"
:isCommentAuthor="isCommentAuthor" :isCommentAuthor="isCommentAuthor"
:boardId="comment.boardId" :boardId="comment.boardId"
:profileName="comment.author" :profileName="comment.author"
@ -11,7 +11,7 @@
:isLike="!isLike" :isLike="!isLike"
:isCommentPassword="comment.isCommentPassword" :isCommentPassword="comment.isCommentPassword"
:isCommentProfile="true" :isCommentProfile="true"
@editClick="$emit('editClick', comment)" @editClick="aaaa"
@deleteClick="$emit('deleteClick', comment)" @deleteClick="$emit('deleteClick', comment)"
@updateReaction="handleUpdateReaction" @updateReaction="handleUpdateReaction"
/> />
@ -29,8 +29,8 @@
</div> </div>
<span v-if="passwordCommentAlert" class="invalid-feedback d-block text-start">{{ passwordCommentAlert }}</span> <span v-if="passwordCommentAlert" class="invalid-feedback d-block text-start">{{ passwordCommentAlert }}</span>
</div> </div>
<p>authorId:{{ comment.authorId }}</p> <!-- <p>authorId:{{ comment.authorId }}</p>
<p>코멘트 비교: {{comment.isCommentAuthor}}</p> <p>코멘트 비교: {{comment.isCommentAuthor}}</p> -->
<div class="mt-6"> <div class="mt-6">
@ -47,20 +47,29 @@
</div> </div>
<PlusButton v-if="isPlusButton" @click="toggleComment" class="mt-6"/> <PlusButton v-if="isPlusButton" @click="toggleComment" class="mt-6"/>
<BoardCommentArea v-if="isComment" @submitComment="submitComment"/> <BoardCommentArea v-if="isComment" :unknown="unknown" @submitComment="submitComment"/>
<!-- 대댓글 --> <!-- 대댓글 -->
<ul v-if="comment.children && comment.children.length" class="list-unstyled"> <ul v-if="comment.children && comment.children.length" class="list-unstyled">
<li <li
v-for="child in comment.children" v-for="child in comment.children"
:key="child.commentId" :key="child.commentId"
class="mt-8 pt-6 ps-10 border-top" class="mt-8 pt-6 ps-10 border-top"
> >
<!-- <p>대댓글 데이터(JSON): {{ JSON.stringify(child, null, 2) }}</p> -->
<!-- <p>comment child: {{ comment.children }}</p> -->
<!-- :unknown="child.author === '익명'" -->
<BoardComment <BoardComment
:comment="child" :comment="child"
:unknown="unknown" :unknown="child.author === '익명'"
:isPlusButton="false" :isPlusButton="false"
:isLike="true" :isLike="true"
:isCommentProfile="true"
:isCommentAuthor="child.isCommentAuthor"
@editClick="$emit('editClick', $event)"
@deleteClick="$emit('deleteClick', child)"
@submitEdit="(comment, editedContent) => $emit('submitEdit', comment, editedContent)"
@cancelEdit="$emit('cancelEdit', child)"
@submitComment="submitComment" @submitComment="submitComment"
@updateReaction="handleUpdateReaction" @updateReaction="handleUpdateReaction"
/> />
@ -155,4 +164,8 @@ const submitEdit = () => {
emit('submitEdit', props.comment, localEditedContent.value); emit('submitEdit', props.comment, localEditedContent.value);
}; };
const aaaa = () => {
emit('editClick', props.comment);
}
</script> </script>

View File

@ -17,6 +17,7 @@
rows="3" rows="3"
v-model="comment" v-model="comment"
></textarea> ></textarea>
<span v-if="commentAlert" class="invalid-feedback d-block text-start ms-2">{{ commentAlert }}</span>
</div> </div>
</div> </div>
@ -42,6 +43,7 @@
id="basic-default-password" id="basic-default-password"
class="form-control flex-grow-1" class="form-control flex-grow-1"
v-model="password" v-model="password"
placeholder="비밀번호 입력"
/> />
<span v-if="passwordAlert" class="invalid-feedback d-block text-start ms-2">{{ passwordAlert }}</span> <span v-if="passwordAlert" class="invalid-feedback d-block text-start ms-2">{{ passwordAlert }}</span>
</div> </div>
@ -74,28 +76,35 @@ const props = defineProps({
passwordAlert: { passwordAlert: {
type: String, type: String,
default: false default: false
},
commentAlert: {
type: String,
default: false
} }
}); });
const comment = ref(''); const comment = ref('');
const password = ref(''); const password = ref('');
const isCheck = ref(false); const isCheck = ref(props.unknown);
const emit = defineEmits(['submitComment']);
const emit = defineEmits(['submitComment']);
const LOCBRDTYP = isCheck.value ? '300102' : null;
function handleCommentSubmit() { function handleCommentSubmit() {
if (props.unknown && isCheck.value && !password.value) {
alert('익명 댓글을 작성하려면 비밀번호를 입력해야 합니다.');
return;
}
const LOCBRDTYP = isCheck.value ? '300102' : null;
emit('submitComment', { emit('submitComment', {
comment: comment.value, comment: comment.value,
password: isCheck.value ? password.value : '', password: isCheck.value ? password.value : '',
LOCBRDTYP, isCheck: isCheck.value,
LOCBRDTYP, // '300102'
isCheck: isCheck.value isCheck: isCheck.value
}); });
comment.value = '';
password.value = '';
isCheck.value = false; //
} }
watch(() => props.passwordAlert, () => {
if (!props.passwordAlert) {
comment.value = '';
password.value = '';
}
});
</script> </script>

View File

@ -140,7 +140,6 @@ import { ref, onMounted, computed } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { useUserInfoStore } from '@/stores/useUserInfoStore'; import { useUserInfoStore } from '@/stores/useUserInfoStore';
import axios from '@api'; import axios from '@api';
import { formattedDate } from '@/common/formattedDate.js';
// //
const profileName = ref(''); const profileName = ref('');
@ -376,63 +375,77 @@ const fetchComments = async (page = 1) => {
}; };
// //
const handleCommentSubmit = async (data) => { const handleCommentSubmit = async (data, isCheck) => {
if (!data) {
console.error("handleCommentSubmit: data가 undefined입니다.");
return;
}
const { comment, password } = data; const { comment, password } = data;
const LOCBRDTYP = data.LOCBRDTYP || null; // undefined const LOCBRDTYP = data.LOCBRDTYP || null;
if (!comment || comment.trim() === "") {
commentAlert.value = '댓글을 입력해주세요.';
return;
} else {
commentAlert.value = '';
}
if (unknown.value && isCheck && (!password || password.trim() === "")) {
passwordAlert.value = "비밀번호를 입력해야 합니다.";
return;
}
try { try {
const response = await axios.post(`board/${currentBoardId.value}/comment`, { const response = await axios.post(`board/${currentBoardId.value}/comment`, {
LOCBRDSEQ: currentBoardId.value, LOCBRDSEQ: currentBoardId.value,
LOCCMTRPY: comment, LOCCMTRPY: comment,
LOCCMTPWD: password, LOCCMTPWD: isCheck ? password : '',
LOCCMTPNT: 1, LOCCMTPNT: 1,
LOCBRDTYP // LOCBRDTYP
}); });
if (response.status === 200) { if (response.status === 200) {
console.log('댓글 작성 성공:', response.data.message); console.log('댓글 작성 성공:', response.data.message);
passwordAlert.value = '';
commentAlert.value = '';
await fetchComments(); await fetchComments();
} else { } else {
console.log('댓글 작성 실패:', response.data.message); console.error('댓글 작성 실패:', response.data.message);
} }
} catch (error) { } catch (error) {
console.log('댓글 작성 중 오류 발생:', error); console.error('댓글 작성 중 오류 발생:', error);
} }
}; };
// ( `BoardCommentList` ) // ( `BoardCommentList` )
const handleCommentReply = async (reply) => { const handleCommentReply = async (reply) => {
try { try {
// ( LOCBRDTYP 300102 ) const response = await axios.post(`board/${currentBoardId.value}/comment`, {
const requestBody = {
LOCBRDSEQ: currentBoardId.value, LOCBRDSEQ: currentBoardId.value,
LOCCMTRPY: reply.comment, LOCCMTRPY: reply.comment,
LOCCMTPWD: reply.password || null, LOCCMTPWD: reply.password || null,
LOCCMTPNT: reply.parentId, LOCCMTPNT: reply.parentId,
LOCBRDTYP: reply.isCheck ? "300102" : null LOCBRDTYP: reply.isCheck ? "300102" : null
}; });
console.log(requestBody)
const response = await axios.post(`board/${currentBoardId.value}/comment`, requestBody);
if (response.status === 200) { if (response.status === 200) {
if (response.data.code === 200) { if (response.data.code === 200) { //
console.log('대댓글 작성 성공:', response.data); console.log('대댓글 작성 성공:', response.data);
await fetchComments(); await fetchComments(); //
} else { } else {
console.log('대댓글 작성 실패 - 서버 응답:', response.data); console.log('대댓글 작성 실패 - 서버 응답:', response.data);
alert('대댓글 작성에 실패했습니다.'); alert('대댓글 작성에 실패했습니다.');
} }
} }
} catch (error) { } catch (error) {
console.error('🚨 대댓글 작성 중 오류 발생:', error); console.error('대댓글 작성 중 오류 발생:', error);
if (error.response) { if (error.response) {
console.error('📌 서버 응답 에러:', error.response.data); console.error('서버 응답 에러:', error.response.data);
} }
alert('대댓글 작성 중 오류가 발생했습니다.'); alert('대댓글 작성 중 오류가 발생했습니다.');
} }
}; }
// //
const editClick = (unknown) => { const editClick = (unknown) => {
@ -484,6 +497,7 @@ const editComment = (comment) => {
// //
if (unknown.value) { if (unknown.value) {
console.log('익명 코멘트인가?')
toggleCommentPassword(comment, "edit"); toggleCommentPassword(comment, "edit");
} }
} }
@ -736,6 +750,14 @@ const handleCommentDeleted = (deletedCommentId) => {
console.error("❌ 삭제할 댓글을 찾을 수 없음:", deletedCommentId); console.error("❌ 삭제할 댓글을 찾을 수 없음:", deletedCommentId);
}; };
//
const formattedDate = (dateString) => {
if (!dateString) return "날짜 없음";
const dateObj = new Date(dateString);
return `${dateObj.getFullYear()}-${String(dateObj.getMonth() + 1).padStart(2, '0')}-${String(dateObj.getDate()).padStart(2, '0')} ${String(dateObj.getHours()).padStart(2, '0')}:${String(dateObj.getMinutes()).padStart(2, '0')}`;
};
const formattedBoardDate = computed(() => formattedDate(date.value)); const formattedBoardDate = computed(() => formattedDate(date.value));
// //