This commit is contained in:
nevermoregb 2025-03-06 15:09:36 +09:00
parent d74c0ddacb
commit 19ce33e503
4 changed files with 385 additions and 368 deletions

View File

@ -52,29 +52,28 @@
</template> </template>
<script setup> <script setup>
import Quill from 'quill'; import Quill from 'quill';
import 'quill/dist/quill.snow.css'; import 'quill/dist/quill.snow.css';
import { onMounted, ref, watch, defineEmits, defineProps } from 'vue'; import { onMounted, ref, watch, defineEmits, defineProps } from 'vue';
import $api from '@api'; import $api from '@api';
const props = defineProps({
const props = defineProps({
isAlert: { isAlert: {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
initialData: { initialData: {
type: String, type: [String, Object],
default: () => null, default: () => null,
}, },
}); });
const editor = ref(null); // DOM const editor = ref(null); // DOM
const font = ref('nanum-gothic'); // const font = ref('nanum-gothic'); //
const fontSize = ref('16px'); // const fontSize = ref('16px'); //
const emit = defineEmits(['update:data']); const emit = defineEmits(['update:data']);
onMounted(() => { onMounted(() => {
// //
const Font = Quill.import('formats/font'); const Font = Quill.import('formats/font');
Font.whitelist = ['nanum-gothic', 'd2coding', 'consolas', 'serif', 'monospace']; Font.whitelist = ['nanum-gothic', 'd2coding', 'consolas', 'serif', 'monospace'];
@ -111,11 +110,11 @@ onMounted(() => {
watch([font, fontSize], () => { watch([font, fontSize], () => {
quillInstance.format('font', font.value); quillInstance.format('font', font.value);
quillInstance.format('size', fontSize.value); quillInstance.format('size', fontSize.value);
}); });
// , HTML // , HTML
if (props.initialData) { if (props.initialData) {
console.log(props.initialData);
quillInstance.setContents(JSON.parse(props.initialData)); quillInstance.setContents(JSON.parse(props.initialData));
} }
@ -150,7 +149,8 @@ onMounted(() => {
formData.append('file', file); formData.append('file', file);
// URL // URL
uploadImageToServer(formData).then(serverImageUrl => { uploadImageToServer(formData)
.then(serverImageUrl => {
const baseUrl = $api.defaults.baseURL.replace(/api\/$/, ''); const baseUrl = $api.defaults.baseURL.replace(/api\/$/, '');
const fullImageUrl = `${baseUrl}${serverImageUrl.replace(/\\/g, '/')}`; const fullImageUrl = `${baseUrl}${serverImageUrl.replace(/\\/g, '/')}`;
@ -158,7 +158,8 @@ onMounted(() => {
quillInstance.insertEmbed(range.index, 'image', fullImageUrl); // quillInstance.insertEmbed(range.index, 'image', fullImageUrl); //
imageUrls.add(fullImageUrl); // URL imageUrls.add(fullImageUrl); // URL
}).catch(e => { })
.catch(e => {
toastStore.onToast('잠시후 다시 시도해주세요.', 'e'); toastStore.onToast('잠시후 다시 시도해주세요.', 'e');
}); });
} }
@ -187,12 +188,12 @@ onMounted(() => {
} }
}); });
} }
}); });
</script> </script>
<style> <style>
@import 'quill/dist/quill.snow.css'; @import 'quill/dist/quill.snow.css';
.ql-editor { .ql-editor {
min-height: 300px; min-height: 300px;
font-family: 'Nanum Gothic', sans-serif; font-family: 'Nanum Gothic', sans-serif;
} }
</style> </style>

View File

