글쓰기 카테고리 공통코드 수정정

This commit is contained in:
dyhj625 2025-02-03 16:18:31 +09:00
parent 8e42b6b2b5
commit 8cfffa6610

View File

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