Merge branch 'boardview'

This commit is contained in:
nevermoregb 2025-03-13 11:03:06 +09:00
commit ff6a032cd6
4 changed files with 49 additions and 30 deletions

View File

@ -1,7 +1,7 @@
import axios from 'axios'; import axios from 'axios';
import { useRoute } from 'vue-router'; import router from '@/router';
import { useToastStore } from '@s/toastStore'; import { useToastStore } from '@s/toastStore';
import { useLoadingStore } from "@s/loadingStore"; import { useLoadingStore } from '@s/loadingStore';
const $api = axios.create({ const $api = axios.create({
baseURL: import.meta.env.VITE_API_URL, baseURL: import.meta.env.VITE_API_URL,
@ -46,8 +46,8 @@ $api.interceptors.response.use(
function (error) { function (error) {
const loadingStore = useLoadingStore(); const loadingStore = useLoadingStore();
loadingStore.stopLoading(); loadingStore.stopLoading();
const toastStore = useToastStore(); const toastStore = useToastStore();
// 오류 응답 처리 // 오류 응답 처리
if (error.response) { if (error.response) {
switch (error.response.status) { switch (error.response.status) {
@ -55,6 +55,7 @@ $api.interceptors.response.use(
if (!error.config.headers.isLogin) { if (!error.config.headers.isLogin) {
// toastStore.onToast('인증이 필요합니다.', 'e'); // toastStore.onToast('인증이 필요합니다.', 'e');
} }
router.push('/login');
break; break;
case 403: case 403:
toastStore.onToast('접근 권한이 없습니다.', 'e'); toastStore.onToast('접근 권한이 없습니다.', 'e');

View File

@ -1,18 +1,20 @@
/* /*
작성자 : 공현지 작성자 : 공현지
작성일 : 2025-01-17 작성일 : 2025-01-17
수정자 : 수정자 : 박성용
수정일 : 수정일 : 2025-03-11
설명 : 공통 스크립트 설명 : 공통 스크립트
*/ */
import Quill from 'quill'; import Quill from 'quill';
/* /*
*템플릿 사용법 : $common.변수 *템플릿 사용법 : $common.변수
*setup() 사용법 : *setup() 사용법 :
const { appContext } = getCurrentInstance(); const { appContext } = getCurrentInstance();
const $common = appContext.config.globalProperties.$common; const $common = appContext.config.globalProperties.$common;
$common.변수 or
import { inject } from 'vue';
const $common = inject('common');
*/ */
const common = { const common = {
// JSON 문자열로 Delta 타입을 변환 // JSON 문자열로 Delta 타입을 변환
@ -74,6 +76,12 @@ const common = {
}; };
}, },
/**
* 빈값 확인
*
* @param {} obj
* @returns
*/
isNotEmpty(obj) { isNotEmpty(obj) {
if (obj === null || obj === undefined) return false; if (obj === null || obj === undefined) return false;
if (typeof obj === 'string' && obj.trim() === '') return false; if (typeof obj === 'string' && obj.trim() === '') return false;
@ -103,12 +111,25 @@ const common = {
/** /**
* 확인 * 확인
* *
* @param {ref} text ex) inNotValidInput(data.value); * @param { ref } text ex) inNotValidInput(data.value);
* @returns * @returns
*/ */
isNotValidInput(text) { isNotValidInput(text) {
return text.trim().length === 0; return text.trim().length === 0;
}, },
/**
* 프로필 이미지 반환
*
* @param { String } profileImg
* @returns
*/
getProfileImage(profileImg) {
let profileImgUrl = '/img/icons/icon.png'; // 기본 프로필 이미지 경로
const UserProfile = `${import.meta.env.VITE_SERVER}upload/img/profile/${profileImg}`;
return !profileImg || profileImg === '' ? profileImgUrl : UserProfile;
},
}; };
export default { export default {

View File

@ -31,17 +31,11 @@
</template> </template>
<script setup> <script setup>
import { computed, defineProps, defineEmits } from 'vue'; import { computed, defineProps, defineEmits, inject } from 'vue';
import DeleteButton from '../button/DeleteBtn.vue'; import DeleteButton from '../button/DeleteBtn.vue';
import EditButton from '../button/EditBtn.vue'; import EditButton from '../button/EditBtn.vue';
import BoardRecommendBtn from '../button/BoardRecommendBtn.vue'; import BoardRecommendBtn from '../button/BoardRecommendBtn.vue';
//
const defaultProfile = '/img/icons/icon.png';
// (Vue )
const baseUrl = import.meta.env.VITE_SERVER; // API URL
// Props // Props
const props = defineProps({ const props = defineProps({
comment: { comment: {
@ -97,6 +91,7 @@
}); });
const emit = defineEmits(['updateReaction', 'editClick', 'deleteClick']); const emit = defineEmits(['updateReaction', 'editClick', 'deleteClick']);
const $common = inject('common');
const isDeletedComment = computed(() => { const isDeletedComment = computed(() => {
return props.comment?.content === '삭제된 댓글입니다' && props.comment?.updateAtRaw !== props.comment?.createdAtRaw; return props.comment?.content === '삭제된 댓글입니다' && props.comment?.updateAtRaw !== props.comment?.createdAtRaw;
@ -123,6 +118,6 @@
// //
const getProfileImage = profileImg => { const getProfileImage = profileImg => {
return profileImg && profileImg != '' ? `${baseUrl}upload/img/profile/${profileImg}` : defaultProfile; return $common.getProfileImage(profileImg);
}; };
</script> </script>

View File

@ -514,7 +514,7 @@
toggleCommentPassword(comment, 'edit'); toggleCommentPassword(comment, 'edit');
} }
} else { } else {
alert('수정이 불가능합니다'); toastStore.onToast('수정에 실패하였습니다.', 'e');
} }
}; };
@ -644,7 +644,7 @@
passwordCommentAlert.value = ''; passwordCommentAlert.value = '';
currentPasswordCommentId.value = null; currentPasswordCommentId.value = null;
} else { } else {
alert('수정 취소를 실패했습니다.'); toastStore.onToast('수정 취소를 실패하였습니다.', 'e');
} }
// //
} else if (lastCommentClickedButton.value === 'delete') { } else if (lastCommentClickedButton.value === 'delete') {
@ -676,13 +676,15 @@
toastStore.onToast('게시물이 삭제되었습니다.'); toastStore.onToast('게시물이 삭제되었습니다.');
router.push({ name: 'BoardList' }); router.push({ name: 'BoardList' });
} else { } else {
alert('삭제 실패: ' + response.data.message); //alert(' : ' + response.data.message);
toastStore.onToast('삭제 실패: ' + response.data.message, 'e');
} }
} catch (error) { } catch (error) {
if (error.response) { if (error.response) {
alert(`삭제 실패: ${error.response.data.message || '서버 오류'}`); const errMsg = `삭제 실패: ${error.response.data.message || '서버 오류'}`;
toastStore.onToast(errMsg, 'e');
} else { } else {
alert('네트워크 오류가 발생했습니다. 다시 시도해주세요.'); toastStore.onToast('네트워크 오류가 발생했습니다. 다시 시도해주세요.', 'e');
} }
} }
} }
@ -710,10 +712,10 @@
targetComment.isDeleted = true; // targetComment.isDeleted = true; //
} }
} else { } else {
alert('댓글 삭제에 실패했습니다.'); toastStore.onToast('댓글 삭제에 실패했습니다.', 'e');
} }
} catch (error) { } catch (error) {
alert('댓글 삭제 중 오류가 발생했습니다.'); toastStore.onToast('댓글 삭제 중 오류가 발생했습니다.', 'e');
} }
}; };
@ -732,13 +734,13 @@
targetComment.content = editedContent; // targetComment.content = editedContent; //
targetComment.isEditTextarea = false; // targetComment.isEditTextarea = false; //
} else { } else {
alert('수정할 댓글을 찾을 수 없습니다.'); toastStore.onToast('수정할 댓글을 찾을 수 없습니다.', 'e');
} }
} else { } else {
alert('댓글 수정 실패했습니다.'); toastStore.onToast('댓글 수정 실패했습니다.', 'e');
} }
} catch (error) { } catch (error) {
alert('댓글 수정 중 오류 발생했습니다.'); toastStore.onToast('댓글 수정 중 오류가 발생하였습니다.', 'e');
} }
}; };
@ -749,7 +751,7 @@
if (targetComment) { if (targetComment) {
targetComment.isEditTextarea = false; targetComment.isEditTextarea = false;
} else { } else {
alert('수정 취소를 실패했습니다.'); toastStore.onToast('수정 취소를 실패했습니다.', 'e');
} }
}; };