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 }
|
}
|