댓글등록 진행중

This commit is contained in:
kimdaae328 2025-02-12 23:43:38 +09:00
parent f33cada52f
commit 12538f0046
4 changed files with 132 additions and 92 deletions

View File

@ -24,7 +24,7 @@
<div class="d-flex justify-content-between flex-wrap mt-4"> <div class="d-flex justify-content-between flex-wrap mt-4">
<div class="d-flex flex-wrap align-items-center"> <div class="d-flex flex-wrap align-items-center">
<!-- 익명 체크박스 (익명게시판일 경우에만)--> <!-- 익명 체크박스 (익명게시판일 경우에만)-->
<div v-if="isAnonymous" class="form-check form-check-inline mb-0 me-4"> <div v-if="unknown" class="form-check form-check-inline mb-0 me-4">
<input <input
class="form-check-input" class="form-check-input"
type="checkbox" type="checkbox"
@ -59,41 +59,38 @@
</template> </template>
<script setup> <script setup>
import { ref, defineEmits, defineProps, computed, watchEffect } from 'vue'; import { ref, defineEmits, defineProps, computed, watch } from 'vue';
const props = defineProps({ const props = defineProps({
profileName: { unknown: {
type: String, type: Boolean,
default: '익명 사용자', default: true,
}, },
parentId: {
type: Number,
default: 0
}
}); });
const isCheck = ref(false);
const comment = ref(''); const comment = ref('');
const password = ref(''); const password = ref('');
const isCheck = ref(false);
const isAnonymous = computed(() => props.profileName === '익명 사용자');
const emit = defineEmits(['submit']); const emit = defineEmits(['submit']);
watchEffect(() => { watch(() => props.unknown, (newVal) => {
console.log('📢 부모로부터 전달된 profileName:', props.profileName); if (!newVal) {
console.log('🔐 익명 여부(isAnonymous):', isAnonymous.value);
if (!isAnonymous.value) {
isCheck.value = false; isCheck.value = false;
} }
}); });
function handleCommentSubmit() { function handleCommentSubmit() {
console.log('📝 댓글 내용:', comment.value);
console.log('🔐 익명 여부:', isAnonymous.value);
console.log('🔑 비밀번호:', password.value);
emit('submit', { emit('submit', {
comment: comment.value, comment: comment.value,
isAnonymous: isAnonymous.value,
password: password.value, password: password.value,
}); });
comment.value = '';
password.value = '';
} }
</script> </script>

View File

