From 6847a4cf1a098f4b5c5dd42ff6ab7ae502872882 Mon Sep 17 00:00:00 2001 From: hwj Date: Thu, 29 Jan 2026 15:00:02 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=99=BA=E8=83=BD=E5=88=B6?= =?UTF-8?q?=E9=80=A0=E4=BA=A7=E7=BA=BF=E5=A4=A7=E5=B1=8F-=E6=88=90?= =?UTF-8?q?=E5=93=81=E6=A3=80=E5=90=88=E6=A0=BC=E7=8E=87=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/mes/plan/index.ts | 3 + .../dashboard8/components/QualityTrend.vue | 56 +++++++++++++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/api/mes/plan/index.ts b/src/api/mes/plan/index.ts index cceb4431..d1fadfd5 100644 --- a/src/api/mes/plan/index.ts +++ b/src/api/mes/plan/index.ts @@ -106,5 +106,8 @@ export const PlanApi = { }, getPlanCapacity: async (type: number) => { return await request.get({ url: `/mes/plan/getPlanCapacity?type=` + type }) + }, + getLastDaysRate: async () => { + return await request.get({ url: `/mes/plan/getLastDaysRate` }) } } diff --git a/src/views/report/dashboardPage/dashboard8/components/QualityTrend.vue b/src/views/report/dashboardPage/dashboard8/components/QualityTrend.vue index 8f732241..fb4a272e 100644 --- a/src/views/report/dashboardPage/dashboard8/components/QualityTrend.vue +++ b/src/views/report/dashboardPage/dashboard8/components/QualityTrend.vue @@ -19,6 +19,7 @@ import { onMounted } from 'vue' import * as echarts from 'echarts' import { useChart, colors, style } from '../utils' +import { PlanApi } from '@/api/mes/plan' const { init } = useChart('chart-quality') @@ -31,7 +32,54 @@ for (let i = 6; i >= 0; i--) { const passRate = [98.5, 99.2, 97.8, 98.9, 99.0, 98.2, 99.5] -onMounted(() => { +type QualityPoint = { + label: string + rate: number +} + +const normalizeQualityData = (raw: any): QualityPoint[] => { + if (!raw) return [] + const source = raw && typeof raw === 'object' && 'data' in raw ? raw.data : raw + const rows: QualityPoint[] = [] + + if (Array.isArray(source)) { + source.forEach((row: any) => { + const rawDate = row?.day ?? row?.date ?? row?.statDate ?? row?.createDate ?? '' + const rawLabel = typeof rawDate === 'string' ? rawDate : String(rawDate || '') + const label = rawLabel.length >= 10 ? rawLabel.slice(5, 10).replace('-', '/') : rawLabel + const rawRate = row?.rate ?? row?.passRate ?? row?.qualifiedRate ?? row?.value ?? 0 + const n = Number(rawRate) + const rate = Number.isNaN(n) ? 0 : n + rows.push({ label, rate }) + }) + } else if (source && typeof source === 'object') { + const entries = Object.entries(source).sort(([a], [b]) => a.localeCompare(b)) + entries.forEach(([key, value]) => { + const rawLabel = String(key || '') + const label = rawLabel.length >= 10 ? rawLabel.slice(5, 10).replace('-', '/') : rawLabel + const n = Number(value) + const rate = Number.isNaN(n) ? 0 : n + rows.push({ label, rate }) + }) + } + + return rows.filter((item) => item.label) +} + +onMounted(async () => { + let xAxisData = last7Days.slice() + let seriesData = passRate.slice() + + try { + const data = await PlanApi.getLastDaysRate() + const list = normalizeQualityData(data) + if (list.length > 0) { + xAxisData = list.map((item) => item.label) + seriesData = list.map((item) => item.rate) + } + } catch { + } + const chart = init() if (!chart) return @@ -39,8 +87,8 @@ onMounted(() => { backgroundColor: 'transparent', tooltip: { trigger: 'axis' }, grid: { top: '18%', left: '6%', right: '6%', bottom: '10%', containLabel: true }, - xAxis: { type: 'category', data: last7Days, axisLine: style.axisLine, axisLabel: style.axisLabel }, - yAxis: { type: 'value', min: 96, max: 100, axisLine: { show: false }, axisLabel: style.axisLabel, splitLine: style.splitLine }, + xAxis: { type: 'category', data: xAxisData, axisLine: style.axisLine, axisLabel: style.axisLabel }, + yAxis: { type: 'value', min: 0, max: 100, axisLine: { show: false }, axisLabel: style.axisLabel, splitLine: style.splitLine }, series: [{ name: '合格率', type: 'bar', @@ -52,7 +100,7 @@ onMounted(() => { { offset: 1, color: 'rgba(139,92,246,0.10)' } ]) }, - data: passRate, + data: seriesData, markLine: { symbol: ['none', 'none'], label: { show: true, color: '#fff', fontSize: 12, formatter: '平均 {c}%' },