Skip to content

Commit a9af8e1

Browse files
夏一飞夏一飞
authored andcommitted
refactor: improve panel page and api handling
1 parent 859c7a6 commit a9af8e1

File tree

20 files changed

+46
-68
lines changed

20 files changed

+46
-68
lines changed

app/api/init/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { NextResponse } from "next/server";
22
import { initDatabase } from "@/lib/db/client";
33

4-
// 初始化数据库
54
let initialized = false;
65

76
export async function GET() {

app/api/v1/config/key/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { NextResponse } from "next/server";
22
import { verifyApiToken } from "@/lib/auth";
33

44
export async function GET(req: Request) {
5-
// 验证API token
65
const authError = verifyApiToken(req);
76
if (authError) {
87
return authError;

app/api/v1/panel/database/import/route.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export async function POST(req: Request) {
1616
}
1717

1818
try {
19-
// 开始事务
2019
await query("BEGIN");
2120

2221
await query("TRUNCATE TABLE user_usage_records CASCADE");
@@ -64,15 +63,13 @@ export async function POST(req: Request) {
6463
}
6564
}
6665

67-
// 提交事务
6866
await query("COMMIT");
6967

7068
return NextResponse.json({
7169
success: true,
7270
message: "Data import successful",
7371
});
7472
} catch (error) {
75-
// 回滚事务
7673
await query("ROLLBACK");
7774
throw error;
7875
}

app/api/v1/panel/records/route.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export async function GET(req: Request) {
1616
const sortOrder = searchParams.get("sortOrder");
1717
const users = searchParams.get("users")?.split(",") || [];
1818
const models = searchParams.get("models")?.split(",") || [];
19+
const startDate = searchParams.get("startDate");
20+
const endDate = searchParams.get("endDate");
1921

2022
const conditions = [];
2123
const params = [];
@@ -33,6 +35,15 @@ export async function GET(req: Request) {
3335
paramIndex++;
3436
}
3537

38+
if (startDate && endDate) {
39+
conditions.push(
40+
`use_time >= $${paramIndex} AND use_time <= $${paramIndex + 1}`
41+
);
42+
params.push(startDate);
43+
params.push(endDate);
44+
paramIndex += 2;
45+
}
46+
3647
const whereClause =
3748
conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
3849

app/api/v1/panel/usage/route.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export async function GET(request: Request) {
1313
const startTime = searchParams.get("startTime");
1414
const endTime = searchParams.get("endTime");
1515

16+
console.log("Query params:", [startTime, endTime]);
17+
1618
const timeFilter =
1719
startTime && endTime ? `WHERE use_time >= $1 AND use_time <= $2` : "";
1820

@@ -88,6 +90,9 @@ export async function GET(request: Request) {
8890
return NextResponse.json(formattedData);
8991
} catch (error) {
9092
console.error("Fail to fetch usage records:", error);
93+
if (error instanceof Error) {
94+
console.error("[DB Query Error]", error);
95+
}
9196
return NextResponse.json(
9297
{ error: "Fail to fetch usage records" },
9398
{ status: 500 }

app/globals.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ body {
8080
display: none;
8181
}
8282

83-
/* 更新模态框样式 */
8483
.update-modal .ant-modal-content {
8584
padding: 24px;
8685
border-radius: 16px;
@@ -222,7 +221,6 @@ body {
222221
background-size: 24px 24px;
223222
}
224223

225-
/* 添加以下样式 */
226224
@media (max-width: 640px) {
227225
.toaster-group {
228226
--viewport-padding: 16px;
@@ -240,7 +238,6 @@ body {
240238
}
241239
}
242240

243-
/* 自定义日期选择器样式 */
244241
.custom-date-picker {
245242
border-radius: 0.5rem;
246243
box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);

app/models/page.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,6 @@ export default function ModelsPage() {
886886

887887
return (
888888
<div className="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-8 pt-24 space-y-8">
889-
{/* 添加 Toaster 组件 */}
890889
<Toaster
891890
richColors
892891
position="top-center"
@@ -895,15 +894,13 @@ export default function ModelsPage() {
895894
duration={1500}
896895
/>
897896

898-
{/* 页面标题部分 */}
899897
<div className="space-y-4">
900898
<h1 className="text-3xl font-bold tracking-tight">
901899
{t("models.title")}
902900
</h1>
903901
<p className="text-muted-foreground">{t("models.description")}</p>
904902
</div>
905903

906-
{/* 操作按钮组 */}
907904
<div className="flex flex-wrap gap-4">
908905
<Button
909906
variant="default"
@@ -1016,15 +1013,13 @@ export default function ModelsPage() {
10161013
/>
10171014
</div>
10181015

1019-
{/* 替换原有的TestProgress组件 */}
10201016
<TestProgressPanel
10211017
isVisible={testing || isTestComplete}
10221018
models={models}
10231019
isComplete={isTestComplete}
10241020
t={t}
10251021
/>
10261022

1027-
{/* 桌面端表格视图 */}
10281023
<div className="hidden sm:block">
10291024
<div className="rounded-xl border border-border/40 bg-card shadow-sm overflow-hidden">
10301025
{loading ? (
@@ -1045,7 +1040,6 @@ export default function ModelsPage() {
10451040
</div>
10461041
</div>
10471042

1048-
{/* 移动端卡片视图 */}
10491043
<div className="sm:hidden">
10501044
{loading ? (
10511045
<LoadingState t={t} />

app/page.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export default function HomePage() {
6060

6161
return (
6262
<main className="relative min-h-screen w-full overflow-hidden bg-gradient-to-br from-rose-50 via-slate-50 to-teal-50 pt-16">
63-
{/* 新增动态网格背景 */}
6463
<AnimatedGridPattern
6564
numSquares={30}
6665
maxOpacity={0.03}
@@ -72,18 +71,15 @@ export default function HomePage() {
7271
)}
7372
/>
7473

75-
{/* 装饰性背景模糊圆 */}
7674
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[1000px] h-[1000px] bg-gradient-to-br from-rose-100/20 via-slate-100/20 to-teal-100/20 rounded-full blur-3xl opacity-40" />
7775
<div className="absolute top-1/4 left-1/4 w-[500px] h-[500px] bg-gradient-to-br from-pink-100/10 to-indigo-100/10 rounded-full blur-3xl opacity-30" />
7876
<div className="absolute bottom-1/4 right-1/4 w-[700px] h-[700px] bg-gradient-to-br from-teal-100/10 to-slate-100/10 rounded-full blur-3xl opacity-30" />
7977

80-
{/* 修改主要内容容器,使用flex布局固定GitHub在底部 */}
8178
<motion.div
8279
initial={{ opacity: 0 }}
8380
animate={{ opacity: 1 }}
8481
className="min-h-[calc(100vh-4rem)] flex flex-col relative z-10"
8582
>
86-
{/* 标题区域保持不变 */}
8783
<motion.div className="flex-1 flex flex-col items-center justify-center">
8884
<motion.div
8985
initial={{ opacity: 0, y: 20 }}
@@ -110,13 +106,10 @@ export default function HomePage() {
110106
</div>
111107
</motion.div>
112108

113-
{/* 重新设计的导航区域 */}
114109
<div className="w-full max-w-2xl px-4 sm:px-6">
115110
<div className="relative">
116-
{/* 装饰性背景 */}
117111
<div className="absolute inset-0 bg-gradient-to-r from-rose-100/20 via-slate-100/20 to-teal-100/20 blur-3xl -z-10" />
118112

119-
{/* 新的垂直导航设计 */}
120113
<div className="space-y-4">
121114
{[
122115
{
@@ -163,15 +156,12 @@ export default function HomePage() {
163156
shadow-[0_4px_20px_-4px_rgba(0,0,0,0.05)]
164157
hover:shadow-[0_8px_30px_-4px_rgba(0,0,0,0.12)]"
165158
>
166-
{/* 移除边框设计,只保留渐变背景 */}
167159
<div
168160
className={`absolute inset-0 bg-gradient-to-r ${item.gradient} opacity-0 group-hover:opacity-100 transition-opacity duration-500`}
169161
/>
170162

171-
{/* 内容区域 */}
172163
<div className="relative p-6">
173164
<div className="flex items-center gap-4">
174-
{/* 图标容器 - 使用投影替代边框 */}
175165
<div
176166
className={cn(
177167
"p-3 rounded-xl transition-all duration-500",
@@ -184,7 +174,6 @@ export default function HomePage() {
184174
{item.icon}
185175
</div>
186176

187-
{/* 文字内容 */}
188177
<div className="flex-1 min-w-0">
189178
<h3 className="text-lg font-medium text-slate-800 group-hover:text-white transition-colors mb-1">
190179
{item.title}
@@ -194,7 +183,6 @@ export default function HomePage() {
194183
</p>
195184
</div>
196185

197-
{/* 箭头 */}
198186
<div
199187
className={cn(
200188
"transform transition-all duration-300",
@@ -226,7 +214,6 @@ export default function HomePage() {
226214
</div>
227215
</motion.div>
228216

229-
{/* GitHub 图标固定在底部 */}
230217
<motion.div
231218
initial={{ opacity: 0 }}
232219
animate={{ opacity: 1 }}
@@ -244,7 +231,6 @@ export default function HomePage() {
244231
</motion.div>
245232
</motion.div>
246233

247-
{/* 更新提示框样式修改 */}
248234
{isUpdateVisible && (
249235
<motion.div
250236
initial={{ opacity: 0, y: 20 }}

app/panel/page.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useState, useEffect } from "react";
44
import Head from "next/head";
5-
import dayjs from "dayjs";
5+
import dayjs from "@/lib/dayjs";
66
import type { TablePaginationConfig } from "antd/es/table";
77
import type { SorterResult } from "antd/es/table/interface";
88
import type { FilterValue } from "antd/es/table/interface";
@@ -109,8 +109,12 @@ export default function PanelPage() {
109109
const fetchUsageData = async (range: [Date, Date]) => {
110110
setLoading(true);
111111
try {
112-
const startTime = dayjs(range[0]).startOf("day").toISOString();
113-
const endTime = dayjs(range[1]).endOf("day").toISOString();
112+
const startTime = dayjs(range[0])
113+
.startOf("day")
114+
.format("YYYY-MM-DDTHH:mm:ssZ");
115+
const endTime = dayjs(range[1])
116+
.endOf("day")
117+
.format("YYYY-MM-DDTHH:mm:ssZ");
114118

115119
const url = `/api/v1/panel/usage?startTime=${startTime}&endTime=${endTime}`;
116120
const token = localStorage.getItem("access_token");
@@ -160,11 +164,11 @@ export default function PanelPage() {
160164

161165
searchParams.append(
162166
"startDate",
163-
dayjs(range[0]).startOf("day").format("YYYY-MM-DD")
167+
dayjs(range[0]).startOf("day").format("YYYY-MM-DDTHH:mm:ssZ")
164168
);
165169
searchParams.append(
166170
"endDate",
167-
dayjs(range[1]).endOf("day").format("YYYY-MM-DD")
171+
dayjs(range[1]).endOf("day").format("YYYY-MM-DDTHH:mm:ssZ")
168172
);
169173

170174
const token = localStorage.getItem("access_token");

app/token/page.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export default function TokenPage() {
7676
)}
7777
/>
7878

79-
{/* 装饰性背景模糊圆 */}
8079
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[1000px] h-[1000px] bg-gradient-to-br from-rose-100/20 via-slate-100/20 to-teal-100/20 rounded-full blur-3xl opacity-40" />
8180
<div className="absolute top-1/4 left-1/4 w-[500px] h-[500px] bg-gradient-to-br from-pink-100/10 to-indigo-100/10 rounded-full blur-3xl opacity-30" />
8281
<div className="absolute bottom-1/4 right-1/4 w-[700px] h-[700px] bg-gradient-to-br from-teal-100/10 to-slate-100/10 rounded-full blur-3xl opacity-30" />
@@ -112,15 +111,13 @@ export default function TokenPage() {
112111
className="backdrop-blur-[20px] bg-white/[0.08] p-10 rounded-[2.5rem] border border-white/20 shadow-2xl relative overflow-hidden
113112
hover:shadow-[0_8px_60px_rgba(120,119,198,0.15)] transition-shadow duration-300 group"
114113
>
115-
{/* 新增流光边框效果 */}
116114
<div
117115
className="absolute inset-0 rounded-[2.5rem] p-[2px]
118116
bg-gradient-to-br from-white/30 via-transparent to-transparent
119117
[mask:linear-gradient(black,black)_content-box,linear-gradient(black,black)]
120118
[mask-composite:xor] opacity-30 group-hover:opacity-50 transition-opacity"
121119
></div>
122120

123-
{/* 新增动态粒子背景 */}
124121
<div className="absolute inset-0 bg-[radial-gradient(ellipse_at_center,_var(--tw-gradient-stops))] from-slate-100/5 via-transparent to-transparent opacity-20" />
125122

126123
<motion.form

0 commit comments

Comments
 (0)