Merge pull request #3718 from wucm667/fix/usage-csv-export-utf8-bom

fix(usage): CSV 导出补 UTF-8 BOM,修复 Excel 打开中文列乱码
This commit is contained in:
Wesley Liddick
2026-07-06 10:12:27 +08:00
committed by GitHub
2 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -677,7 +677,7 @@ const exportToCSV = async () => {
headers.map(escapeCSVValue).join(','),
...rows.map((row) => row.join(',')),
].join('\n')
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' })
const blob = new Blob(['\uFEFF' + csvContent], { type: 'text/csv;charset=utf-8;' })
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
@@ -237,6 +237,11 @@ describe('user UsageView', () => {
}))
expect(clickSpy).toHaveBeenCalled()
expect(showSuccess).toHaveBeenCalled()
expect(csvContent.startsWith('\uFEFF')).toBe(true)
expect(csvContent.slice(1)).toBe([
'Time,API Key Name,Model,Reasoning Effort,Inbound Endpoint,IP Address,Type,Billing Mode,Input Tokens,Output Tokens,Cache Read Tokens,Cache Creation Tokens,Rate Multiplier,Billed Cost,Original Cost,First Token (ms),Duration (ms)',
'2026-03-08T00:00:00Z,demo-key,gpt-5.4,"\'-",,203.0.113.10,Sync,Token,4057,101,278272,4,1,0.09288300,0.09288300,12,345',
].join('\n'))
expect(csvContent).toContain('IP Address')
expect(csvContent).toContain('203.0.113.10')
expect(csvContent).toContain('Billed Cost')