Merge branch 'board_comment5'
This commit is contained in:
commit
5c39cb3dad
44
src/stores/useBoardAccessStore.js
Normal file
44
src/stores/useBoardAccessStore.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
작성자 : 박성용
|
||||||
|
작성일 : 2025-03-14
|
||||||
|
수정자 :
|
||||||
|
수정일 :
|
||||||
|
설명 : 게시글 수정 시 비밀번호 적재용.
|
||||||
|
*/
|
||||||
|
import { ref, computed, watch } from 'vue';
|
||||||
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
|
export const useBoardAccessStore = defineStore(
|
||||||
|
'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) {
|
||||||
|
password.value = input;
|
||||||
|
}
|
||||||
|
|
||||||
|
function $reset() {
|
||||||
|
password.value = '';
|
||||||
|
localStorage.removeItem('tempPassword', newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
password,
|
||||||
|
setBoardPassword,
|
||||||
|
$reset,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{
|
||||||
|
persist: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
@ -85,11 +85,13 @@
|
|||||||
import { ref, onMounted, computed, watch, inject } from 'vue';
|
import { ref, onMounted, computed, watch, inject } from 'vue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import { useToastStore } from '@s/toastStore';
|
import { useToastStore } from '@s/toastStore';
|
||||||
|
import { useBoardAccessStore } from '@s/useBoardAccessStore';
|
||||||
import axios from '@api';
|
import axios from '@api';
|
||||||
|
|
||||||
// 공통
|
// 공통
|
||||||
const $common = inject('common');
|
const $common = inject('common');
|
||||||
const toastStore = useToastStore();
|
const toastStore = useToastStore();
|
||||||
|
const accessStore = useBoardAccessStore();
|
||||||
|
|
||||||
// 상태 변수
|
// 상태 변수
|
||||||
const title = ref('');
|
const title = ref('');
|
||||||
@ -117,22 +119,30 @@
|
|||||||
|
|
||||||
// 게시물 데이터 로드
|
// 게시물 데이터 로드
|
||||||
const fetchBoardDetails = async () => {
|
const fetchBoardDetails = async () => {
|
||||||
try {
|
// 수정 데이터 전송
|
||||||
const response = await axios.get(`board/${currentBoardId.value}`);
|
const password = accessStore.password.value;
|
||||||
const data = response.data.data;
|
const params = {
|
||||||
|
password: password || '',
|
||||||
|
};
|
||||||
|
console.log('params: ', params);
|
||||||
|
//const response = await axios.get(`board/${currentBoardId.value}`);
|
||||||
|
const { data } = await axios.post(`board/${currentBoardId.value}`, params);
|
||||||
|
|
||||||
// 기존 첨부파일 추가
|
if (data.code !== 200) {
|
||||||
if (data.hasAttachment && data.attachments.length > 0) {
|
toastStore.onToast(data.message, 'e');
|
||||||
attachFiles.value = addDisplayFileName([...data.attachments]);
|
router.go(-1);
|
||||||
}
|
return;
|
||||||
|
|
||||||
// 데이터 설정
|
|
||||||
title.value = data.title || '제목 없음';
|
|
||||||
content.value = data.content || '내용 없음';
|
|
||||||
contentLoaded.value = true;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('게시물 가져오기 오류:', error.response || error.message);
|
|
||||||
}
|
}
|
||||||
|
const boardData = data.data;
|
||||||
|
// 기존 첨부파일 추가
|
||||||
|
if (boardData.hasAttachment && boardData.attachments.length > 0) {
|
||||||
|
attachFiles.value = addDisplayFileName([...boardData.attachments]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 데이터 설정
|
||||||
|
title.value = boardData.title || '제목 없음';
|
||||||
|
content.value = boardData.content || '내용 없음';
|
||||||
|
contentLoaded.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 기존 첨부파일명을 노출
|
// 기존 첨부파일명을 노출
|
||||||
@ -254,7 +264,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 컴포넌트 마운트 시 데이터 로드
|
// 컴포넌트 마운트 시 데이터 로드
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
if (currentBoardId.value) {
|
if (currentBoardId.value) {
|
||||||
fetchBoardDetails();
|
fetchBoardDetails();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -139,6 +139,7 @@
|
|||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import { useUserInfoStore } from '@/stores/useUserInfoStore';
|
import { useUserInfoStore } from '@/stores/useUserInfoStore';
|
||||||
import { useToastStore } from '@s/toastStore';
|
import { useToastStore } from '@s/toastStore';
|
||||||
|
import { useBoardAccessStore } from '@s/useBoardAccessStore';
|
||||||
import axios from '@api';
|
import axios from '@api';
|
||||||
|
|
||||||
const $common = inject('common');
|
const $common = inject('common');
|
||||||
@ -161,6 +162,8 @@
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const userStore = useUserInfoStore();
|
const userStore = useUserInfoStore();
|
||||||
const toastStore = useToastStore();
|
const toastStore = useToastStore();
|
||||||
|
const accessStore = useBoardAccessStore();
|
||||||
|
|
||||||
const currentBoardId = ref(Number(route.params.id));
|
const currentBoardId = ref(Number(route.params.id));
|
||||||
const unknown = computed(() => profileName.value === '익명');
|
const unknown = computed(() => profileName.value === '익명');
|
||||||
const currentUserId = computed(() => userStore?.user?.id); // 현재 로그인한 사용자 id
|
const currentUserId = computed(() => userStore?.user?.id); // 현재 로그인한 사용자 id
|
||||||
@ -242,21 +245,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();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 좋아요, 싫어요
|
// 좋아요, 싫어요
|
||||||
@ -609,14 +616,19 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (response.data.code === 200 && response.data.data === true) {
|
if (response.data.code === 200 && response.data.data === true) {
|
||||||
|
accessStore.setBoardPassword(password);
|
||||||
|
console.log('password: ', password.value);
|
||||||
|
console.log('accessStore.password: ', accessStore.password.value);
|
||||||
boardPasswordAlert.value = '';
|
boardPasswordAlert.value = '';
|
||||||
isPassword.value = false;
|
isPassword.value = false;
|
||||||
|
|
||||||
if (lastClickedButton.value === 'edit') {
|
if (lastClickedButton.value === 'edit') {
|
||||||
router.push({ name: 'BoardEdit', params: { id: currentBoardId.value } });
|
router.push({ name: 'BoardEdit', params: { id: currentBoardId.value } });
|
||||||
|
return;
|
||||||
} else if (lastClickedButton.value === 'delete') {
|
} else if (lastClickedButton.value === 'delete') {
|
||||||
await deletePost();
|
await deletePost();
|
||||||
}
|
}
|
||||||
|
accessStore.$reset();
|
||||||
lastClickedButton.value = null;
|
lastClickedButton.value = null;
|
||||||
} else {
|
} else {
|
||||||
boardPasswordAlert.value = '비밀번호가 일치하지 않습니다.';
|
boardPasswordAlert.value = '비밀번호가 일치하지 않습니다.';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user