From 121829a4bd07c3e12053b10b464876cecfbd2d15 Mon Sep 17 00:00:00 2001 From: caozehui <2427765068@qq.com> Date: Thu, 7 May 2026 19:18:05 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=B9=E6=80=A7=E7=82=B9=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/freqConverterDipChart.vue | 134 +++++++++++++++--- 1 file changed, 116 insertions(+), 18 deletions(-) diff --git a/frontend/src/views/machine/freqConverter/components/freqConverterDipChart.vue b/frontend/src/views/machine/freqConverter/components/freqConverterDipChart.vue index d716224..6a91668 100644 --- a/frontend/src/views/machine/freqConverter/components/freqConverterDipChart.vue +++ b/frontend/src/views/machine/freqConverter/components/freqConverterDipChart.vue @@ -50,11 +50,20 @@ interface ChartPoint { status: ChartPointStatus } +interface CharacteristicCurvePoint { + duration: number + residualVoltage: number + time: string | null + timeMs: number | null +} + interface NormalizedTolerantPoint { duration: number residualVoltage: number tolerant: number | null status: ChartPointStatus + time: string | null + timeMs: number | null } const props = defineProps<{ @@ -72,8 +81,8 @@ const STATUS_COLOR_MAP: Record = { const CHARACTERISTIC_POINT_COLOR = '#ff4d4f' const chartPoints = ref([]) -const characteristicCurveData = ref>([]) -const drawnCharacteristicCurveData = ref>([]) +const characteristicCurveData = ref([]) +const drawnCharacteristicCurveData = ref([]) const characteristicCurveVisible = ref(false) const chartRef = ref(null) @@ -117,21 +126,45 @@ const sortedChartPoints = computed(() => { const sortedCharacteristicCurveData = computed(() => { return [...characteristicCurveData.value].sort((a, b) => { - if (a[0] !== b[0]) { - return a[0] - b[0] + if (a.timeMs !== null && b.timeMs !== null && a.timeMs !== b.timeMs) { + return a.timeMs - b.timeMs } - return a[1] - b[1] + if (a.timeMs !== null && b.timeMs === null) { + return -1 + } + + if (a.timeMs === null && b.timeMs !== null) { + return 1 + } + + if (a.duration !== b.duration) { + return a.duration - b.duration + } + + return a.residualVoltage - b.residualVoltage }) }) const sortedDrawnCharacteristicCurveData = computed(() => { return [...drawnCharacteristicCurveData.value].sort((a, b) => { - if (a[0] !== b[0]) { - return a[0] - b[0] + if (a.timeMs !== null && b.timeMs !== null && a.timeMs !== b.timeMs) { + return a.timeMs - b.timeMs } - return a[1] - b[1] + if (a.timeMs !== null && b.timeMs === null) { + return -1 + } + + if (a.timeMs === null && b.timeMs !== null) { + return 1 + } + + if (a.duration !== b.duration) { + return a.duration - b.duration + } + + return a.residualVoltage - b.residualVoltage }) }) @@ -141,12 +174,12 @@ const solidCharacteristicCurveSeriesData = computed(() => { } const curveSource = props.autoDrawCurve ? sortedCharacteristicCurveData.value : sortedDrawnCharacteristicCurveData.value - return curveSource.map(item => [item[0], item[1], '特性曲线']) + return curveSource.map(item => [item.duration, item.residualVoltage, '特性曲线']) }) const characteristicCurvePointSeriesData = computed(() => { return sortedCharacteristicCurveData.value.map(item => ({ - value: [item[0], item[1], '特性点'] + value: [item.duration, item.residualVoltage, '特性点'] })) }) @@ -206,6 +239,58 @@ const toNumber = (value: unknown) => { return Number.isFinite(result) ? result : null } +const parsePointTime = (value: unknown) => { + if (typeof value !== 'string') { + return { + time: null, + timeMs: null + } + } + + const normalizedValue = value.trim() + const match = normalizedValue.match( + /^(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})\.(\d{3})$/ + ) + + if (!match) { + return { + time: normalizedValue || null, + timeMs: null + } + } + + const [, year, month, day, hour, minute, second, millisecond] = match + const parsedDate = new Date( + Number(year), + Number(month) - 1, + Number(day), + Number(hour), + Number(minute), + Number(second), + Number(millisecond) + ) + + if ( + parsedDate.getFullYear() !== Number(year) || + parsedDate.getMonth() !== Number(month) - 1 || + parsedDate.getDate() !== Number(day) || + parsedDate.getHours() !== Number(hour) || + parsedDate.getMinutes() !== Number(minute) || + parsedDate.getSeconds() !== Number(second) || + parsedDate.getMilliseconds() !== Number(millisecond) + ) { + return { + time: normalizedValue, + timeMs: null + } + } + + return { + time: normalizedValue, + timeMs: parsedDate.getTime() + } +} + const normalizeTolerantValue = (value: unknown) => { if (value === undefined || value === null || value === '') { return null @@ -251,6 +336,7 @@ const normalizeStatus = (value: unknown): ChartPointStatus => { const normalizeTolerantPoint = (source: Record): NormalizedTolerantPoint | null => { const duration = normalizeDuration(source) const residualVoltage = normalizeResidualVoltageValue(source) + const { time, timeMs } = parsePointTime(source.time) if (duration === null || residualVoltage === null) { return null @@ -276,6 +362,8 @@ const normalizeTolerantPoint = (source: Record): NormalizedTolerant duration, residualVoltage, tolerant, + time, + timeMs, status: tolerant === 0 ? 'fail' @@ -313,7 +401,7 @@ const normalizePoint = (source: Record): ChartPoint | null => { } const extractCharacteristicCurvePoints = (payload: any) => { - const result: Array<[number, number]> = [] + const result: CharacteristicCurvePoint[] = [] const seen = new Set() const rootPayload = payload?.data && typeof payload.data === 'object' ? payload.data : payload @@ -333,10 +421,15 @@ const extractCharacteristicCurvePoints = (payload: any) => { const point = normalizeTolerantPoint(node) if (point?.tolerant === 2) { - const key = `${point.duration}|${point.residualVoltage}` + const key = point.time ? `${point.time}|${point.duration}|${point.residualVoltage}` : `${point.duration}|${point.residualVoltage}` if (!seen.has(key)) { seen.add(key) - result.push([point.duration, point.residualVoltage]) + result.push({ + duration: point.duration, + residualVoltage: point.residualVoltage, + time: point.time, + timeMs: point.timeMs + }) } } @@ -351,17 +444,21 @@ const extractCharacteristicCurvePoints = (payload: any) => { return result } -const mergeCharacteristicCurvePoints = (points: Array<[number, number]>) => { +const mergeCharacteristicCurvePoints = (points: CharacteristicCurvePoint[]) => { if (!points.length) { return } const existingPointMap = new Map( - characteristicCurveData.value.map(item => [`${item[0]}|${item[1]}`, item] as const) + characteristicCurveData.value.map(item => [ + item.time ? `${item.time}|${item.duration}|${item.residualVoltage}` : `${item.duration}|${item.residualVoltage}`, + item + ] as const) ) points.forEach(item => { - existingPointMap.set(`${item[0]}|${item[1]}`, item) + const key = item.time ? `${item.time}|${item.duration}|${item.residualVoltage}` : `${item.duration}|${item.residualVoltage}` + existingPointMap.set(key, item) }) characteristicCurveData.value = Array.from(existingPointMap.values()) @@ -472,8 +569,9 @@ const exportChartData = () => { const curveSheet = XLSX.utils.json_to_sheet( sortedCharacteristicCurveData.value.map((item, index) => ({ 序号: index + 1, - 持续时间_s: item[0], - 残余电压_pct: item[1] + 持续时间_s: item.duration, + 残余电压_pct: item.residualVoltage, + 时间: item.time ?? '' })) ) XLSX.utils.book_append_sheet(workbook, curveSheet, '特性点')