123
This commit is contained in:
parent
f761e3e15e
commit
74be397b5d
27
src/stores/useBoardAccessStore.js
Normal file
27
src/stores/useBoardAccessStore.js
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
작성자 : 박성용
|
||||
작성일 : 2025-03-14
|
||||
수정자 :
|
||||
수정일 :
|
||||
설명 : 게시글 수정 시 비밀번호 적재용.
|
||||
*/
|
||||
import { ref, computed } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
export const useBoardAccessStore = defineStore('access', () => {
|
||||
const password = ref(null);
|
||||
|
||||
function setBoardPassword(input) {
|
||||
password.value = input;
|
||||
}
|
||||
|
||||
function $reset() {
|
||||
password.value = null;
|
||||
}
|
||||
|
||||
return {
|
||||
password,
|
||||
setBoardPassword,
|
||||
$reset,
|
||||
};
|
||||
});
|
||||
@ -85,11 +85,13 @@
|
||||
import { ref, onMounted, computed, watch, inject } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useToastStore } from '@s/toastStore';
|
||||
import { useBoardAccessStore } from '@s/useBoardAccessStore';
|
||||
import axios from '@api';
|
||||
|
||||
// 공통
|
||||
const $common = inject('common');
|
||||
const toastStore = useToastStore();
|
||||
const accessStore = useBoardAccessStore();
|
||||
|
||||
// 상태 변수
|
||||
const title = ref('');
|
||||
@ -118,9 +120,18 @@
|
||||
// 게시물 데이터 로드
|
||||
const fetchBoardDetails = async () => {
|
||||
try {
|
||||
const response = await axios.get(`board/${currentBoardId.value}`);
|
||||
const data = response.data.data;
|
||||
// 수정 데이터 전송
|
||||
const params = {
|
||||
password: accessStore.password?.value || '',
|
||||
};
|
||||
//const response = await axios.get(`board/${currentBoardId.value}`);
|
||||
const response = await axios.post(`board/${currentBoardId.value}`, params);
|
||||
|
||||
if (response.data.code !== 200) {
|
||||
toastStore.onToast(response.data.message, 'e');
|
||||
router.go(-1);
|
||||
}
|
||||
const data = response.data.data;
|
||||
// 기존 첨부파일 추가
|
||||
if (data.hasAttachment && data.attachments.length > 0) {
|
||||
attachFiles.value = addDisplayFileName([...data.attachments]);
|
||||
|
||||
@ -137,7 +137,9 @@
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useUserInfoStore } from '@/stores/useUserInfoStore';
|
||||
import { useToastStore } from '@s/toastStore';
|
||||
import { useBoardAccessStore } from '@s/useBoardAccessStore';
|
||||
import axios from '@api';
|
||||
|
||||
// 게시물 데이터 상태
|
||||
const profileName = ref('');
|
||||
const boardTitle = ref('제목 없음');
|
||||
@ -157,6 +159,8 @@
|
||||
const router = useRouter();
|
||||
const userStore = useUserInfoStore();
|
||||
const toastStore = useToastStore();
|
||||
const accessStore = useBoardAccessStore();
|
||||
|
||||
const currentBoardId = ref(Number(route.params.id));
|
||||
const unknown = computed(() => profileName.value === '익명');
|
||||
const currentUserId = computed(() => userStore?.user?.id); // 현재 로그인한 사용자 id
|
||||
@ -598,14 +602,19 @@
|
||||
});
|
||||
|
||||
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 = '';
|
||||
isPassword.value = false;
|
||||
|
||||
if (lastClickedButton.value === 'edit') {
|
||||
router.push({ name: 'BoardEdit', params: { id: currentBoardId.value } });
|
||||
return;
|
||||
} else if (lastClickedButton.value === 'delete') {
|
||||
await deletePost();
|
||||
}
|
||||
accessStore.$reset();
|
||||
lastClickedButton.value = null;
|
||||
} else {
|
||||
boardPasswordAlert.value = '비밀번호가 일치하지 않습니다.';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user