From e013e5571dfad469af9bbd657d229a9ee9579989 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 23 Jul 2024 20:18:53 +0200 Subject: [PATCH] perf: use ref at component start --- src/pages/Order/Card/OrderCatalogFilter.vue | 41 +++++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/pages/Order/Card/OrderCatalogFilter.vue b/src/pages/Order/Card/OrderCatalogFilter.vue index d9447e530..62095bf1a 100644 --- a/src/pages/Order/Card/OrderCatalogFilter.vue +++ b/src/pages/Order/Card/OrderCatalogFilter.vue @@ -28,7 +28,34 @@ const props = defineProps({ }, }); const categoryList = ref(null); -const selectedCategoryFk = ref(null); +const params = JSON.parse(route?.query?.params ?? '{}'); +const filter = JSON.parse(params?.filter ?? '{}'); +const selectedCategoryFk = ref(filter?.where?.categoryFk ?? null); +// CHATGPT +/** + // Función para parsear JSON de manera segura +const parseJSON = (str, fallback) => { + try { + return JSON.parse(str); + } catch (e) { + console.error("Error parsing JSON:", e); + return fallback; + } +}; + +// Obtener los parámetros de la ruta +const params = parseJSON(route?.query?.params, {}); + +// Extraer y parsear el filtro de los parámetros +const { filter: filterStr = '{}' } = params; +const filter = parseJSON(filterStr, {}); + +// Obtener el categoryFk del filtro, si existe +const selectedCategoryFk = ref(filter?.where?.categoryFk ?? null); + +console.log(selectedCategoryFk.value); + + */ const typeList = ref([]); const selectedTypeFk = ref(null); const validationsStore = useValidator(); @@ -178,13 +205,13 @@ const setCategoryList = (data) => { })); moreFields.value = useLang(_moreFields); moreFieldsOrder.value = useLang(_moreFieldsTypes); - const { categoryFk } = JSON.parse(JSON.parse(route.query.params).filter).where; + // const { categoryFk } = JSON.parse(JSON.parse(route.query.params).filter).where; - if (!selectedCategoryFk.value) { - selectedCategoryFk.value = categoryFk; - selectedCategory.value = getCategory(categoryFk); - loadTypes(categoryFk); - } + // if (!selectedCategoryFk.value) { + // selectedCategoryFk.value = categoryFk; + // selectedCategory.value = getCategory(categoryFk); + // loadTypes(categoryFk); + // } }; const getCategoryClass = (category, params) => {