From 60069ecaae7881c9b30e16fb8654fe5df40810be Mon Sep 17 00:00:00 2001 From: nevermoregb Date: Mon, 17 Mar 2025 10:29:02 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B2=8C=EC=8B=9C=ED=8C=90=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=B9=84=EB=B0=80?= =?UTF-8?q?=EB=B2=88=ED=98=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/useBoardAccessStore.js | 16 ++++++---- src/views/board/BoardEdit.vue | 53 +++++++++++++++---------------- src/views/board/BoardView.vue | 8 ++--- 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/src/stores/useBoardAccessStore.js b/src/stores/useBoardAccessStore.js index 3960cfe..1e6e7a3 100644 --- a/src/stores/useBoardAccessStore.js +++ b/src/stores/useBoardAccessStore.js @@ -13,28 +13,30 @@ export const useBoardAccessStore = defineStore( () => { const password = ref(''); + // watch(password, newValue => { + // localStorage.setItem('tempPassword', JSON.stringify(newValue.value)); + // }); + if (localStorage.getItem('tempPassword')) { // 저장된 값을 불러와 상태에 할당 - const storedState = JSON.parse(localStorage.getItem('tempPassword')); - password.value = storedState; + const tempPassword = localStorage.getItem('tempPassword'); + if (typeof tempPassword === 'String') password.value = tempPassword; } - watch(password, newValue => { - localStorage.setItem('tempPassword', JSON.stringify(newValue.value)); - }); - function setBoardPassword(input) { password.value = input; + if (typeof input === 'String') localStorage.setItem('tempPassword', input); } function $reset() { password.value = ''; - localStorage.removeItem('tempPassword', newValue); + localStorage.removeItem('tempPassword'); } return { password, setBoardPassword, + getTempPassword, $reset, }; }, diff --git a/src/views/board/BoardEdit.vue b/src/views/board/BoardEdit.vue index f043e27..4813cb9 100644 --- a/src/views/board/BoardEdit.vue +++ b/src/views/board/BoardEdit.vue @@ -120,11 +120,10 @@ // 게시물 데이터 로드 const fetchBoardDetails = async () => { // 수정 데이터 전송 - const password = accessStore.password.value; + const password = accessStore.password; 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); @@ -154,6 +153,7 @@ // 목록 페이지로 이동 const goList = () => { + accessStore.$reset(); router.push('/board'); }; @@ -228,38 +228,37 @@ const updateBoard = async () => { if (checkValidation()) return; - try { - // 수정 데이터 전송 - const boardData = { - LOCBRDTTL: title.value.trim(), - LOCBRDCON: JSON.stringify(content.value), - LOCBRDSEQ: currentBoardId.value, - }; + // 수정 데이터 전송 + const boardData = { + LOCBRDTTL: title.value.trim(), + LOCBRDCON: JSON.stringify(content.value), + LOCBRDSEQ: currentBoardId.value, + }; - // 업로드 된 첨부파일의 삭제목록 - if (delFileIdx.value && delFileIdx.value.length > 0) { - boardData.delFileIdx = [...delFileIdx.value]; - } + // 업로드 된 첨부파일의 삭제목록 + if (delFileIdx.value && delFileIdx.value.length > 0) { + boardData.delFileIdx = [...delFileIdx.value]; + } - const fileArray = newFileFilter(attachFiles); - const formData = new FormData(); + const fileArray = newFileFilter(attachFiles); + const formData = new FormData(); - // formData에 boardData 추가 - Object.entries(boardData).forEach(([key, value]) => { - formData.append(key, value); - }); + // formData에 boardData 추가 + Object.entries(boardData).forEach(([key, value]) => { + formData.append(key, value); + }); - // formData에 새로 추가한 파일 추가 - fileArray.forEach((file, idx) => { - formData.append('files', file); - }); + // formData에 새로 추가한 파일 추가 + fileArray.forEach((file, idx) => { + formData.append('files', file); + }); - await axios.put(`board/${currentBoardId.value}`, formData, { isFormData: true }); + const { data } = await axios.put(`board/${currentBoardId.value}`, formData, { isFormData: true }); + if (data.code === 200 && data.data === true) { toastStore.onToast('게시물이 수정되었습니다.', 's'); goList(); - } catch (error) { - console.error('게시물 수정 중 오류 발생:', error); - toastStore.onToast('게시물 수정에 실패했습니다.'); + } else { + toastStore.onToast('게시물 수정에 실패했습니다.', 'e'); } }; diff --git a/src/views/board/BoardView.vue b/src/views/board/BoardView.vue index b88bc15..4eed1f8 100644 --- a/src/views/board/BoardView.vue +++ b/src/views/board/BoardView.vue @@ -610,15 +610,13 @@ } try { - const response = await axios.post(`board/${currentBoardId.value}/password`, { + const { data } = await axios.post(`board/${currentBoardId.value}/password`, { LOCBRDPWD: password.value, LOCBRDSEQ: currentBoardId.value, }); - if (response.data.code === 200 && response.data.data === true) { - accessStore.setBoardPassword(password); - console.log('password: ', password.value); - console.log('accessStore.password: ', accessStore.password.value); + if (data.code === 200 && data.data === true) { + accessStore.setBoardPassword(password.value); boardPasswordAlert.value = ''; isPassword.value = false;