Blame view

美国版/Food Labeling Management Platform/src/components/layout/Header.tsx 3.91 KB
884054fb   “wangming”   项目初始化
1
  import React from 'react';
ef6b3255   杨鑫   修改BUG
2
  import { Search, Settings } from 'lucide-react';
884054fb   “wangming”   项目初始化
3
4
5
  import { Input } from '../ui/input';
  import { Button } from '../ui/button';
  import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar';
ef6b3255   杨鑫   修改BUG
6
7
8
  import { useAuth } from '../auth/AuthProvider';
  import { displayNameFromUser, displayRolesFromCodes } from '../../lib/currentUserDisplay';
  import { formatRelativeSince } from '../../lib/relativeSince';
884054fb   “wangming”   项目初始化
9
10
11
  
  interface HeaderProps {
    title: string;
699ea6e8   杨鑫   完善打印逻辑
12
13
    /** 右上角设置:默认跳转 Support,与侧栏一致 */
    onSettingsClick?: () => void;
ef6b3255   杨鑫   修改BUG
14
15
    /** 点击右上角姓名/角色区域:进入当前用户编辑(由 Layout/App 处理路由) */
    onProfileClick?: () => void;
884054fb   “wangming”   项目初始化
16
17
  }
  
ef6b3255   杨鑫   修改BUG
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  export function Header({ title, onSettingsClick, onProfileClick }: HeaderProps) {
    const auth = useAuth();
    const displayName = displayNameFromUser(auth.user);
    /** 第一行:姓名;第二行:接口返回的人类可读角色(如 Partner Admin) */
    const primaryName = auth.roleDisplay
      ? (auth.user?.fullName ?? '').trim() ||
        (auth.user?.nick ?? auth.user?.userName ?? '').trim() ||
        displayName
      : displayName;
    const roleLine = auth.roleDisplay ?? displayRolesFromCodes(auth.roleCodes);
    const initials = primaryName
      .split(/\s+/)
      .filter(Boolean)
      .slice(0, 2)
      .map((w) => w[0]?.toUpperCase() ?? '')
      .join('') || 'U';
  
884054fb   “wangming”   项目初始化
35
36
37
38
39
40
41
42
43
44
45
    const currentDate = new Date().toLocaleDateString('en-US', { 
      year: 'numeric', 
      month: 'long', 
      day: 'numeric' 
    });
  
    return (
      <header className="bg-white border-b border-gray-200 px-8 flex items-center justify-between shadow-sm sticky top-0 z-10 shrink-0" style={{ height: 90 }}>
        <div>
          <h1 className="text-2xl font-bold" style={{ color: 'rgb(43, 50, 143)' }}>{title} Overview</h1>
          <p className="text-sm text-gray-500 mt-1 flex items-center gap-2">
ef6b3255   杨鑫   修改BUG
46
47
48
49
            {currentDate} | Last updated:{' '}
            {auth.loading && !auth.user?.lastUpdated
              ? '…'
              : formatRelativeSince(auth.user?.lastUpdated ?? null)}
884054fb   “wangming”   项目初始化
50
51
52
53
54
55
56
57
58
59
60
61
62
          </p>
        </div>
  
        <div className="flex items-center gap-4">
          <div className="flex items-center w-64 h-9 rounded-md border border-gray-200 bg-gray-50 focus-within:bg-white focus-within:ring-2 focus-within:ring-ring/50 focus-within:border-ring transition-colors overflow-hidden">
            <Search className="h-4 w-4 text-gray-400 shrink-0 ml-3 pointer-events-none" />
            <Input
              type="search"
              placeholder="Search..."
              className="flex-1 min-w-0 border-0 bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0 py-2 px-2 h-full"
            />
          </div>
          
699ea6e8   杨鑫   完善打印逻辑
63
64
65
66
67
68
69
70
          <Button
            type="button"
            variant="ghost"
            size="icon"
            className="text-gray-500 hover:text-gray-700"
            aria-label="Open Support"
            onClick={() => onSettingsClick?.()}
          >
884054fb   “wangming”   项目初始化
71
72
73
74
75
            <Settings className="w-5 h-5" />
          </Button>
          
          <div className="h-8 w-px bg-gray-200 mx-2" />
          
ef6b3255   杨鑫   修改BUG
76
77
78
79
80
81
82
83
84
85
86
          <button
            type="button"
            onClick={() => onProfileClick?.()}
            className="flex items-center gap-3 rounded-lg border border-transparent px-2 py-1.5 text-left transition-colors hover:border-gray-200 hover:bg-gray-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40"
            aria-label="Open my profile"
          >
            <div className="text-right hidden md:block min-w-0 max-w-[12rem]">
              <div className="text-sm font-medium text-gray-900 truncate">{primaryName}</div>
              <div className="text-xs text-gray-500 truncate" title={roleLine}>
                {roleLine}
              </div>
884054fb   “wangming”   项目初始化
87
            </div>
ef6b3255   杨鑫   修改BUG
88
            <Avatar className="h-10 w-10 shrink-0 border border-gray-200">
884054fb   “wangming”   项目初始化
89
              <AvatarImage src="https://github.com/shadcn.png" />
ef6b3255   杨鑫   修改BUG
90
              <AvatarFallback>{initials}</AvatarFallback>
884054fb   “wangming”   项目初始化
91
            </Avatar>
ef6b3255   杨鑫   修改BUG
92
          </button>
884054fb   “wangming”   项目初始化
93
94
95
96
        </div>
      </header>
    );
  }