yeg
2026-09-05 2f1220d7ce4157e1ef8e3ff06d5d8ff527229f4e
src/stores/exceptions.ts
@@ -1,5 +1,6 @@
import { ref } from 'vue'
import { closeWarningException, getWarningExceptions, type WarningExceptionRecord } from '@/api/tests'
import { formatBusinessTime } from '@/utils/businessTime'
export type ExceptionStatus = '待处理' | '已处理'
@@ -22,9 +23,21 @@
const records = ref<ExceptionRecord[]>([])
function mapRecord(item: WarningExceptionRecord): ExceptionRecord {
  const offline = item.exceptionType === 'DEVICE_OFFLINE'
  let normalValue = '-'
  try { const rule = JSON.parse(item.ruleSnapshot || '{}'); normalValue = rule.maxValue != null ? `≤ ${rule.maxValue} ${item.unit}` : rule.minValue != null ? `≥ ${rule.minValue} ${item.unit}` : '-' } catch { /* 快照不可解析时仍展示异常事实 */ }
  return { id: item.exceptionId, testId: item.testId, testName: item.testName || `测试 #${item.testId}`, testTime: item.firstOccurredAtUtc, source: `${item.sourceType}${item.sourceIdentity ? ` · ${item.sourceIdentity}` : ''}`, exceptionItem: item.metricCode, abnormalValue: `${item.abnormalValue} ${item.unit}`, normalValue, generatedAt: item.lastOccurredAtUtc, processor: item.handledByName || '', handledAt: item.handledAtUtc || '-', status: item.exceptionStatus === 'OPEN' ? '待处理' : '已处理', handleRemark: item.handlingNote || '' }
  const sourceLabel = ({ CABINET: '检测柜', CABINET_CHANNEL: '检测柜通道', COLLECTOR: '采集器' } as Record<string, string>)[item.sourceType] || item.sourceType
  return {
    id: item.exceptionId, testId: item.testId, testName: item.testName || `测试 #${item.testId}`,
    testTime: formatBusinessTime(item.firstOccurredAtUtc),
    source: `${sourceLabel}${item.sourceIdentity ? ` · ${item.sourceIdentity}` : ''}`,
    exceptionItem: offline ? '设备离线' : item.metricCode,
    abnormalValue: offline ? '离线' : item.abnormalValue == null ? '-' : `${item.abnormalValue} ${item.unit}`,
    normalValue: offline ? '在线' : normalValue,
    generatedAt: formatBusinessTime(item.lastOccurredAtUtc), processor: item.handledByName || '',
    handledAt: formatBusinessTime(item.handledAtUtc), status: item.exceptionStatus === 'OPEN' ? '待处理' : '已处理',
    handleRemark: item.handlingNote || '',
  }
}
export function useExceptions() {