diff --git a/front/components/table/item.vue b/front/components/table/item.vue index 93c7d72..17f5f98 100644 --- a/front/components/table/item.vue +++ b/front/components/table/item.vue @@ -1,37 +1,33 @@ + + \ No newline at end of file diff --git a/front/components/table/stats.vue b/front/components/table/stats.vue index 343dd50..3d7bbab 100644 --- a/front/components/table/stats.vue +++ b/front/components/table/stats.vue @@ -1,32 +1,125 @@ - - \ No newline at end of file + +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 } + ]) +}) + + \ No newline at end of file diff --git a/front/pages/kompas.vue b/front/pages/kompas.vue index d84a355..e2c88a6 100644 --- a/front/pages/kompas.vue +++ b/front/pages/kompas.vue @@ -72,7 +72,7 @@ function updateUIWithResult(data: any, action: any) { // Сохраняем сырые данные на случай непредвиденного типа действия resultData.value = data - if (!data || !data.result || !Array.isArray(data.result)) { + if (!data || !data.result) { console.warn('Некорректный формат данных') return } @@ -231,7 +231,7 @@ async function runSelectedAction() {