fix(csms): fix lint errors, clean up imports and improve code formatting

This commit is contained in:
2026-03-19 21:28:48 +08:00
parent 63349a17ed
commit 524de66ad3
8 changed files with 20 additions and 36 deletions

View File

@@ -185,7 +185,7 @@ export default function ChargePointDetailPage({ params }: { params: Promise<{ id
dayjs().diff(dayjs(cp.lastHeartbeatAt), "second") < (cp.heartbeatInterval ?? 60) * 3;
const commandChannelUnavailable = cp?.transportStatus === "unavailable";
const statusLabel = isOnline ? "在线" : commandChannelUnavailable ? "通道异常" : "离线";
const statusDotClass = isOnline
const transportStatusDotClass = isOnline
? "bg-success animate-pulse"
: commandChannelUnavailable
? "bg-warning"
@@ -253,7 +253,7 @@ export default function ChargePointDetailPage({ params }: { params: Promise<{ id
</Chip>
<div className="flex items-center gap-1.5">
<span
className={`size-2 rounded-full ${statusDotClass}`}
className={`size-2 rounded-full ${transportStatusDotClass}`}
/>
<span className="text-xs text-muted">{statusLabel}</span>
</div>
@@ -445,7 +445,7 @@ export default function ChargePointDetailPage({ params }: { params: Promise<{ id
<dd>
<div className="flex items-center gap-1.5">
<span
className={`size-2 rounded-full ${statusDotClass}`}
className={`size-2 rounded-full ${transportStatusDotClass}`}
/>
<span className="text-sm text-foreground">{statusLabel}</span>
</div>

View File

@@ -184,7 +184,6 @@ export default function PricingPage() {
const [activeTier, setActiveTier] = useState<PriceTier>("peak");
const [isDirty, setIsDirty] = useState(false);
const [saving, setSaving] = useState(false);
const [showPayload, setShowPayload] = useState(false);
// Populate state once remote tariff loads
useEffect(() => {
@@ -286,7 +285,6 @@ export default function PricingPage() {
// ── Derived values ───────────────────────────────────────────────────────
const slots = scheduleToSlots(schedule);
const apiPayload: TariffConfig = { slots, prices };
// ── Admin gate ───────────────────────────────────────────────────────────
if (!isAdmin) {

View File

@@ -8,7 +8,6 @@ import {
Controls,
Handle,
MiniMap,
Panel,
Position,
type Node,
type Edge,
@@ -27,7 +26,8 @@ type ConnectionStatus = "online" | "stale" | "offline";
function getStatus(cp: ChargePoint, connected: string[]): ConnectionStatus {
if (cp.transportStatus === "unavailable") return "stale";
if (cp.transportStatus !== "online" || !connected.includes(cp.chargePointIdentifier)) return "offline";
if (cp.transportStatus !== "online" || !connected.includes(cp.chargePointIdentifier))
return "offline";
if (!cp.lastHeartbeatAt) return "stale";
return dayjs().diff(dayjs(cp.lastHeartbeatAt), "minute") < 5 ? "online" : "stale";
}

View File

@@ -3,18 +3,7 @@
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useState } from "react";
import {
CreditCard,
Gear,
ListCheck,
Person,
PlugConnection,
TagDollar,
Thunderbolt,
ThunderboltFill,
Xmark,
Bars,
} from "@gravity-ui/icons";
import { CreditCard, Gear, TagDollar, Thunderbolt, Xmark, Bars } from "@gravity-ui/icons";
import SidebarFooter from "@/components/sidebar-footer";
import { useSession } from "@/lib/auth-client";
import { EvCharger, Gauge, Network, ReceiptText, UserCog, Users } from "lucide-react";

View File

@@ -4,7 +4,7 @@ const CSMS_INTERNAL_URL =
process.env.CSMS_INTERNAL_URL ?? process.env.NEXT_PUBLIC_CSMS_URL ?? "http://localhost:3001";
/** 检查 CSMS 是否已完成初始化(有用户存在)。 */
async function isInitialized(request: NextRequest): Promise<boolean> {
async function isInitialized(): Promise<boolean> {
try {
const res = await fetch(`${CSMS_INTERNAL_URL}/api/setup`, {
method: "GET",
@@ -25,7 +25,7 @@ export async function proxy(request: NextRequest) {
// /setup 页面:已初始化则跳转登录
if (pathname === "/setup") {
if (await isInitialized(request)) {
if (await isInitialized()) {
return NextResponse.redirect(new URL("/login", request.url));
}
return NextResponse.next();
@@ -33,7 +33,7 @@ export async function proxy(request: NextRequest) {
// /dashboard 路由:检查 session未登录跳转 /login
if (pathname.startsWith("/dashboard")) {
if (!(await isInitialized(request))) {
if (!(await isInitialized())) {
return NextResponse.redirect(new URL("/setup", request.url));
}
@@ -53,7 +53,7 @@ export async function proxy(request: NextRequest) {
// /login 路由:未初始化则跳转 /setup
if (pathname === "/login") {
if (!(await isInitialized(request))) {
if (!(await isInitialized())) {
return NextResponse.redirect(new URL("/setup", request.url));
}
return NextResponse.next();