wsj
3 days ago cd2b7d36f3610417c268d062454b7ec43e9ca937
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
import {
  ArrowUpOutlined,
  ContactsOutlined,
  FileDoneOutlined,
  ReloadOutlined,
  RiseOutlined,
  TeamOutlined,
  UserAddOutlined,
} from '@ant-design/icons';
import type { ReactNode } from 'react';
import {
  App as AntdApp,
  Button,
  Card,
  Col,
  Row,
  Statistic,
  Table,
  Tag,
  Timeline,
} from 'antd';
import type { TableProps } from 'antd';
import dayjs from 'dayjs';
import { useNavigate } from 'react-router-dom';
import { useAuthStore } from '@/store/auth';
import './Dashboard.scss';
 
interface OrderRecord {
  key: string;
  id: string;
  customer: string;
  amount: number;
  status: 'completed' | 'pending' | 'cancelled';
  createdAt: string;
}
 
interface StatItem {
  title: string;
  value: number;
  delta: string;
  icon: ReactNode;
  color: string;
  background: string;
  prefix?: string;
}
 
const stats: StatItem[] = [
  {
    title: '客户总数',
    value: 2864,
    delta: '+12.5%',
    icon: <TeamOutlined />,
    color: '#4f46e5',
    background: '#eef2ff',
  },
  {
    title: '本月新增客户',
    value: 328,
    delta: '+8.2%',
    icon: <UserAddOutlined />,
    color: '#0284c7',
    background: '#e0f2fe',
  },
  {
    title: '本月订单',
    value: 1268,
    delta: '+21.4%',
    icon: <FileDoneOutlined />,
    color: '#059669',
    background: '#d1fae5',
  },
  {
    title: '本月销售额',
    value: 286450,
    delta: '+16.8%',
    icon: <RiseOutlined />,
    color: '#d97706',
    background: '#fef3c7',
    prefix: '¥',
  },
];
 
const quickLinks = [
  {
    title: '用户管理',
    description: '账号、角色与状态',
    path: '/system/users',
    icon: <TeamOutlined />,
    color: '#4f46e5',
    background: '#eef2ff',
  },
  {
    title: '订单管理',
    description: '查看与处理订单',
    path: '/business/orders',
    icon: <FileDoneOutlined />,
    color: '#0284c7',
    background: '#e0f2fe',
  },
  {
    title: '客户管理',
    description: '维护客户资料',
    path: '/customers',
    icon: <ContactsOutlined />,
    color: '#d97706',
    background: '#fef3c7',
  },
];
 
const recentOrders: OrderRecord[] = [
  {
    key: '1',
    id: 'SO20261017001',
    customer: '杭州云启科技有限公司',
    amount: 28600,
    status: 'completed',
    createdAt: '2026-10-17 09:42',
  },
  {
    key: '2',
    id: 'SO20261016008',
    customer: '上海灵犀网络科技',
    amount: 15800,
    status: 'pending',
    createdAt: '2026-10-16 18:20',
  },
  {
    key: '3',
    id: 'SO20261016005',
    customer: '深圳前海智造有限公司',
    amount: 63200,
    status: 'completed',
    createdAt: '2026-10-16 15:08',
  },
  {
    key: '4',
    id: 'SO20261015012',
    customer: '北京星辰数据服务',
    amount: 9600,
    status: 'cancelled',
    createdAt: '2026-10-15 11:36',
  },
  {
    key: '5',
    id: 'SO20261015003',
    customer: '成都锦江数字科技',
    amount: 41200,
    status: 'completed',
    createdAt: '2026-10-15 09:15',
  },
];
 
const statusMap: Record<OrderRecord['status'], { text: string; color: string }> = {
  completed: { text: '已完成', color: 'success' },
  pending: { text: '处理中', color: 'processing' },
  cancelled: { text: '已取消', color: 'default' },
};
 
const columns: TableProps<OrderRecord>['columns'] = [
  {
    title: '订单号',
    dataIndex: 'id',
    render: (value: string) => <span className="dashboard-order-id">{value}</span>,
  },
  { title: '客户', dataIndex: 'customer', ellipsis: true },
  {
    title: '金额',
    dataIndex: 'amount',
    align: 'right',
    render: (value: number) => <strong>¥{value.toLocaleString()}</strong>,
  },
  {
    title: '状态',
    dataIndex: 'status',
    render: (status: OrderRecord['status']) => (
      <Tag color={statusMap[status].color} bordered={false}>
        {statusMap[status].text}
      </Tag>
    ),
  },
  { title: '创建时间', dataIndex: 'createdAt', width: 160 },
];
 