@ -14,7 +14,7 @@
/> />
</div> </div>
<div class="col-2 btn-margin" v-if="!isDisabled"> <div class="col-2 btn-margin" v-if="!isDisabled">
<PlusBtn @click="toggleInput"/> <PlusBtn @click="toggleInput" />
</div> </div>
</div> </div>
@ -44,7 +44,12 @@
/> />
</div> </div>
<div> <div>
<QEditor @update:data="content = $event" @update:imageUrls="imageUrls = $event" :is-alert="wordContentAlert" :initialData="contentValue"/> <QEditor
@update:data="content = $event"
@update:imageUrls="imageUrls = $event"
:is-alert="wordContentAlert"
:initialData="contentValue"
/>
<div class="text-end mt-5"> <div class="text-end mt-5">
<button class="btn btn-primary" @click="saveWord"> <button class="btn btn-primary" @click="saveWord">
<i class="bx bx-check"></i> <i class="bx bx-check"></i>
@ -54,87 +59,84 @@
</template> </template>
<script setup> <script setup>
import { defineProps, computed, ref, defineEmits } from 'vue'; import { defineProps, computed, ref, defineEmits } from 'vue';
import QEditor from '@/components/editor/QEditor.vue'; import QEditor from '@/components/editor/QEditor.vue';
import FormInput from '@/components/input/FormInput.vue'; import FormInput from '@/components/input/FormInput.vue';
import FormSelect from '@/components/input/FormSelect.vue'; import FormSelect from '@/components/input/FormSelect.vue';
import PlusBtn from '../button/PlusBtn.vue'; import PlusBtn from '../button/PlusBtn.vue';
const emit = defineEmits(['close','addCategory','addWord']); const emit = defineEmits(['close', 'addCategory', 'addWord']);
// //
const wordTitle = ref(''); const wordTitle = ref('');
const addCategory = ref(''); const addCategory = ref('');
const content = ref(''); const content = ref('');
const imageUrls = ref([]); const imageUrls = ref([]);
// Vaildation // Vaildation
const wordTitleAlert = ref(false); const wordTitleAlert = ref(false);
const wordContentAlert = ref(false); const wordContentAlert = ref(false);
const addCategoryAlert = ref(false); const addCategoryAlert = ref(false);
// //
const selectCategory = ref(''); const selectCategory = ref('');
// //
const computedTitle = computed(() => const computedTitle = computed(() => (wordTitle.value === '' ? props.titleValue : wordTitle.value));
wordTitle.value === '' ? props.titleValue : wordTitle.value
);
// //
const selectedCategory = computed(() => const selectedCategory = computed(() => (selectCategory.value === '' ? props.formValue : selectCategory.value));
selectCategory.value === '' ? props.formValue : selectCategory.value
);
// ref // ref
const categoryInputRef = ref(null); const categoryInputRef = ref(null);
const props = defineProps({ const props = defineProps({
dataList: { dataList: {
type: Array, type: Array,
default: () => [] default: () => [],
}, },
NumValue : { NumValue: {
type: Number type: Number,
}, },
formValue : { formValue: {
type:[String, Number] type: [String, Number],
}, },
titleValue : { titleValue: {
type:String, type: String,
},contentValue : { },
type:String, contentValue: {
type: String,
}, },
isDisabled: { isDisabled: {
type: Boolean, type: Boolean,
default: false default: false,
} },
}); });
// //
const showInput = ref(false); const showInput = ref(false);
// //
const toggleInput = () => { const toggleInput = () => {
showInput.value = !showInput.value; showInput.value = !showInput.value;
}; };
const onChange = (newValue) => { const onChange = newValue => {
selectCategory.value = newValue.target.value; selectCategory.value = newValue.target.value;
}; };
// //
const saveWord = () => { const saveWord = () => {
//validation //validation
let computedTitleTrim; let computedTitleTrim;
if(computedTitle.value != undefined){ if (computedTitle.value != undefined) {
computedTitleTrim = computedTitle.value.trim() computedTitleTrim = computedTitle.value.trim();
} }
// //
if(computedTitleTrim == undefined || computedTitleTrim == ''){ if (computedTitleTrim == undefined || computedTitleTrim == '') {
wordTitleAlert.value = true; wordTitleAlert.value = true;
return; return;
} else { } else {
@ -144,18 +146,15 @@ const saveWord = () => {
// //
let inserts = []; let inserts = [];
if (inserts.length === 0 && content.value?.ops?.length > 0) { if (inserts.length === 0 && content.value?.ops?.length > 0) {
inserts = content.value.ops.map(op => inserts = content.value.ops.map(op => (typeof op.insert === 'string' ? op.insert.trim() : op.insert));
typeof op.insert === 'string' ? op.insert.trim() : op.insert
);
} }
// //
if(content.value == '' || inserts.join('') === ''){ if (content.value == '' || inserts.join('') === '') {
wordContentAlert.value = true; wordContentAlert.value = true;
return; return;
} }
const wordData = { const wordData = {
id: props.NumValue || null, id: props.NumValue || null,
title: computedTitle.value, title: computedTitle.value,
@ -164,17 +163,16 @@ const saveWord = () => {
}; };
emit('addWord', wordData, addCategory.value); emit('addWord', wordData, addCategory.value);
} };
// focusout
// focusout const handleCategoryFocusout = value => {
const handleCategoryFocusout = (value) => {
const valueTrim = value.trim(); const valueTrim = value.trim();
const existingCategory = props.dataList.find(item => item.label === valueTrim); const existingCategory = props.dataList.find(item => item.label === valueTrim);
// //
if(valueTrim == ''){ if (valueTrim == '') {
addCategoryAlert.value = true; addCategoryAlert.value = true;
// focus // focus
@ -184,9 +182,7 @@ const handleCategoryFocusout = (value) => {
inputElement.focus(); inputElement.focus();
} }
}, 0); }, 0);
} else if (existingCategory) {
}else if (existingCategory) {
addCategoryAlert.value = true; addCategoryAlert.value = true;
// focus // focus
@ -196,23 +192,20 @@ const handleCategoryFocusout = (value) => {
inputElement.focus(); inputElement.focus();
} }
}, 0); }, 0);
} else { } else {
addCategoryAlert.value = false; addCategoryAlert.value = false;
} }
}; };
</script> </script>
<style scoped> <style scoped>
.dict-w { .dict-w {
width: 83%; width: 83%;
}
@media (max-width: 768px) {
.btn-margin {
margin-top: 2.5rem
} }
}
@media (max-width: 768px) {
.btn-margin {
margin-top: 2.5rem;
}
}
</style> </style>

