Merge remote-tracking branch 'origin/main' into board-firstimg

This commit is contained in:
kimdaae328 2025-01-24 15:40:03 +09:00
commit 8ceddc8036

View File

@ -10,14 +10,15 @@
multiple
/>
<div v-if="showError" class="text-danger mt-1">
{{ errorMsg }}
{{ errorMessage }}
</div>
</div>
</div>
</template>
<script setup>
import { ref, watch } from 'vue';
import { ref ,computed} from 'vue';
import { fileMsg } from '@/common/msgEnum';
// Props
const prop = defineProps({
@ -38,27 +39,43 @@ const prop = defineProps({
},
});
// Emits
const emits = defineEmits(['update:data', 'update:isValid']);
// Constants
const MAX_TOTAL_SIZE = 5 * 1024 * 1024; // 5MB
const errorMsg = ref('첨부파일의 총 용량이 5MB를 초과합니다.');
const showError = ref(false);
const MAX_FILE_COUNT = 5; //
const ALLOWED_FILE_TYPES = ['image/jpeg', 'image/png', 'application/pdf']; //
const showError = ref(false);
const fileMsgKey = ref(''); //
// Change Handler
const changeHandler = (event) => {
const files = Array.from(event.target.files);
const totalSize = files.reduce((sum, file) => sum + file.size, 0);
const invalidFiles = files.filter(file => !ALLOWED_FILE_TYPES.includes(file.type));
//
if (totalSize > MAX_TOTAL_SIZE) {
showError.value = true; //
emits('update:data', []); //
emits('update:isValid', false); //
showError.value = true;
fileMsgKey.value = 'FileMaxSizeMsg';
emits('update:data', []);
emits('update:isValid', false);
} else if (files.length > MAX_FILE_COUNT) {
showError.value = true;
fileMsgKey.value = 'FileMaxLengthMsg';
emits('update:data', []);
emits('update:isValid', false);
} else if (invalidFiles.length > 0) {
showError.value = true;
fileMsgKey.value = 'FileNotTypeMsg';
emits('update:data', []);
emits('update:isValid', false);
} else {
showError.value = false; //
emits('update:data', files); //
emits('update:isValid', true); //
showError.value = false;
fileMsgKey.value = '';
emits('update:data', files);
emits('update:isValid', true);
}
};
const errorMessage = computed(() => (fileMsg[fileMsgKey.value] || ''));
</script>