// composables/useKompasDocuments.ts const documentTypeLabels = { 0: 'Неизвестно', 1: 'Чертёж', 2: 'Фрагмент', 3: 'Спецификация', 4: 'Деталь', 5: 'Сборка', 6: 'Текстовый документ', 7: 'Технологическая сборка', } as const type DocumentTypeLabel = typeof documentTypeLabels export function getDocumentLabel(typeCode: number): string { return documentTypeLabels[typeCode as keyof DocumentTypeLabel] || 'Неизвестный тип' } export function useKompasDocuments() { // Список документов из КОМПАС const documents = ref([]) // Фильтр по типам const selectedTypes = ref([]) // Доступные действия (динамически с бэкенда) const availableActions = ref>({}) // Вычисляем количество документов по типам const documentCounts = computed(() => { const counts: Record = {} Object.keys(documentTypeLabels).forEach(key => { const code = Number(key) counts[code] = documents.value.filter(doc => doc.type === code).length }) return counts }) // Отфильтрованный список const filteredDocuments = computed(() => { if (selectedTypes.value.length === 0) return documents.value return documents.value.filter(doc => selectedTypes.value.includes(Number(doc.type))) }) // Какие действия сейчас применимы к документам const applicableActions = computed(() => { const result: Record = {} for (const key in availableActions.value) { const action = availableActions.value[key] const canApply = documents.value.some(doc => action.allowedTypes.includes(doc.type)) if (canApply) { result[key] = { label: action.label } } } return result }) return { documents, selectedTypes, documentCounts, filteredDocuments, documentTypeLabels, getDocumentLabel, applicableActions, } }