View File

@ -10,25 +10,46 @@
<div class="col-xl-12"> <div class="col-xl-12">
<div class="card-body"> <div class="card-body">
<!-- 제목 입력 --> <!-- 제목 입력 -->
<FormInput <FormInput title="제목" name="title" :is-essential="true" :is-alert="titleAlert" v-model="title" />
title="제목"
name="title" <!-- 첨부파일 업로드 -->
:is-essential="true" <FormFile
:is-alert="titleAlert" title="첨부파일"
v-model="title" name="files"
:is-alert="attachFilesAlert"
@update:data="handleFileUpload"
@update:isValid="isFileValid = $event"
/> />
<!-- 실시간 반영된 파일 개수 표시 -->
<p class="text-muted mt-1">첨부파일: {{ fileCount }} / 5</p>
<p v-if="fileError" class="text-danger">{{ fileError }}</p>
<ul class="list-group mt-2" v-if="attachFiles.length">
<li
v-for="(file, index) in attachFiles"
:key="index"
class="list-group-item d-flex justify-content-between align-items-center"
>
{{ file.name }}
<button class="close-btn" @click="removeFile(index)"></button>
</li>
</ul>
<!-- 내용 입력 --> <!-- 내용 입력 -->
<div class="mb-4"> <div class="mb-4">
<label for="html5-tel-input" class="col-md-2 col-form-label"> <label for="html5-tel-input" class="col-md-2 col-form-label">
내용 내용
<span class="text-red">*</span> <span class="text-red">*</span>
<div class="invalid-feedback" :class="contentAlert ? 'display-block' : ''"> <div class="invalid-feedback" :class="contentAlert ? 'display-block' : ''">내용을 확인해주세요.</div>
내용을 확인해주세요.
</div>
</label> </label>
<div class="col-md-12"> <div class="col-md-12">
<QEditor v-model="content" /> <QEditor
v-if="contentLoaded"
@update:data="content = $event"
@update:imageUrls="imageUrls = $event"
:initialData="content"
/>
</div> </div>
</div> </div>
@ -48,30 +69,30 @@
</template> </template>
<script setup> <script setup>
import QEditor from '@c/editor/QEditor.vue'; import QEditor from '@c/editor/QEditor.vue';
import FormInput from '@c/input/FormInput.vue'; import FormInput from '@c/input/FormInput.vue';
import { ref, onMounted } from 'vue'; import { ref, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import axios from '@api'; import axios from '@api';
// //
const title = ref(''); const title = ref('');
const content = ref(''); const content = ref('');
// //
const titleAlert = ref(false); const titleAlert = ref(false);
const contentAlert = ref(false); const contentAlert = ref(false);
const contentLoaded = ref(false); //
// //
const router = useRouter(); const router = useRouter();
const route = useRoute(); const route = useRoute();
const currentBoardId = ref(route.params.id); // ID const currentBoardId = ref(route.params.id); // ID
console.log(currentBoardId.value) //
// const fetchBoardDetails = async () => {
const fetchBoardDetails = async () => {
try { try {
const response = await axios.get(`board/${currentBoardId.value}`); const response = await axios.get(`board/${currentBoardId.value}`);
const data = response.data.data.boardDetail; const data = response.data.data;
if (!data) { if (!data) {
console.error('API에서 게시물 데이터를 반환하지 않았습니다.'); console.error('API에서 게시물 데이터를 반환하지 않았습니다.');
@ -81,19 +102,19 @@ const fetchBoardDetails = async () => {
// //
title.value = data.title || '제목 없음'; title.value = data.title || '제목 없음';
content.value = data.content || '내용 없음'; content.value = data.content || '내용 없음';
contentLoaded.value = true;
} catch (error) { } catch (error) {
console.error('게시물 가져오기 오류:', error.response || error.message); console.error('게시물 가져오기 오류:', error.response || error.message);
} }
}; };
// //
const goList = () => { const goList = () => {
router.push('/board'); router.push('/board');
}; };
// //
const updateBoard = async () => { const updateBoard = async () => {
// //
if (!title.value) { if (!title.value) {
titleAlert.value = true; titleAlert.value = true;
@ -111,7 +132,8 @@ const updateBoard = async () => {
// //
const boardData = { const boardData = {
LOCBRDTTL: title.value, LOCBRDTTL: title.value,
LOCBRDCON: content.value, LOCBRDCON: JSON.stringify(content.value),
LOCBRDSEQ: currentBoardId.value,
}; };
await axios.put(`board/${currentBoardId.value}`, boardData); await axios.put(`board/${currentBoardId.value}`, boardData);
@ -122,21 +144,21 @@ const updateBoard = async () => {
console.error('게시물 수정 중 오류 발생:', error); console.error('게시물 수정 중 오류 발생:', error);
alert('게시물 수정에 실패했습니다.'); alert('게시물 수정에 실패했습니다.');
} }
}; };
// //
onMounted(() => { onMounted(() => {
if (currentBoardId.value) { if (currentBoardId.value) {
fetchBoardDetails(); fetchBoardDetails();
} else { } else {
console.error('잘못된 게시물 ID:', currentBoardId.value); console.error('잘못된 게시물 ID:', currentBoardId.value);
} }
}); });
</script> </script>
<style> <style>
.text-red { .text-red {
color: red; color: red;
text-align: center; text-align: center;
} }
</style> </style>

View File

@ -229,7 +229,7 @@
const data = response.data.data; const data = response.data.data;
profileName.value = data.author || '익명'; profileName.value = data.author || '익명';
console.log(data.author);
authorId.value = data.authorId; authorId.value = data.authorId;
boardTitle.value = data.title || '제목 없음'; boardTitle.value = data.title || '제목 없음';
boardContent.value = data.content || ''; boardContent.value = data.content || '';
@ -569,7 +569,7 @@
try { try {
const response = await axios.post(`board/${currentBoardId.value}/password`, { const response = await axios.post(`board/${currentBoardId.value}/password`, {
LOCBRDPWD: password.value, LOCBRDPWD: password.value,
LOCBRDSEQ: 288, LOCBRDSEQ: currentBoardId.value,
}); });
if (response.data.code === 200 && response.data.data === true) { if (response.data.code === 200 && response.data.data === true) {
@ -586,17 +586,18 @@
passwordAlert.value = '비밀번호가 일치하지 않습니다.'; passwordAlert.value = '비밀번호가 일치하지 않습니다.';
} }
} catch (error) { } catch (error) {
if (error.response) { if (error.reponse && error.reponse.status === 401) passwordAlert.value = '비밀번호가 일치하지 않습니다.';
if (error.response.status === 401) { // if (error.response) {
passwordAlert.value = '비밀번호가 일치하지 않습니다.'; // if (error.response.status === 401) {
} else { // passwordAlert.value = ' .';
passwordAlert.value = error.response.data?.message || '서버 오류가 발생했습니다.'; // } else {
} // passwordAlert.value = error.response.data?.message || ' .';
} else if (error.request) { // }
passwordAlert.value = '네트워크 오류가 발생했습니다. 다시 시도해주세요.'; // } else if (error.request) {
} else { // passwordAlert.value = ' . .';
passwordAlert.value = '요청 중 알 수 없는 오류가 발생했습니다.'; // } else {
} // passwordAlert.value = ' .';
// }
} }
}; };