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 = {
|
const documentTypeLabels = {
|
||||||
0: 'Неизвестно',
|
0: 'Неизвестно',
|
||||||
1: 'Фрагмент',
|
1: 'Чертёж',
|
||||||
2: 'Сборка',
|
2: 'Фрагмент',
|
||||||
3: 'Деталь',
|
3: 'Спецификация',
|
||||||
4: 'Чертёж',
|
4: 'Деталь',
|
||||||
5: 'Спецификация',
|
5: 'Сборка',
|
||||||
|
6: 'Текстовый документ',
|
||||||
|
7: 'Технологическая сборка',
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
type DocumentTypeLabel = typeof documentTypeLabels
|
type DocumentTypeLabel = typeof documentTypeLabels
|
||||||
|
@ -22,6 +24,9 @@ export function useKompasDocuments() {
|
||||||
// Фильтр по типам
|
// Фильтр по типам
|
||||||
const selectedTypes = ref<number[]>([])
|
const selectedTypes = ref<number[]>([])
|
||||||
|
|
||||||
|
// Доступные действия (динамически с бэкенда)
|
||||||
|
const availableActions = ref<Record<string, { label: string; allowedTypes: number[] }>>({})
|
||||||
|
|
||||||
// Вычисляем количество документов по типам
|
// Вычисляем количество документов по типам
|
||||||
const documentCounts = computed(() => {
|
const documentCounts = computed(() => {
|
||||||
const counts: Record<number, number> = {}
|
const counts: Record<number, number> = {}
|
||||||
|
@ -38,6 +43,21 @@ export function useKompasDocuments() {
|
||||||
return documents.value.filter(doc => selectedTypes.value.includes(Number(doc.type)))
|
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 {
|
return {
|
||||||
documents,
|
documents,
|
||||||
selectedTypes,
|
selectedTypes,
|
||||||
|
@ -45,5 +65,6 @@ export function useKompasDocuments() {
|
||||||
filteredDocuments,
|
filteredDocuments,
|
||||||
documentTypeLabels,
|
documentTypeLabels,
|
||||||
getDocumentLabel,
|
getDocumentLabel,
|
||||||
|
applicableActions,
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,44 +11,15 @@ const {
|
||||||
getDocumentLabel,
|
getDocumentLabel,
|
||||||
} = useKompasDocuments()
|
} = useKompasDocuments()
|
||||||
|
|
||||||
|
const {
|
||||||
|
availableActions,
|
||||||
|
loadActions
|
||||||
|
} = useKompasActions()
|
||||||
|
|
||||||
type ActionType = 'iges' | 'drawings' | 'stats' | 'export_pdf'
|
const selectedAction = ref()
|
||||||
|
watch(selectedAction, ()=>{
|
||||||
type ActionConfig = {
|
selectedTypes.value = availableActions.value[selectedAction.value].allowedTypes
|
||||||
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 }
|
|
||||||
)
|
|
||||||
// Синхронизация с КОМПАС
|
// Синхронизация с КОМПАС
|
||||||
async function syncKompas() {
|
async function syncKompas() {
|
||||||
try {
|
try {
|
||||||
|
@ -59,6 +30,7 @@ async function syncKompas() {
|
||||||
documents.value = []
|
documents.value = []
|
||||||
} else {
|
} else {
|
||||||
documents.value = docs
|
documents.value = docs
|
||||||
|
loadActions()
|
||||||
}
|
}
|
||||||
console.warn('Документы из КОМПАС:', docs)
|
console.warn('Документы из КОМПАС:', docs)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -66,6 +38,7 @@ async function syncKompas() {
|
||||||
alert('Не удалось получить список документов из КОМПАС')
|
alert('Не удалось получить список документов из КОМПАС')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -107,16 +80,14 @@ async function syncKompas() {
|
||||||
|
|
||||||
<div class="mb-4 p-3 bg-gray-100 rounded shadow-sm">
|
<div class="mb-4 p-3 bg-gray-100 rounded shadow-sm">
|
||||||
<h3 class="font-medium mb-2">Действия:</h3>
|
<h3 class="font-medium mb-2">Действия:</h3>
|
||||||
<div class="flex flex-wrap gap-4">
|
<div class="flex flex-col gap-2">
|
||||||
<label v-for="(actionConfig, actionKey) in availableActions" :key="actionKey"
|
<label v-for="(action, key) in availableActions" :key="key" class="flex items-center gap-2">
|
||||||
class="flex items-center gap-1">
|
<input type="radio" :value="key" v-model="selectedAction"
|
||||||
<input type="radio" :value="actionKey" v-model="selectedAction"
|
|
||||||
class="form-radio h-4 w-4 text-blue-600" />
|
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>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</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-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"
|
<div v-for="(doc, index) in filteredDocuments" :key="index"
|
||||||
|
|
Loading…
Reference in New Issue