에디터 첨부파일 인덱스 업데이트 로직 추가

This commit is contained in:
nevermoregb 2025-03-20 16:12:54 +09:00
parent ae9c8735b1
commit 93953aedcc
4 changed files with 72 additions and 39 deletions

View File

@ -71,7 +71,8 @@
const editor = ref(null); // DOM
const font = ref('nanum-gothic'); //
const fontSize = ref('16px'); //
const emit = defineEmits(['update:data']);
const emit = defineEmits(['update:data', 'update:uploadedImgList']);
const uploadedImgList = ref([]); //
onMounted(() => {
//
@ -112,6 +113,13 @@
quillInstance.format('size', fontSize.value);
});
//
watch(uploadedImgList, () => {
console.log(!23);
emit('update:uploadedImgList', uploadedImgList.value);
console.log('uploadedImgList.value: ', uploadedImgList.value);
});
// , HTML
if (props.initialData) {
quillInstance.setContents(JSON.parse(props.initialData));
@ -150,7 +158,15 @@
// URL
uploadImageToServer(formData)
.then(serverImageUrl => {
.then(data => {
const uploadImgIdx = data?.fileIndex; // DB
const serverImageUrl = data?.fileUrl; // url
// ( )
if (uploadImgIdx) {
uploadedImgList.value = [...uploadedImgList.value, uploadImgIdx];
}
const baseUrl = $api.defaults.baseURL.replace(/api\/$/, '');
const fullImageUrl = `${baseUrl}${serverImageUrl.replace(/\\/g, '/')}`;
@ -201,7 +217,7 @@
// Throw the error so the caller knows something went wrong
throw error;
}
}
}
//
function checkForDeletedImages() {
@ -216,4 +232,3 @@
}
});
</script>

View File

@ -14,7 +14,6 @@
:value="computedValue"
:disabled="disabled"
:maxLength="maxlength"
:minLength="minlength"
:placeholder="title"
@blur="$emit('blur')"
/>
@ -30,7 +29,6 @@
:value="computedValue"
:disabled="disabled"
:maxLength="maxlength"
:minLength="minlength"
:placeholder="title"
@blur="$emit('blur')"
/>

View File

@ -57,6 +57,7 @@
v-if="contentLoaded"
@update:data="content = $event"
@update:imageUrls="imageUrls = $event"
@update:uploadedImgList="handleUpdateEditorImg"
:initialData="content"
/>
</div>
@ -115,7 +116,7 @@
const attachFilesAlert = ref(false);
const isFileValid = ref(true);
const delFileIdx = ref([]); // ID
const additionalFiles = ref([]); //
const editorUploadedImgList = ref([]);
//
const fetchBoardDetails = async () => {
@ -145,6 +146,10 @@
contentLoaded.value = true;
};
const handleUpdateEditorImg = item => {
editorUploadedImgList.value = item;
};
//
const addDisplayFileName = fileInfos =>
fileInfos.map(file => ({
@ -247,6 +252,11 @@
boardData.delFileIdx = [...delFileIdx.value];
}
//
if (editorUploadedImgList.value && editorUploadedImgList.value.length > 0) {
boardData.editorUploadedImgList = [...editorUploadedImgList.value];
}
const fileArray = newFileFilter(attachFiles);
const formData = new FormData();

View File

@ -83,7 +83,7 @@
<div class="mb-4">
<label class="col-md-2 col-form-label"> 내용 <span class="text-danger">*</span> </label>
<div class="col-md-12">
<QEditor @update:data="content = $event" />
<QEditor @update:data="content = $event" @update:uploadedImgList="handleUpdateEditorImg" />
</div>
<div class="invalid-feedback mt-1" :class="contentAlert ? 'd-block' : 'd-none'">내용을 입력해주세요.</div>
</div>
@ -127,6 +127,7 @@
const maxFiles = 5;
const maxSize = 10 * 1024 * 1024;
const fileError = ref('');
const editorUploadedImgList = ref([]);
const fetchCategories = async () => {
const response = await axios.get('board/categories');
@ -143,6 +144,10 @@
const fileCount = computed(() => attachFiles.value.length);
const handleUpdateEditorImg = item => {
editorUploadedImgList.value = item;
};
const handleFileUpload = files => {
const validFiles = files.filter(file => file.size <= maxSize);
if (files.some(file => file.size > maxSize)) {
@ -215,6 +220,11 @@
LOCBRDTYP: categoryValue.value,
};
//
if (editorUploadedImgList.value && editorUploadedImgList.value.length > 0) {
boardData.editorUploadedImgList = [...editorUploadedImgList.value];
}
const { data: boardResponse } = await axios.post('board', boardData);
const boardId = boardResponse.data;
// ( )