수정정

This commit is contained in:
khj0414 2025-03-07 13:19:19 +09:00
parent 2cc3166756
commit 4641800676
3 changed files with 67 additions and 17 deletions

View File

@ -125,7 +125,6 @@
// //
quillInstance.on('text-change', (delta, oldDelta, source) => { quillInstance.on('text-change', (delta, oldDelta, source) => {
emit('update:data', quillInstance.getContents());
delta.ops.forEach(op => { delta.ops.forEach(op => {
if (op.insert && typeof op.insert === 'object' && op.insert.image) { if (op.insert && typeof op.insert === 'object' && op.insert.image) {
const imageUrl = op.insert.image; // URL const imageUrl = op.insert.image; // URL
@ -134,7 +133,9 @@
checkForDeletedImages(); // checkForDeletedImages(); //
} }
}); });
emit('update:data', quillInstance.getContents());
}); });
// //
async function selectLocalImage() { async function selectLocalImage() {
const input = document.createElement('input'); const input = document.createElement('input');
@ -164,17 +165,43 @@
} }
}; };
} }
// //
async function uploadImageToServer(formData) { async function uploadImageToServer(formData) {
try { try {
const response = await $api.post('quilleditor/upload', formData, { isFormData: true }); // Make the POST request to upload the image
const imageUrl = response.data.data; const response = await $api.post('quilleditor/upload', formData, { isFormData: true });
return imageUrl; // URL
} catch (error) { // Check if the response contains the expected data
toastStore.onToast('잠시후 다시 시도해주세요.', 'e'); if (response.data && response.data.data) {
throw error; const imageUrl = response.data.data;
} return imageUrl; // Return the image URL received from the server
} else {
throw new Error('Image URL not returned from server');
} }
} catch (error) {
// Log detailed error information for debugging purposes
console.error('Image upload failed:', error);
// Handle specific error cases (e.g., network issues, authorization issues)
if (error.response) {
// If the error is from the server (e.g., 4xx or 5xx error)
console.error('Error response:', error.response.data);
toastStore.onToast('서버 오류가 발생했습니다. 잠시 후 다시 시도해주세요.', 'e');
} else if (error.request) {
// If no response is received from the server
console.error('No response received:', error.request);
toastStore.onToast('네트워크 오류가 발생했습니다. 잠시 후 다시 시도해주세요.', 'e');
} else {
// If the error is due to something else (e.g., invalid request setup)
console.error('Error message:', error.message);
toastStore.onToast('파일 업로드 중 문제가 발생했습니다. 다시 시도해주세요.', 'e');
}
// Throw the error so the caller knows something went wrong
throw error;
}
}
// //
function checkForDeletedImages() { function checkForDeletedImages() {
@ -189,6 +216,7 @@
} }
}); });
</script> </script>
<style> <style>
@import 'quill/dist/quill.snow.css'; @import 'quill/dist/quill.snow.css';
.ql-editor { .ql-editor {

View File

@ -42,10 +42,11 @@
:modelValue="titleValue" :modelValue="titleValue"
@update:modelValue="wordTitle = $event" @update:modelValue="wordTitle = $event"
:disabled="isDisabled" :disabled="isDisabled"
@keyup="ValidHandler('title')"
/> />
</div> </div>
<div> <div>
<QEditor @update:data="content = $event" @update:imageUrls="imageUrls = $event" :is-alert="wordContentAlert" :initialData="contentValue"/> <QEditor @keyup="ValidHandler('content')" @update:data="handleContentUpdate" @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>
@ -126,8 +127,23 @@ const onChange = (newValue) => {
selectCategory.value = newValue.target.value; selectCategory.value = newValue.target.value;
}; };
const ValidHandler = (field) => {
if(field == 'title'){
wordTitleAlert.value = false;
}
if(field == 'content'){
wordContentAlert.value = false;
}
}
const handleContentUpdate = (newContent) => {
content.value = newContent;
ValidHandler("content"); //
};
// //
const saveWord = () => { const saveWord = () => {
let valid = true;
//validation //validation
let computedTitleTrim; let computedTitleTrim;
@ -138,7 +154,7 @@ const saveWord = () => {
// //
if(computedTitleTrim == undefined || computedTitleTrim == ''){ if(computedTitleTrim == undefined || computedTitleTrim == ''){
wordTitleAlert.value = true; wordTitleAlert.value = true;
return; valid = false;
} else { } else {
wordTitleAlert.value = false; wordTitleAlert.value = false;
} }
@ -153,7 +169,9 @@ const saveWord = () => {
// //
if(content.value == '' || inserts.join('') === ''){ if(content.value == '' || inserts.join('') === ''){
wordContentAlert.value = true; wordContentAlert.value = true;
return; valid = false;
}else{
wordContentAlert.value = false;
} }
const wordData = { const wordData = {
id: props.NumValue || null, id: props.NumValue || null,
@ -161,9 +179,11 @@ const saveWord = () => {
category: selectedCategory.value, category: selectedCategory.value,
content: content.value, content: content.value,
}; };
emit('addWord', wordData, addCategory.value === '' if(valid){
? (isNaN(selectedCategory.value) ? selectedCategory.value : Number(selectedCategory.value)) emit('addWord', wordData, addCategory.value === ''
: addCategory.value); ? (isNaN(selectedCategory.value) ? selectedCategory.value : Number(selectedCategory.value))
: addCategory.value);
}
} }

View File

@ -9,7 +9,7 @@
<SearchBar @update:data="search"/> <SearchBar @update:data="search"/>
</div> </div>
<!-- 단어 갯수, 작성하기 --> <!-- 단어 갯수, 작성하기 -->
<WriteButton ref="writeButton" @click="writeStore.toggleItem(999999)" :isToggleEnabled="true"/> <WriteButton ref="writeButton" @click="writeStore.toggleItem(999999)" :isToggleEnabled="true"/>
<!-- --> <!-- -->
<DictAlphabetFilter @update:data="handleSelectedAlphabetChange" :indexCategory="indexCategory" :selectedAl="selectedAlphabet" /> <DictAlphabetFilter @update:data="handleSelectedAlphabetChange" :indexCategory="indexCategory" :selectedAl="selectedAlphabet" />
<!-- 카테고리 --> <!-- 카테고리 -->
@ -25,7 +25,7 @@
<!-- 용어 리스트 --> <!-- 용어 리스트 -->
<div > <div >
<!-- 로딩 중일 --> <!-- 로딩 중일 -->
<div v-if="loading">로딩 중...</div> <LoadingSpinner v-if="loading"/>
<!-- 에러 메시지 --> <!-- 에러 메시지 -->
<div v-if="error" class="error">{{ error }}</div> <div v-if="error" class="error">{{ error }}</div>
<!-- 단어 목록 --> <!-- 단어 목록 -->
@ -63,6 +63,7 @@
import commonApi from '@/common/commonApi'; import commonApi from '@/common/commonApi';
import { useToastStore } from '@s/toastStore'; import { useToastStore } from '@s/toastStore';
import { useWriteVisibleStore } from '@s/writeVisible'; import { useWriteVisibleStore } from '@s/writeVisible';
import LoadingSpinner from "@v/LoadingPage.vue";
// //
const writeStore = useWriteVisibleStore(); const writeStore = useWriteVisibleStore();
@ -109,6 +110,7 @@
onMounted(() => { onMounted(() => {
//getwordList(); //getwordList();
getIndex(); getIndex();
writeStore.closeAll();
}); });
// //