댓글과 대댓글 익명으로 저장장
This commit is contained in:
parent
84c43d5baf
commit
99d89008ed
@ -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;
|
||||
};
|
||||
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user