kompas action
This commit is contained in:
parent
106f4b72b9
commit
f753090fe5
|
@ -0,0 +1,49 @@
|
|||
// composables/useKompasActions.ts
|
||||
|
||||
const availableActions = ref<Record<string, { label: string; allowedTypes: number[] }>>({})
|
||||
|
||||
export function useKompasActions() {
|
||||
const { sendCommandToPython, isReady } = usePythonBridge()
|
||||
const loading = ref(false)
|
||||
const error = ref<string | null>(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<string, { label: string; allowedTypes: number[] }> = {}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
|
@ -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<number[]>([])
|
||||
|
||||
// Доступные действия (динамически с бэкенда)
|
||||
const availableActions = ref<Record<string, { label: string; allowedTypes: number[] }>>({})
|
||||
|
||||
// Вычисляем количество документов по типам
|
||||
const documentCounts = computed(() => {
|
||||
const counts: Record<number, number> = {}
|
||||
|
@ -38,6 +43,21 @@ export function useKompasDocuments() {
|
|||
return documents.value.filter(doc => selectedTypes.value.includes(Number(doc.type)))
|
||||
})
|
||||
|
||||
// Какие действия сейчас применимы к документам
|
||||
const applicableActions = computed(() => {
|
||||
const result: Record<string, { label: string }> = {}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
|
@ -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<ActionType, ActionConfig> = {
|
||||
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<ActionType | null>(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('Не удалось получить список документов из КОМПАС')
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -107,16 +80,14 @@ async function syncKompas() {
|
|||
|
||||
<div class="mb-4 p-3 bg-gray-100 rounded shadow-sm">
|
||||
<h3 class="font-medium mb-2">Действия:</h3>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<label v-for="(actionConfig, actionKey) in availableActions" :key="actionKey"
|
||||
class="flex items-center gap-1">
|
||||
<input type="radio" :value="actionKey" v-model="selectedAction"
|
||||
<div class="flex flex-col gap-2">
|
||||
<label v-for="(action, key) in availableActions" :key="key" class="flex items-center gap-2">
|
||||
<input type="radio" :value="key" v-model="selectedAction"
|
||||
class="form-radio h-4 w-4 text-blue-600" />
|
||||
<span class="text-sm">{{ actionConfig.label }}</span>
|
||||
<span class="text-sm">{{ action.label }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Грид документов -->
|
||||
<div v-if="filteredDocuments.length" class="mt-4 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
<div v-for="(doc, index) in filteredDocuments" :key="index"
|
||||
|
|
Loading…
Reference in New Issue