diff --git a/src/common/common.js b/src/common/common.js new file mode 100644 index 0000000..e761219 --- /dev/null +++ b/src/common/common.js @@ -0,0 +1,49 @@ +/* + 작성자 : 공현지 + 작성일 : 2025-01-17 + 수정자 : + 수정일 : + 설명 : 공통 스크립트 +*/ +import Quill from 'quill'; + +/* + *템플릿 사용법 : $common.변수 + *setup() 사용법 : + const { appContext } = getCurrentInstance(); + const $common = appContext.config.globalProperties.$common; + $common.변수 +*/ +const common = { + // JSON 문자열로 Delta 타입을 변환 + contentToHtml(content) { + try { + if (content.startsWith('{') || content.startsWith('[')) { + // Delta 형식으로 변환 + const delta = JSON.parse(content); + const quill = new Quill(document.createElement('div')); + quill.setContents(delta); + return quill.root.innerHTML; // HTML 반환 + } + return content; // 이미 HTML일 경우 그대로 반환 + } catch (error) { + console.error('콘텐츠 변환 오류:', error); + return content; // 오류 발생 시 원본 반환 + } + }, + // Delta 타입을 JSON 문자열로 변환 + deltaAsJson(content) { + if (content && content.ops) { + return JSON.stringify(content.ops); // Delta 객체에서 ops 속성만 JSON 문자열로 변환 + } + console.error('잘못된 Delta 객체:', content); + return null; // Delta 객체가 아니거나 ops가 없을 경우 null 반환 + } + +} + +export default { + install(app) { + app.config.globalProperties.$common = common; + } +}; diff --git a/src/components/editor/QEditor.vue b/src/components/editor/QEditor.vue index 8fb4538..321f170 100644 --- a/src/components/editor/QEditor.vue +++ b/src/components/editor/QEditor.vue @@ -46,20 +46,27 @@
+ + +
내용을 확인해주세요.
- \ No newline at end of file + diff --git a/src/components/input/FormInput.vue b/src/components/input/FormInput.vue index 12a8e79..63be771 100644 --- a/src/components/input/FormInput.vue +++ b/src/components/input/FormInput.vue @@ -1,8 +1,8 @@ - diff --git a/src/views/board/BoardView.vue b/src/views/board/BoardView.vue index d848449..f655bfc 100644 --- a/src/views/board/BoardView.vue +++ b/src/views/board/BoardView.vue @@ -5,17 +5,17 @@
- +
{{ boardTitle }}
-
+
-
@@ -42,11 +39,14 @@ import BoardProfile from '@c/board/BoardProfile.vue'; import { ref, onMounted } from 'vue'; import { useRoute, useRouter } from 'vue-router'; import axios from '@api'; +import Quill from 'quill'; +import DOMPurify from 'dompurify'; // 게시물 데이터 상태 const profileName = ref('익명 사용자'); const boardTitle = ref('제목 없음'); -const boardContent = ref('내용 없음'); +const boardContent = ref(''); +const convertedContent = ref('내용 없음'); const comments = ref([]); const attachments = ref([]); @@ -54,7 +54,6 @@ const attachments = ref([]); const route = useRoute(); const router = useRouter(); const currentBoardId = ref(Number(route.params.id)); -console.log(currentBoardId.value) // 글 수정 페이지로 이동 const goToEditPage = () => { @@ -71,7 +70,22 @@ const fetchBoardDetails = async () => { const boardDetail = data.boardDetail || {}; profileName.value = boardDetail.author || '익명 사용자'; boardTitle.value = boardDetail.title || '제목 없음'; - boardContent.value = boardDetail.content || '내용 없음'; + boardContent.value = boardDetail.content || ''; + + // Quill을 사용하여 Delta 데이터를 HTML로 변환 + if (boardContent.value) { + try { + const quillContainer = document.createElement('div'); + const quillInstance = new Quill(quillContainer); + quillInstance.setContents(JSON.parse(boardContent.value)); + convertedContent.value = DOMPurify.sanitize(quillContainer.innerHTML); + } catch (parseError) { + console.error('Delta 데이터 변환 오류:', parseError); + convertedContent.value = '내용을 표시할 수 없습니다.'; + } + } else { + convertedContent.value = '내용 없음'; + } attachments.value = data.attachments || []; comments.value = data.comments || []; @@ -83,7 +97,6 @@ const fetchBoardDetails = async () => { // 컴포넌트 마운트 시 데이터 로드 onMounted(() => { - console.log('Route Params:', route.params); fetchBoardDetails(); }); diff --git a/src/views/board/BoardWrite.vue b/src/views/board/BoardWrite.vue index 2ff95ec..535bc9e 100644 --- a/src/views/board/BoardWrite.vue +++ b/src/views/board/BoardWrite.vue @@ -9,36 +9,69 @@
- - - - - + +
+ +
+
+ + +
+
+
+ + +
+ +
+ +
-
- +
@@ -49,114 +82,73 @@ - -