diff --git a/src/routes/batteries.tsx b/src/routes/batteries.tsx index 60f427e..3535ad3 100644 --- a/src/routes/batteries.tsx +++ b/src/routes/batteries.tsx @@ -1,9 +1,11 @@ import { useQuery } from '@tanstack/react-query' import { createFileRoute, Link, useNavigate } from '@tanstack/react-router' import { createColumnHelper, flexRender, getCoreRowModel, useReactTable } from '@tanstack/react-table' +import { ArrowLeft, Battery, BatteryCharging, BatteryLow, Database, FilterX, Search, Zap } from 'lucide-react' import { useEffect, useMemo, useState } from 'react' import { z } from 'zod' import { orpc } from '@/client/orpc' +import { Badge, Button, Card, Input, SectionTitle, Select } from '@/components/ui' import type { BatteryInfo, BatteryListSort, PowerStatus } from '@/domain/battery' import { BATTERY_LIST_SORT, BATTERY_LIST_SORT_VALUES, POWER_STATUS, POWER_STATUS_VALUES } from '@/domain/battery' @@ -56,10 +58,10 @@ const powerStatusLabel: Record = { [POWER_STATUS.FULL]: '已充满', } -const powerStatusColor: Record = { - [POWER_STATUS.NOT_CHARGING]: 'text-zinc-400', - [POWER_STATUS.CHARGING]: 'text-teal-400', - [POWER_STATUS.FULL]: 'text-emerald-400', +const powerStatusVariant: Record = { + [POWER_STATUS.NOT_CHARGING]: 'muted', + [POWER_STATUS.CHARGING]: 'info', + [POWER_STATUS.FULL]: 'success', } function powerBarColor(power: number, isLowPower: boolean): string { @@ -158,7 +160,7 @@ function BatteriesPage() { header: '状态', cell: (info) => { const status = info.getValue() - return {powerStatusLabel[status]} + return {powerStatusLabel[status]} }, }), columnHelper.accessor('createTime', { @@ -177,6 +179,21 @@ function BatteriesPage() { getCoreRowModel: getCoreRowModel(), }) + const hasActiveFilters = Boolean(search.search || search.lowPower || search.powerStatus !== undefined) + const clearFilters = () => { + setLocalSearch('') + navigate({ + search: (prev) => ({ + ...prev, + search: undefined, + lowPower: undefined, + powerStatus: undefined, + cursor: undefined, + cursors: [], + }), + }) + } + const handleNextPage = () => { if (!isPlaceholderData && data?.nextCursor) { const nextCursor = data.nextCursor @@ -222,132 +239,184 @@ function BatteriesPage() {
-
+
-

设备电池实时状态

-

+ + MySQL 实时记录 + +

设备电池实时状态

+

+ 只展示 ls_battery_info 最新采集记录,筛选、排序和分页均通过 ORPC 服务端查询完成。 +

+

{data ? `更新于 ${new Date(data.updatedAt).toLocaleString('zh-CN')}` : '加载中…'}

-
-
-
设备总数
-
{data?.total ?? '-'}
-
-
-
低电量
-
{data?.lowPower ?? '-'}
-
-
-
充电中
-
{data?.charging ?? '-'}
-
+ +
+ 设备总数 +
+
{data?.total ?? '-'}
+
+ +
+ 低电量 +
+
{data?.lowPower ?? '-'}
+
+ +
+ 充电中 +
+
{data?.charging ?? '-'}
+
- {/* Controls */} -
-
- setLocalSearch(e.target.value)} + +
+ } + title="筛选设备" + description="按真实采集字段筛选,不在前端伪造或补齐记录。" /> + {hasActiveFilters && ( + + )}
+
+
+ +
+ + setLocalSearch(e.target.value)} + /> +
+
- +
+ + +
- +
+ + +
-
+
+ + +
- + +
+ - -
- -
+
@@ -388,7 +457,7 @@ function BatteriesPage() {
-
+
@@ -396,22 +465,16 @@ function BatteriesPage() { {data?.total ? ` (共 ${data.total} 台)` : ''}
- - + +