This commit is contained in:
dyhj625 2025-02-25 10:13:29 +09:00
parent 99d89008ed
commit a2da67b043
3 changed files with 51 additions and 116 deletions

View File

@ -124,8 +124,7 @@ const toggleComment = () => {
// //
const submitComment = (newComment) => { const submitComment = (newComment) => {
console.log(newComment) emit('submitComment', { parentId: props.comment.commentId, ...newComment });
emit('submitComment', { parentId: props.comment.commentId, ...newComment, LOCBRDTYP: newComment.LOCBRDTYP });
isComment.value = false; isComment.value = false;
}; };

View File

@ -23,7 +23,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="unknown" 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"
@ -35,7 +35,7 @@
</div> </div>
<!-- 비밀번호 입력 필드 (익명이 선택된 경우에만 표시) --> <!-- 비밀번호 입력 필드 (익명이 선택된 경우에만 표시) -->
<div v-if="unknown && isCheck" class="d-flex align-items-center flex-grow-1"> <div v-if="isCheck" class="d-flex align-items-center flex-grow-1">
<label class="form-label mb-0 me-3" for="basic-default-password">비밀번호</label> <label class="form-label mb-0 me-3" for="basic-default-password">비밀번호</label>
<input <input
type="password" type="password"
@ -50,6 +50,7 @@
<!-- 답변 쓰기 버튼 --> <!-- 답변 쓰기 버튼 -->
<div class="ms-auto mt-3 mt-md-0"> <div class="ms-auto mt-3 mt-md-0">
<button class="btn btn-primary" @click="handleCommentSubmit"> <button class="btn btn-primary" @click="handleCommentSubmit">
<!-- <i class="icon-base bx bx-check"></i> -->
확인 확인
</button> </button>
</div> </div>
@ -59,7 +60,7 @@
</template> </template>
<script setup> <script setup>
import { ref, defineEmits, defineProps } from 'vue'; import { ref, defineEmits, defineProps, computed, watch } from 'vue';
const props = defineProps({ const props = defineProps({
unknown: { unknown: {
@ -78,24 +79,23 @@ const props = defineProps({
const comment = ref(''); const comment = ref('');
const password = ref(''); const password = ref('');
const isCheck = ref(false); const isCheck = ref(props.unknown);
const emit = defineEmits(['submitComment']); const emit = defineEmits(['submitComment']);
watch(() => props.unknown, (newVal) => {
isCheck.value = newVal;
});
function handleCommentSubmit() { function handleCommentSubmit() {
if (props.unknown && isCheck.value && !password.value) {
alert('익명 댓글을 작성하려면 비밀번호를 입력해야 합니다.');
return;
}
const LOCBRDTYP = isCheck.value ? '300102' : null;
emit('submitComment', { emit('submitComment', {
comment: comment.value, comment: comment.value,
password: isCheck.value ? password.value : '', password: isCheck.value ? password.value : '',
LOCBRDTYP, // '300102'
isCheck: isCheck.value
}); });
comment.value = ''; comment.value = '';
password.value = ''; password.value = '';
isCheck.value = false; //
} }
</script> </script>

View File

@ -366,17 +366,26 @@ const fetchComments = async (page = 1) => {
// const isSubmitting = ref(false); // const isSubmitting = ref(false);
// //
const handleCommentSubmit = async (data) => { const handleCommentSubmit = async ({ comment, password }) => {
const { comment, password } = data; console.log('댓글')
const LOCBRDTYP = data.LOCBRDTYP || null; // undefined //
// if (!password) {
// passwordAlert.value = " .";
// return;
// }
// console.log(' ')
//
// if (isSubmitting.value) return;
// isSubmitting.value = true;
try { try {
const response = await axios.post(`board/${currentBoardId.value}/comment`, { const response = await axios.post(`board/${currentBoardId.value}/comment`, {
LOCBRDSEQ: currentBoardId.value, LOCBRDSEQ: currentBoardId.value,
LOCCMTRPY: comment, LOCCMTRPY: comment,
LOCCMTPWD: password, LOCCMTPWD: password,
LOCCMTPNT: 1, LOCCMTPNT: 1
LOCBRDTYP //
}); });
if (response.status === 200) { if (response.status === 200) {
@ -390,121 +399,48 @@ const handleCommentSubmit = async (data) => {
} }
}; };
// 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` ) // ( `BoardCommentList` )
const handleCommentReply = async (reply) => { const handleCommentReply = async (reply) => {
try { try {
// ( LOCBRDTYP 300102 ) // console.log(' :', {
// LOCBRDSEQ: currentBoardId.value,
// LOCCMTRPY: reply.comment,
// LOCCMTPWD: reply.password || null,
// LOCCMTPNT: reply.parentId
// });
const requestBody = { const response = await axios.post(`board/${currentBoardId.value}/comment`, {
LOCBRDSEQ: currentBoardId.value, LOCBRDSEQ: currentBoardId.value,
LOCCMTRPY: reply.comment, LOCCMTRPY: reply.comment,
LOCCMTPWD: reply.password || null, LOCCMTPWD: reply.password || null,
LOCCMTPNT: reply.parentId, LOCCMTPNT: reply.parentId
LOCBRDTYP: reply.isCheck ? "300102" : null });
};
console.log(requestBody) //
const response = await axios.post(`board/${currentBoardId.value}/comment`, requestBody); // console.log(' :', {
// status: response.status,
// data: response.data,
// headers: response.headers
// });
if (response.status === 200) { if (response.status === 200) {
if (response.data.code === 200) { if (response.data.code === 200) { //
console.log('✅ 대댓글 작성 성공:', response.data); console.log('대댓글 작성 성공:', response.data);
await fetchComments(); await fetchComments(); //
} else { } else {
console.log('대댓글 작성 실패 - 서버 응답:', response.data); console.log('대댓글 작성 실패 - 서버 응답:', response.data);
alert('대댓글 작성에 실패했습니다.'); alert('대댓글 작성에 실패했습니다.');
} }
} }
} catch (error) { } catch (error) {
console.error('🚨 대댓글 작성 중 오류 발생:', error); console.error('대댓글 작성 중 오류 발생:', error);
if (error.response) { 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) => { const editClick = (unknown) => {