From ad930e39f9bb1fceb37d3a748b91c517db5dbc00 Mon Sep 17 00:00:00 2001 From: seorang42 Date: Mon, 3 Feb 2025 15:36:30 +0900 Subject: [PATCH 1/3] =?UTF-8?q?:sparkles:=20[feat]=20:=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=88=98=EC=A0=95=20=EB=9D=BC?= =?UTF-8?q?=EC=9A=B0=ED=8C=85=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../task-management/CategoryLine.vue | 2 +- .../task-management/CategoryLineSub.vue | 2 +- src/router/index.ts | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/task-management/CategoryLine.vue b/src/components/task-management/CategoryLine.vue index c2457361..700a5192 100644 --- a/src/components/task-management/CategoryLine.vue +++ b/src/components/task-management/CategoryLine.vue @@ -17,7 +17,7 @@
diff --git a/src/components/task-management/CategoryLineSub.vue b/src/components/task-management/CategoryLineSub.vue index 747947bc..5167a064 100644 --- a/src/components/task-management/CategoryLineSub.vue +++ b/src/components/task-management/CategoryLineSub.vue @@ -15,7 +15,7 @@
diff --git a/src/router/index.ts b/src/router/index.ts index 1d335fae..d6474acd 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -60,12 +60,26 @@ const router = createRouter({ { path: '/category-first', name: 'CategoryFirst', - component: () => import('../views/CategoryFirstAdd.vue') + component: () => import('../views/CategoryFirstAdd.vue'), + children: [ + { + path: ':id', + name: 'EditSubCategory', + component: () => import('../views/CategoryFirstAdd.vue') + } + ] }, { path: '/category-second', name: 'CategorySecond', - component: () => import('../views/CategorySecondAdd.vue') + component: () => import('../views/CategorySecondAdd.vue'), + children: [ + { + path: ':id', + name: 'EditMainCategory', + component: () => import('../views/CategorySecondAdd.vue') + } + ] }, { path: '/login-logs', From 2da1d4b27dabdf02a3d0f3b16678282653b1c360 Mon Sep 17 00:00:00 2001 From: seorang42 Date: Tue, 4 Feb 2025 00:16:08 +0900 Subject: [PATCH 2/3] =?UTF-8?q?:sparkles:=20[feat]=20:=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=88=98=EC=A0=95=20API=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/admin.ts | 5 -- src/api/common.ts | 5 ++ .../request-task/RequestTaskDropdown.vue | 7 ++- .../task-management/CategoryAdd.vue | 56 +++++++++++++++---- .../task-management/LabelManagement.vue | 5 +- src/types/user.ts | 1 + 6 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/api/admin.ts b/src/api/admin.ts index 5a952967..e87b88af 100644 --- a/src/api/admin.ts +++ b/src/api/admin.ts @@ -1,11 +1,6 @@ import type { LabelDataTypes, NewLabelTypes } from '@/types/admin' import { axiosInstance } from '@/utils/axios' -export const getLabelsAdmin = async () => { - const response = await axiosInstance.get('/api/managements/labels') - return response.data -} - export const deleteLabelAdmin = async (id: number) => { const response = await axiosInstance.delete(`/api/management/labels/${id}`) return response.data diff --git a/src/api/common.ts b/src/api/common.ts index ade690e6..a55b64f0 100644 --- a/src/api/common.ts +++ b/src/api/common.ts @@ -14,3 +14,8 @@ export const getAllCategory = async () => { const response = await axiosInstance.get('/api/category') return response.data } + +export const getLabels = async () => { + const response = await axiosInstance.get('/api/labels') + return response.data +} diff --git a/src/components/request-task/RequestTaskDropdown.vue b/src/components/request-task/RequestTaskDropdown.vue index 0ede8277..6271a211 100644 --- a/src/components/request-task/RequestTaskDropdown.vue +++ b/src/components/request-task/RequestTaskDropdown.vue @@ -10,8 +10,9 @@
+ class="flex w-full h-11 items-center rounded p-4 border border-border-1" + :class="disabled ? 'bg-background-1 text-disabled' : 'bg-white text-black cursor-pointer'" + @click="!disabled && toggleDropdown()">

{{ modelValue || placeholderText }}

@@ -40,7 +41,7 @@ import type { RequestTaskDropdownProps } from '@/types/user' import { ref } from 'vue' import CommonIcons from '../common/CommonIcons.vue' -const { placeholderText, options, labelName, modelValue, isLabel } = +const { placeholderText, options, labelName, modelValue, isLabel, disabled } = defineProps() const emit = defineEmits(['update:modelValue']) const dropdownOpen = ref(false) diff --git a/src/components/task-management/CategoryAdd.vue b/src/components/task-management/CategoryAdd.vue index f96c4c2e..68a59ff1 100644 --- a/src/components/task-management/CategoryAdd.vue +++ b/src/components/task-management/CategoryAdd.vue @@ -26,7 +26,8 @@ :options="categoryOptions.map(el => el.name)" label-name="1차 카테고리" placeholder-text="1차 카테고리를 선택해주세요" - v-if="categoryStep == '2'" /> + v-if="categoryStep == '2'" + :disabled="route.params.id !== undefined" /> import { CATEGORY_FORM } from '@/constants/admin' import { computed, onMounted, ref, watch } from 'vue' -import { useRouter } from 'vue-router' +import { useRoute, useRouter } from 'vue-router' import FormButtonContainer from '../common/FormButtonContainer.vue' import ModalView from '../ModalView.vue' import RequestTaskDropdown from '../request-task/RequestTaskDropdown.vue' import RequestTaskInput from '../request-task/RequestTaskInput.vue' import { axiosInstance } from '@/utils/axios' -import { getMainCategory } from '@/api/common' -import type { Category, CategoryForm } from '@/types/common' +import { getMainCategory, getSubCategory } from '@/api/common' +import type { Category, CategoryForm, SubCategory } from '@/types/common' const router = useRouter() +const route = useRoute() const { categoryStep } = defineProps<{ categoryStep: string @@ -98,11 +100,18 @@ const handleSubmit = async () => { } try { - const requestUrl = - categoryStep === '1' ? '/api/managements/main-category' : '/api/managements/sub-category' - await axiosInstance.post(requestUrl, categoryForm.value, { - headers: { Authorization: `Bearer ${import.meta.env.VITE_ACCESS_TOKEN}` } - }) + const categoryId = route.params.id + if (categoryId) { + const patchUrl = `/api/managements/categories/${categoryId}` + await axiosInstance.patch(patchUrl, { + name: categoryForm.value.name, + code: categoryForm.value.code + }) + } else { + const postUrl = + categoryStep === '1' ? '/api/managements/main-category' : '/api/managements/sub-category' + await axiosInstance.post(postUrl, categoryForm.value) + } isModalVisible.value.add = true } catch { handleFailModal() @@ -120,9 +129,32 @@ const isCodeInvalidate = computed(() => { const mainCategory = ref('') const categoryOptions = ref([]) onMounted(async () => { - categoryOptions.value = await getMainCategory() - if (categoryStep === '2') - categoryForm.value = { ...categoryForm.value, mainCategoryId: undefined } + const id = Number(route.params.id) + categoryForm.value = { ...CATEGORY_FORM } + if (categoryStep === '1') { + if (id) { + const mainCategories: Category[] = await getMainCategory() + const initailValue = mainCategories.find(el => el.id === id) + if (initailValue) { + categoryForm.value = { name: initailValue.name, code: initailValue.code } + } + } + } else if (categoryStep === '2') { + categoryOptions.value = await getMainCategory() + if (id) { + const subCategory: SubCategory[] = await getSubCategory() + const initailValue = subCategory.find(el => el.id === id) + if (initailValue) { + categoryForm.value = { + name: initailValue.name, + code: initailValue.code, + mainCategoryId: initailValue.mainCategoryId + } + mainCategory.value = + categoryOptions.value.find(el => el.id === initailValue.mainCategoryId)?.name || '' + } + } + } }) watch(mainCategory, () => { categoryForm.value.mainCategoryId = categoryOptions.value.find( diff --git a/src/components/task-management/LabelManagement.vue b/src/components/task-management/LabelManagement.vue index 771f512d..22f948e6 100644 --- a/src/components/task-management/LabelManagement.vue +++ b/src/components/task-management/LabelManagement.vue @@ -58,7 +58,7 @@ - - diff --git a/src/views/CategorySecondAdd.vue b/src/views/CategorySecondAdd.vue index e2fc2bac..cdea7edf 100644 --- a/src/views/CategorySecondAdd.vue +++ b/src/views/CategorySecondAdd.vue @@ -1,6 +1,6 @@