import { ref } from 'vue'
|
|
export interface FormationReportCycle {
|
cycle: number
|
method: string
|
chargeVoltage: string
|
dischargeCapacity: string
|
retention: string
|
result: string
|
}
|
|
export type FormationReportMetricKey = 'voltage' | 'current' | 'positiveVoltage' | 'negativeVoltage' | 'temperature'
|
|
export interface FormationReportRecord {
|
id: number
|
name: string
|
creator: string
|
createdAt: string
|
testName: string
|
batteryGroup: string
|
samples: string[]
|
cycles: FormationReportCycle[]
|
cycleFieldValues?: Record<string, string>
|
reportFieldValues?: Record<string, string>
|
batteryFields?: string[]
|
specialFields?: string[]
|
metrics?: FormationReportMetricKey[]
|
seriesColors?: string[]
|
description: string
|
}
|
|
export type FormationReportPayload = Pick<FormationReportRecord, 'name' | 'creator' | 'testName' | 'batteryGroup' | 'samples' | 'cycles' | 'cycleFieldValues' | 'reportFieldValues' | 'batteryFields' | 'specialFields' | 'metrics' | 'seriesColors' | 'description'>
|
|
const STORAGE_KEY = 'battery_detection_formation_reports_v1'
|
|
const seedRecords: FormationReportRecord[] = [
|
{ id: 7003, name: 'SP2化成过程分析报表', creator: 'Admin', createdAt: '2026-08-06 10:18', testName: 'SP2电池化成测试', batteryGroup: 'SP2样品组', samples: ['SP26-1', 'SP26-2', 'SP26-3'], cycles: [{ cycle: 1, method: '恒流充电 / 恒流放电', chargeVoltage: '4.20', dischargeCapacity: '98.6%', retention: '100%', result: '合格' }, { cycle: 2, method: '恒流充电 / 恒流放电', chargeVoltage: '4.20', dischargeCapacity: '98.1%', retention: '99.5%', result: '合格' }], description: '查看化成阶段容量、内阻和温升变化。' },
|
{ id: 7002, name: '高温化成批次报表', creator: '李工', createdAt: '2026-08-05 16:22', testName: '高温化成测试', batteryGroup: '高温A批', samples: ['HT-01', 'HT-02'], cycles: [{ cycle: 1, method: '恒流充电 / 静置', chargeVoltage: '4.25', dischargeCapacity: '96.4%', retention: '100%', result: '关注' }], description: '高温环境下的化成数据汇总。' },
|
{ id: 7001, name: '首充容量一致性报表', creator: '王工', createdAt: '2026-08-04 09:36', testName: '首充化成测试', batteryGroup: '一致性样品组', samples: ['SP26-4', 'SP26-5', 'SP26-6'], cycles: [{ cycle: 1, method: '恒流充电 / 恒流放电', chargeVoltage: '4.20', dischargeCapacity: '99.2%', retention: '100%', result: '合格' }], description: '首充阶段的容量一致性比较。' },
|
]
|
|
function loadRecords() {
|
try {
|
const stored = localStorage.getItem(STORAGE_KEY)
|
if (stored) return JSON.parse(stored) as FormationReportRecord[]
|
} catch {
|
localStorage.removeItem(STORAGE_KEY)
|
}
|
return seedRecords
|
}
|
|
const records = ref<FormationReportRecord[]>(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 useFormationReports() {
|
function createReport(data: FormationReportPayload) {
|
const id = Math.max(7000, ...records.value.map(item => item.id)) + 1
|
records.value.unshift({ ...data, id, createdAt: nowString() })
|
persist()
|
}
|
function updateReport(id: number, data: FormationReportPayload) {
|
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 }
|
}
|