보드프로필 머지

This commit is contained in:
dyhj625 2025-02-10 14:02:27 +09:00
parent fee7b52384
commit c8dbd53e3a

View File

@ -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>