Blame view

泰额版/Food Labeling Management Platform泰鄂/src/components/dashboard/Dashboard.tsx 13.1 KB
884054fb   “wangming”   项目初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
  import React from 'react';
  import { 
    Printer, 
    Tag, 
    AlertTriangle, 
    Clock, 
    TrendingUp, 
    Plus,
    FileText,
    Users,
    UserCircle,
    Package,
    MapPin,
    ArrowUpRight,
    ArrowDownRight
  } from 'lucide-react';
  import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "../ui/card";
  import { Button } from "../ui/button";
  import { Badge } from "../ui/badge";
  import {
    BarChart,
    Bar,
    XAxis,
    YAxis,
    CartesianGrid,
    Tooltip,
    ResponsiveContainer,
    LineChart,
    Line,
    PieChart,
    Pie,
    Cell
  } from 'recharts';
  import { ScrollArea } from "../ui/scroll-area";
  
  // --- Mock Data ---
  
  const WEEKLY_PRINT_DATA = [
    { day: 'Mon', labels: 145 },
    { day: 'Tue', labels: 230 },
    { day: 'Wed', labels: 185 },
    { day: 'Thu', labels: 278 },
    { day: 'Fri', labels: 190 },
    { day: 'Sat', labels: 120 },
    { day: 'Sun', labels: 85 },
  ];
  
  const CATEGORY_DATA = [
    { name: 'Prep', value: 450, color: '#3b82f6' },
    { name: 'Grab & Go', value: 320, color: '#10b981' },
    { name: 'Catering', value: 150, color: '#f59e0b' },
    { name: 'Delivery', value: 80, color: '#6366f1' },
  ];
  
  const RECENT_LABELS = [
    { id: '1-251201', product: 'Chicken Breast', template: '2" Prep', user: 'Alice J.', time: '10 mins ago', status: 'active' },
    { id: '1-251202', product: 'Caesar Salad', template: '3" Grab\'n\'Go', user: 'Bob S.', time: '25 mins ago', status: 'active' },
    { id: '1-251203', product: 'Tomato Soup', template: '2" Prep', user: 'Charlie B.', time: '40 mins ago', status: 'expired' },
    { id: '1-251204', product: 'Roast Beef', template: '2" x 2" Prep', user: 'Alice J.', time: '1 hour ago', status: 'active' },
    { id: '1-251205', product: 'Iced Tea', template: 'Beverage Label', user: 'David W.', time: '1 hour ago', status: 'active' },
  ];
  
  const ACTIVE_TIMERS = [
    { title: 'Coffee Station', time: '12:45', status: 'running' },
    { title: 'Sanitizer Bucket', time: '04:20', status: 'warning' },
    { title: 'Hot Hold Unit 1', time: '00:00', status: 'expired' },
  ];
  
  export function Dashboard() {
    return (
      <div className="space-y-6">
        {/* Top Hierarchy / Welcome Bar */}
        <div className="bg-white border border-gray-200 p-4 rounded-xl shadow-sm flex flex-col md:flex-row justify-between items-center gap-4">
          <div>
             <h1 className="text-xl font-bold" style={{ color: '#2b328f' }}>Dashboard Overview</h1>
             <p className="text-sm text-gray-500">Welcome back, Admin. Here's what's happening today.</p>
          </div>
          <div className="flex items-center gap-3">
             <Button className="bg-blue-600 text-white hover:bg-blue-700 font-medium">
               <Plus className="w-4 h-4 mr-2" /> New Label
             </Button>
             <Button variant="outline">
               View Reports
             </Button>
          </div>
        </div>
  
        {/* KPI Cards */}
        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
          <KPICard 
            title="Labels Printed Today" 
            value="342" 
            trend="+12%" 
            trendUp={true} 
            icon={Printer} 
            color="text-blue-600" 
            bgColor="bg-blue-50"
          />
          <KPICard 
            title="Active Templates" 
            value="24" 
            trend="+2 New" 
            trendUp={true} 
            icon={FileText} 
            color="text-indigo-600" 
            bgColor="bg-indigo-50"
          />
          <KPICard 
            title="Active Users" 
            value="8" 
            trend="Online Now" 
            trendUp={true} 
            icon={Users} 
            color="text-emerald-600" 
            bgColor="bg-emerald-50"
          />
          <KPICard 
            title="Locations" 
            value="12" 
            trend="+1 New" 
            trendUp={true} 
            icon={MapPin} 
            color="text-sky-600" 
            bgColor="bg-sky-50"
          />
          <KPICard 
            title="People" 
            value="48" 
            trend="+3 New" 
            trendUp={true} 
            icon={UserCircle} 
            color="text-violet-600" 
            bgColor="bg-violet-50"
          />
          <KPICard 
            title="Menu Products" 
            value="156" 
            trend="+8 New" 
            trendUp={true} 
            icon={Package} 
            color="text-amber-600" 
            bgColor="bg-amber-50"
          />
        </div>
  
        {/* Main Content Grid */}
        <div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
          
          {/* Left Column (Charts) */}
          <div className="lg:col-span-2 space-y-6">
            {/* Print Volume Chart */}
            <Card className="shadow-sm border-gray-200">
              <CardHeader>
                <CardTitle className="text-base font-bold text-gray-800 flex items-center gap-2">
                  <TrendingUp className="w-5 h-5 text-gray-500" />
                  Weekly Print Volume
                </CardTitle>
                <CardDescription>Number of labels printed over the last 7 days</CardDescription>
              </CardHeader>
              <CardContent>
                <div className="h-[300px] w-full">
                  <ResponsiveContainer width="100%" height="100%">
                    <LineChart data={WEEKLY_PRINT_DATA}>
                      <CartesianGrid strokeDasharray="3 3" vertical={false} stroke="#e5e7eb" />
                      <XAxis 
                        dataKey="day" 
                        axisLine={false} 
                        tickLine={false} 
                        tick={{ fill: '#6b7280', fontSize: 12 }} 
                        dy={10}
                      />
                      <YAxis 
                        axisLine={false} 
                        tickLine={false} 
                        tick={{ fill: '#6b7280', fontSize: 12 }} 
                      />
                      <Tooltip 
                        contentStyle={{ borderRadius: '8px', border: 'none', boxShadow: '0 4px 6px -1px rgb(0 0 0 / 0.1)' }}
                        cursor={{ stroke: '#d1d5db', strokeWidth: 1 }}
                      />
                      <Line 
                        type="monotone" 
                        dataKey="labels" 
                        stroke="#2563eb" 
                        strokeWidth={3} 
                        dot={{ r: 4, fill: '#2563eb', strokeWidth: 2, stroke: '#fff' }}
                        activeDot={{ r: 6 }}
                      />
                    </LineChart>
                  </ResponsiveContainer>
                </div>
              </CardContent>
            </Card>
  
            {/* Recent Labels Table */}
            <Card className="shadow-sm border-gray-200">
               <CardHeader className="flex flex-row items-center justify-between">
                <div>
                  <CardTitle className="text-base font-bold text-gray-800 flex items-center gap-2">
                    <Tag className="w-5 h-5 text-gray-500" />
                    Recent Labels
                  </CardTitle>
                  <CardDescription>Latest printed labels across all locations</CardDescription>
                </div>
                <Button variant="ghost" size="sm" className="text-blue-600">View All</Button>
              </CardHeader>
              <CardContent>
                <div className="space-y-4">
                  {RECENT_LABELS.map((label) => (
                    <div key={label.id} className="flex items-center justify-between p-3 bg-gray-50 rounded-lg border border-gray-100 hover:bg-gray-100 transition-colors">
                      <div className="flex items-center gap-3">
                        <div className="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center text-blue-600 font-bold text-xs">
                          {label.template.substring(0, 2)}
                        </div>
                        <div>
                          <p className="text-sm font-semibold text-gray-900">{label.product}</p>
                          <p className="text-xs text-gray-500">{label.id} • {label.user}</p>
                        </div>
                      </div>
                      <div className="flex items-center gap-4">
                        <span className="text-xs text-gray-500 font-medium">{label.time}</span>
                        <Badge 
                          variant="secondary" 
                          className={label.status === 'expired' ? 'bg-red-100 text-red-700' : 'bg-green-100 text-green-700'}
                        >
                          {label.status}
                        </Badge>
                      </div>
                    </div>
                  ))}
                </div>
              </CardContent>
            </Card>
          </div>
  
          {/* Right Column (Widgets) */}
          <div className="space-y-6">
            
            {/* Category Distribution */}
            <Card className="shadow-sm border-gray-200">
              <CardHeader>
                <CardTitle className="text-base font-bold text-gray-800 flex items-center gap-2">
                  <Package className="w-5 h-5 text-gray-500" />
                  By Category
                </CardTitle>
              </CardHeader>
              <CardContent>
                <div className="h-[200px] relative">
                  <ResponsiveContainer width="100%" height="100%">
                    <PieChart>
                      <Pie
                        data={CATEGORY_DATA}
                        cx="50%"
                        cy="50%"
                        innerRadius={60}
                        outerRadius={80}
                        paddingAngle={5}
                        dataKey="value"
                      >
                        {CATEGORY_DATA.map((entry, index) => (
                          <Cell key={`cell-${index}`} fill={entry.color} />
                        ))}
                      </Pie>
                      <Tooltip />
                    </PieChart>
                  </ResponsiveContainer>
                  <div className="absolute inset-0 flex items-center justify-center flex-col pointer-events-none">
                    <span className="text-2xl font-bold text-gray-900">1000</span>
                    <span className="text-xs text-gray-500">Total</span>
                  </div>
                </div>
                <div className="mt-4 space-y-2">
                  {CATEGORY_DATA.map((item) => (
                    <div key={item.name} className="flex items-center justify-between text-sm">
                      <div className="flex items-center gap-2">
                        <div className="w-3 h-3 rounded-full" style={{ backgroundColor: item.color }} />
                        <span className="text-gray-600">{item.name}</span>
                      </div>
                      <span className="font-medium text-gray-900">{item.value}</span>
                    </div>
                  ))}
                </div>
              </CardContent>
            </Card>
  
            {/* Active Timers Widget */}
            <Card className="shadow-sm border-gray-200 bg-gray-900 text-white">
              <CardHeader>
                <CardTitle className="text-base font-bold flex items-center gap-2 text-white">
                  <Clock className="w-5 h-5 text-blue-400" />
                  Active Timers
                </CardTitle>
              </CardHeader>
              <CardContent>
                <div className="space-y-3">
                  {ACTIVE_TIMERS.map((timer, idx) => (
                    <div key={idx} className="flex items-center justify-between border-b border-gray-800 last:border-0 pb-3 last:pb-0">
                      <span className="text-sm font-medium text-gray-300">{timer.title}</span>
                      <div className="flex items-center gap-2">
                        <span className={`font-mono font-bold ${timer.status === 'expired' ? 'text-red-500 animate-pulse' : 'text-white'}`}>
                          {timer.time}
                        </span>
                        {timer.status === 'running' && <div className="w-2 h-2 rounded-full bg-green-500" />}
                        {timer.status === 'warning' && <div className="w-2 h-2 rounded-full bg-yellow-500" />}
                        {timer.status === 'expired' && <div className="w-2 h-2 rounded-full bg-red-500" />}
                      </div>
                    </div>
                  ))}
                </div>
                <Button className="w-full mt-4 bg-blue-600 hover:bg-blue-700 text-white">
                  Manage Alerts
                </Button>
              </CardContent>
            </Card>
  
          </div>
        </div>
      </div>
    );
  }
  
  // --- Sub Components ---
  
  function KPICard({ title, value, trend, trendUp, icon: Icon, color, bgColor }: any) {
    return (
      <Card className="border-gray-200 shadow-sm hover:shadow-md transition-shadow">
        <CardContent className="p-6">
          <div className="flex justify-between items-start">
            <div>
              <p className="text-sm font-medium text-gray-500 mb-1">{title}</p>
              <h3 className="text-2xl font-bold text-gray-900">{value}</h3>
            </div>
            <div className={`p-2 rounded-lg ${bgColor}`}>
              <Icon className={`w-5 h-5 ${color}`} />
            </div>
          </div>
          <div className="mt-4 flex items-center text-sm">
            {trendUp ? (
              <ArrowUpRight className="w-4 h-4 text-green-500 mr-1" />
            ) : (
              <ArrowDownRight className="w-4 h-4 text-red-500 mr-1" />
            )}
            <span className={trendUp ? 'text-green-600 font-medium' : 'text-red-600 font-medium'}>
              {trend}
            </span>
            <span className="text-gray-400 ml-1">vs last period</span>
          </div>
        </CardContent>
      </Card>
    );
  }