diff --git a/src/components/board/BoardCommentArea.vue b/src/components/board/BoardCommentArea.vue
index 2ed5141..0a95249 100644
--- a/src/components/board/BoardCommentArea.vue
+++ b/src/components/board/BoardCommentArea.vue
@@ -17,6 +17,7 @@
rows="3"
v-model="comment"
>
+ {{ commentAlert }}
@@ -42,6 +43,7 @@
id="basic-default-password"
class="form-control flex-grow-1"
v-model="password"
+ placeholder="비밀번호 입력"
/>
{{ passwordAlert }}
@@ -74,6 +76,10 @@ const props = defineProps({
passwordAlert: {
type: String,
default: false
+ },
+ commentAlert: {
+ type: String,
+ default: false
}
});
@@ -87,11 +93,16 @@ function handleCommentSubmit() {
emit('submitComment', {
comment: comment.value,
password: isCheck.value ? password.value : '',
+ isCheck: isCheck.value
});
-
- comment.value = '';
- password.value = '';
}
+watch(() => props.passwordAlert, () => {
+ if (!props.passwordAlert) {
+ comment.value = '';
+ password.value = '';
+ }
+});
+
diff --git a/src/components/board/BoardProfile.vue b/src/components/board/BoardProfile.vue
index 2c280f5..7e337f0 100644
--- a/src/components/board/BoardProfile.vue
+++ b/src/components/board/BoardProfile.vue
@@ -21,9 +21,8 @@
-
-
-
+
+
@@ -101,12 +100,12 @@ const emit = defineEmits(['updateReaction', 'editClick', 'deleteClick']);
// 수정
const editClick = () => {
- emit('editClick', props.comment);
+ emit('editClick', { ...props.comment, unknown: props.unknown });
};
// 삭제
const deleteClick = () => {
- emit('deleteClick', props.comment);
+ emit('deleteClick', { ...props.comment, unknown: props.unknown });
};
const handleUpdateReaction = (reactionData) => {
diff --git a/src/views/board/BoardView.vue b/src/views/board/BoardView.vue
index 13aed30..035c9ec 100644
--- a/src/views/board/BoardView.vue
+++ b/src/views/board/BoardView.vue
@@ -94,6 +94,7 @@
@@ -185,6 +186,7 @@ const isCommentPassword = ref(false);
const lastClickedButton = ref("");
const lastCommentClickedButton = ref("");
const isEditTextarea = ref(false);
+const commentAlert = ref('')
const pagination = ref({
currentPage: 1,
@@ -208,7 +210,7 @@ const fetchBoardDetails = async () => {
const response = await axios.get(`board/${currentBoardId.value}`);
const data = response.data.data;
- console.log(data)
+ // console.log(data)
// API 응답 데이터 반영
// const boardDetail = data.boardDetail || {};
@@ -218,6 +220,9 @@ const fetchBoardDetails = async () => {
// 익명확인하고 싶을때
// profileName.value = '익명';
+ console.log("📌 게시글 작성자:", profileName.value); // 작성자 이름 출력
+ console.log("🔍 익명 여부 (unknown.value):", unknown.value); // 익명 여부 확인
+
authorId.value = data.authorId; //게시글 작성자 id
boardTitle.value = data.title || '제목 없음';
@@ -368,33 +373,37 @@ const fetchComments = async (page = 1) => {
console.log('댓글 목록 불러오기 오류:', error);
}
};
-// const isSubmitting = ref(false);
// 댓글 작성
-const handleCommentSubmit = async ({ comment, password }) => {
- // console.log('댓글')
+const handleCommentSubmit = async ({ comment, password, isCheck }) => {
+
+ // 댓글이 비어 있으면 에러 메시지 출력
+ if (comment.trim() === "") {
+ commentAlert.value = '댓글을 입력해주세요.';
+ return;
+ } else {
+ commentAlert.value = '';
+ }
+
//비밀번호 입력 안했을시
- if (unknown && !password) {
+ if (unknown.value && isCheck && !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,
+ LOCCMTPWD: isCheck ? password : '', // 익명 체크된 경우만 비밀번호 포함
LOCCMTPNT: 1
});
+ console.log('여기',response)
if (response.status === 200) {
console.log('댓글 작성 성공:', response.data.message);
+ passwordAlert.value = '';
+ commentAlert.value = '';
await fetchComments();
} else {
console.log('댓글 작성 실패:', response.data.message);
@@ -408,13 +417,6 @@ const handleCommentSubmit = async ({ comment, password }) => {
// 대댓글 추가 (부모 `BoardCommentList`로부터 이벤트 받아서 처리)
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,
@@ -422,13 +424,6 @@ const handleCommentReply = async (reply) => {
LOCCMTPNT: reply.parentId
});
- // 응답 데이터를 자세히 로그로 확인
- // console.log('대댓글 작성 응답:', {
- // status: response.status,
- // data: response.data,
- // headers: response.headers
- // });
-
if (response.status === 200) {
if (response.data.code === 200) { // 서버 응답 코드도 확인
console.log('대댓글 작성 성공:', response.data);
@@ -449,7 +444,9 @@ const handleCommentReply = async (reply) => {
// 게시글 수정 버튼 클릭
const editClick = (unknown) => {
- if (unknown) {
+ const isUnknown = unknown?.unknown ?? false;
+
+ if (isUnknown) {
togglePassword("edit");
} else {
router.push({ name: "BoardEdit", params: { id: currentBoardId.value } });
@@ -480,7 +477,7 @@ const findCommentById = (commentId, commentsList) => {
// 댓글 수정 버튼 클릭
const editComment = (comment) => {
- // console.log('대댓글 수정 버튼 클릭')
+ console.log('대댓글 수정 버튼 클릭')
// 부모 또는 대댓글을 찾아서 가져오기
const targetComment = findCommentById(comment.commentId, comments.value);
@@ -501,8 +498,14 @@ const editComment = (comment) => {
// 댓글 삭제 버튼 클릭
const deleteComment = async (comment) => {
+ console.log('🗑 댓글 삭제 시도:', comment);
+
// 익명 사용자인 경우
- if (unknown.value) {
+ const isMyComment = comment.authorId === currentUserId.value;
+
+ if (unknown.value && !isMyComment) {
+ console.log('🛑 익명 사용자의 댓글 삭제 시도 (비밀번호 필요)');
+
if (comment.isEditTextarea) {
// 현재 수정 중이라면 수정 모드를 끄고, 삭제 비밀번호 입력창을 띄움
comment.isEditTextarea = false;
@@ -512,8 +515,8 @@ const deleteComment = async (comment) => {
toggleCommentPassword(comment, "delete");
}
} else {
- // 로그인 사용자인 경우 (바로 삭제)
- deleteReplyComment(comment)
+ console.log('✅ 로그인 사용자 댓글 삭제 진행');
+ deleteReplyComment(comment);
}
};