파일선택 > 삭제했다가 다시 파일선택시 안들어감
This commit is contained in:
parent
ad3af31e37
commit
8d1748548e
@ -3,7 +3,16 @@
|
|||||||
<label :for="inputId" class="col-md-2 col-form-label">{{ title }}</label>
|
<label :for="inputId" class="col-md-2 col-form-label">{{ title }}</label>
|
||||||
<div class="col-md-10">
|
<div class="col-md-10">
|
||||||
<label :for="inputId" class="btn btn-label-primary">파일 선택</label>
|
<label :for="inputId" class="btn btn-label-primary">파일 선택</label>
|
||||||
<input class="form-control" type="file" style="display: none" :id="inputId" ref="fileInput" @change="changeHandler" multiple />
|
<input
|
||||||
|
class="form-control"
|
||||||
|
type="file"
|
||||||
|
style="display: none"
|
||||||
|
:id="inputId"
|
||||||
|
ref="fileInput"
|
||||||
|
:key="autoIncrement"
|
||||||
|
@change="changeHandler"
|
||||||
|
multiple
|
||||||
|
/>
|
||||||
<div v-if="showError" class="text-danger mt-1">
|
<div v-if="showError" class="text-danger mt-1">
|
||||||
{{ errorMessage }}
|
{{ errorMessage }}
|
||||||
</div>
|
</div>
|
||||||
@ -33,10 +42,14 @@
|
|||||||
required: false,
|
required: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
//:key="autoIncrement" 동일한 파일을 첨부하고 비웠다 다시넣으면 안들어가는 현상 대비.
|
||||||
|
|
||||||
const inputId = computed(() => props.name || 'defaultFileInput');
|
const inputId = computed(() => props.name || 'defaultFileInput');
|
||||||
|
|
||||||
const emits = defineEmits(['update:data', 'update:isValid']);
|
const emits = defineEmits(['update:data', 'update:isValid']);
|
||||||
|
|
||||||
|
const autoIncrement = ref(props.autoIncrement);
|
||||||
|
|
||||||
const MAX_TOTAL_SIZE = 5 * 1024 * 1024; // 5MB
|
const MAX_TOTAL_SIZE = 5 * 1024 * 1024; // 5MB
|
||||||
const MAX_FILE_COUNT = 5; // 최대 파일 개수
|
const MAX_FILE_COUNT = 5; // 최대 파일 개수
|
||||||
const ALLOWED_FILE_TYPES = []; // 모든 파일을 허용
|
const ALLOWED_FILE_TYPES = []; // 모든 파일을 허용
|
||||||
|
|||||||
@ -25,6 +25,7 @@
|
|||||||
title="첨부파일"
|
title="첨부파일"
|
||||||
name="files"
|
name="files"
|
||||||
:is-alert="attachFilesAlert"
|
:is-alert="attachFilesAlert"
|
||||||
|
:key="autoIncrement"
|
||||||
@update:data="handleFileUpload"
|
@update:data="handleFileUpload"
|
||||||
@update:isValid="isFileValid = $event"
|
@update:isValid="isFileValid = $event"
|
||||||
/>
|
/>
|
||||||
@ -98,6 +99,7 @@
|
|||||||
// 상태 변수
|
// 상태 변수
|
||||||
const title = ref('');
|
const title = ref('');
|
||||||
const content = ref('');
|
const content = ref('');
|
||||||
|
const autoIncrement = ref(0);
|
||||||
|
|
||||||
// 경고 상태
|
// 경고 상태
|
||||||
const titleAlert = ref(false);
|
const titleAlert = ref(false);
|
||||||
@ -124,7 +126,6 @@
|
|||||||
const originalPlainText = ref('');
|
const originalPlainText = ref('');
|
||||||
const originalFiles = ref([]);
|
const originalFiles = ref([]);
|
||||||
|
|
||||||
|
|
||||||
function extractPlainText(delta) {
|
function extractPlainText(delta) {
|
||||||
if (!delta || !Array.isArray(delta.ops)) return '';
|
if (!delta || !Array.isArray(delta.ops)) return '';
|
||||||
return delta.ops
|
return delta.ops
|
||||||
@ -145,18 +146,14 @@
|
|||||||
delFileIdx.value.length > 0 || // 삭제된 파일이 있는 경우
|
delFileIdx.value.length > 0 || // 삭제된 파일이 있는 경우
|
||||||
!isSameFiles(
|
!isSameFiles(
|
||||||
attachFiles.value.filter(f => f.id), // 기존 파일(id 있는 것만)
|
attachFiles.value.filter(f => f.id), // 기존 파일(id 있는 것만)
|
||||||
originalFiles.value
|
originalFiles.value,
|
||||||
);
|
);
|
||||||
console.log(isTitleChanged);
|
|
||||||
console.log(isContentChanged);
|
|
||||||
console.log(isFilesChanged);
|
|
||||||
return isTitleChanged || isContentChanged || isFilesChanged;
|
return isTitleChanged || isContentChanged || isFilesChanged;
|
||||||
});
|
});
|
||||||
watch(isChanged, (val) => {
|
watch(isChanged, val => {
|
||||||
console.log('🔄 isChanged changed:', val);
|
console.log('🔄 isChanged changed:', val);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// 파일 비교 함수
|
// 파일 비교 함수
|
||||||
function isSameFiles(current, original) {
|
function isSameFiles(current, original) {
|
||||||
if (current.length !== original.length) return false;
|
if (current.length !== original.length) return false;
|
||||||
@ -165,10 +162,7 @@
|
|||||||
const sortedOriginal = [...original].sort((a, b) => a.id - b.id);
|
const sortedOriginal = [...original].sort((a, b) => a.id - b.id);
|
||||||
|
|
||||||
return sortedCurrent.every((file, idx) => {
|
return sortedCurrent.every((file, idx) => {
|
||||||
return (
|
return file.id === sortedOriginal[idx].id && file.name === sortedOriginal[idx].name;
|
||||||
file.id === sortedOriginal[idx].id &&
|
|
||||||
file.name === sortedOriginal[idx].name
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,11 +197,15 @@
|
|||||||
contentLoaded.value = true;
|
contentLoaded.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(content, (val) => {
|
watch(
|
||||||
|
content,
|
||||||
|
val => {
|
||||||
if (contentLoaded.value && !originalPlainText.value) {
|
if (contentLoaded.value && !originalPlainText.value) {
|
||||||
originalPlainText.value = extractPlainText(val);
|
originalPlainText.value = extractPlainText(val);
|
||||||
}
|
}
|
||||||
}, { immediate: true });
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
|
||||||
const handleUpdateEditorImg = item => {
|
const handleUpdateEditorImg = item => {
|
||||||
editorUploadedImgList.value = item;
|
editorUploadedImgList.value = item;
|
||||||
@ -288,6 +286,7 @@
|
|||||||
if (attachFiles.value.length <= maxFiles) {
|
if (attachFiles.value.length <= maxFiles) {
|
||||||
fileError.value = '';
|
fileError.value = '';
|
||||||
}
|
}
|
||||||
|
autoIncrement.value++;
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(attachFiles, () => {
|
watch(attachFiles, () => {
|
||||||
|
|||||||
@ -69,6 +69,7 @@
|
|||||||
title="첨부파일"
|
title="첨부파일"
|
||||||
name="files"
|
name="files"
|
||||||
:is-alert="attachFilesAlert"
|
:is-alert="attachFilesAlert"
|
||||||
|
:key="autoIncrement"
|
||||||
@update:data="handleFileUpload"
|
@update:data="handleFileUpload"
|
||||||
@update:isValid="isFileValid = $event"
|
@update:isValid="isFileValid = $event"
|
||||||
/>
|
/>
|
||||||
@ -154,6 +155,8 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const autoIncrement = ref(0);
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchCategories();
|
fetchCategories();
|
||||||
});
|
});
|
||||||
@ -180,6 +183,7 @@
|
|||||||
}
|
}
|
||||||
fileError.value = '';
|
fileError.value = '';
|
||||||
attachFiles.value = [...attachFiles.value, ...validFiles].slice(0, maxFiles);
|
attachFiles.value = [...attachFiles.value, ...validFiles].slice(0, maxFiles);
|
||||||
|
console.log('attachFiles.value: ', attachFiles.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeFile = index => {
|
const removeFile = index => {
|
||||||
@ -187,6 +191,7 @@
|
|||||||
if (attachFiles.value.length <= maxFiles) {
|
if (attachFiles.value.length <= maxFiles) {
|
||||||
fileError.value = '';
|
fileError.value = '';
|
||||||
}
|
}
|
||||||
|
autoIncrement.value++;
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(attachFiles, () => {
|
watch(attachFiles, () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user