메인 비밀번호 입력창

This commit is contained in:
kimdaae328 2025-02-20 12:09:42 +09:00
parent 5ece56e31d
commit 5c88ea3115
2 changed files with 79 additions and 119 deletions

View File

@ -34,20 +34,6 @@
:comment="props.comment" :comment="props.comment"
@updateReaction="handleUpdateReaction" @updateReaction="handleUpdateReaction"
/> />
<!-- 비밀번호 입력창 (익명일 경우) -->
<div v-if="isPassword && unknown" class="mt-3">
<div class="input-group">
<input
type="password"
class="form-control"
v-model="password"
placeholder="비밀번호 입력"
/>
<button class="btn btn-primary" @click="$emit('submitPassword', password)">확인</button>
</div>
<span v-if="props.passwordAlert" class="invalid-feedback d-block text-start">{{ props.passwordAlert }}</span>
</div>
</div> </div>
</div> </div>
</template> </template>
@ -58,9 +44,6 @@ import DeleteButton from '../button/DeleteBtn.vue';
import EditButton from '../button/EditBtn.vue'; import EditButton from '../button/EditBtn.vue';
import BoardRecommendBtn from '../button/BoardRecommendBtn.vue'; import BoardRecommendBtn from '../button/BoardRecommendBtn.vue';
// Vue Router
const password = ref('');
// Props // Props
const props = defineProps({ const props = defineProps({
comment: { comment: {
@ -107,18 +90,10 @@ const props = defineProps({
isLike: { isLike: {
type: Boolean, type: Boolean,
default: false, default: false,
},
isPassword: {
type: Boolean,
default: false,
},
passwordAlert: {
type: String,
default: false,
} }
}); });
const emit = defineEmits(['togglePasswordInput', 'updateReaction', 'editClick', 'deleteClick', 'updatePasswordAlert']); const emit = defineEmits(['updateReaction', 'editClick', 'deleteClick']);
// //
const editClick = () => { const editClick = () => {

View File

@ -5,22 +5,34 @@
<div class="card"> <div class="card">
<!-- 프로필 헤더 --> <!-- 프로필 헤더 -->
<div class="card-header"> <div class="card-header">
<BoardProfile <div class="pb-5 border-bottom">
:boardId="currentBoardId" <BoardProfile
:profileName="profileName" :boardId="currentBoardId"
:unknown="unknown" :profileName="profileName"
:author="isAuthor" :unknown="unknown"
:views="views" :author="isAuthor"
:commentNum="commentNum" :views="views"
:date="formattedBoardDate" :commentNum="commentNum"
:isLike="false" :date="formattedBoardDate"
:isPassword="isPassword" :isLike="false"
:passwordAlert="passwordAlert" @editClick="editClick"
@editClick="editClick" @deleteClick="deleteClick"
@deleteClick="deleteClick" />
@submitPassword="submitPassword"
class="pb-6 border-bottom" <!-- 비밀번호 입력창 (익명일 경우) -->
/> <div v-if="isPassword && unknown" class="mt-3 w-25">
<div class="input-group">
<input
type="password"
class="form-control"
v-model="password"
placeholder="비밀번호 입력"
/>
<button class="btn btn-primary" @click="submitPassword">확인</button>
</div>
<span v-if="passwordAlert" class="invalid-feedback d-block text-start">{{ passwordAlert }}</span>
</div>
</div>
</div> </div>
<!-- 게시글 내용 --> <!-- 게시글 내용 -->
<div class="card-body"> <div class="card-body">
@ -87,10 +99,8 @@
:unknown="unknown" :unknown="unknown"
:comments="comments" :comments="comments"
:isEditTextarea="isEditTextarea" :isEditTextarea="isEditTextarea"
:isPassword="isPassword"
@editClick="editClick" @editClick="editClick"
@deleteClick="deleteClick" @deleteClick="deleteClick"
@submitPassword="submitPassword"
@updateReaction="handleUpdateReaction" @updateReaction="handleUpdateReaction"
@submitComment="handleCommentReply" @submitComment="handleCommentReply"
/> />
@ -141,6 +151,7 @@ const isAuthor = computed(() => currentUserId.value === authorId.value);
const isEditTextarea = ref({}); const isEditTextarea = ref({});
const password = ref('');
const passwordAlert = ref(""); const passwordAlert = ref("");
const isPassword = ref(false); const isPassword = ref(false);
const lastClickedButton = ref(""); const lastClickedButton = ref("");
@ -223,18 +234,20 @@ const handleUpdateReaction = async ({ boardId, commentId, isLike, isDislike }) =
// //
const fetchComments = async (page = 1) => { const fetchComments = async (page = 1) => {
try { try {
const { data } = await axios.get(`board/${currentBoardId.value}/comments`, { const response = await axios.get(`board/${currentBoardId.value}/comments`, {
params: { LOCBRDSEQ: currentBoardId.value, page } params: {
LOCBRDSEQ: currentBoardId.value,
page
}
}); });
const { data: replyData } = await axios.get(`board/${currentBoardId.value}/reply`, { // const replyResponse = await axios.get(`board/${currentBoardId.value}/reply`, {
params: { LOCBRDSEQ: currentBoardId.value } // params: { LOCBRDSEQ: currentBoardId.value }
}); // });
console.log("댓글:", data);
console.log("대댓글:", replyData);
if (!data?.data?.list) return; console.log("댓글:", response.data);
// console.log(":", replyResponse.data);
comments.value = data.data.list.map(comment => ({ comments.value = response.data.data.list.map(comment => ({
commentId: comment.LOCCMTSEQ, // ID commentId: comment.LOCCMTSEQ, // ID
boardId: comment.LOCBRDSEQ, boardId: comment.LOCBRDSEQ,
parentId: comment.LOCCMTPNT, // ID parentId: comment.LOCCMTPNT, // ID
@ -245,59 +258,21 @@ const fetchComments = async (page = 1) => {
children: [] // children: [] //
})); }));
let replies = replyData.data.map(reply => ({
commentId: reply.LOCCMTSEQ, // ID
boardId: reply.LOCBRDSEQ,
parentId: reply.LOCCMTPNT, // ID
author: reply.author || "익명 사용자",
content: reply.LOCCMTRPY,
createdAtRaw: new Date(reply.LOCCMTRDT), //
createdAt: formattedDate(reply.LOCCMTRDT) //
}));
// let commentMap = {};
// let rootComments = [];
//
// allComments.forEach(comment => {
// commentMap[comment.commentId] = comment;
// });
//
// replies.forEach(reply => {
// if (commentMap[reply.parentId]) {
// commentMap[reply.parentId].children.push(reply);
// } else {
// console.warn(" :", reply);
// }
// });
// rootComments = allComments.filter(comment => comment.parentId === 1);
//
// rootComments.sort((a, b) => b.createdAtRaw - a.createdAtRaw);
// rootComments.forEach(comment => {
// comment.children.sort((a, b) => b.createdAtRaw - a.createdAtRaw);
// });
// comments.value = rootComments;
// console.log(" comments :", comments.value);
pagination.value = { pagination.value = {
...pagination.value, ...pagination.value,
currentPage: data.data.pageNum, // currentPage: response.data.data.pageNum, //
pages: data.data.pages, // pages: response.data.data.pages, //
prePage: data.data.prePage, // prePage: response.data.data.prePage, //
nextPage: data.data.nextPage, // nextPage: response.data.data.nextPage, //
isFirstPage: data.data.isFirstPage, // isFirstPage: response.data.data.isFirstPage, //
isLastPage: data.data.isLastPage, // isLastPage: response.data.data.isLastPage, //
hasPreviousPage: data.data.hasPreviousPage, // hasPreviousPage: response.data.data.hasPreviousPage, //
hasNextPage: data.data.hasNextPage, // hasNextPage: response.data.data.hasNextPage, //
navigatePages: data.data.navigatePages, // navigatePages: response.data.data.navigatePages, //
navigatepageNums: data.data.navigatepageNums, // navigatepageNums: response.data.data.navigatepageNums, //
navigateFirstPage: data.data.navigateFirstPage, // navigateFirstPage: response.data.data.navigateFirstPage, //
navigateLastPage: data.data.navigateLastPage // navigateLastPage: response.data.data.navigateLastPage //
}; };
} catch (error) { } catch (error) {
@ -370,24 +345,24 @@ const togglePassword = (button) => {
}; };
const submitPassword = async (inputPassword) => { const submitPassword = async () => {
console.log(inputPassword) if (!password.value) {
if (!inputPassword) {
passwordAlert.value = "비밀번호를 입력해주세요."; passwordAlert.value = "비밀번호를 입력해주세요.";
return; return;
} }
console.log("📌 요청 시작: submitPassword 실행됨");
try { try {
const requestData = { const response = await axios.post(`board/${currentBoardId.value}/password`, {
LOCBRDPWD: inputPassword, LOCBRDPWD: password.value,
LOCBRDSEQ: 288 LOCBRDSEQ: 288, // ID
}; });
const postResponse = await axios.post(`board/${currentBoardId.value}/password`, requestData); if (response.data.code === 200 && response.data.data === true) {
password.value = '';
if (postResponse.data.code === 200 && postResponse.data.data === true) { // passwordAlert.value = "";
isPassword.value = false; isPassword.value = false;
passwordAlert.value = "";
if (lastClickedButton.value === "edit") { if (lastClickedButton.value === "edit") {
router.push({ name: "BoardEdit", params: { id: currentBoardId.value } }); router.push({ name: "BoardEdit", params: { id: currentBoardId.value } });
@ -396,15 +371,25 @@ const submitPassword = async (inputPassword) => {
} }
lastClickedButton.value = null; lastClickedButton.value = null;
} else { } else {
console.log('비밀번호 틀렸음둥')
passwordAlert.value = "비밀번호가 일치하지 않습니다."; passwordAlert.value = "비밀번호가 일치하지 않습니다.";
} }
} catch (error) { } catch (error) {
if (error.response && error.response.status === 401) { if (error.response) {
passwordAlert.value = "비밀번호가 일치하지 않습니다."; console.error("📌 서버 응답 상태 코드:", error.response.status);
} else if (error.response) { console.error("📌 서버 응답 데이터:", error.response.data);
alert(`오류 발생: ${error.response.data.message || "서버 오류"}`);
if (error.response.status === 401) {
passwordAlert.value = "비밀번호가 일치하지 않습니다.";
} else {
passwordAlert.value = error.response.data?.message || "서버 오류가 발생했습니다.";
}
} else if (error.request) {
console.error("📌 요청이 서버에 도달하지 못함:", error.request);
passwordAlert.value = "네트워크 오류가 발생했습니다. 다시 시도해주세요.";
} else { } else {
alert("네트워크 오류가 발생했습니다. 다시 시도해주세요."); console.error("📌 요청 설정 중 오류 발생:", error.message);
passwordAlert.value = "요청 중 알 수 없는 오류가 발생했습니다.";
} }
} }
}; };