TopBar.tsx
3.2 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
import {
AppstoreOutlined,
HomeOutlined,
SearchOutlined,
BellOutlined,
BankOutlined,
DownOutlined,
} from "@ant-design/icons";
import { Dropdown } from "antd";
import { useAppDispatch, useAppSelector } from "@/store";
import { logout } from "@/store/authSlice";
import { resetTabs, setActiveTab } from "@/store/tabsSlice";
import { useNavigate } from "react-router-dom";
interface Props {
onOpenMegaNav: () => void;
}
export default function TopBar({ onOpenMegaNav }: Props) {
const auth = useAppSelector((s) => s.auth);
const dispatch = useAppDispatch();
const navigate = useNavigate();
const onLogout = () => {
dispatch(logout());
dispatch(resetTabs());
navigate("/login", { replace: true });
};
const goHome = () => {
dispatch(setActiveTab("home"));
};
return (
<div className="top-bar">
<button className="top-btn" onClick={onOpenMegaNav} title="全部导航">
<AppstoreOutlined /> 全部导航
</button>
<button className="top-btn" onClick={goHome} title="主页">
<HomeOutlined /> 主页
</button>
<div
style={{
flex: 1,
minWidth: 0,
display: "flex",
alignItems: "center",
gap: 8,
paddingLeft: 12,
overflow: "hidden",
}}
>
<Brand />
<span
style={{
color: "#fff",
fontSize: 13,
fontWeight: 500,
letterSpacing: 1,
whiteSpace: "nowrap",
flex: "none",
}}
>
XLY-ERP
</span>
<span
style={{
color: "var(--text-on-dark-muted)",
fontSize: 11,
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
minWidth: 0,
}}
>
· {auth.companyName ?? ""}
</span>
</div>
<button className="top-btn">
<SearchOutlined />
</button>
<button className="top-btn">
<span style={{ position: "relative", display: "inline-flex" }}>
<BellOutlined />
<span
style={{
position: "absolute",
top: -2,
right: -3,
width: 6,
height: 6,
background: "var(--danger)",
borderRadius: 3,
}}
/>
</span>
</button>
<Dropdown
menu={{ items: [{ key: "logout", label: "登出", onClick: onLogout }] }}
placement="bottomRight"
>
<button className="top-btn">
<BankOutlined /> {auth.user?.sUserName ?? "用户"}({auth.user?.sUserType ?? ""})
<DownOutlined style={{ fontSize: 10, marginLeft: 2 }} />
</button>
</Dropdown>
</div>
);
}
function Brand() {
return (
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" style={{ flex: "none" }}>
<rect x="2" y="2" width="10" height="10" stroke="rgba(255,255,255,0.95)" strokeWidth="1.5" />
<rect x="6" y="6" width="10" height="10" stroke="rgba(255,255,255,0.85)" strokeWidth="1.5" />
<rect x="10" y="10" width="10" height="10" stroke="rgba(255,255,255,0.7)" strokeWidth="1.5" />
</svg>
);
}