优化后端构建方式,修改首页报表 bug

This commit is contained in:
eafonyang
2026-07-30 15:08:05 +08:00
parent f2bbaa6876
commit b1c88fc5e6
12 changed files with 56 additions and 54 deletions
+2 -2
View File
@@ -139,7 +139,7 @@ router.post('/api/blacklist/', async (req: Request, res: Response) => {
try {
const parsed = BlackListCreateSchema.safeParse(req.body);
if (!parsed.success) {
const errors = parsed.error.errors.map((e) => e.message).join('; ');
const errors = parsed.error.issues.map((e: { message: string }) => e.message).join('; ');
res.json(ApiResponse.error(errors));
return;
}
@@ -174,7 +174,7 @@ router.put('/api/blacklist/:id', async (req: Request, res: Response) => {
const parsed = BlackListUpdateSchema.safeParse(req.body);
if (!parsed.success) {
const errors = parsed.error.errors.map((e) => e.message).join('; ');
const errors = parsed.error.issues.map((e: { message: string }) => e.message).join('; ');
res.json(ApiResponse.error(errors));
return;
}
+11 -3
View File
@@ -8,6 +8,14 @@ import { authMiddleware } from '../middleware/auth.js';
const router: RouterType = Router();
/** 格式化为本地日期字符串 YYYY-MM-DD(避免 toISOString 的 UTC 偏移) */
function toLocalDateStr(d: Date): string {
const y = d.getFullYear();
const m = String(d.getMonth() + 1).padStart(2, '0');
const day = String(d.getDate()).padStart(2, '0');
return `${y}-${m}-${day}`;
}
// 所有 dashboard 接口需登录
router.use(authMiddleware);
@@ -135,7 +143,7 @@ router.get('/api/dashboard/device-daily', async (req: Request, res: Response) =>
const dateList: string[] = [];
const tmp = new Date(startDate);
while (tmp <= now) {
dateList.push(tmp.toISOString().slice(0, 10));
dateList.push(toLocalDateStr(tmp));
tmp.setDate(tmp.getDate() + 1);
}
@@ -228,14 +236,14 @@ router.get('/api/dashboard/active-daily', async (req: Request, res: Response) =>
const dateList: string[] = [];
const tmp = new Date(startDate);
while (tmp <= now) {
dateList.push(tmp.toISOString().slice(0, 10));
dateList.push(toLocalDateStr(tmp));
tmp.setDate(tmp.getDate() + 1);
}
const modelSet = new Set<string>();
const dataMap = new Map<string, Record<string, number>>();
for (const row of rows) {
const dateStr = String(row.active_date).slice(0, 10);
const dateStr = toLocalDateStr(new Date(row.active_date));
modelSet.add(row.model);
if (!dataMap.has(dateStr)) dataMap.set(dateStr, {});
dataMap.get(dateStr)![row.model] = Number(row.count);
+2 -2
View File
@@ -184,7 +184,7 @@ router.post('/api/ota/', async (req: Request, res: Response) => {
try {
const parsed = OtaCreateSchema.safeParse(req.body);
if (!parsed.success) {
const errors = parsed.error.errors.map((e) => e.message).join('; ');
const errors = parsed.error.issues.map((e: { message: string }) => e.message).join('; ');
res.json(ApiResponse.error(errors));
return;
}
@@ -241,7 +241,7 @@ router.put('/api/ota/:ota_id', async (req: Request, res: Response) => {
const parsed = OtaUpdateSchema.safeParse(req.body);
if (!parsed.success) {
const errors = parsed.error.errors.map((e) => e.message).join('; ');
const errors = parsed.error.issues.map((e: { message: string }) => e.message).join('; ');
res.json(ApiResponse.error(errors));
return;
}
@@ -139,7 +139,7 @@ router.post('/api/ota-target-device/', async (req: Request, res: Response) => {
try {
const parsed = OtaTargetDeviceCreateSchema.safeParse(req.body);
if (!parsed.success) {
const errors = parsed.error.errors.map((e) => e.message).join('; ');
const errors = parsed.error.issues.map((e: { message: string }) => e.message).join('; ');
res.json(ApiResponse.error(errors));
return;
}
@@ -185,7 +185,7 @@ router.put('/api/ota-target-device/:id', async (req: Request, res: Response) =>
const parsed = OtaTargetDeviceUpdateSchema.safeParse(req.body);
if (!parsed.success) {
const errors = parsed.error.errors.map((e) => e.message).join('; ');
const errors = parsed.error.issues.map((e: { message: string }) => e.message).join('; ');
res.json(ApiResponse.error(errors));
return;
}