Обновил боковое меню для динамического отображения групп
This commit is contained in:
@@ -1,31 +1,11 @@
|
||||
import { ref } from 'vue'
|
||||
import partsItems from '@/data/parts.js'
|
||||
|
||||
const parts = ref([])
|
||||
let loadPromise = null
|
||||
const parts = ref([...partsItems])
|
||||
|
||||
export function usePartsCatalog() {
|
||||
async function loadParts() {
|
||||
if (parts.value.length) {
|
||||
return parts.value
|
||||
}
|
||||
|
||||
if (!loadPromise) {
|
||||
loadPromise = fetch('/droneComponents/components.json')
|
||||
.then((response) => (response.ok ? response.json() : []))
|
||||
.then((data) => {
|
||||
parts.value = data
|
||||
return data
|
||||
})
|
||||
.catch(() => {
|
||||
parts.value = []
|
||||
return []
|
||||
})
|
||||
.finally(() => {
|
||||
loadPromise = null
|
||||
})
|
||||
}
|
||||
|
||||
return loadPromise
|
||||
return parts.value
|
||||
}
|
||||
|
||||
function getPartById(id) {
|
||||
|
||||
@@ -1,20 +1,34 @@
|
||||
import { usePartsCatalog } from '@/composables/usePartsCatalog'
|
||||
import termsItems from '@/data/terms.js'
|
||||
import partsItems from '@/data/parts.js'
|
||||
|
||||
export async function resolveTopic(source, id) {
|
||||
if (source === 'parts') {
|
||||
const { loadParts, getPartById } = usePartsCatalog()
|
||||
await loadParts()
|
||||
const part = getPartById(Number(id))
|
||||
const numericId = Number(id)
|
||||
|
||||
if (!part) {
|
||||
return null
|
||||
}
|
||||
if (source === 'terms') {
|
||||
const term = termsItems.find((item) => item.id === numericId)
|
||||
if (!term) return null
|
||||
|
||||
return {
|
||||
title: part.name,
|
||||
subtitle: part.category,
|
||||
title: term.title,
|
||||
subtitle: term.subtitle,
|
||||
image: term.image,
|
||||
description: term.description,
|
||||
hrefToCourse: term.hrefToCourse,
|
||||
hrefToDoc: term.hrefToDoc,
|
||||
}
|
||||
}
|
||||
|
||||
if (source === 'parts') {
|
||||
const part = partsItems.find((item) => item.id === numericId)
|
||||
if (!part) return null
|
||||
|
||||
return {
|
||||
title: part.title,
|
||||
subtitle: part.subtitle,
|
||||
image: part.image,
|
||||
description: part.description,
|
||||
hrefToCourse: null,
|
||||
hrefToDoc: null,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user