보드프로필 머지
This commit is contained in:
parent
fee7b52384
commit
c8dbd53e3a
@ -21,8 +21,28 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="ms-auto btn-area">
|
<div class="ms-auto btn-area">
|
||||||
<template v-if="showDetail">
|
<template v-if="showDetail">
|
||||||
<EditButton @click="handleEdit" />
|
<div class="text-end">
|
||||||
<DeleteButton @click="handleDelete" />
|
<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>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<template v-if="author">
|
<template v-if="author">
|
||||||
@ -42,7 +62,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, defineProps } from 'vue';
|
import { ref, onMounted, defineProps } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import axios from '@api';
|
import axios from '@api';
|
||||||
import DeleteButton from '../button/DeleteBtn.vue';
|
import DeleteButton from '../button/DeleteBtn.vue';
|
||||||
@ -54,6 +74,10 @@ const router = useRouter();
|
|||||||
|
|
||||||
// Props 정의
|
// Props 정의
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
boardId: {
|
||||||
|
type: Number,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
profileName: {
|
profileName: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '익명',
|
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 = () => {
|
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 () => {
|
const handleDelete = () => {
|
||||||
if (confirm('정말 이 게시물을 삭제하시겠습니까?')) {
|
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 {
|
try {
|
||||||
await axios.delete(`board/${boardId}`);
|
await axios.delete(`board/100`);
|
||||||
alert('게시물이 성공적으로 삭제되었습니다.');
|
alert('게시물이 삭제되었습니다.');
|
||||||
router.push({ name: 'BoardList' });
|
router.push({ name: 'BoardList' });
|
||||||
} catch (error) {
|
} 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>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user