const timelineItems = [
  {
    color: 'green',
    children: (
      <div className="dashboard-activity">
        <p>
          <strong>新订单</strong> 来自「杭州云启科技」
        </p>
        <span>10 分钟前</span>
      </div>
    ),
  },
  {
    color: 'blue',
    children: (
      <div className="dashboard-activity">
        <p>
          <strong>新增客户</strong> 深圳前海智造有限公司
        </p>
        <span>1 小时前</span>
      </div>
    ),
  },
  {
    color: 'purple',
    children: (
      <div className="dashboard-activity">
        <p>
          <strong>成员调整</strong> 销售组已新增 2 名成员
        </p>
        <span>3 小时前</span>
      </div>
    ),
  },
  {
    color: 'gray',
    children: (
      <div className="dashboard-activity">
        <p>
          <strong>系统维护</strong> 数据备份已完成
        </p>
        <span>昨天 23:30</span>
      </div>
    ),
  },
];
 
const Dashboard = () => {
  const navigate = useNavigate();
  const user = useAuthStore((state) => state.user);
  const { message } = AntdApp.useApp();
 
  const hour = dayjs().hour();
  const greeting = hour < 12 ? '早上好' : hour < 18 ? '下午好' : '晚上好';
 
  return (
    <div className="dashboard-page">
      <div className="page-header">
        <div>
          <h1 className="page-header__title">
            {greeting},{user?.nickname} 👋
          </h1>
          <p className="page-header__desc">
            今天是 {dayjs().format('YYYY年MM月DD日 dddd')},这是 CRM 运营概览。
          </p>
        </div>
        <div className="page-header__actions">
          <Tag color="purple" bordered={false}>
            演示数据
          </Tag>
          <Button icon={<ReloadOutlined />} onClick={() => message.success('数据已刷新')}>
            刷新数据
          </Button>
        </div>
      </div>
 
      <Row gutter={[16, 16]}>
        {stats.map((stat) => (
          <Col key={stat.title} xs={24} sm={12} xl={6}>
            <Card className="stat-card" variant="borderless">
              <div className="stat-card__top">
                <span className="stat-card__title">{stat.title}</span>
                <span
                  className="stat-card__icon"
                  style={{ color: stat.color, background: stat.background }}
                >
                  {stat.icon}
                </span>
              </div>
              <Statistic
                value={stat.value}
                prefix={stat.prefix}
                groupSeparator=","
                valueStyle={{ fontSize: 28, fontWeight: 700, color: 'var(--app-text)' }}
              />
              <div className="stat-card__delta">
                <ArrowUpOutlined />
                <span>{stat.delta}</span>
                <em>较上月</em>
              </div>
            </Card>
          </Col>
        ))}
      </Row>
 
      <Row gutter={[16, 16]} className="dashboard-row">
        <Col xs={24} lg={15}>
          <Card
            className="dashboard-card"
            variant="borderless"
            title="快捷入口"
            extra={<span className="text-muted">常用功能</span>}
          >
            <div className="quick-grid">
              {quickLinks.map((link) => (
                <button
                  key={link.path}
                  type="button"
                  className="quick-link"
                  onClick={() => navigate(link.path)}
                >
                  <span
                    className="quick-link__icon"
                    style={{ color: link.color, background: link.background }}
                  >
                    {link.icon}
                  </span>
                  <span className="quick-link__text">
                    <strong>{link.title}</strong>
                    <small>{link.description}</small>
                  </span>
                </button>
              ))}
            </div>
          </Card>
        </Col>
 
        <Col xs={24} lg={9}>
          <Card className="dashboard-card" variant="borderless" title="系统动态">
            <Timeline items={timelineItems} />
          </Card>
        </Col>
      </Row>
 
      <Card
        className="dashboard-card dashboard-orders"
        variant="borderless"
        title="最近订单"
        extra={
          <Button type="link" onClick={() => navigate('/business/orders')}>
            查看全部
          </Button>
        }
      >
        <Table<OrderRecord>
          rowKey="key"
          columns={columns}
          dataSource={recentOrders}
          pagination={false}
          scroll={{ x: 680 }}
        />
      </Card>
    </div>
  );
};
 
export default Dashboard;