댓글 비밀번호 진행중

This commit is contained in:
kimdaae328 2025-02-21 03:50:17 +09:00
parent 2da40134c3
commit 62361b7ae9
3 changed files with 210 additions and 132 deletions

View File

@ -9,15 +9,13 @@
:showDetail="false" :showDetail="false"
:author="true" :author="true"
:isLike="!isLike" :isLike="!isLike"
:isPassword="isPassword" :isCommentPassword="comment.isCommentPassword"
@editClick="editClick" @editClick="$emit('editClick', comment)"
@deleteClick="deleteClick" @deleteClick="$emit('deleteClick', comment)"
@submitPassword="submitPassword"
@updateReaction="handleUpdateReaction" @updateReaction="handleUpdateReaction"
@toggleEdit="toggleEdit(true)"
/> />
<!-- 댓글 비밀번호 입력창 (익명일 경우) --> <!-- 댓글 비밀번호 입력창 (익명일 경우) -->
<div v-if="isPassword && unknown" class="mt-3 w-25 ms-auto"> <div v-if="isCommentPassword && unknown" class="mt-3 w-25 ms-auto">
<div class="input-group"> <div class="input-group">
<input <input
type="password" type="password"
@ -25,18 +23,18 @@
v-model="password" v-model="password"
placeholder="비밀번호 입력" placeholder="비밀번호 입력"
/> />
<button class="btn btn-primary" @click="submitPassword">확인</button> <button class="btn btn-primary" @click="logPasswordAndEmit">확인</button>
</div> </div>
<span v-if="passwordAlert" class="invalid-feedback d-block text-start">{{ passwordAlert }}</span> <span v-if="passwordAlert" class="invalid-feedback d-block text-start">{{ passwordAlert }}</span>
</div> </div>
<div class="mt-6"> <div class="mt-6">
<template v-if="isEditTextarea"> <template v-if="comment.isEditTextarea">
<textarea v-model="editedContent" class="form-control"></textarea> <textarea v-model="editedContent" class="form-control"></textarea>
<div class="mt-2 d-flex justify-content-end"> <div class="mt-2 d-flex justify-content-end">
<button class="btn btn-secondary me-2" @click="cancelEdit">취소</button> <button class="btn btn-secondary me-2" @click="$emit('cancelEdit', comment)">취소</button>
<button class="btn btn-primary" @click="submitEdit">수정</button> <button class="btn btn-primary" @click="$emit('submitEdit', comment, editedContent)">수정</button>
</div> </div>
</template> </template>
<template v-else> <template v-else>
@ -68,8 +66,7 @@
</template> </template>
<script setup> <script setup>
import axios from '@api'; import { defineProps, defineEmits, ref, computed, watch } from 'vue';
import { defineProps, defineEmits, ref } from 'vue';
import BoardProfile from './BoardProfile.vue'; import BoardProfile from './BoardProfile.vue';
import BoardCommentArea from './BoardCommentArea.vue'; import BoardCommentArea from './BoardCommentArea.vue';
import PlusButton from '../button/PlusBtn.vue'; import PlusButton from '../button/PlusBtn.vue';
@ -91,18 +88,29 @@ const props = defineProps({
type: Boolean, type: Boolean,
default: false, default: false,
}, },
editedContent: {
type: String,
default: ""
},
isEditTextarea: { isEditTextarea: {
type: Boolean, type: Boolean,
default: false default: false
}, },
isPassword: { isCommentPassword: {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
passwordAlert: {
type: String,
default: false
}
}); });
// emits // emits
const emit = defineEmits(['submitComment', 'updateReaction', 'toggleEdit',]); const emit = defineEmits(['submitComment', 'updateReaction', 'editClick', 'deleteClick', 'submitPassword', 'submitEdit', 'cancelEdit']);
const password = ref('');
// //
const isComment = ref(false); const isComment = ref(false);
@ -110,22 +118,6 @@ const toggleComment = () => {
isComment.value = !isComment.value; isComment.value = !isComment.value;
}; };
// &
const password = ref('');
const passwordAlert = ref('');
const isPassword = ref(false);
const isEditTextarea = ref(false);
const lastClickedButton = ref("");
const toggleEdit = (status) => {
if (props.unknown) {
isPassword.value = status; //
lastClickedButton.value = "edit";
} else {
isEditTextarea.value = status; //
}
};
// //
const submitComment = (newComment) => { const submitComment = (newComment) => {
emit('submitComment', { parentId: props.comment.commentId, ...newComment }); emit('submitComment', { parentId: props.comment.commentId, ...newComment });
@ -143,103 +135,23 @@ const handleUpdateReaction = (reactionData) => {
}; };
//
const editClick = () => { //
if (props.unknown) { const logPasswordAndEmit = () => {
console.log('수정') // console.log("BoardComment.vue - :", password.value);
togglePassword("edit"); emit('submitPassword', props.comment, password.value);
}
}; };
const deleteClick = () => { //
if (props.unknown) { // const cancelEdit = () => {
console.log('삭제') // isEditTextarea.value = false;
togglePassword("delete"); // };
}
};
const togglePassword = (button) => { //
if (lastClickedButton.value === button) { // const submitEdit = () => {
isPassword.value = !isPassword.value; // emit('submitComment', { commentId: props.comment.commentId, content: editedContent.value });
} else { // isEditTextarea.value = false; //
isPassword.value = true;
}
lastClickedButton.value = button;
};
// const deleteComment = async () => {
// if (!confirm(" ?")) return;
// try {
// console.log(" :");
// console.log(" ID:", props.comment.commentId);
// console.log(" ID:", props.comment.boardId);
// console.log(" :", props.unknown ? " ( )" : " ( )");
// const response = await axios.delete(`board/${props.comment.commentId}`, {
// data: { LOCCMTSEQ: props.comment.commentId }
// });
// console.log("📌 :", response.data);
// if (response.data.code === 200) {
// console.log(" !");
// // emit("commentDeleted", props.comment.commentId);
// } else {
// console.log(" :", response.data.message);
// // alert(" .");
// }
// } catch (error) {
// console.log("🚨 :", error);
// alert(" .");
// }
// }; // };
//
const submitPassword = async () => {
if (!password.value) {
passwordAlert.value = "비밀번호를 입력해주세요.";
return;
}
console.log(props.comment.commentId)
try {
const response = await axios.post(`board/${props.comment.commentId}/password`, {
LOCCMTPWD: password.value,
LOCCMTSEQ: 288,
});
console.log("응답!!!!!!!!", response); //
console.log("응답 데이터:", response.data);
if (response.data.code === 200 && response.data.data === true) {
console.log('되는거니')
// deleteComment()
// // password.value = '';
// // isPassword.value = false;
// // isEditTextarea.value = true;
} else {
passwordAlert.value = "비밀번호가 일치하지 않습니다.";
}
} catch (error) {
passwordAlert.value = "비밀번호 검증 중 오류가 발생했습니다.";
}
};
const editedContent = ref(props.comment.content);
//
const cancelEdit = () => {
isEditTextarea.value = false;
};
//
const submitEdit = () => {
emit('submitComment', { commentId: props.comment.commentId, content: editedContent.value });
isEditTextarea.value = false; //
};
</script> </script>

View File

@ -8,13 +8,16 @@
<BoardComment <BoardComment
:unknown="unknown" :unknown="unknown"
:comment="comment" :comment="comment"
:isPassword="isPassword" :isCommentPassword="comment.isCommentPassword"
:isEditTextarea="isEditTextarea" :isEditTextarea="comment.isEditTextarea"
@editClick="editClick" :passwordAlert="passwordAlert"
@deleteClick="deleteClick" @editClick="$emit('editClick', comment)"
@deleteClick="$emit('deleteClick', comment)"
@submitPassword="submitPassword" @submitPassword="submitPassword"
@submitComment="submitComment" @submitComment="submitComment"
@commentDeleted="handleCommentDeleted" @commentDeleted="handleCommentDeleted"
@submitEdit="$emit('submitEdit', comment, editedContent)"
@cancelEdit="$emit('cancelEdit', comment)"
@updateReaction="(reactionData) => handleUpdateReaction(reactionData, comment.commentId, comment.boardId)" @updateReaction="(reactionData) => handleUpdateReaction(reactionData, comment.commentId, comment.boardId)"
/> />
</li> </li>
@ -35,17 +38,21 @@ const props = defineProps({
type: Boolean, type: Boolean,
default: true, default: true,
}, },
isPassword: { isCommentPassword: {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
isEditTextarea: { isEditTextarea: {
type: Boolean, type: Boolean,
default: false, default: false,
},
passwordAlert: {
type: String,
default: false
} }
}); });
const emit = defineEmits(['submitComment', 'updateReaction', 'editClick']); const emit = defineEmits(['submitComment', 'updateReaction', 'editClick', 'submitPassword']);
const submitComment = (replyData) => { const submitComment = (replyData) => {
emit('submitComment', replyData); emit('submitComment', replyData);
@ -65,4 +72,9 @@ const editClick = (data) => {
emit('editClick', data); emit('editClick', data);
}; };
const submitPassword = (comment, password) => {
// console.log("BoardCommentList.vue - :", password, " :", comment);
emit('submitPassword', comment, password);
};
</script> </script>

View File

@ -98,9 +98,17 @@
<BoardCommentList <BoardCommentList
:unknown="unknown" :unknown="unknown"
:comments="comments" :comments="comments"
:isCommentPassword="isCommentPassword"
:isEditTextarea="isEditTextarea"
:passwordAlert="passwordAlert"
@editClick="editComment"
@deleteClick="deleteComment"
@updateReaction="handleCommentReaction" @updateReaction="handleCommentReaction"
@submitComment="handleCommentReply" @submitComment="handleCommentReply"
@submitPassword="submitCommentPassword"
@commentDeleted="handleCommentDeleted" @commentDeleted="handleCommentDeleted"
@cancelEdit="handleCancelEdit"
@submitEdit="handleSubmitEdit"
/> />
<Pagination <Pagination
v-if="pagination.pages" v-if="pagination.pages"
@ -150,8 +158,12 @@ const isAuthor = computed(() => currentUserId.value === authorId.value);
const password = ref(''); const password = ref('');
const passwordAlert = ref(""); const passwordAlert = ref("");
const passwordCommentAlert = ref("");
const isPassword = ref(false); const isPassword = ref(false);
const isCommentPassword = ref(false);
const lastClickedButton = ref(""); const lastClickedButton = ref("");
const lastCommentClickedButton = ref("");
const isEditTextarea = ref(false);
const pagination = ref({ const pagination = ref({
currentPage: 1, currentPage: 1,
@ -274,7 +286,9 @@ const fetchComments = async (page = 1) => {
dislikeClicked: comment.dislikeClicked || false, dislikeClicked: comment.dislikeClicked || false,
createdAtRaw: new Date(comment.LOCCMTRDT), // createdAtRaw: new Date(comment.LOCCMTRDT), //
createdAt: formattedDate(comment.LOCCMTRDT), // createdAt: formattedDate(comment.LOCCMTRDT), //
children: [] // children: [], //
// isCommentPassword: false, //
// isEditTextarea: false //
})); }));
for (const comment of commentsList) { for (const comment of commentsList) {
@ -406,6 +420,7 @@ const handleCommentReply = async (reply) => {
} }
} }
//
const editClick = (unknown) => { const editClick = (unknown) => {
if (unknown) { if (unknown) {
togglePassword("edit"); togglePassword("edit");
@ -414,6 +429,7 @@ const editClick = (unknown) => {
} }
}; };
//
const deleteClick = (unknown) => { const deleteClick = (unknown) => {
if (unknown) { if (unknown) {
togglePassword("delete"); togglePassword("delete");
@ -422,6 +438,49 @@ const deleteClick = (unknown) => {
} }
}; };
//
const editComment = (comment) => {
if (unknown.value) {
toggleCommentPassword(comment, "edit");
} else {
comment.isEditTextarea = true;
}
// comments.value.forEach(c => {
// c.isEditTextarea = false;
// c.isCommentPassword = false;
// });
// if (comment.unknown) {
// comment.isCommentPassword = true;
// } else {
// comment.isEditTextarea = true;
// }
}
//
const deleteComment = (comment) => {
if (unknown.value) {
toggleCommentPassword(comment, "delete");
} else {
comments.value = comments.value.filter(c => c.commentId !== comment.commentId);
}
};
const toggleCommentPassword = (comment, button) => {
if (lastCommentClickedButton.value === button && comment.isCommentPassword) {
comment.isCommentPassword = false;
} else {
//
comments.value.forEach(c => (c.isCommentPassword = false));
//
comment.isCommentPassword = true;
}
lastCommentClickedButton.value = button;
};
const togglePassword = (button) => { const togglePassword = (button) => {
if (lastClickedButton.value === button) { if (lastClickedButton.value === button) {
isPassword.value = !isPassword.value; isPassword.value = !isPassword.value;
@ -431,7 +490,7 @@ const togglePassword = (button) => {
lastClickedButton.value = button; lastClickedButton.value = button;
}; };
//
const submitPassword = async () => { const submitPassword = async () => {
if (!password.value) { if (!password.value) {
passwordAlert.value = "비밀번호를 입력해주세요."; passwordAlert.value = "비밀번호를 입력해주세요.";
@ -457,7 +516,7 @@ const submitPassword = async () => {
} }
lastClickedButton.value = null; lastClickedButton.value = null;
} else { } else {
passwordAlert.value = "비밀번호가 일치하지 않습니다.????"; passwordAlert.value = "비밀번호가 일치하지 않습니다.";
} }
} catch (error) { } catch (error) {
// console.log("📌 :", error); // console.log("📌 :", error);
@ -476,6 +535,42 @@ const submitPassword = async () => {
} }
}; };
//
const submitCommentPassword = async (comment, password) => {
console.log("BoardView.vue - 최종 비밀번호 전달 확인:", password, "댓글 정보:", comment);
if (!password) {
passwordAlert.value = "비밀번호를 입력해주세요.";
return;
}
console.log('코멘트아이디:', comment.commentId, '비번:', password)
comment.isEditTextarea = true;
//
try {
const response = await axios.post(`board/comment/${comment.commentId}/password`, {
LOCCMTPWD: password,
LOCCMTSEQ: comment.commentId,
});
console.log("응답!!!!!!!!", response); //
console.log("응답 데이터:", response.data);
if (response.data.code === 200 && response.data.data === true) {
console.log('되는거니')
// deleteComment()
// // password.value = '';
// // isPassword.value = false;
// // isEditTextarea.value = true;
} else {
passwordAlert.value = "비밀번호가 일치하지 않습니다.";
}
} catch (error) {
passwordAlert.value = "비밀번호 검증 중 오류가 발생했습니다.";
}
};
//
const deletePost = async () => { const deletePost = async () => {
if (confirm("정말 삭제하시겠습니까?")) { if (confirm("정말 삭제하시겠습니까?")) {
try { try {
@ -499,6 +594,65 @@ const deletePost = async () => {
} }
}; };
//
// const deleteComment = async () => {
// if (!confirm(" ?")) return;
// try {
// console.log(" :");
// console.log(" ID:", props.comment.commentId);
// console.log(" ID:", props.comment.boardId);
// console.log(" :", props.unknown ? " ( )" : " ( )");
// const response = await axios.delete(`board/${props.comment.commentId}`, {
// data: { LOCCMTSEQ: props.comment.commentId }
// });
// console.log("📌 :", response.data);
// if (response.data.code === 200) {
// console.log(" !");
// // emit("commentDeleted", props.comment.commentId);
// } else {
// console.log(" :", response.data.message);
// // alert(" .");
// }
// } catch (error) {
// console.log("🚨 :", error);
// alert(" .");
// }
// };
//
const handleCancelEdit = (comment) => {
console.log("BoardView.vue - 댓글 수정 취소:", comment);
comment.isEditTextarea = false;
};
//
const handleSubmitEdit = async (comment, editedContent) => {
console.log("BoardView.vue - 댓글 수정:", comment, "수정된 내용:", editedContent);
// editedContent = ref(props.comment.content)
try {
await axios.put(`board/comment/${comment.commentId}/edit`, {
LOCCMTSEQ: comment.commentId,
LOCCMTRPY: editedContent
});
//
comment.content = editedContent;
comment.isEditTextarea = false;
} catch (error) {
console.error("댓글 수정 중 오류 발생:", error);
}
};
// const submitEdit = () => {
// emit('submitComment', { commentId: props.comment.commentId, content: editedContent.value });
// isEditTextarea.value = false; //
// };
// //
const handlePageChange = (page) => { const handlePageChange = (page) => {
if (page !== pagination.value.currentPage) { if (page !== pagination.value.currentPage) {