stat tadbe data

This commit is contained in:
Kseninia Mikhaylova 2025-06-30 14:50:35 +03:00
parent 8335b16bad
commit 3e1a205162
3 changed files with 141 additions and 52 deletions

View File

@ -1,37 +1,33 @@
<script setup lang="ts"> <script setup lang="ts">
defineProps({ defineProps({
caption: { headers: {
type: String, type: Array as () => string[],
default: '' required: true,
default: () => []
}, },
items: { rows: {
type: Object, type: Array as () => string[][],
required: true required: true,
}, default: () => []
labelKey: {
type: String,
default: 'Ключ'
},
labelValue: {
type: String,
default: 'Значение'
} }
}) })
</script> </script>
<template> <template>
<table class="min-w-full mt-4 border-collapse"> <table class="min-w-full border-collapse mt-4 bg-white shadow rounded-lg overflow-hidden">
<caption v-if="caption" class="caption-top font-medium text-left">{{ caption }}</caption> <thead class="bg-gray-100 text-left">
<thead class="bg-gray-100">
<tr> <tr>
<th class="border px-4 py-2 text-left">{{ labelKey }}</th> <th v-for="(header, i) in headers" :key="i" class="px-4 py-2 font-medium border-b">
<th class="border px-4 py-2 text-left">{{ labelValue }}</th> {{ header }}
</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="(value, key) in items" :key="key"> <tr v-for="(row, rowIndex) in rows" :key="rowIndex" class="hover:bg-gray-50">
<td class="border px-4 py-2">{{ key }}</td> <td v-for="(cell, cellIndex) in row" :key="cellIndex" class="px-4 py-2 border-b">
<td class="border px-4 py-2">{{ value }}</td> {{ cell }}
</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</template> </template>

View File

@ -1,32 +1,125 @@
<template>
<div v-if="item">
<h3 class="text-xl font-bold mb-2">{{ item.name }}</h3>
<p>Количество элементов: {{ item.elements_count }}</p>
<p>Количество гибов: {{ item.bends_count }}</p>
<!-- Имя -->
<TableItem caption="По названию:" :items="item.statistics.Name" label-key="Название" label-value="Количество" />
<!-- Материал -->
<TableItem caption="По материалу:" :items="item.statistics.Material" label-key="Материал"
label-value="Количество" />
<!-- Площадь -->
<TableItem caption="Площадь материалов:" :items="item.statistics.Area" label-key="Материал"
label-value="Площадь (м²)" />
<!-- Сварки -->
<TableItem caption="Сварные швы:" :items="item.statistics.Welding" label-key="Имя сварки"
label-value="Длина (мм)" />
</div>
</template>
<script setup> <script setup>
const props = defineProps({
defineProps({ statsData: {
item: {
type: Object, type: Object,
required: true required: true
} }
}) })
</script>
function generateTableData(data, config, showDetails = true) {
const headers = config.map(c => c.label)
const rows = []
for (const key in data) {
const entries = data[key]
if (!entries.length) continue
// Считаем итоговые значения
const totals = {}
config.forEach(c => {
if (c.total) {
totals[c.key] = entries.reduce((sum, entry) => {
const val = parseFloat(entry[c.key])
return sum + (isNaN(val) ? 0 : val)
}, 0)
}
})
// Основная строка
const mainRow = config.map(c => {
if (c.key === 'key') return key
if (c.key === 'count') return entries.length
if (c.total) return totals[c.key].toFixed(c.precision ?? 6)
return ''
})
rows.push(mainRow)
// Подстроки (если нужно)
if (entries.length > 1 && showDetails) {
for (const entry of entries) {
const subRow = config.map(c => {
if (c.key === 'key') return ''
if (c.key === 'count') return 1
const value = entry[c.key]
if (typeof value === 'number') {
return value.toFixed(c.precision ?? 6)
}
return value ?? '-'
})
rows.push(subRow)
}
}
}
return {
headers,
rows
}
}
const standardTableData = computed(() => {
const standard = props.statsData?.Standard || {}
return generateTableData(standard, [
{ key: 'key', label: 'Название' },
{ key: 'count', label: 'Количество' }
], false)
})
const weldTableData = computed(() => {
const weld = props.statsData?.Weld || {}
return generateTableData(weld, [
{ key: 'key', label: 'Сварка' },
{ key: 'count', label: 'Элементов' },
{ key: 'dummy', label: '-' }, // пустая колонка
{ key: 'length', label: 'Длина шва', total: true, precision: 6 }
])
})
const sheetTableData = computed(() => {
const sheet = props.statsData?.Sheet || {}
return generateTableData(sheet, [
{ key: 'key', label: 'Параметры листа' },
{ key: 'count', label: 'Количество' },
{ key: 'name', label: 'Имя детали' },
{ key: 'radius', label: 'Радиус гиба', precision: 1 },
{ key: 'area', label: 'Площадь (м²)', total: true, precision: 6 },
{ key: 'mass', label: 'Масса (кг)', total: true, precision: 6 }
])
})
const pipeTableData = computed(() => {
const pipe = props.statsData?.Pipe || {}
return generateTableData(pipe, [
{ key: 'key', label: 'Сечение' },
{ key: 'count', label: 'Элементов' },
{ key: 'key', label: 'Сечение' }, // дублируем для отображения в подстроках
{ key: 'length', label: 'Общая длина', total: true, precision: 6 }
])
})
</script>
<template>
<!-- === Листовой металл через TableItem === -->
<div v-if="sheetTableData.rows.length" class="mt-6">
<h3 class="text-lg font-semibold mb-2">Листовой металл</h3>
<TableItem v-bind="sheetTableData" />
</div>
<div v-if="weldTableData.rows.length" class="mt-6">
<h3 class="text-lg font-semibold mb-2">Сварочные швы</h3>
<TableItem v-bind="weldTableData" />
</div>
<div v-if="pipeTableData.rows.length" class="mt-6">
<h3 class="text-lg font-semibold mb-2">Трубы</h3>
<TableItem v-bind="pipeTableData" />
</div>
<div v-if="standardTableData.rows.length" class="mt-6">
<h3 class="text-lg font-semibold mb-2">Стандартные изделия</h3>
<TableItem v-bind="standardTableData" />
</div>
</template>

View File

@ -72,7 +72,7 @@ function updateUIWithResult(data: any, action: any) {
// Сохраняем сырые данные на случай непредвиденного типа действия // Сохраняем сырые данные на случай непредвиденного типа действия
resultData.value = data resultData.value = data
if (!data || !data.result || !Array.isArray(data.result)) { if (!data || !data.result) {
console.warn('Некорректный формат данных') console.warn('Некорректный формат данных')
return return
} }
@ -231,7 +231,7 @@ async function runSelectedAction() {
<TableFiles :files="(filesData as any).result" /> <TableFiles :files="(filesData as any).result" />
</template> </template>
<template v-if="statsData"> <template v-if="statsData">
<TableStats v-for="item in (statsData as any).result" :key="item.name" :item="item" /> <TableStats :statsData="(statsData as any).result"/>
</template> </template>
<template v-if="drawingData"> <template v-if="drawingData">
<TableDrawing :drawingData="(drawingData as any).result" /> <TableDrawing :drawingData="(drawingData as any).result" />