yeg
2026-08-26 9f48020dfd3e29d1c0049a3da9df3203c40bc264
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { ref } from 'vue'
import type { FormationReportMetricKey } from '@/stores/formationReports'
 
export interface SpliceTestSelection {
  id: number
  name: string
  type: string
  durationMinutes: number
}
 
export interface SpliceReportRecord {
  id: number
  name: string
  creator: string
  createdAt: string
  experimentName: string
  batteryGroup: string
  samples: string[]
  tests: SpliceTestSelection[]
  batteryFields: string[]
  specialFields: string[]
  detailFieldValues: Record<string, Record<string, string>>
  metrics: FormationReportMetricKey[]
  seriesColors: string[]
}
 
export type SpliceReportPayload = Pick<SpliceReportRecord, 'name' | 'creator' | 'experimentName' | 'batteryGroup' | 'samples' | 'tests' | 'batteryFields' | 'specialFields' | 'detailFieldValues' | 'metrics' | 'seriesColors'>
 
const STORAGE_KEY = 'battery_detection_splice_reports_v1'
const defaultMetrics: FormationReportMetricKey[] = ['voltage', 'current', 'positiveVoltage', 'negativeVoltage', 'temperature']
const defaultColors = ['#3978f6', '#7d42d8', '#f08a3e']
 
const seedRecords: SpliceReportRecord[] = [
  {
    id: 8053,
    name: 'SP2化成与静置连续曲线',
    creator: 'Admin',
    createdAt: '2026-08-06 15:20',
    experimentName: 'SP2连续工况实验',
    batteryGroup: 'SP2样品组',
    samples: ['SP26-1', 'SP26-2', 'SP26-3'],
    tests: [
      { id: 101, name: 'SP2电池化成测试', type: '化成', durationMinutes: 90 },
      { id: 102, name: '化成后静置测试', type: '静置', durationMinutes: 60 },
      { id: 103, name: '首次容量测试', type: '容量', durationMinutes: 75 },
    ],
    batteryFields: ['额定容量', '内阻'],
    specialFields: ['环境温度'],
    detailFieldValues: {},
    metrics: [...defaultMetrics],
    seriesColors: [...defaultColors],
  },
  {
    id: 8052,
    name: '高温化成分段拼接报表',
    creator: '李工',
    createdAt: '2026-08-05 17:42',
    experimentName: '高温化成连续观察',
    batteryGroup: '高温A批',
    samples: ['HT-01', 'HT-02', 'HT-03'],
    tests: [
      { id: 201, name: '高温化成测试', type: '化成', durationMinutes: 100 },
      { id: 202, name: '高温静置测试', type: '静置', durationMinutes: 45 },
    ],
    batteryFields: ['额定容量'],
    specialFields: ['环境温度'],
    detailFieldValues: {},
    metrics: [...defaultMetrics],
    seriesColors: [...defaultColors],
  },
  {
    id: 8051,
    name: '首充与容量标定拼接报表',
    creator: '王工',
    createdAt: '2026-08-04 13:10',
    experimentName: '首充连续数据实验',
    batteryGroup: '一致性样品组',
    samples: ['SP26-4', 'SP26-5', 'SP26-6'],
    tests: [
      { id: 301, name: '首充化成测试', type: '化成', durationMinutes: 80 },
      { id: 302, name: '容量标定测试', type: '容量', durationMinutes: 70 },
    ],
    batteryFields: ['额定容量', '内阻'],
    specialFields: [],
    detailFieldValues: {},
    metrics: [...defaultMetrics],
    seriesColors: [...defaultColors],
  },
]
 
function loadRecords() {
  try {
    const stored = localStorage.getItem(STORAGE_KEY)
    if (stored) return JSON.parse(stored) as SpliceReportRecord[]
  } catch {
    localStorage.removeItem(STORAGE_KEY)
  }
  return seedRecords
}
 
const records = ref<SpliceReportRecord[]>(loadRecords())
 
function persist() {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(records.value))
}
 
function nowString() {
  const date = new Date()
  const pad = (value: number) => String(value).padStart(2, '0')
  return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`
}
 
export function useSpliceReports() {
  function createReport(data: SpliceReportPayload) {
    const id = Math.max(8000, ...records.value.map(item => item.id)) + 1
    records.value.unshift({ ...data, id, createdAt: nowString() })
    persist()
  }
 
  function updateReport(id: number, data: SpliceReportPayload) {
    const target = records.value.find(item => item.id === id)
    if (!target) return false
    Object.assign(target, data)
    persist()
    return true
  }
 
  function removeReport(id: number) {
    records.value = records.value.filter(item => item.id !== id)
    persist()
  }
 
  return { records, createReport, updateReport, removeReport }
}