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