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

View File

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

View File

@ -10,25 +10,46 @@
<div class="col-xl-12">
<div class="card-body">
<!-- 제목 입력 -->
<FormInput
title="제목"
name="title"
:is-essential="true"
:is-alert="titleAlert"
v-model="title"
<FormInput title="제목" name="title" :is-essential="true" :is-alert="titleAlert" v-model="title" />
<!-- 첨부파일 업로드 -->
<FormFile
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">
<label for="html5-tel-input" class="col-md-2 col-form-label">
내용
<span class="text-red">*</span>
<div class="invalid-feedback" :class="contentAlert ? 'display-block' : ''">
내용을 확인해주세요.
</div>
<div class="invalid-feedback" :class="contentAlert ? 'display-block' : ''">내용을 확인해주세요.</div>
</label>
<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>
@ -48,30 +69,30 @@
</template>
<script setup>
import QEditor from '@c/editor/QEditor.vue';
import FormInput from '@c/input/FormInput.vue';
import { ref, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import axios from '@api';
import QEditor from '@c/editor/QEditor.vue';
import FormInput from '@c/input/FormInput.vue';
import { ref, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import axios from '@api';
//
const title = ref('');
const content = ref('');
//
const title = ref('');
const content = ref('');
//
const titleAlert = ref(false);
const contentAlert = ref(false);
//
const titleAlert = ref(false);
const contentAlert = ref(false);
const contentLoaded = ref(false); //
//
const router = useRouter();
const route = useRoute();
const currentBoardId = ref(route.params.id); // ID
console.log(currentBoardId.value)
//
const fetchBoardDetails = async () => {
//
const router = useRouter();
const route = useRoute();
const currentBoardId = ref(route.params.id); // ID
//
const fetchBoardDetails = async () => {
try {
const response = await axios.get(`board/${currentBoardId.value}`);
const data = response.data.data.boardDetail;
const data = response.data.data;
if (!data) {
console.error('API에서 게시물 데이터를 반환하지 않았습니다.');
@ -81,19 +102,19 @@ const fetchBoardDetails = async () => {
//
title.value = data.title || '제목 없음';
content.value = data.content || '내용 없음';
contentLoaded.value = true;
} catch (error) {
console.error('게시물 가져오기 오류:', error.response || error.message);
}
};
};
//
const goList = () => {
//
const goList = () => {
router.push('/board');
};
};
//
const updateBoard = async () => {
//
const updateBoard = async () => {
//
if (!title.value) {
titleAlert.value = true;
@ -111,7 +132,8 @@ const updateBoard = async () => {
//
const boardData = {
LOCBRDTTL: title.value,
LOCBRDCON: content.value,
LOCBRDCON: JSON.stringify(content.value),
LOCBRDSEQ: currentBoardId.value,
};
await axios.put(`board/${currentBoardId.value}`, boardData);
@ -122,21 +144,21 @@ const updateBoard = async () => {
console.error('게시물 수정 중 오류 발생:', error);
alert('게시물 수정에 실패했습니다.');
}
};
};
//
onMounted(() => {
//
onMounted(() => {
if (currentBoardId.value) {
fetchBoardDetails();
} else {
console.error('잘못된 게시물 ID:', currentBoardId.value);
}
});
});
</script>
<style>
.text-red {
.text-red {
color: red;
text-align: center;
}
}
</style>

View File

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