수정화면 비밀번호 확인 로직 추가

This commit is contained in:
nevermoregb 2025-03-17 09:13:25 +09:00
parent 74be397b5d
commit 277524c0c3
3 changed files with 74 additions and 54 deletions

View File

@ -5,18 +5,31 @@
수정일 : 수정일 :
설명 : 게시글 수정 비밀번호 적재용. 설명 : 게시글 수정 비밀번호 적재용.
*/ */
import { ref, computed } from 'vue'; import { ref, computed, watch } from 'vue';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
export const useBoardAccessStore = defineStore('access', () => { export const useBoardAccessStore = defineStore(
const password = ref(null); 'access',
() => {
const password = ref('');
if (localStorage.getItem('tempPassword')) {
// 저장된 값을 불러와 상태에 할당
const storedState = JSON.parse(localStorage.getItem('tempPassword'));
password.value = storedState;
}
watch(password, newValue => {
localStorage.setItem('tempPassword', JSON.stringify(newValue.value));
});
function setBoardPassword(input) { function setBoardPassword(input) {
password.value = input; password.value = input;
} }
function $reset() { function $reset() {
password.value = null; password.value = '';
localStorage.removeItem('tempPassword', newValue);
} }
return { return {
@ -24,4 +37,8 @@ export const useBoardAccessStore = defineStore('access', () => {
setBoardPassword, setBoardPassword,
$reset, $reset,
}; };
}); },
{
persist: true,
},
);

View File

@ -119,31 +119,30 @@
// //
const fetchBoardDetails = async () => { const fetchBoardDetails = async () => {
try {
// //
const password = accessStore.password.value;
const params = { const params = {
password: accessStore.password?.value || '', password: password || '',
}; };
console.log('params: ', params);
//const response = await axios.get(`board/${currentBoardId.value}`); //const response = await axios.get(`board/${currentBoardId.value}`);
const response = await axios.post(`board/${currentBoardId.value}`, params); const { data } = await axios.post(`board/${currentBoardId.value}`, params);
if (response.data.code !== 200) { if (data.code !== 200) {
toastStore.onToast(response.data.message, 'e'); toastStore.onToast(data.message, 'e');
router.go(-1); router.go(-1);
return;
} }
const data = response.data.data; const boardData = data.data;
// //
if (data.hasAttachment && data.attachments.length > 0) { if (boardData.hasAttachment && boardData.attachments.length > 0) {
attachFiles.value = addDisplayFileName([...data.attachments]); attachFiles.value = addDisplayFileName([...boardData.attachments]);
} }
// //
title.value = data.title || '제목 없음'; title.value = boardData.title || '제목 없음';
content.value = data.content || '내용 없음'; content.value = boardData.content || '내용 없음';
contentLoaded.value = true; contentLoaded.value = true;
} catch (error) {
console.error('게시물 가져오기 오류:', error.response || error.message);
}
}; };
// //
@ -265,7 +264,7 @@
}; };
// //
onMounted(() => { onMounted(async () => {
if (currentBoardId.value) { if (currentBoardId.value) {
fetchBoardDetails(); fetchBoardDetails();
} else { } else {

View File

@ -240,21 +240,25 @@
}; };
// //
const fetchBoardDetails = async () => { const fetchBoardDetails = async () => {
const response = await axios.get(`board/${currentBoardId.value}`); const { data } = await axios.get(`board/${currentBoardId.value}`);
const data = response.data.data; if (data?.data) {
const boardData = data.data;
profileName.value = data.author || '익명'; profileName.value = boardData.author || '익명';
authorId.value = data.authorId; authorId.value = boardData.authorId;
boardTitle.value = data.title || '제목 없음'; boardTitle.value = boardData.title || '제목 없음';
boardContent.value = data.content || ''; boardContent.value = boardData.content || '';
profileImg.value = data.profileImg || ''; profileImg.value = boardData.profileImg || '';
date.value = data.date || ''; date.value = boardData.date || '';
views.value = data.cnt || 0; views.value = boardData.cnt || 0;
likes.value = data.likeCount || 0; likes.value = boardData.likeCount || 0;
dislikes.value = data.dislikeCount || 0; dislikes.value = boardData.dislikeCount || 0;
attachment.value = data.hasAttachment || null; attachment.value = boardData.hasAttachment || null;
commentNum.value = data.commentCount || 0; commentNum.value = boardData.commentCount || 0;
attachments.value = data.attachments || []; attachments.value = boardData.attachments || [];
} else {
toastStore.onToast(data.message, 'e');
router.back();
}
}; };
// , // ,