index.tsx
5.22 KB
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
// 工作台 = 欢迎页。
// 业务概览(KPI / 趋势 / 分布)暂无规划,故不做任何假数据看板:
// 只保留「问候 + 账号信息 + 真实快捷入口 + 账号安全入口」,入口全部按当前权限过滤。
import { useNavigate } from 'react-router-dom';
import {
UploadOutlined,
AuditOutlined,
ShopOutlined,
TeamOutlined,
UserOutlined,
ArrowRightOutlined,
SafetyOutlined,
} from '@ant-design/icons';
import type { ReactNode } from 'react';
import { UCard, UButton, UText } from '@uj/ui';
import { useAppStore } from '@/store/useAppStore';
import { useAccess, roleLabels, type ResourceKey } from '@/access';
/** 按时段给问候语 */
function greeting(): string {
const h = new Date().getHours();
if (h < 6) return '凌晨好';
if (h < 12) return '上午好';
if (h < 14) return '中午好';
if (h < 18) return '下午好';
return '晚上好';
}
interface QuickLink {
path: string;
label: string;
desc: string;
icon: ReactNode;
resource: ResourceKey;
}
// 快捷入口:与后端菜单一一对应,展示与否由当前账号权限决定(can)
const QUICK_LINKS: QuickLink[] = [
{
path: '/store/import',
label: '导入门店信息',
desc: '下载模板、上传并校验,确认后提交审批',
icon: <UploadOutlined />,
resource: 'store:import',
},
{
path: '/store/approval',
label: '门店审批',
desc: '审核待上架门店,通过或打回',
icon: <AuditOutlined />,
resource: 'store:approve',
},
{
path: '/store/listing',
label: '门店列表',
desc: '查看、筛选与维护已上架门店',
icon: <ShopOutlined />,
resource: 'store:list',
},
{
path: '/system/role',
label: '角色管理',
desc: '配置角色权限与菜单可见范围',
icon: <TeamOutlined />,
resource: 'system:role',
},
{
path: '/system/user',
label: '账号管理',
desc: '维护系统账号、重置密码与启停',
icon: <UserOutlined />,
resource: 'system:user',
},
];
export default function Dashboard() {
const navigate = useNavigate();
const { currentUser } = useAppStore();
const { can, role, roleCodes } = useAccess();
const dateText = new Date().toLocaleDateString('zh-CN', {
year: 'numeric',
month: 'long',
day: 'numeric',
weekday: 'long',
});
const roleText = roleCodes.length ? roleCodes.join(' / ') : roleLabels[role];
const links = QUICK_LINKS.filter((l) => can(l.resource));
return (
<div className="uj-dash">
{/* 品牌欢迎条:浅色卡片 + 品牌色点睛(不再大面积铺深色,避免压抑) */}
<div className="uj-dash-hero">
<div className="uj-dash-hero-id">
<div className="uj-dash-hero-brand">
<span className="uj-dash-hero-mark" />
STORE LAUNCH PLATFORM
</div>
<h1 className="uj-dash-hero-title">
{greeting()},{currentUser.name || '欢迎回来'}
</h1>
<p className="uj-dash-hero-sub">{dateText} · 欢迎回到优加门店上架系统</p>
</div>
<div className="uj-dash-hero-meta">
<div className="uj-dash-meta-item">
<span className="uj-dash-meta-label">账号</span>
<span className="uj-dash-meta-value">{currentUser.account || '-'}</span>
</div>
<div className="uj-dash-meta-item">
<span className="uj-dash-meta-label">角色</span>
<span className="uj-dash-meta-value">{roleText}</span>
</div>
</div>
</div>
{/* 快捷入口:按权限过滤,无权限的不出现 */}
<div>
<div className="uj-welcome-title">快捷开始</div>
{links.length ? (
<div className="uj-welcome-quick">
{links.map((l) => (
<UCard
key={l.path}
hoverable
className="uj-quick-card"
onClick={() => navigate(l.path)}
styles={{ body: { padding: 18 } }}
>
<div className="uj-quick-icon">{l.icon}</div>
<div className="uj-quick-label">{l.label}</div>
<div className="uj-quick-desc">{l.desc}</div>
<div className="uj-quick-go">
进入 <ArrowRightOutlined />
</div>
</UCard>
))}
</div>
) : (
<UCard styles={{ body: { padding: 20 } }}>
<UText type="secondary">暂无可用功能,请联系管理员分配权限。</UText>
</UCard>
)}
</div>
{/* 账号与安全 */}
<UCard styles={{ body: { padding: '14px 18px' } }}>
<div className="uj-welcome-sec">
<div className="uj-welcome-sec-icon">
<SafetyOutlined />
</div>
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{ fontSize: 14, fontWeight: 600, color: '#1D2533' }}>账号与安全</div>
<UText type="secondary" style={{ fontSize: 12 }}>
建议定期更新密码;如使用初始密码登录,请尽快修改。
</UText>
</div>
<UButton onClick={() => navigate('/profile')}>前往修改</UButton>
</div>
</UCard>
</div>
);
}