diff --git a/src/components/pages/StatisticsPage.tsx b/src/components/pages/StatisticsPage.tsx index 6f0e672..ca0fc0b 100644 --- a/src/components/pages/StatisticsPage.tsx +++ b/src/components/pages/StatisticsPage.tsx @@ -1,4 +1,4 @@ -import React from "react" +import { useState, useEffect } from "react" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui/card" import { Button } from "../ui/button" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select" @@ -16,13 +16,59 @@ import { CheckCircle, Clock, MapPin, + Building2, + HardHat, } from "lucide-react" +import { apiGet } from "@/services/api" +import { getUserData } from "@/utils/storage" + +// 定义统计数据接口 +interface StatisticsData { + equipmentTotal: number + equipmentGrowth: string + completedWorkOrders: number + workOrdersGrowth: string + systemUsers: number + usersGrowth: string + systemMerchants: number + merchantsGrowth: string + systemMalls: number | null + mallsGrowth: string + systemWorkers: number + workersGrowth: string + totalMerchants: number +} export default function StatisticsPage() { + const [statisticsData, setStatisticsData] = useState(null) + const [loading, setLoading] = useState(true) + const userData = getUserData() + + // 判断是否是总公司账号(根据实际业务逻辑调整) + const isHeadquarters = userData?.role === 'admin' || userData?.roleType === 'headquarters' + + useEffect(() => { + fetchStatistics() + }, []) + + const fetchStatistics = async () => { + try { + setLoading(true) + const response = await apiGet<{ code: number; msg: string; data: StatisticsData }>('/back/statistics/planTop') + if (response.code === 200) { + setStatisticsData(response.data) + } + } catch (error) { + console.error('获取统计数据失败:', error) + } finally { + setLoading(false) + } + } + const stats = { - totalEquipment: 1248, - activeWorkOrders: 23, - totalUsers: 156, + totalEquipment: statisticsData?.equipmentTotal || 0, + activeWorkOrders: statisticsData?.completedWorkOrders || 0, + totalUsers: statisticsData?.systemUsers || 0, lowStock: 8, equipmentStatus: { normal: 1156, @@ -161,21 +207,21 @@ export default function StatisticsPage() { }, ] - // 区域设备分布 - const regionEquipmentData = [ - { region: "华东区", equipment: 456, workOrders: 89 }, - { region: "华南区", equipment: 342, workOrders: 67 }, - { region: "华北区", equipment: 298, workOrders: 52 }, - { region: "华中区", equipment: 152, workOrders: 34 }, - ] + // 区域设备分布(暂未使用) + // const regionEquipmentData = [ + // { region: "华东区", equipment: 456, workOrders: 89 }, + // { region: "华南区", equipment: 342, workOrders: 67 }, + // { region: "华北区", equipment: 298, workOrders: 52 }, + // { region: "华中区", equipment: 152, workOrders: 34 }, + // ] - // 设备类型分布 - const equipmentTypeData = [ - { type: "干粉灭火器", count: 567, percentage: 45.4 }, - { type: "自动喷淋", count: 234, percentage: 18.8 }, - { type: "烟感器", count: 298, percentage: 23.9 }, - { type: "消防栓", count: 149, percentage: 11.9 }, - ] + // 设备类型分布(暂未使用) + // const equipmentTypeData = [ + // { type: "干粉灭火器", count: 567, percentage: 45.4 }, + // { type: "自动喷淋", count: 234, percentage: 18.8 }, + // { type: "烟感器", count: 298, percentage: 23.9 }, + // { type: "消防栓", count: 149, percentage: 11.9 }, + // ] return (
@@ -205,58 +251,112 @@ export default function StatisticsPage() {
+ {/* 1. 所有地区设备总数 */} - 设备总数 + 所有地区设备总数 -
{stats.totalEquipment}
+
{loading ? '-' : statisticsData?.equipmentTotal || 0}

- 较上月增长 12% + 较上月增长 {loading ? '-' : statisticsData?.equipmentGrowth || '0%'}

+ {/* 2. 完成工单 */} - 活跃工单 - + 完成工单 + -
{stats.activeWorkOrders}
+
{loading ? '-' : statisticsData?.completedWorkOrders || 0}

- - 平均处理时间 2.3天 + + 较上月增长 {loading ? '-' : statisticsData?.workOrdersGrowth || '0%'}

+ {/* 3. 系统用户 */} 系统用户 -
{stats.totalUsers}
-

活跃用户 142 人

-
-
- - - - 库存预警 - - - -
{stats.lowStock}
+
{loading ? '-' : statisticsData?.systemUsers || 0}

- - 需要补货 + + 较上月增长 {loading ? '-' : statisticsData?.usersGrowth || '0%'}

+ + {/* 4. 系统商户 */} + + + 系统商户 + + + +
{loading ? '-' : statisticsData?.systemMerchants || 0}
+

+ + 较上月增长 {loading ? '-' : statisticsData?.merchantsGrowth || '0%'} +

+
+
+ + {/* 5. 系统商场 */} + + + 系统商场 + + + +
{loading ? '-' : statisticsData?.systemMalls || 0}
+

+ + 较上月增长 {loading ? '-' : statisticsData?.mallsGrowth || '0%'} +

+
+
+ + {/* 6. 系统工人 */} + + + 系统工人 + + + +
{loading ? '-' : statisticsData?.systemWorkers || 0}
+

+ + 较上月增长 {loading ? '-' : statisticsData?.workersGrowth || '0%'} +

+
+
+ + {/* 7. 总商户 - 仅总公司账号可见 */} + {isHeadquarters && ( + + + 总商户 + + + +
{loading ? '-' : statisticsData?.totalMerchants || 0}
+

+ + 较上月增长 {loading ? '-' : statisticsData?.merchantsGrowth || '0%'} +

+
+
+ )}
diff --git a/src/components/pages/WorkOrdersPage.tsx b/src/components/pages/WorkOrdersPage.tsx index f458269..c77eac0 100644 --- a/src/components/pages/WorkOrdersPage.tsx +++ b/src/components/pages/WorkOrdersPage.tsx @@ -435,20 +435,22 @@ export default function WorkOrdersPage() { 类型 状态 负责人 - 时间 + 创建时间 + 截至时间 + 完成时间 操作 {loadingWorkOrders ? ( - +
加载中...
) : filteredWorkOrders.length === 0 ? ( - +
暂无工单数据
@@ -485,12 +487,21 @@ export default function WorkOrdersPage() { -
-
- - 截止: {item.scheduledDate || "未设置"} -
-
创建: {item.createdDate}
+
{item.createdDate || "-"}
+ + +
+ + {item.scheduledDate || "未设置"} +
+
+ +
+ {item.completedDate ? ( + {item.completedDate} + ) : ( + - + )}