diff --git a/front/composables/useKompasActions.ts b/front/composables/useKompasActions.ts new file mode 100644 index 0000000..840c560 --- /dev/null +++ b/front/composables/useKompasActions.ts @@ -0,0 +1,49 @@ +// composables/useKompasActions.ts + +const availableActions = ref>({}) + +export function useKompasActions() { + const { sendCommandToPython, isReady } = usePythonBridge() + const loading = ref(false) + const error = ref(null) + + /** + * Загружает список действий с бэкенда + */ + async function loadActions() { + loading.value = true + error.value = null + try { + const actions = await sendCommandToPython<{ + [key: string]: { label: string; allowed_types: number[] } + }>('get_available_actions') + + if (actions) { + // Преобразуем все ключи `allowed_types` → `allowedTypes` + const convertedActions: Record = {} + + for (const key in actions) { + const { label, allowed_types } = actions[key] + convertedActions[key] = { + label, + allowedTypes: allowed_types + } + } + + availableActions.value = convertedActions + } + } catch (err: any) { + console.error('Ошибка при получении действий:', err) + error.value = 'Не удалось загрузить список действий' + } finally { + loading.value = false + } + } + + return { + availableActions, + loading, + error, + loadActions, + } +} \ No newline at end of file diff --git a/front/composables/useKompasDocuments.ts b/front/composables/useKompasDocuments.ts index a80b81e..2eb3ee2 100644 --- a/front/composables/useKompasDocuments.ts +++ b/front/composables/useKompasDocuments.ts @@ -2,11 +2,13 @@ const documentTypeLabels = { 0: 'Неизвестно', - 1: 'Фрагмент', - 2: 'Сборка', - 3: 'Деталь', - 4: 'Чертёж', - 5: 'Спецификация', + 1: 'Чертёж', + 2: 'Фрагмент', + 3: 'Спецификация', + 4: 'Деталь', + 5: 'Сборка', + 6: 'Текстовый документ', + 7: 'Технологическая сборка', } as const type DocumentTypeLabel = typeof documentTypeLabels @@ -22,6 +24,9 @@ export function useKompasDocuments() { // Фильтр по типам const selectedTypes = ref([]) + // Доступные действия (динамически с бэкенда) + const availableActions = ref>({}) + // Вычисляем количество документов по типам const documentCounts = computed(() => { const counts: Record = {} @@ -38,6 +43,21 @@ export function useKompasDocuments() { 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, @@ -45,5 +65,6 @@ export function useKompasDocuments() { filteredDocuments, documentTypeLabels, getDocumentLabel, + applicableActions, } } \ No newline at end of file diff --git a/front/pages/kompas.vue b/front/pages/kompas.vue index 5f58827..82a8e01 100644 --- a/front/pages/kompas.vue +++ b/front/pages/kompas.vue @@ -11,44 +11,15 @@ const { getDocumentLabel, } = useKompasDocuments() +const { + availableActions, + loadActions +} = useKompasActions() -type ActionType = 'iges' | 'drawings' | 'stats' | 'export_pdf' - -type ActionConfig = { - label: string - allowedTypes: number[] // допустимые типы документов -} - -const availableActions: Record = { - iges: { - label: 'Сохранить как IGES', - allowedTypes: [3], // только детали - }, - drawings: { - label: 'Создать чертежи', - allowedTypes: [2, 3], // сборки и детали - }, - stats: { - label: 'Собрать статистику', - allowedTypes: [1, 2, 3, 4, 5], // почти все типы - }, - export_pdf: { - label: 'Экспортировать в PDF', - allowedTypes: [4], // только чертежи - }, -} -const selectedAction = ref(null) -watch( - selectedAction, - (newAction) => { - if (newAction) { - console.log('Выбрано действие:', newAction) - const allowedTypes = availableActions[newAction].allowedTypes - selectedTypes.value = [...allowedTypes] // обновляем выбранные типы - } - }, - { immediate: false } -) +const selectedAction = ref() +watch(selectedAction, ()=>{ + selectedTypes.value = availableActions.value[selectedAction.value].allowedTypes +}) // Синхронизация с КОМПАС async function syncKompas() { try { @@ -59,6 +30,7 @@ async function syncKompas() { documents.value = [] } else { documents.value = docs + loadActions() } console.warn('Документы из КОМПАС:', docs) } catch (err) { @@ -66,6 +38,7 @@ async function syncKompas() { alert('Не удалось получить список документов из КОМПАС') } } +