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

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

@ -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;
};

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

@ -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) => {