This commit is contained in:
khj0414 2025-02-04 11:01:10 +09:00
commit 822223ff0d

View File

@ -22,7 +22,7 @@
<label class="col-md-2 col-form-label">카테고리 <span class="text-danger">*</span></label>
<div class="d-flex flex-wrap align-items-center mt-3 ms-1">
<div
v-for="(categoryName, index) in categoryList"
v-for="(category, index) in categoryList"
:key="index"
class="form-check me-3"
>
@ -30,18 +30,19 @@
class="form-check-input"
type="radio"
:id="`category-${index}`"
:value="index"
v-model="category"
:value="category.CMNCODVAL"
v-model="categoryValue"
/>
<label class="form-check-label" :for="`category-${index}`">
{{ categoryName }}
{{ category.CMNCODNAM }}
</label>
</div>
</div>
<div class="invalid-feedback" :class="categoryAlert ? 'display-block' : ''">카테고리를 선택해주세요.</div>
</div>
<!-- 비밀번호 필드 -->
<div v-if="category === 1" class="mb-4">
<div v-if="categoryValue === 300102" class="mb-4">
<FormInput
title="비밀번호"
name="pw"
@ -94,25 +95,39 @@
import QEditor from '@c/editor/QEditor.vue';
import FormInput from '@c/input/FormInput.vue';
import FormFile from '@c/input/FormFile.vue';
import { getCurrentInstance, ref } from 'vue';
import { getCurrentInstance, ref, onMounted } from 'vue';
import router from '@/router';
import axios from '@api';
const categoryList = ['자유', '익명', '공지사항']; //
const categoryList = ref([]);
const title = ref('');
const password = ref('');
const category = ref(0); // 0
const categoryValue = ref(null);
const content = ref('');
const attachFiles = ref(null);
const isFileValid = ref(true); //
const isFileValid = ref(true);
const titleAlert = ref(false);
const passwordAlert = ref(false);
const contentAlert = ref(false);
const categoryAlert = ref(false);
const attachFilesAlert = ref(false);
const { appContext } = getCurrentInstance();
const $common = appContext.config.globalProperties.$common; // $common
const $common = appContext.config.globalProperties.$common;
const fetchCategories = async () => {
try {
const response = await axios.get('board/categories');
categoryList.value = response.data.data;
} catch (error) {
console.error('카테고리 불러오기 오류:', error);
}
};
onMounted(() => {
fetchCategories();
});
const goList = () => {
router.push('/board');
@ -120,10 +135,11 @@ const goList = () => {
const write = async () => {
titleAlert.value = !title.value;
passwordAlert.value = category.value === 1 && !password.value;
passwordAlert.value = categoryValue.value === 300102 && !password.value;
contentAlert.value = !content.value;
categoryAlert.value = !categoryValue.value;
if (titleAlert.value || passwordAlert.value || contentAlert.value || !isFileValid.value) {
if (titleAlert.value || passwordAlert.value || contentAlert.value || categoryAlert.value || !isFileValid.value) {
return;
}
@ -131,8 +147,8 @@ const write = async () => {
const boardData = {
LOCBRDTTL: title.value,
LOCBRDCON: $common.deltaAsJson(content.value),
LOCBRDPWD: category.value === 1 ? password.value : null,
LOCBRDTYP: category.value === 1 ? 'S' : 'F',
LOCBRDPWD: categoryValue.value === 300102 ? password.value : null,
LOCBRDTYP: categoryValue.value
};
const { data: boardResponse } = await axios.post('board', boardData);