163 lines
5.8 KiB
Vue
163 lines
5.8 KiB
Vue
<template>
|
|
<div class="container-xxl flex-grow-1 container-p-y">
|
|
<div class="card">
|
|
<div class="pb-4 rounded-top">
|
|
<div class="container py-12 px-xl-10 px-4" style="padding-bottom: 0px !important">
|
|
<h3 class="text-center mb-2 mt-4">글 작성</h3>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-xl-12">
|
|
<div class="card-body">
|
|
<FormInput title="제목" name="title" :is-essential="true" :is-alert="titleAlert" @update:data="title = $event" />
|
|
|
|
<FormSelect title="카테고리" name="cate" :is-essential="true" :data="categoryList" @update:data="category = $event" />
|
|
|
|
<FormInput
|
|
v-show="category == 1"
|
|
title="비밀번호"
|
|
name="pw"
|
|
type="password"
|
|
:is-essential="true"
|
|
:is-alert="passwordAlert"
|
|
@update:data="password = $event"
|
|
/>
|
|
|
|
<FormFile title="첨부파일" name="files" :is-alert="attachFilesAlert" @update:data="attachFiles = $event" />
|
|
|
|
<div class="mb-4">
|
|
<label for="html5-tel-input" class="col-md-2 col-form-label">
|
|
내용
|
|
<span class="text-red">*</span>
|
|
<div class="invalid-feedback" :class="contentAlert ? 'display-block' : ''">내용을 확인해주세요.</div>
|
|
</label>
|
|
<div class="col-md-12">
|
|
<!-- <TEditor @update:data="content = $event"/> -->
|
|
<QEditor @update:data="content = $event" />
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-4 d-flex justify-content-end">
|
|
<button type="button" class="btn btn-info right" @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>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import QEditor from '@c/editor/QEditor.vue';
|
|
import TEditor from '@c/editor/TEditor.vue';
|
|
import FormInput from '@c/input/FormInput.vue';
|
|
import FormSelect from '@c/input/FormSelect.vue';
|
|
import FormFile from '@c/input/FormFile.vue';
|
|
import { ref, watch } from 'vue';
|
|
import router from '@/router';
|
|
import axios from '@api';
|
|
|
|
const categoryList = ['자유', '익명', '공지사항'];
|
|
// input 경고문 만들어야함!!
|
|
const title = ref('');
|
|
const password = ref('');
|
|
const category = ref(0);
|
|
const content = ref('');
|
|
const attachFiles = ref(null);
|
|
|
|
//input 경고창 관리
|
|
const titleAlert = ref(true);
|
|
const passwordAlert = ref(false);
|
|
const contentAlert = ref(false);
|
|
const attachFilesAlert = ref(false);
|
|
|
|
|
|
const goList = () => {
|
|
// 목록으로 이동 나중엔 페이지 정보 ,검색 정보도 붙여야됨
|
|
router.push('/board');
|
|
};
|
|
|
|
const write = async () => {
|
|
// 입력값 유효성 검사
|
|
if (!title.value) {
|
|
titleAlert.value = true;
|
|
return;
|
|
} else {
|
|
titleAlert.value = false;
|
|
}
|
|
|
|
if (category.value === 1 && !password.value) {
|
|
passwordAlert.value = true;
|
|
return;
|
|
} else {
|
|
passwordAlert.value = false;
|
|
}
|
|
|
|
if (!content.value) {
|
|
contentAlert.value = true;
|
|
return;
|
|
} else {
|
|
contentAlert.value = false;
|
|
}
|
|
|
|
try {
|
|
// 게시물 작성 데이터 준비
|
|
const boardData = {
|
|
LOCBRDTTL: title.value,
|
|
LOCBRDCON: content.value,
|
|
LOCBRDPWD: category.value === 1 ? password.value : null,
|
|
LOCBRDTYP: category.value === 1 ? 'S' : 'F', //공지사항 추가해야함!!
|
|
// MEMBERSEQ: 로그인이용자 id(세션)
|
|
};
|
|
|
|
// 게시물 작성 API 호출
|
|
const { data: boardResponse } = await axios.post('/board', boardData);
|
|
const boardId = boardResponse.data.boardId;
|
|
|
|
// 첨부파일 처리
|
|
if (attachFiles.value && attachFiles.value.length > 0) {
|
|
for (const file of attachFiles.value) {
|
|
const realName = file.name.substring(0, file.name.lastIndexOf('.'));
|
|
const fileInfo = {
|
|
path: "/uploads", // 파일 경로 (수정 필요)
|
|
originalName: realName, // 확장자를 제외한 파일명
|
|
extension: file.name.split('.').pop(), // 파일 확장자
|
|
registrantId: 1, // 등록자 ID (수정 필요)
|
|
};
|
|
|
|
|
|
const formData = new FormData();
|
|
formData.append("file", file); // 첨부 파일
|
|
formData.append("CMNFLEPAT", fileInfo.path); // 파일 경로
|
|
formData.append("CMNFLENAM", fileInfo.originalName); // 파일 명(확장자제외)
|
|
formData.append("CMNFLEORG", fileInfo.originalName); // 원본 파일명(확장자제외)
|
|
formData.append("CMNFLEEXT", fileInfo.extension); // 파일 확장자
|
|
formData.append("CMNFLESIZ", file.size); // 파일 크기
|
|
formData.append("CMNFLEREG", fileInfo.registrantId); // 등록자 ID
|
|
|
|
const response = await axios.post(`/board/${boardId}/attachments`, formData, {
|
|
headers: {
|
|
"Content-Type": "multipart/form-data",
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
alert("게시물이 작성되었습니다.");
|
|
goList();
|
|
} catch (error) {
|
|
console.error(error);
|
|
alert("게시물 작성 중 오류가 발생했습니다.");
|
|
}
|
|
};
|
|
|
|
|
|
</script>
|
|
|
|
<style>
|
|
.text-red {
|
|
color: red;
|
|
text-align: center;
|
|
}
|
|
</style>
|