@tsingroc/tsingroc-components 3.14.1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Auth.d.ts +98 -15
- package/dist/components/Auth.js +147 -63
- package/dist/components/Auth.js.map +1 -1
- package/dist/components/Sidebar.js +38 -19
- package/dist/components/Sidebar.js.map +1 -1
- package/dist/components/UserButton.js +24 -17
- package/dist/components/UserButton.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/src/components/Auth.tsx +301 -82
- package/src/components/Sidebar.tsx +89 -64
- package/src/components/UserButton.tsx +38 -22
- package/src/index.ts +3 -0
|
@@ -14,8 +14,13 @@ import {
|
|
|
14
14
|
} from "@ant-design/icons";
|
|
15
15
|
import type { Account } from "casdoor-js-sdk/lib/esm/sdk";
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
import {
|
|
18
|
+
AuthCheck, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
19
|
+
AuthProvider, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
20
|
+
type CasdoorAuth,
|
|
21
|
+
type LocalAuth,
|
|
22
|
+
useAuth,
|
|
23
|
+
} from "./Auth";
|
|
19
24
|
|
|
20
25
|
export interface UserButtonProps extends ButtonProps {
|
|
21
26
|
/**
|
|
@@ -60,20 +65,22 @@ export interface UserButtonProps extends ButtonProps {
|
|
|
60
65
|
function UserButton(props: UserButtonProps) {
|
|
61
66
|
const { token } = theme.useToken();
|
|
62
67
|
const auth = useAuth("UserButton");
|
|
63
|
-
const userInfo = auth.userInfo;
|
|
68
|
+
const userInfo = (auth as CasdoorAuth).userInfo;
|
|
64
69
|
const {
|
|
65
70
|
compact,
|
|
66
71
|
layout = "sidebar",
|
|
67
|
-
onOpenProfile =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
onOpenProfile = auth.mode === "casdoor"
|
|
73
|
+
? () => {
|
|
74
|
+
const account =
|
|
75
|
+
auth.accessToken === undefined
|
|
76
|
+
? undefined
|
|
77
|
+
: { accessToken: auth.accessToken };
|
|
78
|
+
location.href = auth.sdk.getMyProfileUrl(
|
|
79
|
+
account as Account,
|
|
80
|
+
location.href,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
: undefined,
|
|
77
84
|
onLogout = () => {
|
|
78
85
|
auth.logout();
|
|
79
86
|
location.href = "/";
|
|
@@ -88,13 +95,15 @@ function UserButton(props: UserButtonProps) {
|
|
|
88
95
|
{...dropdownProps}
|
|
89
96
|
menu={{
|
|
90
97
|
items: [
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
onOpenProfile
|
|
99
|
+
? {
|
|
100
|
+
key: "profile",
|
|
101
|
+
label: <>账户</>, // 如果使用字符串,在缩小时会被裁剪,即使宽度足够
|
|
102
|
+
icon: <UserOutlined />,
|
|
103
|
+
title: "", // 若不设置,在缩小时总是会显示工具提示,即使宽度足够
|
|
104
|
+
onClick: onOpenProfile,
|
|
105
|
+
}
|
|
106
|
+
: null,
|
|
98
107
|
{
|
|
99
108
|
key: "logout",
|
|
100
109
|
icon: <LogoutOutlined />,
|
|
@@ -113,7 +122,11 @@ function UserButton(props: UserButtonProps) {
|
|
|
113
122
|
<Button
|
|
114
123
|
type="text"
|
|
115
124
|
icon={
|
|
116
|
-
<Avatar
|
|
125
|
+
<Avatar
|
|
126
|
+
alt="头像"
|
|
127
|
+
src={userInfo?.picture ?? undefined}
|
|
128
|
+
icon={<UserOutlined />}
|
|
129
|
+
/>
|
|
117
130
|
}
|
|
118
131
|
{...rest}
|
|
119
132
|
styles={{
|
|
@@ -139,7 +152,10 @@ function UserButton(props: UserButtonProps) {
|
|
|
139
152
|
{!compact && (
|
|
140
153
|
<>
|
|
141
154
|
<span style={{ marginRight: token.marginXXS }}>
|
|
142
|
-
{userInfo?.name ??
|
|
155
|
+
{userInfo?.name ??
|
|
156
|
+
userInfo?.prefered_username ??
|
|
157
|
+
(auth as LocalAuth).userInfo?.username ??
|
|
158
|
+
"平台用户"}
|
|
143
159
|
</span>
|
|
144
160
|
{layout === "sidebar" ? <UpOutlined /> : <DownOutlined />}
|
|
145
161
|
</>
|