@ -11,38 +11,48 @@
</template> </template>
<script setup> <script setup>
import { ref } from 'vue'; import { ref, defineProps, defineEmits } from 'vue';
import BoardComment from './BoardComment.vue' import BoardComment from './BoardComment.vue'
const comments = ref([ const props = defineProps({
{ comments: Array
id: 1, });
author: '홍길동',
content: '저도 궁금합니다.', const emit = defineEmits(['reply']);
children: [
{ const addComment = (replyData) => {
id: 2, emit('reply', replyData);
author: '사용자1', };
content: '저도요!',
}, // const comments = ref([
{ // {
id: 3, // id: 1,
author: '사용자2', // author: '',
content: '저도..', // content: ' .',
}, // children: [
], // {
}, // id: 2,
{ // author: '1',
id: 4, // content: '!',
author: '사용자4', // },
content: '흥미로운 주제네요.', // {
children: [], // id: 3,
}, // author: '2',
{ // content: '..',
id: 5, // },
author: '사용자5', // ],
content: '우오아아아아아앙', // },
children: [], // {
}, // id: 4,
]); // author: '4',
// content: ' .',
// children: [],
// },
// {
// id: 5,
// author: '5',
// content: '',
// children: [],
// },
// ]);
</script> </script>

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="d-flex align-items-center flex-wrap"> <div class="d-flex align-items-center flex-wrap">
<div class="d-flex align-items-center"> <div class="d-flex align-items-center">
<div class="avatar me-2" v-if="unknown"> <div class="avatar me-2" v-if="!unknown">
<img src="/img/avatars/2.png" alt="Avatar" class="rounded-circle" /> <img src="/img/avatars/2.png" alt="Avatar" class="rounded-circle" />
</div> </div>
<div class="me-2"> <div class="me-2">
@ -13,7 +13,7 @@
<i class="fa-regular fa-eye"></i> {{ views }} <i class="fa-regular fa-eye"></i> {{ views }}
</span> </span>
<span> <span>
<i class="bx bx-comment"></i> {{ comments }} <i class="bx bx-comment"></i> {{ commentNum }}
</span> </span>
</template> </template>
</div> </div>
@ -25,7 +25,7 @@
<EditButton @click="handleEdit" /> <EditButton @click="handleEdit" />
<DeleteButton @click="handleDelete" /> <DeleteButton @click="handleDelete" />
<div class="mt-3" v-if="isPassword && unknown"> <div class="mt-3" v-if="isPassword && !unknown">
<div class="input-group"> <div class="input-group">
<input <input
type="password" type="password"
@ -40,6 +40,7 @@
</div> </div>
</template> </template>
<template v-else> <template v-else>
<!-- 게시글의 작성자 여부를 확인 : 현재 로그인한 사용자가 게시글의 작성자인지 여부 -->
<template v-if="author"> <template v-if="author">
<EditButton /> <EditButton />
<DeleteButton /> <DeleteButton />
@ -57,7 +58,7 @@
</template> </template>
<script setup> <script setup>
import { ref, onMounted, defineProps } from 'vue'; import { ref, defineProps, computed } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import axios from '@api'; import axios from '@api';
import DeleteButton from '../button/DeleteBtn.vue'; import DeleteButton from '../button/DeleteBtn.vue';
@ -79,7 +80,7 @@ const props = defineProps({
}, },
profileName: { profileName: {
type: String, type: String,
default: '익명', default: '익명 사용자',
}, },
unknown: { unknown: {
type: Boolean, type: Boolean,
@ -89,6 +90,7 @@ const props = defineProps({
type: Boolean, type: Boolean,
default: true, default: true,
}, },
// :
author: { author: {
type: Boolean, type: Boolean,
default: false, default: false,
@ -101,7 +103,7 @@ const props = defineProps({
type: Number, type: Number,
default: 0, default: 0,
}, },
comments: { commentNum: {
type: Number, type: Number,
default: 0, default: 0,
}, },

View File

@ -8,8 +8,10 @@
<BoardProfile <BoardProfile
:boardId="currentBoardId" :boardId="currentBoardId"
:profileName="profileName" :profileName="profileName"
:unknown="unknown"
:author="isAuthor"
:views="views" :views="views"
:comments="comments" :commentNum="commentNum"
:date="formattedBoardDate" :date="formattedBoardDate"
class="pb-6 border-bottom" class="pb-6 border-bottom"
/> />
@ -65,15 +67,12 @@
</ul> --> </ul> -->
<!-- 댓글 입력 영역 --> <!-- 댓글 입력 영역 -->
<BoardComentArea :profileName="profileName" @submit="handleCommentSubmit"/> <BoardComentArea :profileName="profileName" :unknown="unknown" @submit="handleCommentSubmit"/>
<!-- 수정 버튼 -->
<!-- <button class="btn btn-primary" @click="goToEditPage">
수정
</button> -->
</div> </div>
<!-- 댓글 목록 -->
<div class="card-footer"> <div class="card-footer">
<BoardCommentList/> <BoardCommentList :comments="comments" />
<Pagination/> <Pagination/>
</div> </div>
@ -103,17 +102,16 @@ const likes = ref(0);
const dislikes = ref(0); const dislikes = ref(0);
const likeClicked = ref(false); const likeClicked = ref(false);
const dislikeClicked = ref(false); const dislikeClicked = ref(false);
const comments = ref(0); const commentNum = ref(0);
const attachment = ref(false); const attachment = ref(false);
// ID
const route = useRoute(); const route = useRoute();
const currentBoardId = ref(Number(route.params.id)); const currentBoardId = ref(Number(route.params.id));
const unknown = computed(() => profileName.value === '익명 사용자');
const currentUserId = ref('김자바'); // id
const authorId = ref(null); // id
// const isAuthor = computed(() => currentUserId.value === authorId.value);
const goToEditPage = () => {
router.push({ name: 'BoardEdit', params: { id: currentBoardId.value } });
};
// //
const fetchBoardDetails = async () => { const fetchBoardDetails = async () => {
@ -129,6 +127,9 @@ const fetchBoardDetails = async () => {
// //
// profileName.value = ' '; // profileName.value = ' ';
// :
authorId.value = data.author;
boardTitle.value = data.title || '제목 없음'; boardTitle.value = data.title || '제목 없음';
boardContent.value = data.content || ''; boardContent.value = data.content || '';
date.value = data.date || ''; date.value = data.date || '';
@ -136,7 +137,7 @@ const fetchBoardDetails = async () => {
likes.value = data.likeCount || 0; likes.value = data.likeCount || 0;
dislikes.value = data.dislikeCount || 0; dislikes.value = data.dislikeCount || 0;
attachment.value = data.hasAttachment || null; attachment.value = data.hasAttachment || null;
comments.value = data.commentCount || 0; commentNum.value = data.commentCount || 0;
} catch (error) { } catch (error) {
alert('게시물 데이터를 불러오는 중 오류가 발생했습니다.'); alert('게시물 데이터를 불러오는 중 오류가 발생했습니다.');
@ -145,47 +146,78 @@ const fetchBoardDetails = async () => {
// , // ,
const handleUpdateReaction = async ({ boardId, commentId, isLike, isDislike }) => { const handleUpdateReaction = async ({ boardId, commentId, isLike, isDislike }) => {
// console.log(type, boardId)
try { try {
await axios.post(`/board/${boardId}/${commentId}/reaction`, {
const requestData = {
LOCBRDSEQ: boardId, LOCBRDSEQ: boardId,
LOCCMTSEQ: commentId, LOCCMTSEQ: commentId,
MEMBERSEQ: 1, // 1 MEMBERSEQ: 1, // 1
LOCGOBGOD: isLike ? 'T' : 'F', LOCGOBGOD: isLike ? 'T' : 'F',
LOCGOBBAD: isDislike ? 'T' : 'F' LOCGOBBAD: isDislike ? 'T' : 'F'
}; });
console.log(requestData)
const postResponse = await axios.post(`/board/${boardId}/${commentId}/reaction`, requestData);
// await axios.post(`board/${boardId}/${commentId}/reaction`, { type });
const response = await axios.get(`board/${boardId}`); const response = await axios.get(`board/${boardId}`);
console.log(response.data)
const updatedData = response.data.data; const updatedData = response.data.data;
console.log('post요청 결과:', postResponse.data);
console.log('get요청 결과(좋아요):', response.data.data.likeCount);
likes.value = updatedData.likeCount; likes.value = updatedData.likeCount;
dislikes.value = updatedData.dislikeCount; dislikes.value = updatedData.dislikeCount;
likeClicked.value = isLike; likeClicked.value = isLike;
dislikeClicked.value = isDislike; dislikeClicked.value = isDislike;
console.log('반응 결과:', postResponse.data);
} catch (error) { } catch (error) {
alert('반응을 업데이트하는 중 오류 발생'); alert('반응을 업데이트하는 중 오류 발생');
} }
}; };
function handleCommentSubmit(payload) { //
console.log('댓글 내용:', payload.comment); const handleCommentSubmit = async ({ comment, password }) => {
console.log('익명 여부:', payload.isAnonymous); try {
console.log('비밀번호:', payload.password); // const payload = {
// LOCBRDSEQ: currentBoardId.value,
// LOCCMTRPY: comment,
// LOCCMTPWD: password || null,
// LOCCMTPNT: 1
// };
// alert(` : ${comment}`);
// console.log('📤 :', payload); //
// const response = await axios.post(`board/${currentBoardId.value}/comment`, payload);
const response = await axios.post(`board/${currentBoardId.value}/comment`, {
LOCBRDSEQ: currentBoardId.value,
LOCCMTRPY: comment,
LOCCMTPWD: password || null,
LOCCMTPNT: 0
});
console.log('📥 서버 응답 전체:', response);
if (response.status === 200) {
console.log('댓글 작성 성공:', response.data.message);
// await fetchComments(); //
} else {
console.error('댓글 작성 실패:', response.data.message);
}
} catch (error) {
console.error('댓글 작성 중 오류 발생:', error);
}
};
//
// const fetchComments = async () => {
// try {
// const response = await axios.get(`board/${currentBoardId.value}/comments`);
// if (response.status === 200) {
// comments.value = response.data.data || [];
// console.log('📋 :', comments.value);
// }
// } catch (error) {
// console.error(' :', error);
// }
// };
}
// //
const formattedBoardDate = computed(() => { const formattedBoardDate = computed(() => {
@ -193,9 +225,8 @@ const formattedBoardDate = computed(() => {
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')}`; 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')}`;
}); });
// //
onMounted(() => { onMounted(() => {
fetchBoardDetails(); fetchBoardDetails()
}); });
</script> </script>