生产管理系统 - 将用户基础数据同步到zustand

This commit is contained in:
2025-11-04 20:32:28 +08:00
parent e92be97393
commit c386350df5
4 changed files with 102 additions and 149 deletions

View File

@@ -8,7 +8,7 @@
'use client';
import { Card } from '@/components/ui/card';
import { Building2, Users, Layers } from 'lucide-react';
import { Building2, Layers, GitBranch } from 'lucide-react';
import { DepartmentStats } from '../types';
interface DepartmentStatsCardsProps {
@@ -31,7 +31,7 @@ export function DepartmentStatsCards({
{
label: '二级部门',
value: stats.level2,
icon: <Users className="w-5 h-5" />,
icon: <GitBranch className="w-5 h-5" />,
color: 'text-green-600 dark:text-green-400',
bg: 'bg-green-50 dark:bg-green-950',
},

View File

@@ -171,21 +171,33 @@ export default function DepartmentManagementPage() {
}
};
// 统计部门数量
// 统计部门数量(递归计算所有层级)
const countDepartments = (depts: Department[]): { level1: number; level2: number; total: number } => {
let level1 = 0;
let level2 = 0;
let total = 0;
depts.forEach(dept => {
if (!dept.parentId) {
level1++;
if (dept.children) {
level2 += dept.children.length;
const countRecursive = (departments: Department[]) => {
departments.forEach(dept => {
total++; // 每个部门都计入总数
// 根据level字段统计各级部门
if (dept.level === 1) {
level1++; // 统计一级部门
} else if (dept.level === 2) {
level2++; // 统计二级部门
}
}
});
return { level1, level2, total: level1 + level2 };
// 递归计算子部门
if (dept.children && dept.children.length > 0) {
countRecursive(dept.children);
}
});
};
countRecursive(depts);
return { level1, level2, total };
};
const stats = countDepartments(state.departments);