게시판 저장 수정정,파일제한 추가
This commit is contained in:
parent
2f0f5fd378
commit
fb12e345a7
@ -1,17 +1,25 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="mb-4 row">
|
<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">
|
<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>
|
||||||
<div class="invalid-feedback" :class="isAlert ? 'display-block' : ''">{{ errorMsg }}</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { fileMsg } from '@/common/msgEnum';
|
import { ref, watch } from 'vue';
|
||||||
import { ref } from 'vue';
|
|
||||||
|
|
||||||
|
// Props
|
||||||
const prop = defineProps({
|
const prop = defineProps({
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
@ -23,24 +31,34 @@ const prop = defineProps({
|
|||||||
default: 'nameplz',
|
default: 'nameplz',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
isAlert : {
|
isAlert: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
required: false,
|
required: false,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const emits = defineEmits(['update:data']);
|
// Emits
|
||||||
const errorMsg = ref(fileMsg.FileMaxSizeMsg);
|
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 changeHandler = (event) => {
|
||||||
const files = Array.from(event.target.files);
|
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>
|
</script>
|
||||||
|
|
||||||
<style>
|
|
||||||
</style>
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
<div class="mb-2 row">
|
<div class="mb-2 row">
|
||||||
<label :for="name" class="col-md-2 col-form-label" :class="isLabel ? 'd-block' : 'd-none'">
|
<label :for="name" class="col-md-2 col-form-label" :class="isLabel ? 'd-block' : 'd-none'">
|
||||||
{{ title }}
|
{{ title }}
|
||||||
<span :class="isEssential ? 'text-red' : 'none'">*</span>
|
<span v-if="isEssential" class="text-danger">*</span>
|
||||||
</label>
|
</label>
|
||||||
<div class="col-md-10">
|
<div class="col-md-10">
|
||||||
<input
|
<input
|
||||||
|
|||||||
@ -57,6 +57,7 @@
|
|||||||
name="files"
|
name="files"
|
||||||
:is-alert="attachFilesAlert"
|
:is-alert="attachFilesAlert"
|
||||||
@update:data="attachFiles = $event"
|
@update:data="attachFiles = $event"
|
||||||
|
@update:isValid="isFileValid = $event"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
@ -71,8 +72,17 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-4 d-flex justify-content-end">
|
<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-info" @click="goList">
|
||||||
<button type="button" class="btn btn-primary ms-1" @click="write"><i class='bx bx-check'></i></button>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -94,6 +104,7 @@ const password = ref('');
|
|||||||
const category = ref(0); // 기본값 0
|
const category = ref(0); // 기본값 0
|
||||||
const content = ref('');
|
const content = ref('');
|
||||||
const attachFiles = ref(null);
|
const attachFiles = ref(null);
|
||||||
|
const isFileValid = ref(true); // 파일 유효성 상태 추가
|
||||||
|
|
||||||
const titleAlert = ref(false);
|
const titleAlert = ref(false);
|
||||||
const passwordAlert = ref(false);
|
const passwordAlert = ref(false);
|
||||||
@ -112,7 +123,7 @@ const write = async () => {
|
|||||||
passwordAlert.value = category.value === 1 && !password.value;
|
passwordAlert.value = category.value === 1 && !password.value;
|
||||||
contentAlert.value = !content.value;
|
contentAlert.value = !content.value;
|
||||||
|
|
||||||
if (titleAlert.value || passwordAlert.value || contentAlert.value) {
|
if (titleAlert.value || passwordAlert.value || contentAlert.value || !isFileValid.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +136,6 @@ const write = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const { data: boardResponse } = await axios.post('board', boardData);
|
const { data: boardResponse } = await axios.post('board', boardData);
|
||||||
console.log(boardResponse.data);
|
|
||||||
const boardId = boardResponse.data;
|
const boardId = boardResponse.data;
|
||||||
|
|
||||||
if (attachFiles.value && attachFiles.value.length > 0) {
|
if (attachFiles.value && attachFiles.value.length > 0) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user