게시판 insert예시

This commit is contained in:
dyhj625 2025-01-13 12:52:44 +09:00
parent 3aed02e3f1
commit 4df399ac36

View File

@ -55,9 +55,10 @@ 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 'axios';
const categoryList = ['자유', '익명', '공지사항'];
// input
// input !!
const title = ref('');
const password = ref('');
const category = ref(0);
@ -76,9 +77,80 @@ const goList = () => {
router.push('/board');
};
const write = () => {
console.log('작성');
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', // !!
};
// API
const { data: boardResponse } = await axios.post('/api/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(`/api/board/${boardId}/attachments`, formData, {
headers: {
"Content-Type": "multipart/form-data",
},
});
}
}
alert("게시물이 작성되었습니다.");
goList();
} catch (error) {
console.error(error);
alert("게시물 작성 중 오류가 발생했습니다.");
}
};
</script>
<style>