Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a3c1bc63
authored
Jan 01, 2026
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复 timestamp2string1 跨年显示问题,仅在数据跨年时显示年份
parent
87a75b05
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
12 deletions
+32
-12
web/src/helpers/dashboard.jsx
+17
-5
web/src/helpers/utils.jsx
+15
-7
No files found.
web/src/helpers/dashboard.jsx
View file @
a3c1bc63
...
...
@@ -26,6 +26,7 @@ import {
import
{
timestamp2string
,
timestamp2string1
,
isDataCrossYear
,
copy
,
showSuccess
,
}
from
'./utils'
;
...
...
@@ -259,13 +260,16 @@ export const processRawData = (
timeCountMap
:
new
Map
(),
};
// 检查数据是否跨年
const
showYear
=
isDataCrossYear
(
data
.
map
(
item
=>
item
.
created_at
));
data
.
forEach
((
item
)
=>
{
result
.
uniqueModels
.
add
(
item
.
model_name
);
result
.
totalTokens
+=
item
.
token_used
;
result
.
totalQuota
+=
item
.
quota
;
result
.
totalTimes
+=
item
.
count
;
const
timeKey
=
timestamp2string1
(
item
.
created_at
,
dataExportDefaultTime
);
const
timeKey
=
timestamp2string1
(
item
.
created_at
,
dataExportDefaultTime
,
showYear
);
if
(
!
result
.
timePoints
.
includes
(
timeKey
))
{
result
.
timePoints
.
push
(
timeKey
);
}
...
...
@@ -323,8 +327,11 @@ export const calculateTrendData = (
export
const
aggregateDataByTimeAndModel
=
(
data
,
dataExportDefaultTime
)
=>
{
const
aggregatedData
=
new
Map
();
// 检查数据是否跨年
const
showYear
=
isDataCrossYear
(
data
.
map
(
item
=>
item
.
created_at
));
data
.
forEach
((
item
)
=>
{
const
timeKey
=
timestamp2string1
(
item
.
created_at
,
dataExportDefaultTime
);
const
timeKey
=
timestamp2string1
(
item
.
created_at
,
dataExportDefaultTime
,
showYear
);
const
modelKey
=
item
.
model_name
;
const
key
=
`
${
timeKey
}
-
${
modelKey
}
`
;
...
...
@@ -358,10 +365,15 @@ export const generateChartTimePoints = (
const
lastTime
=
Math
.
max
(...
data
.
map
((
item
)
=>
item
.
created_at
));
const
interval
=
getTimeInterval
(
dataExportDefaultTime
,
true
);
chartTimePoints
=
Array
.
from
(
// 生成时间点数组,用于检查是否跨年
const
generatedTimestamps
=
Array
.
from
(
{
length
:
DEFAULTS
.
MAX_TREND_POINTS
},
(
_
,
i
)
=>
timestamp2string1
(
lastTime
-
(
6
-
i
)
*
interval
,
dataExportDefaultTime
),
(
_
,
i
)
=>
lastTime
-
(
6
-
i
)
*
interval
,
);
const
showYear
=
isDataCrossYear
(
generatedTimestamps
);
chartTimePoints
=
generatedTimestamps
.
map
(
ts
=>
timestamp2string1
(
ts
,
dataExportDefaultTime
,
showYear
),
);
}
...
...
web/src/helpers/utils.jsx
View file @
a3c1bc63
...
...
@@ -217,15 +217,12 @@ export function timestamp2string(timestamp) {
);
}
export
function
timestamp2string1
(
timestamp
,
dataExportDefaultTime
=
'hour'
)
{
export
function
timestamp2string1
(
timestamp
,
dataExportDefaultTime
=
'hour'
,
showYear
=
false
)
{
let
date
=
new
Date
(
timestamp
*
1000
);
// let year = date.getFullYear().toString
();
let
year
=
date
.
getFullYear
();
let
month
=
(
date
.
getMonth
()
+
1
).
toString
();
let
day
=
date
.
getDate
().
toString
();
let
hour
=
date
.
getHours
().
toString
();
if
(
day
===
'24'
)
{
console
.
log
(
'timestamp'
,
timestamp
);
}
if
(
month
.
length
===
1
)
{
month
=
'0'
+
month
;
}
...
...
@@ -235,11 +232,13 @@ export function timestamp2string1(timestamp, dataExportDefaultTime = 'hour') {
if
(
hour
.
length
===
1
)
{
hour
=
'0'
+
hour
;
}
let
str
=
month
+
'-'
+
day
;
// 仅在跨年时显示年份
let
str
=
showYear
?
year
+
'-'
+
month
+
'-'
+
day
:
month
+
'-'
+
day
;
if
(
dataExportDefaultTime
===
'hour'
)
{
str
+=
' '
+
hour
+
':00'
;
}
else
if
(
dataExportDefaultTime
===
'week'
)
{
let
nextWeek
=
new
Date
(
timestamp
*
1000
+
6
*
24
*
60
*
60
*
1000
);
let
nextWeekYear
=
nextWeek
.
getFullYear
();
let
nextMonth
=
(
nextWeek
.
getMonth
()
+
1
).
toString
();
let
nextDay
=
nextWeek
.
getDate
().
toString
();
if
(
nextMonth
.
length
===
1
)
{
...
...
@@ -248,11 +247,20 @@ export function timestamp2string1(timestamp, dataExportDefaultTime = 'hour') {
if
(
nextDay
.
length
===
1
)
{
nextDay
=
'0'
+
nextDay
;
}
str
+=
' - '
+
nextMonth
+
'-'
+
nextDay
;
// 周视图结束日期也仅在跨年时显示年份
let
nextStr
=
showYear
?
nextWeekYear
+
'-'
+
nextMonth
+
'-'
+
nextDay
:
nextMonth
+
'-'
+
nextDay
;
str
+=
' - '
+
nextStr
;
}
return
str
;
}
// 检查时间戳数组是否跨年
export
function
isDataCrossYear
(
timestamps
)
{
if
(
!
timestamps
||
timestamps
.
length
===
0
)
return
false
;
const
years
=
new
Set
(
timestamps
.
map
(
ts
=>
new
Date
(
ts
*
1000
).
getFullYear
()));
return
years
.
size
>
1
;
}
export
function
downloadTextAsFile
(
text
,
filename
)
{
let
blob
=
new
Blob
([
text
],
{
type
:
'text/plain;charset=utf-8'
});
let
url
=
URL
.
createObjectURL
(
blob
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment