Merge branch 'main' into khj

This commit is contained in:
yoon 2025-01-24 15:06:45 +09:00
commit dfbfbabc2e
3 changed files with 49 additions and 20 deletions

View File

@ -1,17 +1,25 @@
<template>
<div class="mb-4 row">
<label :for="name" class="col-md-2 col-form-label">{{ title }} </label>
<label :for="name" class="col-md-2 col-form-label">{{ title }}</label>
<div class="col-md-10">
<input class="form-control" type="file" :id="name" @change="changeHandler" multiple />
<input
class="form-control"
type="file"
:id="name"
@change="changeHandler"
multiple
/>
<div v-if="showError" class="text-danger mt-1">
{{ errorMsg }}
</div>
</div>
<div class="invalid-feedback" :class="isAlert ? 'display-block' : ''">{{ errorMsg }}</div>
</div>
</template>
<script setup>
import { fileMsg } from '@/common/msgEnum';
import { ref } from 'vue';
import { ref, watch } from 'vue';
// Props
const prop = defineProps({
title: {
type: String,
@ -23,24 +31,34 @@ const prop = defineProps({
default: 'nameplz',
required: true,
},
isAlert : {
isAlert: {
type: Boolean,
default: false,
required: false,
}
},
});
const emits = defineEmits(['update:data']);
const errorMsg = ref(fileMsg.FileMaxSizeMsg);
// ...
// 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);
// Change Handler
const changeHandler = (event) => {
const files = Array.from(event.target.files);
emits('update:data', files);
const totalSize = files.reduce((sum, file) => sum + file.size, 0);
if (totalSize > MAX_TOTAL_SIZE) {
showError.value = true; //
emits('update:data', []); //
emits('update:isValid', false); //
} else {
showError.value = false; //
emits('update:data', files); //
emits('update:isValid', true); //
}
};
</script>
<style>
</style>

View File

@ -2,7 +2,7 @@
<div class="mb-2 row">
<label :for="name" class="col-md-2 col-form-label" :class="isLabel ? 'd-block' : 'd-none'">
{{ title }}
<span :class="isEssential ? 'text-red' : 'none'">*</span>
<span v-if="isEssential" class="text-danger">*</span>
</label>
<div class="col-md-10">
<input

View File

@ -57,6 +57,7 @@
name="files"
:is-alert="attachFilesAlert"
@update:data="attachFiles = $event"
@update:isValid="isFileValid = $event"
/>
<div class="mb-4">
@ -71,8 +72,17 @@
</div>
<div class="mb-4 d-flex justify-content-end">
<button type="button" class="btn btn-info" @click="goList"><i class='bx bx-left-arrow-alt'></i></button>
<button type="button" class="btn btn-primary ms-1" @click="write"><i class='bx bx-check'></i></button>
<button type="button" class="btn btn-info" @click="goList">
<i class="bx bx-left-arrow-alt"></i>
</button>
<button
type="button"
class="btn btn-primary ms-1"
@click="write"
:disabled="!isFileValid"
>
<i class="bx bx-check"></i>
</button>
</div>
</div>
</div>
@ -94,6 +104,7 @@ const password = ref('');
const category = ref(0); // 0
const content = ref('');
const attachFiles = ref(null);
const isFileValid = ref(true); //
const titleAlert = ref(false);
const passwordAlert = ref(false);
@ -112,7 +123,7 @@ const write = async () => {
passwordAlert.value = category.value === 1 && !password.value;
contentAlert.value = !content.value;
if (titleAlert.value || passwordAlert.value || contentAlert.value) {
if (titleAlert.value || passwordAlert.value || contentAlert.value || !isFileValid.value) {
return;
}
@ -125,7 +136,7 @@ const write = async () => {
};
const { data: boardResponse } = await axios.post('board', boardData);
const boardId = boardResponse.data.CMNBRDSEQ;
const boardId = boardResponse.data;
if (attachFiles.value && attachFiles.value.length > 0) {
for (const file of attachFiles.value) {