feat(全局概览): 快捷入口下方新增人员操作统计区域
- 表格展示每人 接收/转交/上传备注/总次数,按总次数降序 - 跟随顶部时间筛选(今天/近7天/近30天/自定义)联动刷新
This commit is contained in:
@ -1,14 +1,14 @@
|
|||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import {
|
import {
|
||||||
Package, ClipboardList, Bell, TrendingUp, AlertTriangle,
|
Package, ClipboardList, Bell, TrendingUp, AlertTriangle,
|
||||||
RefreshCw, Loader2, AlertCircle, ArrowRight, Clock, MessageCircle, CheckCircle2,
|
RefreshCw, Loader2, AlertCircle, ArrowRight, Clock, MessageCircle, CheckCircle2, Users,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { Radio, DatePicker, Drawer, Input } from "antd";
|
import { Radio, DatePicker, Drawer, Input } from "antd";
|
||||||
import dayjs, { type Dayjs } from "dayjs";
|
import dayjs, { type Dayjs } from "dayjs";
|
||||||
import {
|
import {
|
||||||
fetchDashboardStats, fetchWipTasks, fetchDashboardMessages, fetchCompletedTasks, fetchRejectedTasks,
|
fetchDashboardStats, fetchWipTasks, fetchDashboardMessages, fetchCompletedTasks, fetchRejectedTasks, fetchUserOperations,
|
||||||
type DashboardStats, type WipTask, type ProductMessageItem, type CompletedTask, type RejectedTask,
|
type DashboardStats, type WipTask, type ProductMessageItem, type CompletedTask, type RejectedTask, type UserOperation,
|
||||||
} from "../../services/dashboardApi";
|
} from "../../services/dashboardApi";
|
||||||
|
|
||||||
const { RangePicker } = DatePicker;
|
const { RangePicker } = DatePicker;
|
||||||
@ -269,6 +269,10 @@ export default function AdminDashboard() {
|
|||||||
const [rejectedTasks, setRejectedTasks] = useState<RejectedTask[]>([]);
|
const [rejectedTasks, setRejectedTasks] = useState<RejectedTask[]>([]);
|
||||||
const [rejectedLoading, setRejectedLoading] = useState(false);
|
const [rejectedLoading, setRejectedLoading] = useState(false);
|
||||||
|
|
||||||
|
// 人员操作统计
|
||||||
|
const [opStats, setOpStats] = useState<UserOperation[]>([]);
|
||||||
|
const [opLoading, setOpLoading] = useState(false);
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
// ── 加载主数据 ──
|
// ── 加载主数据 ──
|
||||||
@ -323,6 +327,18 @@ export default function AdminDashboard() {
|
|||||||
.finally(() => setRejectedLoading(false));
|
.finally(() => setRejectedLoading(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 人员操作统计 — 跟随顶部时间筛选
|
||||||
|
const loadUserOperations = useCallback(() => {
|
||||||
|
setOpLoading(true);
|
||||||
|
const { since, until } = rangeToParams(dateKey, customRange);
|
||||||
|
fetchUserOperations(since, until)
|
||||||
|
.then(setOpStats)
|
||||||
|
.catch(() => setOpStats([]))
|
||||||
|
.finally(() => setOpLoading(false));
|
||||||
|
}, [dateKey, customRange]);
|
||||||
|
|
||||||
|
useEffect(() => { loadUserOperations(); }, [loadUserOperations]);
|
||||||
|
|
||||||
const onMsgSearch = (value: string) => {
|
const onMsgSearch = (value: string) => {
|
||||||
setMsgKeyword(value);
|
setMsgKeyword(value);
|
||||||
loadMessages(value);
|
loadMessages(value);
|
||||||
@ -528,6 +544,50 @@ export default function AdminDashboard() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* ═══ 人员操作统计 ═══ */}
|
||||||
|
<div className="rounded-xl bg-white p-5 shadow-sm">
|
||||||
|
<div className="mb-3 flex items-center justify-between">
|
||||||
|
<h3 className="flex items-center gap-2 text-sm font-semibold text-gray-700">
|
||||||
|
<Users className="h-4 w-4 text-blue-500" /> 👥 人员操作统计
|
||||||
|
</h3>
|
||||||
|
<span className="text-[11px] text-gray-400">接收 / 转交 / 上传备注 · 跟随时间筛选</span>
|
||||||
|
</div>
|
||||||
|
{opLoading ? (
|
||||||
|
<div className="flex items-center justify-center py-12">
|
||||||
|
<Loader2 className="h-6 w-6 animate-spin text-blue-500" />
|
||||||
|
</div>
|
||||||
|
) : opStats.length === 0 ? (
|
||||||
|
<div className="py-12 text-center text-sm text-gray-400">该时段暂无操作记录</div>
|
||||||
|
) : (
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="w-full text-left text-sm">
|
||||||
|
<thead>
|
||||||
|
<tr className="border-b border-gray-100 text-xs text-gray-400">
|
||||||
|
<th className="py-2 pr-3 font-medium">#</th>
|
||||||
|
<th className="py-2 pr-3 font-medium">人员</th>
|
||||||
|
<th className="py-2 pr-3 text-right font-medium">接收</th>
|
||||||
|
<th className="py-2 pr-3 text-right font-medium">转交</th>
|
||||||
|
<th className="py-2 pr-3 text-right font-medium">上传备注</th>
|
||||||
|
<th className="py-2 text-right font-medium">总次数</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{opStats.map((u, idx) => (
|
||||||
|
<tr key={u.user_id} className="border-b border-gray-50 last:border-0 hover:bg-gray-50/50">
|
||||||
|
<td className="py-2 pr-3 text-xs text-gray-400">{idx + 1}</td>
|
||||||
|
<td className="py-2 pr-3 font-medium text-gray-800">{u.user_name}</td>
|
||||||
|
<td className="py-2 pr-3 text-right text-gray-600">{u.receive_count}</td>
|
||||||
|
<td className="py-2 pr-3 text-right text-gray-600">{u.transfer_count}</td>
|
||||||
|
<td className="py-2 pr-3 text-right text-gray-600">{u.record_count}</td>
|
||||||
|
<td className="py-2 text-right font-bold text-blue-600">{u.total}</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* ═══ 留言抽屉 ═══ */}
|
{/* ═══ 留言抽屉 ═══ */}
|
||||||
<Drawer
|
<Drawer
|
||||||
title={<span className="text-base font-bold">💬 协同留言板 <span className="font-normal text-gray-400">全厂 · {msgTotal} 条</span></span>}
|
title={<span className="text-base font-bold">💬 协同留言板 <span className="font-normal text-gray-400">全厂 · {msgTotal} 条</span></span>}
|
||||||
|
|||||||
@ -54,6 +54,15 @@ export interface RejectedTask {
|
|||||||
rejected_at: string | null;
|
rejected_at: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UserOperation {
|
||||||
|
user_id: string;
|
||||||
|
user_name: string;
|
||||||
|
receive_count: number;
|
||||||
|
transfer_count: number;
|
||||||
|
record_count: number;
|
||||||
|
total: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface PersonDevice {
|
export interface PersonDevice {
|
||||||
product_id: string;
|
product_id: string;
|
||||||
serial_number: string;
|
serial_number: string;
|
||||||
@ -142,6 +151,14 @@ export async function fetchRejectedTasks(since?: string, until?: string): Promis
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchUserOperations(since?: string, until?: string): Promise<UserOperation[]> {
|
||||||
|
const params: Record<string, string> = {};
|
||||||
|
if (since) params.since = since;
|
||||||
|
if (until) params.until = until;
|
||||||
|
const { data } = await api.get<UserOperation[]>("/dashboard/user-operations", { params });
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchPeopleWorkload(): Promise<PersonWorkload[]> {
|
export async function fetchPeopleWorkload(): Promise<PersonWorkload[]> {
|
||||||
const { data } = await api.get<PersonWorkload[]>("/dashboard/people-workload");
|
const { data } = await api.get<PersonWorkload[]>("/dashboard/people-workload");
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
Reference in New Issue
Block a user