commonApi 로직 수정

This commit is contained in:
yoon 2025-02-13 14:38:07 +09:00
parent 8ab9e79b5a
commit 558008acc5

View File

@ -8,29 +8,35 @@
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import $api from '@api'; import $api from '@api';
const commonApi = () => { const commonApi = (options = {}) => {
const colorList = ref([]); const colorList = ref([]);
const mbtiList = ref([]); const mbtiList = ref([]);
const pwhintList = ref([]); const pwhintList = ref([]);
const yearCategory = ref([]); const yearCategory = ref([]);
const cateList = ref([]); const cateList = ref([]);
const CommonCode = async (path, endpoint, targetList) => { // type 파라미터를 추가로 받도록 수정
const CommonCode = async (path, endpoint, targetList, type = null) => {
const response = await $api.get(`${path}/${endpoint}`); const params = type ? { type } : {};
const response = await $api.get(`${path}/${endpoint}`, {
params
});
targetList.value = response.data.data.map(item => ({ targetList.value = response.data.data.map(item => ({
label: item.CMNCODNAM, label: item.CMNCODNAM,
value: item.CMNCODVAL, value: item.CMNCODVAL,
})); }));
}; };
onMounted(async () => { onMounted(async () => {
await CommonCode("user", "color", colorList); // 요청할 데이터가 옵션으로 전달 -> 그에 맞게 호출
await CommonCode("user", "mbti", mbtiList); // color 옵션에 type 정보 포함
await CommonCode("user", "pwhint", pwhintList); if (options.loadColor) {
await CommonCode("project", "yearCategory", yearCategory); await CommonCode("user", "color", colorList, options.colorType);
await CommonCode("worddict", "getWordCategory", cateList); }
if (options.loadMbti) await CommonCode("user", "mbti", mbtiList);
if (options.loadPwhint) await CommonCode("user", "pwhint", pwhintList);
if (options.loadYearCategory) await CommonCode("project", "yearCategory", yearCategory);
if (options.loadCateList) await CommonCode("worddict", "getWordCategory", cateList);
}); });
return { colorList, mbtiList, pwhintList, yearCategory, cateList }; return { colorList, mbtiList, pwhintList, yearCategory, cateList };