보드프로필 머지
This commit is contained in:
parent
fee7b52384
commit
c8dbd53e3a
@ -21,8 +21,28 @@
|
||||
</div>
|
||||
<div class="ms-auto btn-area">
|
||||
<template v-if="showDetail">
|
||||
<EditButton @click="handleEdit" />
|
||||
<DeleteButton @click="handleDelete" />
|
||||
<div class="text-end">
|
||||
<EditButton @click="handleEdit" />
|
||||
<DeleteButton @click="handleDelete" />
|
||||
|
||||
<div class="input-group mt-3" v-if="isPassword && unknown">
|
||||
<input
|
||||
type="password"
|
||||
v-model="password"
|
||||
class="form-control"
|
||||
placeholder="비밀번호 입력"
|
||||
/>
|
||||
<!-- <input
|
||||
type="password"
|
||||
class="form-control"
|
||||
placeholder="비밀번호 입력"
|
||||
:is-alert="idAlert"
|
||||
@update:data="handleIdChange"
|
||||
:value="id"
|
||||
/> -->
|
||||
<button class="btn btn-primary" type="button" @click="handlePasswordSubmit">확인</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<template v-if="author">
|
||||
@ -42,7 +62,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, defineProps } from 'vue';
|
||||
import { ref, onMounted, defineProps } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import axios from '@api';
|
||||
import DeleteButton from '../button/DeleteBtn.vue';
|
||||
@ -54,6 +74,10 @@ const router = useRouter();
|
||||
|
||||
// Props 정의
|
||||
const props = defineProps({
|
||||
boardId: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
profileName: {
|
||||
type: String,
|
||||
default: '익명',
|
||||
@ -88,26 +112,82 @@ const props = defineProps({
|
||||
}
|
||||
});
|
||||
|
||||
const boardId = 100; //수정필요!!
|
||||
// 수정 버튼 핸들러
|
||||
const isPassword = ref(false);
|
||||
const password = ref('');
|
||||
const lastClickedButton = ref('');
|
||||
|
||||
const boardId = 100; //수정필요!
|
||||
|
||||
const emit = defineEmits(['togglePasswordInput']);
|
||||
|
||||
// 수정 버튼
|
||||
const handleEdit = () => {
|
||||
router.push({ name: 'BoardEdit', params: { id: boardId } });
|
||||
// router.push({ name: 'BoardEdit', params: { id: boardId } });
|
||||
|
||||
if (props.unknown) {
|
||||
togglePassword('edit');
|
||||
} else {
|
||||
router.push({ name: 'BoardEdit', params: { id: 100 } }); // 로그인한 경우 바로 편집
|
||||
}
|
||||
};
|
||||
|
||||
// 삭제 버튼 핸들러
|
||||
const handleDelete = async () => {
|
||||
if (confirm('정말 이 게시물을 삭제하시겠습니까?')) {
|
||||
// 삭제 버튼
|
||||
const handleDelete = () => {
|
||||
if (props.unknown) {
|
||||
togglePassword('delete');
|
||||
} else {
|
||||
deletePost(); // 로그인한 경우 바로 삭제
|
||||
}
|
||||
};
|
||||
|
||||
// 비밀번호 입력 토글
|
||||
const togglePassword = (button) => {
|
||||
if (lastClickedButton.value === button) {
|
||||
isPassword.value = !isPassword.value;
|
||||
} else {
|
||||
isPassword.value = true;
|
||||
}
|
||||
lastClickedButton.value = button;
|
||||
};
|
||||
|
||||
// 비밀번호 확인
|
||||
const handlePasswordSubmit = () => {
|
||||
isPassword.value = false;
|
||||
lastClickedButton.value = null;
|
||||
|
||||
console.log('비밀번호:', password.value);
|
||||
|
||||
|
||||
|
||||
|
||||
// router.push({ name: 'BoardEdit', params: { id: props.boardId } }); // 편집 예시
|
||||
};
|
||||
|
||||
const deletePost = async () => {
|
||||
if (confirm('정말 삭제하시겠습니까?')) {
|
||||
try {
|
||||
await axios.delete(`board/${boardId}`);
|
||||
alert('게시물이 성공적으로 삭제되었습니다.');
|
||||
await axios.delete(`board/100`);
|
||||
alert('게시물이 삭제되었습니다.');
|
||||
router.push({ name: 'BoardList' });
|
||||
} catch (error) {
|
||||
console.error('게시물 삭제 중 오류 발생:', error);
|
||||
alert('게시물 삭제에 실패했습니다.');
|
||||
alert('삭제 중 오류 발생');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// const fetchBoardDetails = async () => {
|
||||
// try {
|
||||
// const response = await axios.get(`board/${props.boardId}`);
|
||||
// console.log(response.data);
|
||||
// } catch (error) {
|
||||
// console.error('게시물 데이터 불러오기 오류:', error);
|
||||
// }
|
||||
// };
|
||||
|
||||
// onMounted(() => {
|
||||
// // fetchBoardDetails();
|
||||
// });
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user