@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.
@@ -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
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
- import { AuthCheck, AuthProvider, useAuth } from "./Auth";
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
- const account =
69
- auth.accessToken === undefined
70
- ? undefined
71
- : { accessToken: auth.accessToken };
72
- location.href = auth.sdk.getMyProfileUrl(
73
- account as Account,
74
- location.href,
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
- key: "profile",
93
- label: <>账户</>, // 如果使用字符串,在缩小时会被裁剪,即使宽度足够
94
- icon: <UserOutlined />,
95
- title: "", // 若不设置,在缩小时总是会显示工具提示,即使宽度足够
96
- onClick: onOpenProfile,
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 alt="头像" src={userInfo?.picture} icon={<UserOutlined />} />
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 ?? userInfo?.prefered_username ?? "平台用户"}
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
  </>
package/src/index.ts CHANGED
@@ -6,6 +6,9 @@ export {
6
6
  AuthCallback,
7
7
  type AuthCallbackProps,
8
8
  useAuth,
9
+ type Auth,
10
+ type CasdoorAuth,
11
+ type LocalAuth,
9
12
  } from "./components/Auth";
10
13
 
11
14
  export { default as Calendar, type CalendarProps } from "./components/Calendar";